From 9cf8c2c8daafbda89de79334f4975812a68c6fc7 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sat, 12 Jun 2010 11:20:58 +0000 Subject: [PATCH] [VFATLIB] - Get rid of the hard-coded sector size as large sector (4KB) harddisks are already available. - When a partition is formatted, choose the FAT type according to the partition type. The size of the partition does not matter here as it is up to the caller to set the right partition type according to its size. svn path=/trunk/; revision=47765 --- reactos/lib/fslib/vfatlib/fat12.c | 6 +++--- reactos/lib/fslib/vfatlib/fat16.c | 6 +++--- reactos/lib/fslib/vfatlib/fat32.c | 10 +++++----- reactos/lib/fslib/vfatlib/vfatlib.c | 19 +++++++++++++------ reactos/lib/fslib/vfatlib/vfatlib.h | 2 -- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/reactos/lib/fslib/vfatlib/fat12.c b/reactos/lib/fslib/vfatlib/fat12.c index 2e7d9b696e8..58725223777 100644 --- a/reactos/lib/fslib/vfatlib/fat12.c +++ b/reactos/lib/fslib/vfatlib/fat12.c @@ -62,12 +62,12 @@ Fat12WriteBootSector(IN HANDLE FileHandle, /* Allocate buffer for new bootsector */ NewBootSector = (PUCHAR)RtlAllocateHeap(RtlGetProcessHeap (), 0, - SECTORSIZE); + BootSector->BytesPerSector); if (NewBootSector == NULL) return STATUS_INSUFFICIENT_RESOURCES; /* Zero the new bootsector */ - memset(NewBootSector, 0, SECTORSIZE); + memset(NewBootSector, 0, BootSector->BytesPerSector); /* Copy FAT16 BPB to new bootsector */ memcpy((NewBootSector + 3), @@ -82,7 +82,7 @@ Fat12WriteBootSector(IN HANDLE FileHandle, NULL, &IoStatusBlock, NewBootSector, - SECTORSIZE, + BootSector->BytesPerSector, &FileOffset, NULL); if (!NT_SUCCESS(Status)) diff --git a/reactos/lib/fslib/vfatlib/fat16.c b/reactos/lib/fslib/vfatlib/fat16.c index 384c01194dd..1194de905e7 100644 --- a/reactos/lib/fslib/vfatlib/fat16.c +++ b/reactos/lib/fslib/vfatlib/fat16.c @@ -62,12 +62,12 @@ Fat16WriteBootSector(IN HANDLE FileHandle, /* Allocate buffer for new bootsector */ NewBootSector = (PUCHAR)RtlAllocateHeap(RtlGetProcessHeap(), 0, - SECTORSIZE); + BootSector->BytesPerSector); if (NewBootSector == NULL) return STATUS_INSUFFICIENT_RESOURCES; /* Zero the new bootsector */ - memset(NewBootSector, 0, SECTORSIZE); + memset(NewBootSector, 0, BootSector->BytesPerSector); /* Copy FAT16 BPB to new bootsector */ memcpy((NewBootSector + 3), @@ -82,7 +82,7 @@ Fat16WriteBootSector(IN HANDLE FileHandle, NULL, &IoStatusBlock, NewBootSector, - SECTORSIZE, + BootSector->BytesPerSector, &FileOffset, NULL); if (!NT_SUCCESS(Status)) diff --git a/reactos/lib/fslib/vfatlib/fat32.c b/reactos/lib/fslib/vfatlib/fat32.c index c0e93c842cf..9be3e050b12 100644 --- a/reactos/lib/fslib/vfatlib/fat32.c +++ b/reactos/lib/fslib/vfatlib/fat32.c @@ -62,12 +62,12 @@ Fat32WriteBootSector(IN HANDLE FileHandle, /* Allocate buffer for new bootsector */ NewBootSector = (PUCHAR)RtlAllocateHeap(RtlGetProcessHeap(), 0, - SECTORSIZE); + BootSector->BytesPerSector); if (NewBootSector == NULL) return STATUS_INSUFFICIENT_RESOURCES; /* Zero the new bootsector */ - memset(NewBootSector, 0, SECTORSIZE); + memset(NewBootSector, 0, BootSector->BytesPerSector); /* Copy FAT32 BPB to new bootsector */ memcpy((NewBootSector + 3), @@ -82,7 +82,7 @@ Fat32WriteBootSector(IN HANDLE FileHandle, NULL, &IoStatusBlock, NewBootSector, - SECTORSIZE, + BootSector->BytesPerSector, &FileOffset, NULL); if (!NT_SUCCESS(Status)) @@ -97,14 +97,14 @@ Fat32WriteBootSector(IN HANDLE FileHandle, /* Write backup boot sector */ if (BootSector->BootBackup != 0x0000) { - FileOffset.QuadPart = (ULONGLONG)((ULONG) BootSector->BootBackup * SECTORSIZE); + FileOffset.QuadPart = (ULONGLONG)((ULONG)BootSector->BootBackup * BootSector->BytesPerSector); Status = NtWriteFile(FileHandle, NULL, NULL, NULL, &IoStatusBlock, NewBootSector, - SECTORSIZE, + BootSector->BytesPerSector, &FileOffset, NULL); if (!NT_SUCCESS(Status)) diff --git a/reactos/lib/fslib/vfatlib/vfatlib.c b/reactos/lib/fslib/vfatlib/vfatlib.c index 9537b9b5b11..58738e68f54 100755 --- a/reactos/lib/fslib/vfatlib/vfatlib.c +++ b/reactos/lib/fslib/vfatlib/vfatlib.c @@ -143,9 +143,9 @@ VfatFormat(IN PUNICODE_STRING DriveRoot, Callback (PROGRESS, 0, (PVOID)&Context.Percent); } - if (PartitionInfo.PartitionLength.QuadPart < (4200LL * 1024LL)) + if (PartitionInfo.PartitionType == PARTITION_FAT_12) { - /* FAT12 (volume is smaller than 4.1MB) */ + /* FAT12 */ Status = Fat12Format(FileHandle, &PartitionInfo, &DiskGeometry, @@ -154,9 +154,11 @@ VfatFormat(IN PUNICODE_STRING DriveRoot, ClusterSize, &Context); } - else if (PartitionInfo.PartitionLength.QuadPart < (512LL * 1024LL * 1024LL)) + else if (PartitionInfo.PartitionType == PARTITION_FAT_16 || + PartitionInfo.PartitionType == PARTITION_HUGE || + PartitionInfo.PartitionType == PARTITION_XINT13) { - /* FAT16 (volume is smaller than 512MB) */ + /* FAT16 */ Status = Fat16Format(FileHandle, &PartitionInfo, &DiskGeometry, @@ -165,9 +167,10 @@ VfatFormat(IN PUNICODE_STRING DriveRoot, ClusterSize, &Context); } - else + else if (PartitionInfo.PartitionType == PARTITION_FAT32 || + PartitionInfo.PartitionType == PARTITION_FAT32_XINT13) { - /* FAT32 (volume is 512MB or larger) */ + /* FAT32 */ Status = Fat32Format(FileHandle, &PartitionInfo, &DiskGeometry, @@ -176,6 +179,10 @@ VfatFormat(IN PUNICODE_STRING DriveRoot, ClusterSize, &Context); } + else + { + Status = STATUS_INVALID_PARAMETER; + } NtClose(FileHandle); diff --git a/reactos/lib/fslib/vfatlib/vfatlib.h b/reactos/lib/fslib/vfatlib/vfatlib.h index 6ae54e63163..8e96ca574ec 100755 --- a/reactos/lib/fslib/vfatlib/vfatlib.h +++ b/reactos/lib/fslib/vfatlib/vfatlib.h @@ -19,8 +19,6 @@ #include "check/file.h" #include "check/check.h" -#define SECTORSIZE 512 - #include typedef struct _FAT16_BOOT_SECTOR { -- 2.17.1