Reactos

[VFATLIB] Add GPT partition support

Eric Kohl d39657cf bdf1b0ca

+116 -64
+2 -2
sdk/lib/fslib/vfatlib/fat12.c
··· 237 237 238 238 NTSTATUS 239 239 Fat12Format(IN HANDLE FileHandle, 240 - IN PPARTITION_INFORMATION PartitionInfo, 240 + IN PPARTITION_INFORMATION_EX PartitionInfo, 241 241 IN PDISK_GEOMETRY DiskGeometry, 242 242 IN PUNICODE_STRING Label, 243 243 IN BOOLEAN QuickFormat, ··· 289 289 BootSector.FATSectors = 0; /* Set later. See below. */ 290 290 BootSector.SectorsPerTrack = DiskGeometry->SectorsPerTrack; 291 291 BootSector.Heads = DiskGeometry->TracksPerCylinder; 292 - BootSector.HiddenSectors = PartitionInfo->HiddenSectors; 292 + BootSector.HiddenSectors = (PartitionInfo->PartitionStyle == PARTITION_STYLE_MBR) ? PartitionInfo->Mbr.HiddenSectors : 0; 293 293 BootSector.SectorsHuge = (SectorCount >= 0x10000) ? (unsigned long)SectorCount : 0; 294 294 BootSector.Drive = (DiskGeometry->MediaType == FixedMedia) ? 0x80 : 0x00; 295 295 BootSector.ExtBootSignature = 0x29;
+2 -2
sdk/lib/fslib/vfatlib/fat16.c
··· 236 236 237 237 NTSTATUS 238 238 Fat16Format(IN HANDLE FileHandle, 239 - IN PPARTITION_INFORMATION PartitionInfo, 239 + IN PPARTITION_INFORMATION_EX PartitionInfo, 240 240 IN PDISK_GEOMETRY DiskGeometry, 241 241 IN PUNICODE_STRING Label, 242 242 IN BOOLEAN QuickFormat, ··· 296 296 BootSector.FATSectors = 0; /* Set later. See below. */ 297 297 BootSector.SectorsPerTrack = DiskGeometry->SectorsPerTrack; 298 298 BootSector.Heads = DiskGeometry->TracksPerCylinder; 299 - BootSector.HiddenSectors = PartitionInfo->HiddenSectors; 299 + BootSector.HiddenSectors = (PartitionInfo->PartitionStyle == PARTITION_STYLE_MBR) ? PartitionInfo->Mbr.HiddenSectors : 0; 300 300 BootSector.SectorsHuge = (SectorCount >= 0x10000) ? (unsigned long)SectorCount : 0; 301 301 BootSector.Drive = (DiskGeometry->MediaType == FixedMedia) ? 0x80 : 0x00; 302 302 BootSector.ExtBootSignature = 0x29;
+2 -2
sdk/lib/fslib/vfatlib/fat32.c
··· 384 384 385 385 NTSTATUS 386 386 Fat32Format(IN HANDLE FileHandle, 387 - IN PPARTITION_INFORMATION PartitionInfo, 387 + IN PPARTITION_INFORMATION_EX PartitionInfo, 388 388 IN PDISK_GEOMETRY DiskGeometry, 389 389 IN PUNICODE_STRING Label, 390 390 IN BOOLEAN QuickFormat, ··· 441 441 BootSector.FATSectors = 0; 442 442 BootSector.SectorsPerTrack = DiskGeometry->SectorsPerTrack; 443 443 BootSector.Heads = DiskGeometry->TracksPerCylinder; 444 - BootSector.HiddenSectors = PartitionInfo->HiddenSectors; 444 + BootSector.HiddenSectors = (PartitionInfo->PartitionStyle == PARTITION_STYLE_MBR) ? PartitionInfo->Mbr.HiddenSectors : 0; 445 445 BootSector.SectorsHuge = PartitionInfo->PartitionLength.QuadPart >> 446 446 GetShiftCount(BootSector.BytesPerSector); /* Use shifting to avoid 64-bit division */ 447 447 BootSector.FATSectors32 = 0; /* Set later */
+98 -55
sdk/lib/fslib/vfatlib/vfatlib.c
··· 60 60 DISK_GEOMETRY DiskGeometry; 61 61 IO_STATUS_BLOCK Iosb; 62 62 HANDLE FileHandle; 63 - PARTITION_INFORMATION PartitionInfo; 63 + PARTITION_INFORMATION_EX PartitionInfo; 64 64 FORMAT_CONTEXT Context; 65 + FAT_TYPE FatType = FAT_UNKNOWN; 65 66 NTSTATUS Status, LockStatus; 66 67 67 68 DPRINT("VfatFormat(DriveRoot '%wZ')\n", DriveRoot); ··· 128 129 NULL, 129 130 NULL, 130 131 &Iosb, 131 - IOCTL_DISK_GET_PARTITION_INFO, 132 + IOCTL_DISK_GET_PARTITION_INFO_EX, 132 133 NULL, 133 134 0, 134 135 &PartitionInfo, 135 - sizeof(PARTITION_INFORMATION)); 136 + sizeof(PARTITION_INFORMATION_EX)); 136 137 if (!NT_SUCCESS(Status)) 137 138 { 138 - DPRINT("IOCTL_DISK_GET_PARTITION_INFO failed with status 0x%08x\n", Status); 139 + DPRINT("IOCTL_DISK_GET_PARTITION_INFO_EX failed with status 0x%08x\n", Status); 139 140 NtClose(FileHandle); 140 141 return FALSE; 141 142 } 142 143 } 143 144 else 144 145 { 145 - PartitionInfo.PartitionType = 0; 146 + PartitionInfo.PartitionStyle = PARTITION_STYLE_MBR; 147 + PartitionInfo.Mbr.PartitionType = 0; 146 148 PartitionInfo.StartingOffset.QuadPart = 0ULL; 147 149 PartitionInfo.PartitionLength.QuadPart = 148 150 DiskGeometry.Cylinders.QuadPart * 149 151 (ULONGLONG)DiskGeometry.TracksPerCylinder * 150 152 (ULONGLONG)DiskGeometry.SectorsPerTrack * 151 153 (ULONGLONG)DiskGeometry.BytesPerSector; 152 - PartitionInfo.HiddenSectors = 0; 154 + PartitionInfo.Mbr.HiddenSectors = 0; 153 155 PartitionInfo.PartitionNumber = 0; 154 - PartitionInfo.BootIndicator = FALSE; 156 + PartitionInfo.Mbr.BootIndicator = FALSE; 155 157 PartitionInfo.RewritePartition = FALSE; 156 - PartitionInfo.RecognizedPartition = FALSE; 158 + PartitionInfo.Mbr.RecognizedPartition = FALSE; 157 159 } 158 160 159 161 /* If it already has a FAT FS, we'll use that type. 160 162 * If it doesn't, we will determine the FAT type based on size and offset */ 161 - if (PartitionInfo.PartitionType != PARTITION_FAT_12 && 162 - PartitionInfo.PartitionType != PARTITION_FAT_16 && 163 - PartitionInfo.PartitionType != PARTITION_HUGE && 164 - PartitionInfo.PartitionType != PARTITION_XINT13 && 165 - PartitionInfo.PartitionType != PARTITION_FAT32 && 166 - PartitionInfo.PartitionType != PARTITION_FAT32_XINT13) 163 + 164 + if (PartitionInfo.PartitionStyle == PARTITION_STYLE_MBR) 167 165 { 168 - /* Determine the correct type based upon size and offset (copied from usetup) */ 169 - if (PartitionInfo.PartitionLength.QuadPart < (4200LL * 1024LL)) 166 + if (PartitionInfo.Mbr.PartitionType == PARTITION_FAT_12) 170 167 { 171 - /* FAT12 CHS partition (disk is smaller than 4.1MB) */ 172 - PartitionInfo.PartitionType = PARTITION_FAT_12; 168 + FatType = FAT_12; 169 + } 170 + else if (PartitionInfo.Mbr.PartitionType == PARTITION_FAT_16 || 171 + PartitionInfo.Mbr.PartitionType == PARTITION_HUGE || 172 + PartitionInfo.Mbr.PartitionType == PARTITION_XINT13) 173 + { 174 + FatType = FAT_16; 173 175 } 174 - else if (PartitionInfo.StartingOffset.QuadPart < (1024LL * 255LL * 63LL * 512LL)) 176 + else if (PartitionInfo.Mbr.PartitionType == PARTITION_FAT32 || 177 + PartitionInfo.Mbr.PartitionType == PARTITION_FAT32_XINT13) 175 178 { 176 - /* Partition starts below the 8.4GB boundary ==> CHS partition */ 179 + FatType = FAT_32; 180 + } 177 181 178 - if (PartitionInfo.PartitionLength.QuadPart < (32LL * 1024LL * 1024LL)) 182 + if (FatType == FAT_UNKNOWN) 183 + { 184 + /* Determine the correct type based upon size and offset (copied from usetup) */ 185 + if (PartitionInfo.PartitionLength.QuadPart < (4200LL * 1024LL)) 179 186 { 180 - /* FAT16 CHS partition (partition size < 32MB) */ 181 - PartitionInfo.PartitionType = PARTITION_FAT_16; 187 + /* FAT12 CHS partition (disk is smaller than 4.1MB) */ 188 + FatType = FAT_12; 182 189 } 183 - else if (PartitionInfo.PartitionLength.QuadPart < (512LL * 1024LL * 1024LL)) 190 + else if (PartitionInfo.StartingOffset.QuadPart < (1024LL * 255LL * 63LL * 512LL)) 184 191 { 185 - /* FAT16 CHS partition (partition size < 512MB) */ 186 - PartitionInfo.PartitionType = PARTITION_HUGE; 192 + /* Partition starts below the 8.4GB boundary ==> CHS partition */ 193 + 194 + if (PartitionInfo.PartitionLength.QuadPart < (32LL * 1024LL * 1024LL)) 195 + { 196 + /* FAT16 CHS partition (partition size < 32MB) */ 197 + FatType = FAT_16; 198 + } 199 + else if (PartitionInfo.PartitionLength.QuadPart < (512LL * 1024LL * 1024LL)) 200 + { 201 + /* FAT16 CHS partition (partition size < 512MB) */ 202 + FatType = FAT_16; 203 + } 204 + else 205 + { 206 + /* FAT32 CHS partition (partition size >= 512MB) */ 207 + FatType = FAT_32; 208 + } 187 209 } 188 210 else 189 211 { 190 - /* FAT32 CHS partition (partition size >= 512MB) */ 191 - PartitionInfo.PartitionType = PARTITION_FAT32; 212 + /* Partition starts above the 8.4GB boundary ==> LBA partition */ 213 + 214 + if (PartitionInfo.PartitionLength.QuadPart < (512LL * 1024LL * 1024LL)) 215 + { 216 + /* FAT16 LBA partition (partition size < 512MB) */ 217 + FatType = FAT_16; 218 + } 219 + else 220 + { 221 + /* FAT32 LBA partition (partition size >= 512MB) */ 222 + FatType = FAT_32; 223 + } 192 224 } 225 + } 226 + 227 + DPRINT("PartitionType 0x%x\n", PartitionInfo.Mbr.PartitionType); 228 + DPRINT("StartingOffset %I64d\n", PartitionInfo.StartingOffset.QuadPart); 229 + DPRINT("PartitionLength %I64d\n", PartitionInfo.PartitionLength.QuadPart); 230 + DPRINT("HiddenSectors %lu\n", PartitionInfo.Mbr.HiddenSectors); 231 + DPRINT("PartitionNumber %d\n", PartitionInfo.PartitionNumber); 232 + DPRINT("BootIndicator 0x%x\n", PartitionInfo.Mbr.BootIndicator); 233 + DPRINT("RewritePartition %d\n", PartitionInfo.RewritePartition); 234 + DPRINT("RecognizedPartition %d\n", PartitionInfo.Mbr.RecognizedPartition); 235 + } 236 + else if (PartitionInfo.PartitionStyle == PARTITION_STYLE_GPT) 237 + { 238 + if (PartitionInfo.PartitionLength.QuadPart < (4200LL * 1024LL)) 239 + { 240 + /* FAT12 CHS partition (disk is smaller than 4.1MB) */ 241 + FatType = FAT_12; 242 + } 243 + else if (PartitionInfo.PartitionLength.QuadPart < (512LL * 1024LL * 1024LL)) 244 + { 245 + /* FAT16 partition (partition size < 512MB) */ 246 + FatType = FAT_16; 247 + } 248 + else if (PartitionInfo.PartitionLength.QuadPart <= (32LL * 1024LL * 1024LL * 1024LL)) 249 + { 250 + /* FAT32 partition (partition size < 32GB) */ 251 + FatType = FAT_32; 193 252 } 194 253 else 195 254 { 196 - /* Partition starts above the 8.4GB boundary ==> LBA partition */ 197 - 198 - if (PartitionInfo.PartitionLength.QuadPart < (512LL * 1024LL * 1024LL)) 199 - { 200 - /* FAT16 LBA partition (partition size < 512MB) */ 201 - PartitionInfo.PartitionType = PARTITION_XINT13; 202 - } 203 - else 204 - { 205 - /* FAT32 LBA partition (partition size >= 512MB) */ 206 - PartitionInfo.PartitionType = PARTITION_FAT32_XINT13; 207 - } 255 + DPRINT1("The partition ist too large (> 32 GB) for the FAT file system!\n"); 256 + NtClose(FileHandle); 257 + return FALSE; 208 258 } 209 - } 210 259 211 - DPRINT("PartitionType 0x%x\n", PartitionInfo.PartitionType); 212 - DPRINT("StartingOffset %I64d\n", PartitionInfo.StartingOffset.QuadPart); 213 - DPRINT("PartitionLength %I64d\n", PartitionInfo.PartitionLength.QuadPart); 214 - DPRINT("HiddenSectors %lu\n", PartitionInfo.HiddenSectors); 215 - DPRINT("PartitionNumber %d\n", PartitionInfo.PartitionNumber); 216 - DPRINT("BootIndicator 0x%x\n", PartitionInfo.BootIndicator); 217 - DPRINT("RewritePartition %d\n", PartitionInfo.RewritePartition); 218 - DPRINT("RecognizedPartition %d\n", PartitionInfo.RecognizedPartition); 260 + DPRINT("StartingOffset %I64d\n", PartitionInfo.StartingOffset.QuadPart); 261 + DPRINT("PartitionLength %I64d\n", PartitionInfo.PartitionLength.QuadPart); 262 + DPRINT("PartitionNumber %d\n", PartitionInfo.PartitionNumber); 263 + DPRINT("RewritePartition %d\n", PartitionInfo.RewritePartition); 264 + } 219 265 220 266 if (Callback != NULL) 221 267 { ··· 238 284 DPRINT1("WARNING: Failed to lock volume for formatting! Format may fail! (Status: 0x%x)\n", LockStatus); 239 285 } 240 286 241 - if (PartitionInfo.PartitionType == PARTITION_FAT_12) 287 + if (FatType == FAT_12) 242 288 { 243 289 /* FAT12 */ 244 290 Status = Fat12Format(FileHandle, ··· 249 295 ClusterSize, 250 296 &Context); 251 297 } 252 - else if (PartitionInfo.PartitionType == PARTITION_FAT_16 || 253 - PartitionInfo.PartitionType == PARTITION_HUGE || 254 - PartitionInfo.PartitionType == PARTITION_XINT13) 298 + else if (FatType == FAT_16) 255 299 { 256 300 /* FAT16 */ 257 301 Status = Fat16Format(FileHandle, ··· 262 306 ClusterSize, 263 307 &Context); 264 308 } 265 - else if (PartitionInfo.PartitionType == PARTITION_FAT32 || 266 - PartitionInfo.PartitionType == PARTITION_FAT32_XINT13) 309 + else if (FatType == FAT_32) 267 310 { 268 311 /* FAT32 */ 269 312 Status = Fat32Format(FileHandle,
+12 -3
sdk/lib/fslib/vfatlib/vfatlib.h
··· 109 109 ULONG Percent; 110 110 } FORMAT_CONTEXT, *PFORMAT_CONTEXT; 111 111 112 + typedef enum 113 + { 114 + FAT_UNKNOWN, 115 + FAT_12, 116 + FAT_16, 117 + FAT_32 118 + } FAT_TYPE; 119 + 120 + 112 121 #include "common.h" 113 122 114 123 115 124 NTSTATUS 116 125 Fat12Format(HANDLE FileHandle, 117 - PPARTITION_INFORMATION PartitionInfo, 126 + PPARTITION_INFORMATION_EX PartitionInfo, 118 127 PDISK_GEOMETRY DiskGeometry, 119 128 PUNICODE_STRING Label, 120 129 BOOLEAN QuickFormat, ··· 123 132 124 133 NTSTATUS 125 134 Fat16Format(HANDLE FileHandle, 126 - PPARTITION_INFORMATION PartitionInfo, 135 + PPARTITION_INFORMATION_EX PartitionInfo, 127 136 PDISK_GEOMETRY DiskGeometry, 128 137 PUNICODE_STRING Label, 129 138 BOOLEAN QuickFormat, ··· 132 141 133 142 NTSTATUS 134 143 Fat32Format(HANDLE FileHandle, 135 - PPARTITION_INFORMATION PartitionInfo, 144 + PPARTITION_INFORMATION_EX PartitionInfo, 136 145 PDISK_GEOMETRY DiskGeometry, 137 146 PUNICODE_STRING Label, 138 147 BOOLEAN QuickFormat,