~ubuntu-branches/ubuntu/trusty/gparted/trusty

« back to all changes in this revision

Viewing changes to src/Dialog_Partition_Resize_Move.cc

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2010-06-30 21:37:01 UTC
  • mfrom: (6.3.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20100630213701-mb46ic0orpuz7l6m
Tags: 0.6.0-1
* New upstream release 
* Fix out-of-date-standards-version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Copyright (C) 2004 Bart
 
2
 * Copyright (C) 2010 Curtis Gedak
2
3
 *
3
4
 *  This program is free software; you can redistribute it and/or modify
4
5
 *  it under the terms of the GNU General Public License as published by
93
94
        //also check the partitions file system ( if this is a 'resize-only' then previous should be 0 )        
94
95
        if ( t >= 1 && partitions[t -1].type == GParted::TYPE_UNALLOCATED && ! this ->fixed_start )
95
96
        { 
96
 
                previous = partitions[t -1] .get_length() ;
 
97
                previous = partitions[t -1] .get_sector_length() ;
97
98
                START = partitions[t -1] .sector_start ;
98
99
        } 
99
100
        else
100
101
                START = selected_partition .sector_start ;
101
102
        
102
103
        if ( t +1 < partitions .size() && partitions[t +1] .type == GParted::TYPE_UNALLOCATED )
103
 
                next = partitions[t +1] .get_length() ;
104
 
        
105
 
        total_length = previous + selected_partition .get_length() + next;
106
 
        TOTAL_MB = Utils::round( Utils::sector_to_unit( total_length, GParted::UNIT_MIB ) ) ;
 
104
                next = partitions[t +1] .get_sector_length() ;
 
105
 
 
106
        MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record( selected_partition ) ;
 
107
        total_length = previous + selected_partition .get_sector_length() + next;
 
108
        TOTAL_MB = Utils::round( Utils::sector_to_unit( total_length, selected_partition .sector_size, UNIT_MIB ) ) ;
107
109
        
108
110
        MB_PER_PIXEL = TOTAL_MB / 500.00 ;
109
111
                
110
112
        //now calculate proportional length of partition 
 
113
        frame_resizer_base ->set_x_min_space_before( Utils::round( MIN_SPACE_BEFORE_MB / MB_PER_PIXEL ) ) ;
111
114
        frame_resizer_base ->set_x_start( Utils::round( previous / ( total_length / 500.00 ) ) ) ;
112
115
        frame_resizer_base ->set_x_end( 
113
 
                Utils::round( selected_partition .get_length() / ( total_length / 500.00 ) ) + frame_resizer_base ->get_x_start() ) ;
 
116
                Utils::round( selected_partition .get_sector_length() / ( total_length / 500.00 ) ) + frame_resizer_base ->get_x_start() ) ;
114
117
        frame_resizer_base ->set_used( Utils::round( selected_partition.sectors_used / ( total_length / 500.00 ) ) ) ;
115
118
 
116
119
        //set MIN
117
120
        if ( fs .shrink )
118
121
        {
119
122
                //since some file systems have lower limits we need to check for this
120
 
                if ( selected_partition .sectors_used > fs .MIN )
121
 
                        fs .MIN = selected_partition .sectors_used ;
122
 
 
123
 
                //if fs. MIN is 0 here (means used == 0 as well) it's safe to have BUF / 2
124
 
                fs .MIN += fs .MIN ? BUF : BUF/2 ;
125
 
 
126
 
                //in certain (rare) cases fs .MIN is (now) larger than 'selected_partition'..
127
 
                if ( fs .MIN > selected_partition .get_length() )
128
 
                        fs .MIN = selected_partition .get_length() ;
 
123
                if ( selected_partition .sectors_used > (fs .MIN / selected_partition .sector_size) )
 
124
                        fs .MIN = selected_partition .sectors_used * selected_partition .sector_size ;
 
125
 
 
126
                //ensure that minimum size is at least one mebibyte
 
127
                if ( ! fs .MIN || fs .MIN < MEBIBYTE )
 
128
                        fs .MIN = MEBIBYTE ;
129
129
        }
130
130
        else
131
 
                fs .MIN = selected_partition .get_length() ;
132
 
        
 
131
                fs .MIN = selected_partition .get_byte_length() ;
 
132
 
133
133
        //set MAX
134
134
        if ( fs .grow )
135
 
        {
136
 
                if ( ! fs .MAX || fs .MAX > (TOTAL_MB * MEBIBYTE) ) 
137
 
                        fs .MAX = TOTAL_MB * MEBIBYTE ;
138
 
                else
139
 
                        fs .MAX -= BUF/2 ;
140
 
        }
 
135
                fs .MAX = (TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE ;
141
136
        else
142
 
                fs .MAX = selected_partition .get_length() ;
 
137
                fs .MAX = selected_partition .get_byte_length() ;
143
138
 
144
 
        
145
139
        //set values of spinbutton_before
146
140
        if ( ! fixed_start )
147
141
        {
148
 
                spinbutton_before .set_range( 
149
 
                        0,
150
 
                        TOTAL_MB - Utils::round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ) ) ;
151
 
                spinbutton_before .set_value( 
152
 
                        Utils::round( Utils::sector_to_unit( previous, GParted::UNIT_MIB ) ) ) ;
 
142
                spinbutton_before .set_range( MIN_SPACE_BEFORE_MB
 
143
                                            , TOTAL_MB - ceil( fs .MIN / double(MEBIBYTE) )
 
144
                                            ) ;
 
145
                spinbutton_before .set_value(
 
146
                        Utils::round( Utils::sector_to_unit( previous, selected_partition .sector_size, UNIT_MIB ) ) ) ;
153
147
        }
154
 
        
 
148
 
155
149
        //set values of spinbutton_size 
156
 
        spinbutton_size .set_range( 
157
 
                Utils::round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ),
158
 
                Utils::round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
 
150
        spinbutton_size .set_range( ceil( fs .MIN / double(MEBIBYTE) )
 
151
                                  , ceil( fs .MAX / double(MEBIBYTE) )
 
152
                                  ) ;
159
153
        spinbutton_size .set_value( 
160
 
                Utils::round( Utils::sector_to_unit( selected_partition .get_length(), GParted::UNIT_MIB ) ) ) ;
 
154
                Utils::round( Utils::sector_to_unit( selected_partition .get_sector_length(), selected_partition .sector_size, UNIT_MIB ) ) ) ;
161
155
        
162
156
        //set values of spinbutton_after
163
157
        Sector after_min = ( ! fs .grow && ! fs .move ) ? next : 0 ;
164
158
        spinbutton_after .set_range( 
165
 
                Utils::round( Utils::sector_to_unit( after_min, GParted::UNIT_MIB ) ),
166
 
                TOTAL_MB - Utils::round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ) ) ;
 
159
                Utils::round( Utils::sector_to_unit( after_min, selected_partition .sector_size, UNIT_MIB ) ),
 
160
                TOTAL_MB - MIN_SPACE_BEFORE_MB - ceil( fs .MIN / double(MEBIBYTE) ) ) ;
167
161
        spinbutton_after .set_value( 
168
 
                Utils::round( Utils::sector_to_unit( next, GParted::UNIT_MIB ) ) ) ;
169
 
        
 
162
                Utils::round( Utils::sector_to_unit( next, selected_partition .sector_size, UNIT_MIB ) ) ) ;
 
163
 
170
164
        frame_resizer_base ->set_size_limits( Utils::round( fs .MIN / (MB_PER_PIXEL * MEBIBYTE) ),
171
165
                                              Utils::round( fs .MAX / (MB_PER_PIXEL * MEBIBYTE) ) ) ;
172
 
        
 
166
 
173
167
        //set contents of label_minmax
174
 
        Set_MinMax_Text( 
175
 
                Utils::round( Utils::sector_to_unit( fs .MIN, GParted::UNIT_MIB ) ),
176
 
                Utils::round( Utils::sector_to_unit( fs .MAX, GParted::UNIT_MIB ) ) ) ;
 
168
        Set_MinMax_Text( ceil( fs .MIN / double(MEBIBYTE) )
 
169
                       , ceil( fs .MAX / double(MEBIBYTE) )
 
170
                       ) ;
177
171
}
178
172
 
179
173
void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector<Partition> & partitions )
188
182
        //calculate length and start of previous
189
183
        if ( t > 0 && partitions[t -1] .type == GParted::TYPE_UNALLOCATED )
190
184
        {
191
 
                previous = partitions[t -1] .get_length() ;
 
185
                previous = partitions[t -1] .get_sector_length() ;
192
186
                START = partitions[t -1] .sector_start ;
193
187
        } 
194
188
        else
196
190
        
197
191
        //calculate length of next
198
192
        if ( t +1 < partitions .size() && partitions[ t +1 ] .type == GParted::TYPE_UNALLOCATED )
199
 
                next = partitions[ t +1 ] .get_length() ;
 
193
                next = partitions[ t +1 ] .get_sector_length() ;
200
194
                
201
195
        //now we have enough data to calculate some important values..
202
 
        total_length = previous + selected_partition .get_length() + next;
203
 
        TOTAL_MB = Utils::round( Utils::sector_to_unit( total_length, UNIT_MIB ) ) ;
 
196
        MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record( selected_partition ) ;
 
197
        total_length = previous + selected_partition .get_sector_length() + next;
 
198
        TOTAL_MB = Utils::round( Utils::sector_to_unit( total_length, selected_partition .sector_size, UNIT_MIB ) ) ;
204
199
        MB_PER_PIXEL = TOTAL_MB / 500.00 ;
205
200
        
206
201
        //calculate proportional length of partition ( in pixels )
 
202
        frame_resizer_base ->set_x_min_space_before( Utils::round( MIN_SPACE_BEFORE_MB / MB_PER_PIXEL ) ) ;
207
203
        frame_resizer_base ->set_x_start( Utils::round( previous / ( total_length / 500.00 ) ) ) ;
208
 
        frame_resizer_base ->set_x_end( Utils::round( selected_partition .get_length() / ( total_length / 500.00 ) ) + frame_resizer_base ->get_x_start() ) ;
 
204
        frame_resizer_base ->set_x_end( Utils::round( selected_partition .get_sector_length() / ( total_length / 500.00 ) ) + frame_resizer_base ->get_x_start() ) ;
209
205
        
210
206
        //used is a bit different here... we consider start of first logical to end last logical as used space
211
 
        Sector first =0, used =0 ;
212
 
        for ( unsigned int i = 0 ; i < partitions[ t ] .logicals .size() ; i++ )
 
207
        Sector first =0, last = 0, used =0 ;
 
208
        if ( ! (   selected_partition .logicals .size() == 1
 
209
                && selected_partition .logicals .back() .type == GParted::TYPE_UNALLOCATED
 
210
               )
 
211
           )
213
212
        {
214
 
                if ( partitions[ t ] .logicals[ i ] .type == GParted::TYPE_LOGICAL )
 
213
                //logical partitions other than unallocated exist
 
214
                first = selected_partition .sector_end ;
 
215
                last = selected_partition .sector_start ;
 
216
                for ( unsigned int i = 0 ; i < partitions[ t ] .logicals .size() ; i++ )
215
217
                {
216
 
                        if ( first == 0 )
217
 
                                first = partitions[ t ] .logicals[ i ] .sector_start ;
218
 
                        
219
 
                        used = partitions[ t ] .logicals[ i ] .sector_end - first;
 
218
                        if ( partitions[ t ] .logicals[ i ] .type == GParted::TYPE_LOGICAL )
 
219
                        {
 
220
                                if ( partitions[ t ] .logicals[ i ] .sector_start < first )
 
221
                                        first = partitions[ t ] .logicals[ i ] .sector_start - (MEBIBYTE / selected_partition .sector_size) ;
 
222
                                if ( first < 0 )
 
223
                                        first = 0 ;
 
224
                                if ( partitions[ t ] .logicals[ i ] .sector_end > last )
 
225
                                        last = partitions[ t ] .logicals[ i ] .sector_end ;
 
226
                        }
220
227
                }
221
 
        }
 
228
                used = last - first;
 
229
        }
 
230
        //set MIN
 
231
        if ( used == 0 )
 
232
        {
 
233
                //Reasonable minimum of 1 MiB for EBR plus 1 MiB for small partition
 
234
                fs .MIN = MEBIBYTE ;
 
235
        }
 
236
        else 
 
237
                fs .MIN = used * selected_partition .sector_size ;
 
238
 
 
239
        //set MAX
 
240
        fs .MAX = (TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE ;
222
241
 
223
242
        dynamic_cast<Frame_Resizer_Extended *>( frame_resizer_base ) ->
224
243
                set_used_start( Utils::round( (first - START) / ( total_length / 500.00 ) ) ) ;
226
245
        
227
246
        //set values of spinbutton_before (we assume there is no fixed start.)
228
247
        if ( first == 0 ) //no logicals
229
 
                spinbutton_before .set_range( 0, TOTAL_MB - Utils::round( Utils::sector_to_unit( BUF/2, GParted::UNIT_MIB ) ) ) ;
 
248
                spinbutton_before .set_range( MIN_SPACE_BEFORE_MB, TOTAL_MB - MIN_SPACE_BEFORE_MB - ceil( fs .MIN / double(MEBIBYTE) ) ) ;
230
249
        else
231
 
                spinbutton_before .set_range( 0, Utils::round( Utils::sector_to_unit( first - START, GParted::UNIT_MIB ) ) ) ;
 
250
                spinbutton_before .set_range( MIN_SPACE_BEFORE_MB, Utils::round( Utils::sector_to_unit( first - START, selected_partition .sector_size, UNIT_MIB ) ) ) ;
232
251
        
233
 
        spinbutton_before .set_value( Utils::round( Utils::sector_to_unit( previous, GParted::UNIT_MIB ) ) ) ;
 
252
        spinbutton_before .set_value( Utils::round( Utils::sector_to_unit( previous, selected_partition .sector_size, UNIT_MIB ) ) ) ;
234
253
        
235
254
        //set values of spinbutton_size
236
 
        if ( first == 0 ) //no logicals
237
 
                spinbutton_size .set_range( Utils::round( Utils::sector_to_unit( BUF/2, GParted::UNIT_MIB ) ), TOTAL_MB ) ;
238
 
        else
239
 
                spinbutton_size .set_range( Utils::round( Utils::sector_to_unit( used, GParted::UNIT_MIB ) ), TOTAL_MB ) ;
 
255
        spinbutton_size .set_range( ceil( fs .MIN / double(MEBIBYTE) ), TOTAL_MB - MIN_SPACE_BEFORE_MB ) ;
240
256
        
241
257
        spinbutton_size .set_value(
242
 
                Utils::round( Utils::sector_to_unit( selected_partition .get_length(), GParted::UNIT_MIB ) ) ) ;
 
258
                Utils::round( Utils::sector_to_unit( selected_partition .get_sector_length(), selected_partition .sector_size, UNIT_MIB ) ) ) ;
243
259
        
244
260
        //set values of spinbutton_after
245
261
        if ( first == 0 ) //no logicals
246
262
                spinbutton_after .set_range( 
247
 
                        0, TOTAL_MB - Utils::round( Utils::sector_to_unit( BUF/2, GParted::UNIT_MIB ) ) ) ;
 
263
                        0, TOTAL_MB - ceil( fs .MIN / double(MEBIBYTE) ) - MIN_SPACE_BEFORE_MB ) ;
248
264
        else
249
265
                spinbutton_after .set_range( 
250
 
                        0, Utils::round( Utils::sector_to_unit( total_length + START - first - used, GParted::UNIT_MIB ) ) ) ;
 
266
                        0, Utils::round( Utils::sector_to_unit( total_length + START - first - used, selected_partition .sector_size, UNIT_MIB ) ) ) ;
251
267
        
252
 
        spinbutton_after .set_value( Utils::round( Utils::sector_to_unit( next, GParted::UNIT_MIB ) ) ) ;
 
268
        spinbutton_after .set_value( Utils::round( Utils::sector_to_unit( next, selected_partition .sector_size, UNIT_MIB ) ) ) ;
253
269
        
254
270
        //set contents of label_minmax
255
 
        Set_MinMax_Text( Utils::round( Utils::sector_to_unit( first == 0 ? BUF/2 : used, GParted::UNIT_MIB ) ),
256
 
                         Utils::round( Utils::sector_to_unit( total_length, GParted::UNIT_MIB ) ) ) ;
 
271
        Set_MinMax_Text( ceil( fs .MIN / double(MEBIBYTE) )
 
272
                       , Utils::round( Utils::sector_to_unit( total_length - (MIN_SPACE_BEFORE_MB * (MEBIBYTE / selected_partition .sector_size)), selected_partition .sector_size, UNIT_MIB ) ) ) ;
257
273
}
258
274
 
259
275
} //GParted