~ubuntu-branches/ubuntu/saucy/gparted/saucy

« back to all changes in this revision

Viewing changes to src/btrfs.cc

  • Committer: Package Import Robot
  • Author(s): Anibal Monsalve Salazar
  • Date: 2011-11-13 09:45:30 UTC
  • mfrom: (6.3.18)
  • Revision ID: package-import@ubuntu.com-20111113094530-bpv6kjk4rwozc1jf
Tags: 0.10.0-1
* New upstream release

  GParted 0.10.0  (2011-11-01)

  * Merge overlapping operations
  * Add ability to resize btrfs file systems
  * Add detection of exfat file systems

  GParted 0.9.1   (2011-09-19)

  * Fix NTFS partition resize fail problem
  * Fix some compiler warnings

  GParted 0.9.0   (2011-07-18)

  * Fix size off by one sector with unrecognized disk label
  * Fix GParted crashes with assertion (head_size <= 63)
    - Requires libparted-2.4 or higher
    - LP: #545911

* Fix out-of-date-standards-version
* Fix debian-rules-missing-recommended-target

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Copyright (C) 2009,2010 Luca Bruno <lucab@debian.org>
2
 
 * Copyright (C) 2010 Curtis Gedak
 
2
 * Copyright (C) 2010, 2011 Curtis Gedak
3
3
 *
4
4
 *  This program is free software; you can redistribute it and/or modify
5
5
 *  it under the terms of the GNU General Public License as published by
39
39
        if ( ! Glib::find_program_in_path( "btrfsck" ) .empty() )
40
40
                fs .check = GParted::FS::EXTERNAL ;
41
41
 
 
42
        //resizing of btrfs requires btrfsctl, mount, and umount
 
43
        if (    ! Glib::find_program_in_path( "btrfsctl" ) .empty()
 
44
             && ! Glib::find_program_in_path( "mount" ) .empty()
 
45
             && ! Glib::find_program_in_path( "umount" ) .empty()
 
46
             && fs .check
 
47
           )
 
48
        {
 
49
                fs .grow = FS::EXTERNAL ;
 
50
                if ( fs .read ) //needed to determine a minimum file system size.
 
51
                        fs .shrink = FS::EXTERNAL ;
 
52
        }
 
53
 
42
54
        if ( fs .check )
43
55
        {
44
56
                fs .copy = GParted::FS::GPARTED ;
125
137
 
126
138
bool btrfs::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
127
139
{
128
 
// TODO
129
 
        return true ;
 
140
        //Create directory
 
141
        Glib::ustring str_temp = _( "create temporary directory" ) ;
 
142
        operationdetail .add_child( OperationDetail( str_temp, STATUS_NONE, FONT_BOLD_ITALIC ) ) ;
 
143
        char dtemplate[] = "/tmp/gparted-XXXXXXXX" ;
 
144
        Glib::ustring dname =  mkdtemp( dtemplate ) ;
 
145
        if( dname .empty() )
 
146
        {
 
147
                //Failed to create temporary directory
 
148
                str_temp = _( "Failed to create temporary directory." );
 
149
                operationdetail .get_last_child() .add_child( OperationDetail( str_temp, STATUS_NONE, FONT_ITALIC ) ) ;
 
150
                return false ;
 
151
        }
 
152
 
 
153
        /*TO TRANSLATORS: looks like  Created temporary directory /tmp/gparted-XXCOOO8U */
 
154
        str_temp = String::ucompose ( _("Created temporary directory %1"), dname ) ;
 
155
        operationdetail .get_last_child() .add_child( OperationDetail( str_temp, STATUS_NONE, FONT_ITALIC ) ) ;
 
156
 
 
157
        //Mount file system.  Needed to resize btrfs.
 
158
        str_temp = "mount -v -t btrfs " + partition_new .get_path() + " " + dname ;
 
159
        exit_status = ! execute_command( str_temp, operationdetail ) ;
 
160
 
 
161
        if ( exit_status )
 
162
        {
 
163
                //Build resize command
 
164
                str_temp = "btrfsctl" ;
 
165
                if ( ! fill_partition )
 
166
                {
 
167
                        str_temp += " -r " + Utils::num_to_str( floor( Utils::sector_to_unit(
 
168
                                                partition_new .get_sector_length(), partition_new .sector_size, UNIT_KIB ) ) ) + "K" ;
 
169
                }
 
170
                else
 
171
                        str_temp += " -r max" ;
 
172
                str_temp += " " + dname ;
 
173
 
 
174
                //Execute the command
 
175
                exit_status = execute_command( str_temp, operationdetail ) ;
 
176
                //Sometimes btrfsctl returns an exit status of 256 on successful resize.
 
177
                exit_status = ( exit_status == 0 || exit_status == 256 ) ;
 
178
 
 
179
                //Always unmount the file system
 
180
                str_temp = "umount -v " + dname ;
 
181
                execute_command( str_temp, operationdetail ) ;
 
182
        }
 
183
 
 
184
        //Always remove the temporary directory name
 
185
        str_temp = "rmdir -v " + dname ;
 
186
        execute_command( str_temp, operationdetail ) ;
 
187
 
 
188
        return exit_status ;
130
189
}
131
190
 
132
191
void btrfs::read_label( Partition & partition )