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 )
96
previous = partitions[t -1] .get_length() ;
97
previous = partitions[t -1] .get_sector_length() ;
97
98
START = partitions[t -1] .sector_start ;
100
101
START = selected_partition .sector_start ;
102
103
if ( t +1 < partitions .size() && partitions[t +1] .type == GParted::TYPE_UNALLOCATED )
103
next = partitions[t +1] .get_length() ;
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() ;
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 ) ) ;
108
110
MB_PER_PIXEL = TOTAL_MB / 500.00 ;
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 ) ) ) ;
117
120
if ( fs .shrink )
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 ;
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 ;
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 ;
126
//ensure that minimum size is at least one mebibyte
127
if ( ! fs .MIN || fs .MIN < MEBIBYTE )
131
fs .MIN = selected_partition .get_length() ;
131
fs .MIN = selected_partition .get_byte_length() ;
136
if ( ! fs .MAX || fs .MAX > (TOTAL_MB * MEBIBYTE) )
137
fs .MAX = TOTAL_MB * MEBIBYTE ;
135
fs .MAX = (TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE ;
142
fs .MAX = selected_partition .get_length() ;
137
fs .MAX = selected_partition .get_byte_length() ;
145
139
//set values of spinbutton_before
146
140
if ( ! fixed_start )
148
spinbutton_before .set_range(
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) )
145
spinbutton_before .set_value(
146
Utils::round( Utils::sector_to_unit( previous, selected_partition .sector_size, UNIT_MIB ) ) ) ;
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) )
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 ) ) ) ;
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 ) ) ) ;
162
Utils::round( Utils::sector_to_unit( next, selected_partition .sector_size, UNIT_MIB ) ) ) ;
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) ) ) ;
173
167
//set contents of label_minmax
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) )
179
173
void Dialog_Partition_Resize_Move::Resize_Move_Extended( const std::vector<Partition> & partitions )
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() ;
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 ;
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() ) ;
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
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++ )
217
first = partitions[ t ] .logicals[ i ] .sector_start ;
219
used = partitions[ t ] .logicals[ i ] .sector_end - first;
218
if ( partitions[ t ] .logicals[ i ] .type == GParted::TYPE_LOGICAL )
220
if ( partitions[ t ] .logicals[ i ] .sector_start < first )
221
first = partitions[ t ] .logicals[ i ] .sector_start - (MEBIBYTE / selected_partition .sector_size) ;
224
if ( partitions[ t ] .logicals[ i ] .sector_end > last )
225
last = partitions[ t ] .logicals[ i ] .sector_end ;
233
//Reasonable minimum of 1 MiB for EBR plus 1 MiB for small partition
237
fs .MIN = used * selected_partition .sector_size ;
240
fs .MAX = (TOTAL_MB - MIN_SPACE_BEFORE_MB) * MEBIBYTE ;
223
242
dynamic_cast<Frame_Resizer_Extended *>( frame_resizer_base ) ->
224
243
set_used_start( Utils::round( (first - START) / ( total_length / 500.00 ) ) ) ;
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) ) ) ;
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 ) ) ) ;
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 ) ) ) ;
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 ) ;
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 ) ;
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 ) ) ) ;
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 ) ;
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 ) ) ) ;
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 ) ) ) ;
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 ) ) ) ;