From cb15da56e16a15e9f594df0fd1d8ce69d414baa7 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Tue, 19 Aug 2003 19:15:20 +0000 Subject: [PATCH] * Added trailing fs info sector signature * Calculate correct cluster size svn path=/trunk/; revision=5677 --- reactos/lib/fslib/vfatlib/vfatlib.c | 32 ++++++++++++++++++++++++++--- reactos/lib/fslib/vfatlib/vfatlib.h | 19 +++++++++-------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/reactos/lib/fslib/vfatlib/vfatlib.c b/reactos/lib/fslib/vfatlib/vfatlib.c index 0cf8d7d630f..fd94a645dcd 100755 --- a/reactos/lib/fslib/vfatlib/vfatlib.c +++ b/reactos/lib/fslib/vfatlib/vfatlib.c @@ -134,6 +134,7 @@ VfatWriteFsInfo(IN HANDLE FileHandle, FsInfo->StrucSig = 0x61417272; FsInfo->FreeCount = 0xffffffff; FsInfo->NextFree = 0xffffffff; + FsInfo->TrailSig = 0xaa550000; /* Write sector */ FileOffset.QuadPart = BootSector->FSInfoSector * BootSector->BytesPerSector; @@ -194,7 +195,7 @@ VfatWriteFAT(IN HANDLE FileHandle, Buffer[4] = 0xff; /* Clean shutdown, no disk read/write errors, end-of-cluster (EOC) mark */ Buffer[5] = 0xff; Buffer[6] = 0xff; - Buffer[7] = 0x0f; + Buffer[7] = 0x0f; /* FAT cluster 2 */ Buffer[8] = 0xff; /* End of root directory */ Buffer[9] = 0xff; @@ -425,10 +426,35 @@ VfatFormat( return Status; } + /* Calculate cluster size */ + if (ClusterSize == 0) + { + if (PartitionInfo.PartitionLength.QuadPart < 8ULL * 1024ULL * 1024ULL) + { + /* Partition < 8GB ==> 4KB Cluster */ + ClusterSize = 4096; + } + else if (PartitionInfo.PartitionLength.QuadPart < 16ULL * 1024ULL * 1024ULL) + { + /* Partition 8GB - 16GB ==> 8KB Cluster */ + ClusterSize = 8192; + } + else if (PartitionInfo.PartitionLength.QuadPart < 32ULL * 1024ULL * 1024ULL) + { + /* Partition 16GB - 32GB ==> 16KB Cluster */ + ClusterSize = 16384; + } + else + { + /* Partition >= 32GB ==> 32KB Cluster */ + ClusterSize = 32768; + } + } + memset(&BootSector, 0, sizeof(FAT32_BOOT_SECTOR)); memcpy(&BootSector.OEMName[0], "MSWIN4.1", 8); BootSector.BytesPerSector = DiskGeometry.BytesPerSector; - BootSector.SectorsPerCluster = 4096 / BootSector.BytesPerSector; // 4KB clusters /* FIXME: */ + BootSector.SectorsPerCluster = ClusterSize / BootSector.BytesPerSector; BootSector.ReservedSectors = 32; BootSector.FATCount = 2; BootSector.RootEntries = 0; @@ -437,7 +463,7 @@ VfatFormat( BootSector.FATSectors = 0; BootSector.SectorsPerTrack = DiskGeometry.SectorsPerTrack; BootSector.Heads = DiskGeometry.TracksPerCylinder; - BootSector.HiddenSectors = PartitionInfo.HiddenSectors; + BootSector.HiddenSectors = DiskGeometry.SectorsPerTrack; //PartitionInfo.HiddenSectors; BootSector.SectorsHuge = PartitionInfo.PartitionLength.QuadPart >> GetShiftCount(BootSector.BytesPerSector); /* Use shifting to avoid 64-bit division */ BootSector.FATSectors32 = 0; /* Set later */ diff --git a/reactos/lib/fslib/vfatlib/vfatlib.h b/reactos/lib/fslib/vfatlib/vfatlib.h index c5acfb380a2..1a97eca6802 100755 --- a/reactos/lib/fslib/vfatlib/vfatlib.h +++ b/reactos/lib/fslib/vfatlib/vfatlib.h @@ -26,9 +26,9 @@ typedef struct _FAT32_BOOT_SECTOR unsigned char Media; // 21 unsigned short FATSectors; // 22 unsigned short SectorsPerTrack; // 24 - unsigned short Heads; // 22 - unsigned long HiddenSectors; // 24 - unsigned long SectorsHuge; // 28 + unsigned short Heads; // 26 + unsigned long HiddenSectors; // 28 + unsigned long SectorsHuge; // 32 unsigned long FATSectors32; // 36 unsigned short ExtFlag; // 40 unsigned short FSVersion; // 42 @@ -48,10 +48,11 @@ typedef struct _FAT32_BOOT_SECTOR typedef struct _FAT32_FSINFO { - unsigned int LeadSig; // 0 - unsigned char Res1[480]; // 4 - unsigned int StrucSig; // 484 - unsigned int FreeCount; // 488 - unsigned int NextFree; // 492 - unsigned int Res2; // 496 + unsigned long LeadSig; // 0 + unsigned char Res1[480]; // 4 + unsigned long StrucSig; // 484 + unsigned long FreeCount; // 488 + unsigned long NextFree; // 492 + unsigned long Res2[3]; // 496 + unsigned long TrailSig; // 508 } __attribute__((packed)) FAT32_FSINFO, *PFAT32_FSINFO;