tangled
alpha
login
or
join now
huwcampbell.com
/
reactos
0
fork
atom
Reactos
0
fork
atom
overview
issues
pulls
pipelines
[VFATLIB] Add GPT partition support
Eric Kohl
3 months ago
d39657cf
bdf1b0ca
+116
-64
5 changed files
expand all
collapse all
unified
split
sdk
lib
fslib
vfatlib
fat12.c
fat16.c
fat32.c
vfatlib.c
vfatlib.h
+2
-2
sdk/lib/fslib/vfatlib/fat12.c
···
237
237
238
238
NTSTATUS
239
239
Fat12Format(IN HANDLE FileHandle,
240
240
-
IN PPARTITION_INFORMATION PartitionInfo,
240
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
292
-
BootSector.HiddenSectors = PartitionInfo->HiddenSectors;
292
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
239
-
IN PPARTITION_INFORMATION PartitionInfo,
239
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
299
-
BootSector.HiddenSectors = PartitionInfo->HiddenSectors;
299
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
387
-
IN PPARTITION_INFORMATION PartitionInfo,
387
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
444
-
BootSector.HiddenSectors = PartitionInfo->HiddenSectors;
444
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
63
-
PARTITION_INFORMATION PartitionInfo;
63
63
+
PARTITION_INFORMATION_EX PartitionInfo;
64
64
FORMAT_CONTEXT Context;
65
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
131
-
IOCTL_DISK_GET_PARTITION_INFO,
132
132
+
IOCTL_DISK_GET_PARTITION_INFO_EX,
132
133
NULL,
133
134
0,
134
135
&PartitionInfo,
135
135
-
sizeof(PARTITION_INFORMATION));
136
136
+
sizeof(PARTITION_INFORMATION_EX));
136
137
if (!NT_SUCCESS(Status))
137
138
{
138
138
-
DPRINT("IOCTL_DISK_GET_PARTITION_INFO failed with status 0x%08x\n", Status);
139
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
145
-
PartitionInfo.PartitionType = 0;
146
146
+
PartitionInfo.PartitionStyle = PARTITION_STYLE_MBR;
147
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
152
-
PartitionInfo.HiddenSectors = 0;
154
154
+
PartitionInfo.Mbr.HiddenSectors = 0;
153
155
PartitionInfo.PartitionNumber = 0;
154
154
-
PartitionInfo.BootIndicator = FALSE;
156
156
+
PartitionInfo.Mbr.BootIndicator = FALSE;
155
157
PartitionInfo.RewritePartition = FALSE;
156
156
-
PartitionInfo.RecognizedPartition = FALSE;
158
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
161
-
if (PartitionInfo.PartitionType != PARTITION_FAT_12 &&
162
162
-
PartitionInfo.PartitionType != PARTITION_FAT_16 &&
163
163
-
PartitionInfo.PartitionType != PARTITION_HUGE &&
164
164
-
PartitionInfo.PartitionType != PARTITION_XINT13 &&
165
165
-
PartitionInfo.PartitionType != PARTITION_FAT32 &&
166
166
-
PartitionInfo.PartitionType != PARTITION_FAT32_XINT13)
163
163
+
164
164
+
if (PartitionInfo.PartitionStyle == PARTITION_STYLE_MBR)
167
165
{
168
168
-
/* Determine the correct type based upon size and offset (copied from usetup) */
169
169
-
if (PartitionInfo.PartitionLength.QuadPart < (4200LL * 1024LL))
166
166
+
if (PartitionInfo.Mbr.PartitionType == PARTITION_FAT_12)
170
167
{
171
171
-
/* FAT12 CHS partition (disk is smaller than 4.1MB) */
172
172
-
PartitionInfo.PartitionType = PARTITION_FAT_12;
168
168
+
FatType = FAT_12;
169
169
+
}
170
170
+
else if (PartitionInfo.Mbr.PartitionType == PARTITION_FAT_16 ||
171
171
+
PartitionInfo.Mbr.PartitionType == PARTITION_HUGE ||
172
172
+
PartitionInfo.Mbr.PartitionType == PARTITION_XINT13)
173
173
+
{
174
174
+
FatType = FAT_16;
173
175
}
174
174
-
else if (PartitionInfo.StartingOffset.QuadPart < (1024LL * 255LL * 63LL * 512LL))
176
176
+
else if (PartitionInfo.Mbr.PartitionType == PARTITION_FAT32 ||
177
177
+
PartitionInfo.Mbr.PartitionType == PARTITION_FAT32_XINT13)
175
178
{
176
176
-
/* Partition starts below the 8.4GB boundary ==> CHS partition */
179
179
+
FatType = FAT_32;
180
180
+
}
177
181
178
178
-
if (PartitionInfo.PartitionLength.QuadPart < (32LL * 1024LL * 1024LL))
182
182
+
if (FatType == FAT_UNKNOWN)
183
183
+
{
184
184
+
/* Determine the correct type based upon size and offset (copied from usetup) */
185
185
+
if (PartitionInfo.PartitionLength.QuadPart < (4200LL * 1024LL))
179
186
{
180
180
-
/* FAT16 CHS partition (partition size < 32MB) */
181
181
-
PartitionInfo.PartitionType = PARTITION_FAT_16;
187
187
+
/* FAT12 CHS partition (disk is smaller than 4.1MB) */
188
188
+
FatType = FAT_12;
182
189
}
183
183
-
else if (PartitionInfo.PartitionLength.QuadPart < (512LL * 1024LL * 1024LL))
190
190
+
else if (PartitionInfo.StartingOffset.QuadPart < (1024LL * 255LL * 63LL * 512LL))
184
191
{
185
185
-
/* FAT16 CHS partition (partition size < 512MB) */
186
186
-
PartitionInfo.PartitionType = PARTITION_HUGE;
192
192
+
/* Partition starts below the 8.4GB boundary ==> CHS partition */
193
193
+
194
194
+
if (PartitionInfo.PartitionLength.QuadPart < (32LL * 1024LL * 1024LL))
195
195
+
{
196
196
+
/* FAT16 CHS partition (partition size < 32MB) */
197
197
+
FatType = FAT_16;
198
198
+
}
199
199
+
else if (PartitionInfo.PartitionLength.QuadPart < (512LL * 1024LL * 1024LL))
200
200
+
{
201
201
+
/* FAT16 CHS partition (partition size < 512MB) */
202
202
+
FatType = FAT_16;
203
203
+
}
204
204
+
else
205
205
+
{
206
206
+
/* FAT32 CHS partition (partition size >= 512MB) */
207
207
+
FatType = FAT_32;
208
208
+
}
187
209
}
188
210
else
189
211
{
190
190
-
/* FAT32 CHS partition (partition size >= 512MB) */
191
191
-
PartitionInfo.PartitionType = PARTITION_FAT32;
212
212
+
/* Partition starts above the 8.4GB boundary ==> LBA partition */
213
213
+
214
214
+
if (PartitionInfo.PartitionLength.QuadPart < (512LL * 1024LL * 1024LL))
215
215
+
{
216
216
+
/* FAT16 LBA partition (partition size < 512MB) */
217
217
+
FatType = FAT_16;
218
218
+
}
219
219
+
else
220
220
+
{
221
221
+
/* FAT32 LBA partition (partition size >= 512MB) */
222
222
+
FatType = FAT_32;
223
223
+
}
192
224
}
225
225
+
}
226
226
+
227
227
+
DPRINT("PartitionType 0x%x\n", PartitionInfo.Mbr.PartitionType);
228
228
+
DPRINT("StartingOffset %I64d\n", PartitionInfo.StartingOffset.QuadPart);
229
229
+
DPRINT("PartitionLength %I64d\n", PartitionInfo.PartitionLength.QuadPart);
230
230
+
DPRINT("HiddenSectors %lu\n", PartitionInfo.Mbr.HiddenSectors);
231
231
+
DPRINT("PartitionNumber %d\n", PartitionInfo.PartitionNumber);
232
232
+
DPRINT("BootIndicator 0x%x\n", PartitionInfo.Mbr.BootIndicator);
233
233
+
DPRINT("RewritePartition %d\n", PartitionInfo.RewritePartition);
234
234
+
DPRINT("RecognizedPartition %d\n", PartitionInfo.Mbr.RecognizedPartition);
235
235
+
}
236
236
+
else if (PartitionInfo.PartitionStyle == PARTITION_STYLE_GPT)
237
237
+
{
238
238
+
if (PartitionInfo.PartitionLength.QuadPart < (4200LL * 1024LL))
239
239
+
{
240
240
+
/* FAT12 CHS partition (disk is smaller than 4.1MB) */
241
241
+
FatType = FAT_12;
242
242
+
}
243
243
+
else if (PartitionInfo.PartitionLength.QuadPart < (512LL * 1024LL * 1024LL))
244
244
+
{
245
245
+
/* FAT16 partition (partition size < 512MB) */
246
246
+
FatType = FAT_16;
247
247
+
}
248
248
+
else if (PartitionInfo.PartitionLength.QuadPart <= (32LL * 1024LL * 1024LL * 1024LL))
249
249
+
{
250
250
+
/* FAT32 partition (partition size < 32GB) */
251
251
+
FatType = FAT_32;
193
252
}
194
253
else
195
254
{
196
196
-
/* Partition starts above the 8.4GB boundary ==> LBA partition */
197
197
-
198
198
-
if (PartitionInfo.PartitionLength.QuadPart < (512LL * 1024LL * 1024LL))
199
199
-
{
200
200
-
/* FAT16 LBA partition (partition size < 512MB) */
201
201
-
PartitionInfo.PartitionType = PARTITION_XINT13;
202
202
-
}
203
203
-
else
204
204
-
{
205
205
-
/* FAT32 LBA partition (partition size >= 512MB) */
206
206
-
PartitionInfo.PartitionType = PARTITION_FAT32_XINT13;
207
207
-
}
255
255
+
DPRINT1("The partition ist too large (> 32 GB) for the FAT file system!\n");
256
256
+
NtClose(FileHandle);
257
257
+
return FALSE;
208
258
}
209
209
-
}
210
259
211
211
-
DPRINT("PartitionType 0x%x\n", PartitionInfo.PartitionType);
212
212
-
DPRINT("StartingOffset %I64d\n", PartitionInfo.StartingOffset.QuadPart);
213
213
-
DPRINT("PartitionLength %I64d\n", PartitionInfo.PartitionLength.QuadPart);
214
214
-
DPRINT("HiddenSectors %lu\n", PartitionInfo.HiddenSectors);
215
215
-
DPRINT("PartitionNumber %d\n", PartitionInfo.PartitionNumber);
216
216
-
DPRINT("BootIndicator 0x%x\n", PartitionInfo.BootIndicator);
217
217
-
DPRINT("RewritePartition %d\n", PartitionInfo.RewritePartition);
218
218
-
DPRINT("RecognizedPartition %d\n", PartitionInfo.RecognizedPartition);
260
260
+
DPRINT("StartingOffset %I64d\n", PartitionInfo.StartingOffset.QuadPart);
261
261
+
DPRINT("PartitionLength %I64d\n", PartitionInfo.PartitionLength.QuadPart);
262
262
+
DPRINT("PartitionNumber %d\n", PartitionInfo.PartitionNumber);
263
263
+
DPRINT("RewritePartition %d\n", PartitionInfo.RewritePartition);
264
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
241
-
if (PartitionInfo.PartitionType == PARTITION_FAT_12)
287
287
+
if (FatType == FAT_12)
242
288
{
243
289
/* FAT12 */
244
290
Status = Fat12Format(FileHandle,
···
249
295
ClusterSize,
250
296
&Context);
251
297
}
252
252
-
else if (PartitionInfo.PartitionType == PARTITION_FAT_16 ||
253
253
-
PartitionInfo.PartitionType == PARTITION_HUGE ||
254
254
-
PartitionInfo.PartitionType == PARTITION_XINT13)
298
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
265
-
else if (PartitionInfo.PartitionType == PARTITION_FAT32 ||
266
266
-
PartitionInfo.PartitionType == PARTITION_FAT32_XINT13)
309
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
112
+
typedef enum
113
113
+
{
114
114
+
FAT_UNKNOWN,
115
115
+
FAT_12,
116
116
+
FAT_16,
117
117
+
FAT_32
118
118
+
} FAT_TYPE;
119
119
+
120
120
+
112
121
#include "common.h"
113
122
114
123
115
124
NTSTATUS
116
125
Fat12Format(HANDLE FileHandle,
117
117
-
PPARTITION_INFORMATION PartitionInfo,
126
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
126
-
PPARTITION_INFORMATION PartitionInfo,
135
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
135
-
PPARTITION_INFORMATION PartitionInfo,
144
144
+
PPARTITION_INFORMATION_EX PartitionInfo,
136
145
PDISK_GEOMETRY DiskGeometry,
137
146
PUNICODE_STRING Label,
138
147
BOOLEAN QuickFormat,