58{
66
67 DPRINT(
"VfatFormat(DriveRoot '%wZ')\n", DriveRoot);
68
69
72
78
80 DriveRoot,
81 0,
84
92 {
95 }
96
104 0,
105 &DiskGeometry,
108 {
109 DPRINT(
"IOCTL_DISK_GET_DRIVE_GEOMETRY failed with status 0x%08x\n",
Status);
112 }
113
115 {
120 DPRINT(
"DiskSize %I64d\n",
125
133 0,
137 {
138 DPRINT(
"IOCTL_DISK_GET_PARTITION_INFO failed with status 0x%08x\n",
Status);
141 }
142 }
143 else
144 {
157 }
158
159
160
167 {
168
169 if (
PartitionInfo.PartitionLength.QuadPart < (4200LL * 1024LL))
170 {
171
173 }
174 else if (
PartitionInfo.StartingOffset.QuadPart < (1024LL * 255LL * 63LL * 512LL))
175 {
176
177
178 if (
PartitionInfo.PartitionLength.QuadPart < (32LL * 1024LL * 1024LL))
179 {
180
182 }
183 else if (
PartitionInfo.PartitionLength.QuadPart < (512LL * 1024LL * 1024LL))
184 {
185
187 }
188 else
189 {
190
192 }
193 }
194 else
195 {
196
197
198 if (
PartitionInfo.PartitionLength.QuadPart < (512LL * 1024LL * 1024LL))
199 {
200
202 }
203 else
204 {
205
207 }
208 }
209 }
210
219
221 {
224 }
225
233 0,
235 0);
237 {
238 DPRINT1(
"WARNING: Failed to lock volume for formatting! Format may fail! (Status: 0x%x)\n", LockStatus);
239 }
240
242 {
243
246 &DiskGeometry,
251 }
255 {
256
259 &DiskGeometry,
264 }
267 {
268
271 &DiskGeometry,
276 }
277 else
278 {
280 }
281
282
290 0,
292 0);
294 {
295 DPRINT1(
"Failed to umount volume (Status: 0x%x)\n", LockStatus);
296 }
297
305 0,
307 0);
309 {
310 DPRINT1(
"Failed to unlock volume (Status: 0x%x)\n", LockStatus);
311 }
312
314
317}
#define PARTITION_FAT32_XINT13
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
NTSTATUS Fat12Format(IN HANDLE FileHandle, IN PPARTITION_INFORMATION PartitionInfo, IN PDISK_GEOMETRY DiskGeometry, IN PUNICODE_STRING Label, IN BOOLEAN QuickFormat, IN ULONG ClusterSize, IN OUT PFORMAT_CONTEXT Context)
NTSTATUS Fat16Format(IN HANDLE FileHandle, IN PPARTITION_INFORMATION PartitionInfo, IN PDISK_GEOMETRY DiskGeometry, IN PUNICODE_STRING Label, IN BOOLEAN QuickFormat, IN ULONG ClusterSize, IN OUT PFORMAT_CONTEXT Context)
NTSTATUS Fat32Format(IN HANDLE FileHandle, IN PPARTITION_INFORMATION PartitionInfo, IN PDISK_GEOMETRY DiskGeometry, IN PUNICODE_STRING Label, IN BOOLEAN QuickFormat, IN ULONG ClusterSize, IN OUT PFORMAT_CONTEXT Context)
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
#define FILE_SYNCHRONOUS_IO_ALERT
#define InitializeObjectAttributes(p, n, a, r, s)
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
#define FSCTL_LOCK_VOLUME
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define FSCTL_UNLOCK_VOLUME
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
#define FSCTL_DISMOUNT_VOLUME
NTSYSAPI NTSTATUS NTAPI NtFsControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define FILE_GENERIC_READ
#define FILE_GENERIC_WRITE
#define IOCTL_DISK_GET_PARTITION_INFO
#define STATUS_INVALID_PARAMETER
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo