Skip to content

Commit

Permalink
[cmds] Fix mkfs to clear reserved sector corresponding to old MINIX s…
Browse files Browse the repository at this point in the history
…uperblock
  • Loading branch information
ghaerr committed Oct 7, 2024
1 parent 852d8a9 commit aced7e2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions elkscmd/disk_utils/mkfat.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,17 @@ static int fatfs_create_fsinfo_sector(uint32 sector_lba)
return 1;
}
//-----------------------------------------------------------------------------
// fatfs_zero_reserved_sector: Clear reserved sector corresponding to MINIX superblock
//-----------------------------------------------------------------------------
static int fatfs_zero_reserved_sector(uint32 sector_lba)
{
memset(sector, 0, FAT_SECTOR_SIZE);
lseek(ofd, sector_lba * FAT_SECTOR_SIZE, SEEK_SET);
if (write(ofd, sector, FAT_SECTOR_SIZE) != FAT_SECTOR_SIZE)
return 0;
return 1;
}
//-----------------------------------------------------------------------------
// fatfs_erase_fat: Erase FAT table using fs details in fs struct
//-----------------------------------------------------------------------------
static int fatfs_erase_fat(int is_fat32)
Expand Down Expand Up @@ -551,6 +562,12 @@ int fatfs_format_fat32(uint32 volume_sectors, const char *name)
if (!fatfs_create_boot_sector(lba_begin, volume_sectors, name, 1))
return 0;

// zero "block 1/superblock" if reserved in case previous filesystem was MINIX
if (reserved_sectors >= 2) {
if (!fatfs_zero_reserved_sector(lba_begin+2))
return 0;
}

// First FAT LBA address
fat_begin_lba = lba_begin + reserved_sectors;

Expand Down

0 comments on commit aced7e2

Please sign in to comment.