Skip to content

Commit

Permalink
Merge pull request #2067 from ghaerr/mkfat
Browse files Browse the repository at this point in the history
[cmds] Fix mkfs to clear reserved sector corresponding to old MINIX superblock
  • Loading branch information
ghaerr authored Oct 7, 2024
2 parents 852d8a9 + aced7e2 commit adaa9a2
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 adaa9a2

Please sign in to comment.