diff --git a/reactos/lib/fslib/vfatlib/fat12.c b/reactos/lib/fslib/vfatlib/fat12.c index 679e614611d..ca699f25d2e 100644 --- a/reactos/lib/fslib/vfatlib/fat12.c +++ b/reactos/lib/fslib/vfatlib/fat12.c @@ -272,7 +272,7 @@ Fat12Format (HANDLE FileHandle, PFMIFSCALLBACK Callback) { FAT16_BOOT_SECTOR BootSector; - ANSI_STRING VolumeLabel; + OEM_STRING VolumeLabel; ULONG SectorCount; ULONG RootDirSectors; ULONG TmpVal1; @@ -290,10 +290,7 @@ Fat12Format (HANDLE FileHandle, SectorCount = PartitionInfo->PartitionLength.QuadPart >> GetShiftCount(DiskGeometry->BytesPerSector); /* Use shifting to avoid 64-bit division */ -// SectorCount = -// PartitionInfo->PartitionLength.u.LowPart / DiskGeometry->BytesPerSector; - - DPRINT1("SectorCount = %lu\n", SectorCount); + DPRINT("SectorCount = %lu\n", SectorCount); memset(&BootSector, 0, sizeof(FAT16_BOOT_SECTOR)); memcpy(&BootSector.OEMName[0], "MSWIN4.1", 8); @@ -307,7 +304,7 @@ Fat12Format (HANDLE FileHandle, BootSector.FATSectors = 0; /* Set later. See below. */ BootSector.SectorsPerTrack = DiskGeometry->SectorsPerTrack; BootSector.Heads = DiskGeometry->TracksPerCylinder; - BootSector.HiddenSectors = DiskGeometry->SectorsPerTrack; //PartitionInfo->HiddenSectors; /* FIXME: Hack! */ + BootSector.HiddenSectors = PartitionInfo->HiddenSectors; BootSector.SectorsHuge = (SectorCount >= 0x10000) ? (unsigned long)SectorCount : 0; BootSector.Drive = 0xff; /* No BIOS boot drive available */ BootSector.ExtBootSignature = 0x29; @@ -318,24 +315,25 @@ Fat12Format (HANDLE FileHandle, } else { - RtlUnicodeStringToAnsiString(&VolumeLabel, Label, TRUE); + RtlUnicodeStringToOemString(&VolumeLabel, Label, TRUE); memset(&BootSector.VolumeLabel[0], ' ', 11); memcpy(&BootSector.VolumeLabel[0], VolumeLabel.Buffer, VolumeLabel.Length < 11 ? VolumeLabel.Length : 11); - RtlFreeAnsiString(&VolumeLabel); + RtlFreeOemString(&VolumeLabel); } memcpy(&BootSector.SysType[0], "FAT12 ", 8); RootDirSectors = ((BootSector.RootEntries * 32) + (BootSector.BytesPerSector - 1)) / BootSector.BytesPerSector; - /* 341 FAT entries (12bit) fit into one 512 byte sector */ + /* Calculate number of FAT sectors */ + /* ((BootSector.BytesPerSector * 2) / 3) FAT entries (12bit) fit into one sector */ TmpVal1 = SectorCount - (BootSector.ReservedSectors + RootDirSectors); - TmpVal2 = (341 * BootSector.SectorsPerCluster) + BootSector.FATCount; + TmpVal2 = (((BootSector.BytesPerSector * 2) / 3) * BootSector.SectorsPerCluster) + BootSector.FATCount; TmpVal3 = (TmpVal1 + (TmpVal2 - 1)) / TmpVal2; BootSector.FATSectors = (unsigned short)(TmpVal3 & 0xffff); - DPRINT1("BootSector.FATSectors = %hx\n", BootSector.FATSectors); + DPRINT("BootSector.FATSectors = %hx\n", BootSector.FATSectors); Status = Fat12WriteBootSector(FileHandle, &BootSector); diff --git a/reactos/lib/fslib/vfatlib/fat16.c b/reactos/lib/fslib/vfatlib/fat16.c index 3beb4dfe4ef..60785c6d8ce 100644 --- a/reactos/lib/fslib/vfatlib/fat16.c +++ b/reactos/lib/fslib/vfatlib/fat16.c @@ -275,7 +275,7 @@ Fat16Format (HANDLE FileHandle, PFMIFSCALLBACK Callback) { FAT16_BOOT_SECTOR BootSector; - ANSI_STRING VolumeLabel; + OEM_STRING VolumeLabel; ULONG SectorCount; ULONG RootDirSectors; ULONG TmpVal1; @@ -323,7 +323,7 @@ Fat16Format (HANDLE FileHandle, BootSector.FATSectors = 0; /* Set later. See below. */ BootSector.SectorsPerTrack = DiskGeometry->SectorsPerTrack; BootSector.Heads = DiskGeometry->TracksPerCylinder; - BootSector.HiddenSectors = DiskGeometry->SectorsPerTrack; //PartitionInfo->HiddenSectors; /* FIXME: Hack! */ + BootSector.HiddenSectors = PartitionInfo->HiddenSectors; BootSector.SectorsHuge = (SectorCount >= 0x10000) ? (unsigned long)SectorCount : 0; BootSector.Drive = 0xff; /* No BIOS boot drive available */ BootSector.ExtBootSignature = 0x29; @@ -334,11 +334,11 @@ Fat16Format (HANDLE FileHandle, } else { - RtlUnicodeStringToAnsiString(&VolumeLabel, Label, TRUE); + RtlUnicodeStringToOemString(&VolumeLabel, Label, TRUE); memset(&BootSector.VolumeLabel[0], ' ', 11); memcpy(&BootSector.VolumeLabel[0], VolumeLabel.Buffer, VolumeLabel.Length < 11 ? VolumeLabel.Length : 11); - RtlFreeAnsiString(&VolumeLabel); + RtlFreeOemString(&VolumeLabel); } memcpy(&BootSector.SysType[0], "FAT16 ", 8); @@ -347,13 +347,13 @@ Fat16Format (HANDLE FileHandle, RootDirSectors = ((BootSector.RootEntries * 32) + (BootSector.BytesPerSector - 1)) / BootSector.BytesPerSector; - /* 265 FAT entries (16bit) fit into one 512 byte sector */ + /* Calculate number of FAT sectors */ + /* (BootSector.BytesPerSector / 2) FAT entries (16bit) fit into one sector */ TmpVal1 = SectorCount - (BootSector.ReservedSectors + RootDirSectors); - TmpVal2 = (256 * BootSector.SectorsPerCluster) + BootSector.FATCount; + TmpVal2 = ((BootSector.BytesPerSector / 2) * BootSector.SectorsPerCluster) + BootSector.FATCount; TmpVal3 = (TmpVal1 + (TmpVal2 - 1)) / TmpVal2; BootSector.FATSectors = (unsigned short)(TmpVal3 & 0xffff); - - DPRINT("BootSector.FATSectors = %hx\n", BootSector.FATSectors); + DPRINT("BootSector.FATSectors = %hu\n", BootSector.FATSectors); Status = Fat16WriteBootSector(FileHandle, &BootSector); diff --git a/reactos/lib/fslib/vfatlib/fat32.c b/reactos/lib/fslib/vfatlib/fat32.c index 4db82d7dbaf..9f651de2649 100644 --- a/reactos/lib/fslib/vfatlib/fat32.c +++ b/reactos/lib/fslib/vfatlib/fat32.c @@ -344,11 +344,10 @@ Fat32Format (HANDLE FileHandle, PFMIFSCALLBACK Callback) { FAT32_BOOT_SECTOR BootSector; - ANSI_STRING VolumeLabel; + OEM_STRING VolumeLabel; ULONG RootDirSectors; ULONG TmpVal1; ULONG TmpVal2; - ULONG TmpVal3; NTSTATUS Status; /* Calculate cluster size */ @@ -388,7 +387,7 @@ Fat32Format (HANDLE FileHandle, BootSector.FATSectors = 0; BootSector.SectorsPerTrack = DiskGeometry->SectorsPerTrack; BootSector.Heads = DiskGeometry->TracksPerCylinder; - BootSector.HiddenSectors = DiskGeometry->SectorsPerTrack; //PartitionInfo->HiddenSectors; /* FIXME: Hack! */ + BootSector.HiddenSectors = PartitionInfo->HiddenSectors; BootSector.SectorsHuge = PartitionInfo->PartitionLength.QuadPart >> GetShiftCount(BootSector.BytesPerSector); /* Use shifting to avoid 64-bit division */ BootSector.FATSectors32 = 0; /* Set later */ @@ -406,45 +405,23 @@ Fat32Format (HANDLE FileHandle, } else { - RtlUnicodeStringToAnsiString(&VolumeLabel, Label, TRUE); + RtlUnicodeStringToOemString(&VolumeLabel, Label, TRUE); memset(&BootSector.VolumeLabel[0], ' ', 11); memcpy(&BootSector.VolumeLabel[0], VolumeLabel.Buffer, VolumeLabel.Length < 11 ? VolumeLabel.Length : 11); - RtlFreeAnsiString(&VolumeLabel); + RtlFreeOemString(&VolumeLabel); } memcpy(&BootSector.SysType[0], "FAT32 ", 8); RootDirSectors = ((BootSector.RootEntries * 32) + (BootSector.BytesPerSector - 1)) / BootSector.BytesPerSector; - TmpVal1 = BootSector.SectorsHuge - (BootSector.ReservedSectors + RootDirSectors); - TmpVal2 = (256 * BootSector.SectorsPerCluster) + BootSector.FATCount; - if (TRUE /* FAT32 */) - { - TmpVal2 = 0; - do - { - if (TmpVal2 == 0) - { - TmpVal3 = 0xffffffff; - } - else - { - TmpVal3 = TmpVal2; - } - TmpVal2 = ((TmpVal1 - TmpVal2 * BootSector.FATCount) / BootSector.SectorsPerCluster) + 2; - TmpVal2 = (sizeof(ULONG) * TmpVal2 + BootSector.BytesPerSector - 1) / BootSector.BytesPerSector; - } - while (TmpVal3 > TmpVal2); - BootSector.FATSectors32 = TmpVal2; - } -#if 0 - /* experimental */ - /* 128 FAT entries (32bit) fit into one 512 byte sector */ + /* Calculate number of FAT sectors */ + /* (BytesPerSector / 4) FAT entries (32bit) fit into one sector */ TmpVal1 = BootSector.SectorsHuge - BootSector.ReservedSectors; - TmpVal2 = (128 * BootSector.SectorsPerCluster) + BootSector.FATCount; + TmpVal2 = ((BootSector.BytesPerSector / 4) * BootSector.SectorsPerCluster) + BootSector.FATCount; BootSector.FATSectors32 = (TmpVal1 + (TmpVal2 - 1)) / TmpVal2; -#endif + DPRINT("FATSectors32 = %lu\n", BootSector.FATSectors32); Status = Fat32WriteBootSector(FileHandle, &BootSector); diff --git a/reactos/lib/fslib/vfatlib/vfatlib.c b/reactos/lib/fslib/vfatlib/vfatlib.c index 8667f317ea2..2851f1a31b7 100755 --- a/reactos/lib/fslib/vfatlib/vfatlib.c +++ b/reactos/lib/fslib/vfatlib/vfatlib.c @@ -107,6 +107,12 @@ VfatFormat( NtClose(FileHandle); return Status; } + + /* + * FIXME: This is a hack! + * Partitioning software MUST set the correct number of hidden sectors! + */ + PartitionInfo.HiddenSectors = DiskGeometry.SectorsPerTrack; } else { @@ -118,10 +124,10 @@ VfatFormat( (ULONGLONG)DiskGeometry.SectorsPerTrack * (ULONGLONG)DiskGeometry.BytesPerSector; PartitionInfo.HiddenSectors = 0; - PartitionInfo.PartitionNumber = 1; + PartitionInfo.PartitionNumber = 0; PartitionInfo.BootIndicator = FALSE; PartitionInfo.RewritePartition = FALSE; - PartitionInfo.RecognizedPartition = TRUE; + PartitionInfo.RecognizedPartition = FALSE; } DPRINT("PartitionType 0x%x\n", PartitionInfo.PartitionType);