Skip to content

Commit 24fc1d7

Browse files
committed
fix critical error where disk is wiped when deleting logical
The error occurred if there were 23 logical partitions defined for a drive. FDISK then wrote a zeroed-out EMBR to sector 0.
1 parent d795693 commit 24fc1d7

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

source/fdisk/pcompute.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ int Create_Logical_Drive( int numeric_type, unsigned long size_in_MB )
7272

7373
int free_space_loc = pDrive->log_free_loc;
7474

75+
if ( ( (pDrive->num_of_log_drives >= MAX_LOGICAL_DRIVES ) && ( free_space_loc != 0 ) ) ||
76+
( (pDrive->num_of_log_drives > MAX_LOGICAL_DRIVES ) && ( free_space_loc == 0 ) ) ) {
77+
/* ran out of data table space */
78+
return 99;
79+
}
7580
if ( !pDrive->usable || !pDrive->ext_usable ) {
7681
return 99;
7782
}

source/fdisk/pdiskio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ int Delete_EMBR_Chain_Node( Partition_Table *pDrive,
835835
Clear_Partition( &pDrive->next_ext[MAX_LOGICAL_DRIVES - 1] );
836836
pDrive->log_drive_created[MAX_LOGICAL_DRIVES - 1] = FALSE;
837837
pDrive->next_ext_exists[MAX_LOGICAL_DRIVES - 1] = FALSE;
838+
pDrive->next_ext_exists[MAX_LOGICAL_DRIVES - 2] = FALSE;
838839
pDrive->num_of_log_drives--;
839840
}
840841
else {

0 commit comments

Comments
 (0)