Skip to content

Commit 268696c

Browse files
committed
make sure we compute largest free space, and not ANY free space
1 parent 24fc1d7 commit 268696c

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

source/fdisk/pcompute.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ static void Determine_Log_Free_Space( Partition_Table *pDrive )
416416
{
417417
int index = 0;
418418
int last_used_partition = UNUSED;
419+
unsigned long ext_free_space;
419420

420421
/* Determine the location and size of the largest free space in the */
421422
/* extended partition, if it exists. */
@@ -443,20 +444,25 @@ static void Determine_Log_Free_Space( Partition_Table *pDrive )
443444
last_used_partition = index;
444445
}
445446

446-
if ( ( pDrive->log_drive[index + 1].num_type > 0 ) &&
447+
if ( ( index < MAX_LOGICAL_DRIVES - 1 ) &&
448+
( pDrive->log_drive[index + 1].num_type > 0 ) &&
447449
( pDrive->log_drive[index + 1].start_cyl >
448450
pDrive->log_drive[index].end_cyl + 1 ) ) {
449-
pDrive->ext_free_space =
451+
452+
ext_free_space =
450453
( pDrive->log_drive[index + 1].start_cyl -
451454
pDrive->log_drive[index].end_cyl - 1 );
452-
pDrive->log_start_cyl = pDrive->log_drive[index].end_cyl + 1;
453-
pDrive->log_end_cyl =
454-
pDrive->log_drive[index + 1].start_cyl - 1;
455-
pDrive->log_free_loc = index + 1;
455+
456+
if ( ext_free_space >= pDrive->ext_free_space ) {
457+
pDrive->ext_free_space = ext_free_space;
458+
pDrive->log_start_cyl = pDrive->log_drive[index].end_cyl + 1;
459+
pDrive->log_end_cyl = pDrive->log_drive[index + 1].start_cyl - 1;
460+
pDrive->log_free_loc = index + 1;
461+
}
456462
}
457463

458464
index++;
459-
} while ( index < MAX_LOGICAL_DRIVES - 1 );
465+
} while ( index < MAX_LOGICAL_DRIVES );
460466

461467
/* Determine if there is any free space before the first logical */
462468
/* drive in the extended partition. */

0 commit comments

Comments
 (0)