ReactOS 0.4.16-dev-555-g690643f
fsutil.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Setup Library
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Filesystem Format and ChkDsk support functions
5 * COPYRIGHT: Copyright 2003-2019 Casper S. Hornstrup <chorns@users.sourceforge.net>
6 * Copyright 2017-2024 Hermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
7 */
8
9//
10// See also: https://git.reactos.org/?p=reactos.git;a=blob;f=reactos/dll/win32/fmifs/init.c;h=e895f5ef9cae4806123f6bbdd3dfed37ec1c8d33;hb=b9db9a4e377a2055f635b2fb69fef4e1750d219c
11// for how to get FS providers in a dynamic way. In the (near) future we may
12// consider merging some of this code with us into a fmifs / fsutil / fslib library...
13//
14
15/* INCLUDES *****************************************************************/
16
17#include "precomp.h"
18
19#include "partlist.h"
20#include "fsrec.h"
21#include "bootcode.h"
22#include "fsutil.h"
23
24#include <fslib/vfatlib.h>
25#include <fslib/btrfslib.h>
26// #include <fslib/ext2lib.h>
27// #include <fslib/ntfslib.h>
28
29#define NDEBUG
30#include <debug.h>
31
32
33/* TYPEDEFS *****************************************************************/
34
35#include <pshpack1.h>
36typedef struct _FAT_BOOTSECTOR
37{
38 UCHAR JumpBoot[3]; // Jump instruction to boot code
39 CHAR OemName[8]; // "MSWIN4.1" for MS formatted volumes
40 USHORT BytesPerSector; // Bytes per sector
41 UCHAR SectorsPerCluster; // Number of sectors in a cluster
42 USHORT ReservedSectors; // Reserved sectors, usually 1 (the bootsector)
43 UCHAR NumberOfFats; // Number of FAT tables
44 USHORT RootDirEntries; // Number of root directory entries (fat12/16)
45 USHORT TotalSectors; // Number of total sectors on the drive, 16-bit
46 UCHAR MediaDescriptor; // Media descriptor byte
47 USHORT SectorsPerFat; // Sectors per FAT table (fat12/16)
48 USHORT SectorsPerTrack; // Number of sectors in a track
49 USHORT NumberOfHeads; // Number of heads on the disk
50 ULONG HiddenSectors; // Hidden sectors (sectors before the partition start like the partition table)
51 ULONG TotalSectorsBig; // This field is the new 32-bit total count of sectors on the volume
52 UCHAR DriveNumber; // Int 0x13 drive number (e.g. 0x80)
53 UCHAR Reserved1; // Reserved (used by Windows NT). Code that formats FAT volumes should always set this byte to 0.
54 UCHAR BootSignature; // Extended boot signature (0x29). This is a signature byte that indicates that the following three fields in the boot sector are present.
55 ULONG VolumeSerialNumber; // Volume serial number
56 CHAR VolumeLabel[11]; // Volume label. This field matches the 11-byte volume label recorded in the root directory
57 CHAR FileSystemType[8]; // One of the strings "FAT12 ", "FAT16 ", or "FAT "
58
59 UCHAR BootCodeAndData[448]; // The remainder of the boot sector
60
62
65
66typedef struct _FAT32_BOOTSECTOR
67{
68 UCHAR JumpBoot[3]; // Jump instruction to boot code
69 CHAR OemName[8]; // "MSWIN4.1" for MS formatted volumes
70 USHORT BytesPerSector; // Bytes per sector
71 UCHAR SectorsPerCluster; // Number of sectors in a cluster
72 USHORT ReservedSectors; // Reserved sectors, usually 1 (the bootsector)
73 UCHAR NumberOfFats; // Number of FAT tables
74 USHORT RootDirEntries; // Number of root directory entries (fat12/16)
75 USHORT TotalSectors; // Number of total sectors on the drive, 16-bit
76 UCHAR MediaDescriptor; // Media descriptor byte
77 USHORT SectorsPerFat; // Sectors per FAT table (fat12/16)
78 USHORT SectorsPerTrack; // Number of sectors in a track
79 USHORT NumberOfHeads; // Number of heads on the disk
80 ULONG HiddenSectors; // Hidden sectors (sectors before the partition start like the partition table)
81 ULONG TotalSectorsBig; // This field is the new 32-bit total count of sectors on the volume
82 ULONG SectorsPerFatBig; // This field is the FAT32 32-bit count of sectors occupied by ONE FAT. BPB_FATSz16 must be 0
83 USHORT ExtendedFlags; // Extended flags (fat32)
84 USHORT FileSystemVersion; // File system version (fat32)
85 ULONG RootDirStartCluster; // Starting cluster of the root directory (fat32)
86 USHORT FsInfo; // Sector number of FSINFO structure in the reserved area of the FAT32 volume. Usually 1.
87 USHORT BackupBootSector; // If non-zero, indicates the sector number in the reserved area of the volume of a copy of the boot record. Usually 6.
88 UCHAR Reserved[12]; // Reserved for future expansion
89 UCHAR DriveNumber; // Int 0x13 drive number (e.g. 0x80)
90 UCHAR Reserved1; // Reserved (used by Windows NT). Code that formats FAT volumes should always set this byte to 0.
91 UCHAR BootSignature; // Extended boot signature (0x29). This is a signature byte that indicates that the following three fields in the boot sector are present.
92 ULONG VolumeSerialNumber; // Volume serial number
93 CHAR VolumeLabel[11]; // Volume label. This field matches the 11-byte volume label recorded in the root directory
94 CHAR FileSystemType[8]; // Always set to the string "FAT32 "
95
96 UCHAR BootCodeAndData[420]; // The remainder of the boot sector
97
99
102
103typedef struct _BTRFS_BOOTSECTOR
104{
109 UCHAR Fill[1521]; // 1536 - 15
113
114typedef struct _NTFS_BOOTSECTOR
115{
139 UCHAR BootCodeAndData[7680]; // The remainder of the boot sector (8192 - 512)
142
143// TODO: Add more bootsector structures!
144
145#include <poppack.h>
146
147
148/* LOCALS *******************************************************************/
149
151typedef struct _FILE_SYSTEM
152{
157
158/* The list of file systems on which we can install ReactOS */
160{
161 /* NOTE: The FAT formatter will automatically
162 * determine whether to use FAT12/16 or FAT32. */
163 { L"FAT" , VfatFormat, VfatChkdsk },
164 { L"FAT32", VfatFormat, VfatChkdsk },
165#if 0
166 { L"FATX" , VfatxFormat, VfatxChkdsk },
167 { L"NTFS" , NtfsFormat, NtfsChkdsk },
168#endif
169 { L"BTRFS", BtrfsFormat, BtrfsChkdsk },
170#if 0
171 { L"EXT2" , Ext2Format, Ext2Chkdsk },
172 { L"EXT3" , Ext2Format, Ext2Chkdsk },
173 { L"EXT4" , Ext2Format, Ext2Chkdsk },
174#endif
175};
176
177
178/* FUNCTIONS ****************************************************************/
179
182NTAPI
184 IN ULONG Index,
185 OUT PCWSTR* FileSystemName)
186{
188 return FALSE;
189
190 *FileSystemName = RegisteredFileSystems[Index].FileSystemName;
191
192 return TRUE;
193}
194
195
197static PFILE_SYSTEM
199 IN PCWSTR FileSystemName)
200{
201#if 0 // Reenable when the list of registered FSes will again be dynamic
202
203 PLIST_ENTRY ListEntry;
205
206 ListEntry = List->ListHead.Flink;
207 while (ListEntry != &List->ListHead)
208 {
209 Item = CONTAINING_RECORD(ListEntry, FILE_SYSTEM_ITEM, ListEntry);
210 if (Item->FileSystemName &&
211 (_wcsicmp(FileSystemName, Item->FileSystemName) == 0))
212 {
213 return Item;
214 }
215
216 ListEntry = ListEntry->Flink;
217 }
218
219#else
220
223
224 ASSERT(FileSystems && Count != 0);
225
226 while (Count--)
227 {
228 if (FileSystems->FileSystemName &&
229 (_wcsicmp(FileSystemName, FileSystems->FileSystemName) == 0))
230 {
231 return FileSystems;
232 }
233
234 ++FileSystems;
235 }
236
237#endif
238
239 return NULL;
240}
241
242
245NTAPI
247 _In_ PUNICODE_STRING DriveRoot,
248 _In_ PCWSTR FileSystemName,
251 _In_ BOOLEAN CheckOnlyIfDirty,
252 _In_ BOOLEAN ScanDrive,
254{
258
259 FileSystem = GetFileSystemByName(FileSystemName);
260
261 if (!FileSystem || !FileSystem->ChkdskFunc)
262 {
263 // Success = FALSE;
264 // Callback(DONE, 0, &Success);
266 }
267
269 Success = FileSystem->ChkdskFunc(DriveRoot,
270 Callback,
271 FixErrors,
272 Verbose,
273 CheckOnlyIfDirty,
274 ScanDrive,
275 NULL,
276 NULL,
277 NULL,
278 NULL,
279 (PULONG)&Status);
280 if (!Success)
281 DPRINT1("ChkdskFunc() failed with Status 0x%lx\n", Status);
282
283 // Callback(DONE, 0, &Success);
284
285 return Status;
286}
287
289NTAPI
291 _In_ PCWSTR DriveRoot,
292 _In_ PCWSTR FileSystemName,
295 _In_ BOOLEAN CheckOnlyIfDirty,
296 _In_ BOOLEAN ScanDrive,
298{
299 UNICODE_STRING DriveRootU;
300
301 RtlInitUnicodeString(&DriveRootU, DriveRoot);
302 return ChkdskFileSystem_UStr(&DriveRootU,
303 FileSystemName,
304 FixErrors,
305 Verbose,
306 CheckOnlyIfDirty,
307 ScanDrive,
308 Callback);
309}
310
311
314NTAPI
316 _In_ PUNICODE_STRING DriveRoot,
317 _In_ PCWSTR FileSystemName,
318 _In_ FMIFS_MEDIA_FLAG MediaFlag,
323{
326 BOOLEAN BackwardCompatible = FALSE; // Default to latest FS versions.
327 MEDIA_TYPE MediaType;
328
329 FileSystem = GetFileSystemByName(FileSystemName);
330
331 if (!FileSystem || !FileSystem->FormatFunc)
332 {
333 // Success = FALSE;
334 // Callback(DONE, 0, &Success);
336 }
337
338 /* Set the BackwardCompatible flag in case we format with older FAT12/16 */
339 if (_wcsicmp(FileSystemName, L"FAT") == 0)
340 BackwardCompatible = TRUE;
341 // else if (_wcsicmp(FileSystemName, L"FAT32") == 0)
342 // BackwardCompatible = FALSE;
343
344 /* Convert the FMIFS MediaFlag to a NT MediaType */
345 // FIXME: Actually covert all the possible flags.
346 switch (MediaFlag)
347 {
348 case FMIFS_FLOPPY:
349 MediaType = F5_320_1024; // FIXME: This is hardfixed!
350 break;
351 case FMIFS_REMOVABLE:
352 MediaType = RemovableMedia;
353 break;
354 case FMIFS_HARDDISK:
355 MediaType = FixedMedia;
356 break;
357 default:
358 DPRINT1("Unknown FMIFS MediaFlag %d, converting 1-to-1 to NT MediaType\n",
359 MediaFlag);
360 MediaType = (MEDIA_TYPE)MediaFlag;
361 break;
362 }
363
364 Success = FileSystem->FormatFunc(DriveRoot,
365 Callback,
367 BackwardCompatible,
368 MediaType,
369 Label,
371 if (!Success)
372 DPRINT1("FormatFunc() failed\n");
373
374 // Callback(DONE, 0, &Success);
375
377}
378
380NTAPI
382 _In_ PCWSTR DriveRoot,
383 _In_ PCWSTR FileSystemName,
384 _In_ FMIFS_MEDIA_FLAG MediaFlag,
389{
390 UNICODE_STRING DriveRootU;
391 UNICODE_STRING LabelU;
392
393 RtlInitUnicodeString(&DriveRootU, DriveRoot);
394 RtlInitUnicodeString(&LabelU, Label);
395
396 return FormatFileSystem_UStr(&DriveRootU,
397 FileSystemName,
398 MediaFlag,
399 &LabelU,
402 Callback);
403}
404
405
406//
407// Bootsector routines
408//
409
412 IN PCWSTR SrcPath, // FAT12/16 bootsector source file (on the installation medium)
413 IN HANDLE DstPath, // Where to save the bootsector built from the source + partition information
414 IN HANDLE RootPartition) // Partition holding the (old) FAT12/16 information
415{
420 BOOTCODE OrigBootSector = {0};
421 BOOTCODE NewBootSector = {0};
422
423 /* Allocate and read the current original partition bootsector */
424 Status = ReadBootCodeByHandle(&OrigBootSector,
427 if (!NT_SUCCESS(Status))
428 return Status;
429
430 /* Allocate and read the new bootsector from SrcPath */
431 RtlInitUnicodeString(&Name, SrcPath);
432 Status = ReadBootCodeFromFile(&NewBootSector,
433 &Name,
435 if (!NT_SUCCESS(Status))
436 {
437 FreeBootCode(&OrigBootSector);
438 return Status;
439 }
440
441 /* Adjust the bootsector (copy a part of the FAT12/16 BPB) */
442 RtlCopyMemory(&((PFAT_BOOTSECTOR)NewBootSector.BootCode)->OemName,
443 &((PFAT_BOOTSECTOR)OrigBootSector.BootCode)->OemName,
444 FIELD_OFFSET(FAT_BOOTSECTOR, BootCodeAndData) -
446
447 /* Free the original bootsector */
448 FreeBootCode(&OrigBootSector);
449
450 /* Write the new bootsector to DstPath */
451 FileOffset.QuadPart = 0ULL;
453 NULL,
454 NULL,
455 NULL,
457 NewBootSector.BootCode,
458 NewBootSector.Length,
459 &FileOffset,
460 NULL);
461
462 /* Free the new bootsector */
463 FreeBootCode(&NewBootSector);
464
465 return Status;
466}
467
470 IN PCWSTR SrcPath, // FAT32 bootsector source file (on the installation medium)
471 IN HANDLE DstPath, // Where to save the bootsector built from the source + partition information
472 IN HANDLE RootPartition) // Partition holding the (old) FAT32 information
473{
479 BOOTCODE OrigBootSector = {0};
480 BOOTCODE NewBootSector = {0};
481
482 /* Allocate and read the current original partition bootsector */
483 Status = ReadBootCodeByHandle(&OrigBootSector,
486 if (!NT_SUCCESS(Status))
487 return Status;
488
489 /* Allocate and read the new bootsector (2 sectors) from SrcPath */
490 RtlInitUnicodeString(&Name, SrcPath);
491 Status = ReadBootCodeFromFile(&NewBootSector,
492 &Name,
494 if (!NT_SUCCESS(Status))
495 {
496 FreeBootCode(&OrigBootSector);
497 return Status;
498 }
499
500 /* Adjust the bootsector (copy a part of the FAT32 BPB) */
501 RtlCopyMemory(&((PFAT32_BOOTSECTOR)NewBootSector.BootCode)->OemName,
502 &((PFAT32_BOOTSECTOR)OrigBootSector.BootCode)->OemName,
503 FIELD_OFFSET(FAT32_BOOTSECTOR, BootCodeAndData) -
505
506 /*
507 * We know we copy the boot code to a file only when DstPath != RootPartition,
508 * otherwise the boot code is copied to the specified root partition.
509 */
510 if (DstPath != RootPartition)
511 {
512 /* Copy to a file: Disable the backup bootsector */
513 ((PFAT32_BOOTSECTOR)NewBootSector.BootCode)->BackupBootSector = 0;
514 }
515 else
516 {
517 /* Copy to a disk: Get the location of the backup bootsector */
518 BackupBootSector = ((PFAT32_BOOTSECTOR)OrigBootSector.BootCode)->BackupBootSector;
519 }
520
521 /* Free the original bootsector */
522 FreeBootCode(&OrigBootSector);
523
524 /* Write the first sector of the new bootcode to DstPath sector 0 */
525 FileOffset.QuadPart = 0ULL;
527 NULL,
528 NULL,
529 NULL,
531 NewBootSector.BootCode,
533 &FileOffset,
534 NULL);
535 if (!NT_SUCCESS(Status))
536 {
537 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
538 FreeBootCode(&NewBootSector);
539 return Status;
540 }
541
542 if (DstPath == RootPartition)
543 {
544 /* Copy to a disk: Write the backup bootsector */
545 if ((BackupBootSector != 0x0000) && (BackupBootSector != 0xFFFF))
546 {
549 NULL,
550 NULL,
551 NULL,
553 NewBootSector.BootCode,
555 &FileOffset,
556 NULL);
557 if (!NT_SUCCESS(Status))
558 {
559 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
560 FreeBootCode(&NewBootSector);
561 return Status;
562 }
563 }
564 }
565
566 /* Write the second sector of the new bootcode to boot disk sector 14 */
567 // FileOffset.QuadPart = (ULONGLONG)(14 * FAT32_BOOTSECTOR_SIZE);
568 FileOffset.QuadPart = 14 * FAT32_BOOTSECTOR_SIZE;
569 Status = NtWriteFile(DstPath, // or really RootPartition ???
570 NULL,
571 NULL,
572 NULL,
574 ((PUCHAR)NewBootSector.BootCode + FAT32_BOOTSECTOR_SIZE),
576 &FileOffset,
577 NULL);
578 if (!NT_SUCCESS(Status))
579 {
580 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
581 }
582
583 /* Free the new bootsector */
584 FreeBootCode(&NewBootSector);
585
586 return Status;
587}
588
591 IN PCWSTR SrcPath, // BTRFS bootsector source file (on the installation medium)
592 IN HANDLE DstPath, // Where to save the bootsector built from the source + partition information
593 IN HANDLE RootPartition) // Partition holding the (old) BTRFS information
594{
596 NTSTATUS LockStatus;
601 BOOTCODE NewBootSector = {0};
602
603 /* Allocate and read the new bootsector from SrcPath */
604 RtlInitUnicodeString(&Name, SrcPath);
605 Status = ReadBootCodeFromFile(&NewBootSector,
606 &Name,
608 if (!NT_SUCCESS(Status))
609 return Status;
610
611 /*
612 * The BTRFS driver requires the volume to be locked in order to modify
613 * the first sectors of the partition, even though they are outside the
614 * file-system space / in the reserved area (they are situated before
615 * the super-block at 0x1000) and is in principle allowed by the NT
616 * storage stack.
617 * So we lock here in order to write the bootsector at sector 0.
618 * If locking fails, we ignore and continue nonetheless.
619 */
620 LockStatus = NtFsControlFile(DstPath,
621 NULL,
622 NULL,
623 NULL,
626 NULL,
627 0,
628 NULL,
629 0);
630 if (!NT_SUCCESS(LockStatus))
631 {
632 DPRINT1("WARNING: Failed to lock BTRFS volume for writing bootsector! Operations may fail! (Status 0x%lx)\n", LockStatus);
633 }
634
635 /* Obtain partition info and write it to the bootsector */
637 NULL,
638 NULL,
639 NULL,
642 NULL,
643 0,
644 &PartInfo,
645 sizeof(PartInfo));
646 if (!NT_SUCCESS(Status))
647 {
648 DPRINT1("IOCTL_DISK_GET_PARTITION_INFO_EX failed (Status %lx)\n", Status);
649 goto Quit;
650 }
651
652 /* Write new bootsector to RootPath */
653 ((PBTRFS_BOOTSECTOR)NewBootSector.BootCode)->PartitionStartLBA =
655
656 /* Write sector 0 */
657 FileOffset.QuadPart = 0ULL;
659 NULL,
660 NULL,
661 NULL,
663 NewBootSector.BootCode,
664 NewBootSector.Length,
665 &FileOffset,
666 NULL);
667 if (!NT_SUCCESS(Status))
668 {
669 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
670 goto Quit;
671 }
672
673Quit:
674 /* Unlock the volume */
675 LockStatus = NtFsControlFile(DstPath,
676 NULL,
677 NULL,
678 NULL,
681 NULL,
682 0,
683 NULL,
684 0);
685 if (!NT_SUCCESS(LockStatus))
686 {
687 DPRINT1("Failed to unlock BTRFS volume (Status 0x%lx)\n", LockStatus);
688 }
689
690 /* Free the new bootsector */
691 FreeBootCode(&NewBootSector);
692
693 return Status;
694}
695
698 IN PCWSTR SrcPath, // NTFS bootsector source file (on the installation medium)
699 IN HANDLE DstPath, // Where to save the bootsector built from the source + partition information
700 IN HANDLE RootPartition) // Partition holding the (old) NTFS information
701{
706 BOOTCODE OrigBootSector = {0};
707 BOOTCODE NewBootSector = {0};
708
709 /* Allocate and read the current original partition bootsector */
711 if (!NT_SUCCESS(Status))
712 {
713 DPRINT1("InstallNtfsBootCode: Status %lx\n", Status);
714 return Status;
715 }
716
717 /* Allocate and read the new bootsector (16 sectors) from SrcPath */
718 RtlInitUnicodeString(&Name, SrcPath);
720 if (!NT_SUCCESS(Status))
721 {
722 DPRINT1("InstallNtfsBootCode: Status %lx\n", Status);
723 FreeBootCode(&OrigBootSector);
724 return Status;
725 }
726
727 /* Adjust the bootsector (copy a part of the NTFS BPB) */
728 RtlCopyMemory(&((PNTFS_BOOTSECTOR)NewBootSector.BootCode)->OEMID,
729 &((PNTFS_BOOTSECTOR)OrigBootSector.BootCode)->OEMID,
731
732 /* Write sector 0 */
733 FileOffset.QuadPart = 0ULL;
735 NULL,
736 NULL,
737 NULL,
739 NewBootSector.BootCode,
740 NewBootSector.Length,
741 &FileOffset,
742 NULL);
743 if (!NT_SUCCESS(Status))
744 {
745 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
746 goto Quit;
747 }
748
749Quit:
750 /* Free the new bootsector */
751 FreeBootCode(&NewBootSector);
752
753 return Status;
754}
755
756
757//
758// Formatting routines
759//
760
762NTAPI
767 _In_ BOOLEAN CheckOnlyIfDirty,
768 _In_ BOOLEAN ScanDrive,
770{
771 /* Do not check a volume with an unknown file system */
772 if (!*Volume->FileSystem)
774
775 /* Check the volume */
776 DPRINT("Volume->DeviceName: %S\n", Volume->DeviceName);
777 return ChkdskFileSystem(Volume->DeviceName,
778 Volume->FileSystem,
779 FixErrors,
780 Verbose,
781 CheckOnlyIfDirty,
782 ScanDrive,
783 Callback);
784}
785
787NTAPI
789 _In_ PPARTENTRY PartEntry,
792 _In_ BOOLEAN CheckOnlyIfDirty,
793 _In_ BOOLEAN ScanDrive,
795{
796 ASSERT(PartEntry->IsPartitioned && PartEntry->PartitionNumber != 0);
797 ASSERT(PartEntry->Volume);
798
799 // if (!PartEntry->Volume) { check_raw_sectors(); } else { check_FS(); }
800
801 /* Check the associated volume */
802 return ChkdskVolume(&PartEntry->Volume->Info,
803 FixErrors,
804 Verbose,
805 CheckOnlyIfDirty,
806 ScanDrive,
807 Callback);
808}
809
811NTAPI
814 _In_ PCWSTR FileSystemName,
815 _In_ FMIFS_MEDIA_FLAG MediaFlag,
820{
822
823 if (!FileSystemName || !*FileSystemName)
824 {
825 DPRINT1("No file system specified\n");
827 }
828
829 /* Format the volume */
830 DPRINT("Volume->DeviceName: %S\n", Volume->DeviceName);
831 Status = FormatFileSystem(Volume->DeviceName,
832 FileSystemName,
833 MediaFlag,
834 Label,
837 Callback);
838 if (!NT_SUCCESS(Status))
839 return Status;
840
841 /* Set the new volume's file system and label */
842 RtlStringCbCopyW(Volume->FileSystem, sizeof(Volume->FileSystem), FileSystemName);
843 if (!Label) Label = L"";
844 RtlStringCbCopyW(Volume->VolumeLabel, sizeof(Volume->VolumeLabel), Label);
845
846 return STATUS_SUCCESS;
847}
848
850NTAPI
852 _In_ PPARTENTRY PartEntry,
853 _In_ PCWSTR FileSystemName,
854 _In_ FMIFS_MEDIA_FLAG MediaFlag,
859{
861 PDISKENTRY DiskEntry = PartEntry->DiskEntry;
863
864 ASSERT(PartEntry->IsPartitioned && PartEntry->PartitionNumber != 0);
865
866 if (!FileSystemName || !*FileSystemName)
867 {
868 DPRINT1("No file system specified\n");
870 }
871
872 /*
873 * Prepare the partition for formatting (for MBR disks, reset the
874 * partition type), and adjust the file system name in case of FAT
875 * vs. FAT32, depending on the geometry of the partition.
876 */
877
878// FIXME: Do this only if QuickFormat == FALSE? What about FAT handling?
879
880 /*
881 * Retrieve a partition type as a hint only. It will be used to determine
882 * whether to actually use FAT12/16 or FAT32 file system, depending on the
883 * geometry of the partition. If the partition resides on an MBR disk,
884 * the partition style will be reset to this value as well, unless the
885 * partition is OEM.
886 */
888 PartEntry->StartSector.QuadPart,
889 PartEntry->SectorCount.QuadPart);
891 {
892 /* Unknown file system */
893 DPRINT1("Unknown file system '%S'\n", FileSystemName);
895 }
896
897 /* Reset the MBR partition type, unless this is an OEM partition */
898 if (DiskEntry->DiskStyle == PARTITION_STYLE_MBR)
899 {
900 if (!IsOEMPartition(PartEntry->PartitionType))
902 }
903
904 /*
905 * Adjust the file system name in case of FAT vs. FAT32, according to
906 * the type of partition returned by FileSystemToMBRPartitionType().
907 */
908 if (_wcsicmp(FileSystemName, L"FAT") == 0)
909 {
912 {
913 FileSystemName = L"FAT32";
914 }
915 }
916
917 /* Commit the partition changes to the disk */
918 Status = WritePartitions(DiskEntry);
919 if (!NT_SUCCESS(Status))
920 {
921 DPRINT1("WritePartitions(disk %lu) failed, Status 0x%08lx\n",
922 DiskEntry->DiskNumber, Status);
924 }
925
926 /* We must have an associated volume now */
927 ASSERT(PartEntry->Volume);
928
929 /* Format the associated volume */
930 Status = FormatVolume(&PartEntry->Volume->Info,
931 FileSystemName,
932 MediaFlag,
933 Label,
936 Callback);
937 if (!NT_SUCCESS(Status))
938 return Status;
939
940 PartEntry->Volume->FormatState = Formatted;
941 PartEntry->Volume->New = FALSE;
942 return STATUS_SUCCESS;
943}
944
945
946//
947// FileSystem Volume Operations Queue
948//
949
950static FSVOL_OP
955{
958 PPARTENTRY PartEntry;
959 FORMAT_VOLUME_INFO FmtInfo = {0};
960
961 PartEntry = Volume->PartEntry;
962 ASSERT(PartEntry && (PartEntry->Volume == Volume));
963
964 FmtInfo.Volume = Volume;
965
966RetryFormat:
969 (ULONG_PTR)&FmtInfo,
971 if (Result != FSVOL_DOIT)
972 goto EndFormat;
973
974 ASSERT(FmtInfo.FileSystemName && *FmtInfo.FileSystemName);
975
976 /* Format the partition */
977 Status = FormatPartition(PartEntry,
978 FmtInfo.FileSystemName,
979 FmtInfo.MediaFlag,
980 FmtInfo.Label,
981 FmtInfo.QuickFormat,
982 FmtInfo.ClusterSize,
983 FmtInfo.Callback);
984 if (!NT_SUCCESS(Status))
985 {
986 // FmtInfo.NtPathPartition = PathBuffer;
987 FmtInfo.ErrorStatus = Status;
988
991 (ULONG_PTR)&FmtInfo,
992 0);
993 if (Result == FSVOL_RETRY)
994 goto RetryFormat;
995 // else if (Result == FSVOL_ABORT || Result == FSVOL_SKIP), stop.
996 }
997
999 /* This notification is always sent, even in case of error or abort */
1000 FmtInfo.ErrorStatus = Status;
1003 (ULONG_PTR)&FmtInfo,
1004 0);
1005 return Result;
1006}
1007
1008static FSVOL_OP
1013{
1016 CHECK_VOLUME_INFO ChkInfo = {0};
1017
1018 ASSERT(*Volume->Info.FileSystem);
1019
1020 ChkInfo.Volume = Volume;
1021
1022RetryCheck:
1025 (ULONG_PTR)&ChkInfo,
1026 FSVOL_CHECK);
1027 if (Result != FSVOL_DOIT)
1028 goto EndCheck;
1029
1030 /* Check the volume */
1031 Status = ChkdskVolume(&Volume->Info,
1032 ChkInfo.FixErrors,
1033 ChkInfo.Verbose,
1034 ChkInfo.CheckOnlyIfDirty,
1035 ChkInfo.ScanDrive,
1036 ChkInfo.Callback);
1037
1038 /* If volume checking succeeded, or if it is not supported
1039 * with the current file system, disable checks on the volume */
1041 Volume->NeedsCheck = FALSE;
1042
1043 if (!NT_SUCCESS(Status))
1044 {
1045 // ChkInfo.NtPathPartition = PathBuffer;
1046 ChkInfo.ErrorStatus = Status;
1047
1050 (ULONG_PTR)&ChkInfo,
1051 0);
1052 if (Result == FSVOL_RETRY)
1053 goto RetryCheck;
1054 // else if (Result == FSVOL_ABORT || Result == FSVOL_SKIP), stop.
1055
1056 // Volume->NeedsCheck = FALSE;
1057 }
1058
1059EndCheck:
1060 /* This notification is always sent, even in case of error or abort */
1061 ChkInfo.ErrorStatus = Status;
1064 (ULONG_PTR)&ChkInfo,
1065 0);
1066 return Result;
1067}
1068
1069static
1074{
1076
1077 for (;;)
1078 {
1079 /* If we have a current volume, get the next one, otherwise get the first */
1080 Entry = (Volume ? &Volume->ListEntry : &List->VolumesList);
1081 Entry = Entry->Flink;
1082
1083 if (Entry == &List->VolumesList)
1084 return NULL;
1085
1086 Volume = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
1087 if (Volume->New && (Volume->FormatState == Unformatted))
1088 {
1089 /* Found a candidate, return it */
1090 return Volume;
1091 }
1092 }
1093}
1094
1095BOOLEAN
1096NTAPI
1103{
1104 BOOLEAN Success = TRUE; // Suppose success originally.
1108
1109 /* Machine state for the format step */
1110 typedef enum _FORMATMACHINESTATE
1111 {
1112 Start,
1113 FormatSystemVolume,
1114 FormatInstallVolume,
1115 FormatOtherVolume,
1116 FormatDone
1117 } FORMATMACHINESTATE;
1118 FORMATMACHINESTATE FormatState, OldFormatState;
1119 static const PCSTR FormatStateNames[] = {
1120 "Start",
1121 "FormatSystemVolume",
1122 "FormatInstallVolume",
1123 "FormatOtherVolume",
1124 "FormatDone"
1125 };
1126
1128
1129 /* Commit all partition changes to all the disks */
1131 {
1132 DPRINT("WritePartitionsToDisk() failed\n");
1133 /* Result = */ FsVolCallback(Context,
1135 STATUS_PARTITION_FAILURE, // FIXME
1136 0);
1137 return FALSE;
1138 }
1139
1140//
1141// FIXME: Should we do the following here, or in the caller?
1142//
1143 /*
1144 * In all cases, whether or not we are going to perform a formatting,
1145 * we must perform a file system check of both the system and the
1146 * installation volumes.
1147 */
1148 SystemVolume->NeedsCheck = TRUE;
1149 InstallVolume->NeedsCheck = TRUE;
1150
1153 0, 0);
1154 if (Result == FSVOL_ABORT)
1155 return FALSE;
1156
1157 /*
1158 * Commit the Format queue
1159 */
1160
1164 0);
1165 if (Result == FSVOL_ABORT)
1166 return FALSE;
1168 if (Result == FSVOL_SKIP)
1169 goto StartCheckQueue;
1172 /* Reset the formatter machine state */
1173 FormatState = Start;
1174 Volume = NULL;
1175NextFormat:
1176 OldFormatState = FormatState;
1177 switch (FormatState)
1178 {
1179 case Start:
1180 {
1181 /*
1182 * We start by formatting the system volume in case it is new
1183 * (it didn't exist before) and is not the same as the installation
1184 * volume. Otherwise we just require a file system check on it,
1185 * and start by formatting the installation volume instead.
1186 */
1188 {
1190
1191 if (Volume->FormatState == Unformatted)
1192 {
1193 // TODO: Should we let the user use a custom file system,
1194 // or should we always use FAT(32) for it?
1195 // For "compatibility", FAT(32) would be best indeed.
1196
1197 FormatState = FormatSystemVolume;
1198 DPRINT1("FormatState: %s --> %s\n",
1199 FormatStateNames[OldFormatState], FormatStateNames[FormatState]);
1200 break;
1201 }
1202
1203 /* The system volume is separate, so it had better be formatted! */
1204 ASSERT(Volume->FormatState == Formatted);
1205
1206 /* Require a file system check on the system volume too */
1207 Volume->NeedsCheck = TRUE;
1208 }
1210 }
1211
1212 case FormatSystemVolume:
1213 {
1215
1216 FormatState = FormatInstallVolume;
1217 DPRINT1("FormatState: %s --> %s\n",
1218 FormatStateNames[OldFormatState], FormatStateNames[FormatState]);
1219 break;
1220 }
1221
1222 case FormatInstallVolume:
1223 /* Restart volume enumeration */
1224 Volume = NULL;
1225 case FormatOtherVolume:
1226 {
1228
1229 FormatState = (Volume ? FormatOtherVolume : FormatDone);
1230 DPRINT1("FormatState: %s --> %s\n",
1231 FormatStateNames[OldFormatState], FormatStateNames[FormatState]);
1232 if (Volume)
1233 break;
1235 }
1236
1237 case FormatDone:
1238 {
1239 DPRINT1("FormatState: FormatDone\n");
1240 Success = TRUE;
1241 goto EndFormat;
1242 }
1244 }
1245
1247 if (Result == FSVOL_ABORT)
1248 {
1249 Success = FALSE;
1250 goto Quit;
1251 }
1252 /* Schedule a check for this volume */
1253 Volume->NeedsCheck = TRUE;
1254 /* Go to the next volume to be formatted */
1255 goto NextFormat;
1256
1257EndFormat:
1261 0);
1262
1263
1264 /*
1265 * Commit the CheckFS queue
1266 */
1267
1268StartCheckQueue:
1272 0);
1273 if (Result == FSVOL_ABORT)
1274 return FALSE;
1275
1276 /* Loop through each unchecked volume and do the check */
1279 Entry = Entry->Flink)
1280 {
1281 Volume = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
1282 if (!Volume->NeedsCheck)
1283 continue;
1284
1285 /* Found a candidate */
1286 ASSERT(Volume->FormatState == Formatted);
1288 if (Result == FSVOL_ABORT)
1289 {
1290 Success = FALSE;
1291 goto Quit;
1292 }
1293 /* Go to the next volume to be checked */
1294 }
1295 Success = TRUE;
1296
1300 0);
1301
1302
1303Quit:
1304 /* All the queues have been committed */
1307 Success,
1308 0);
1309 return Success;
1310}
1311
1312/* EOF */
unsigned char BOOLEAN
struct NameRec_ * Name
Definition: cdprocs.h:460
FILESYSTEM_CHKDSK FileSystems[]
Definition: autochk.c:47
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
static FSVOL_OP CALLBACK FsVolCallback(_In_opt_ PVOID Context, _In_ FSVOLNOTIFY FormatStatus, _In_ ULONG_PTR Param1, _In_ ULONG_PTR Param2)
Definition: reactos.c:1291
#define SystemVolume
Definition: reactos.c:51
#define InstallVolume
Definition: reactos.c:46
BOOL FixErrors
Definition: chkdsk.c:69
BOOL Verbose
Definition: chkdsk.c:72
BOOL QuickFormat
Definition: format.c:66
PWCHAR Label
Definition: format.c:70
DWORD ClusterSize
Definition: format.c:67
PWCHAR FileSystem
Definition: format.c:72
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:87
#define PARTITION_FAT32
Definition: disk.h:96
#define PARTITION_FAT32_XINT13
Definition: disk.h:97
BOOL BackupBootSector(LPCTSTR lpszVolumeName)
Definition: install.c:61
VOID FreeBootCode(IN OUT PBOOTCODE BootCodeInfo)
Definition: bootcode.c:104
NTSTATUS ReadBootCodeByHandle(IN OUT PBOOTCODE BootCodeInfo, IN HANDLE FileHandle, IN ULONG Length OPTIONAL)
Definition: bootcode.c:21
NTSTATUS ReadBootCodeFromFile(IN OUT PBOOTCODE BootCodeInfo, IN PUNICODE_STRING FilePath, IN ULONG Length OPTIONAL)
Definition: bootcode.c:69
#define SECTORSIZE
Definition: bootcode.h:13
BOOLEAN NTAPI BtrfsFormat(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN QuickFormat, IN BOOLEAN BackwardCompatible, IN MEDIA_TYPE MediaType, IN PUNICODE_STRING Label, IN ULONG ClusterSize)
BOOLEAN NTAPI BtrfsChkdsk(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PVOID pUnknown1, IN PVOID pUnknown2, IN PVOID pUnknown3, IN PVOID pUnknown4, IN PULONG ExitStatus)
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
@ Success
Definition: eventcreate.c:712
BOOLEAN NTAPI Ext2Chkdsk(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PVOID pUnknown1, IN PVOID pUnknown2, IN PVOID pUnknown3, IN PVOID pUnknown4, IN PULONG ExitStatus)
Definition: Mke2fs.c:1007
BOOLEAN NTAPI Ext2Format(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN QuickFormat, IN BOOLEAN BackwardCompatible, IN MEDIA_TYPE MediaType, IN PUNICODE_STRING Label, IN ULONG ClusterSize)
Definition: Mke2fs.c:803
IN PDCB IN POEM_STRING OemName
Definition: fatprocs.h:1305
#define IOCTL_DISK_GET_PARTITION_INFO_EX
Definition: ntddk_ex.h:206
FMIFS_MEDIA_FLAG
Definition: fmifs.h:52
@ FMIFS_FLOPPY
Definition: fmifs.h:61
@ FMIFS_REMOVABLE
Definition: fmifs.h:64
@ FMIFS_HARDDISK
Definition: fmifs.h:65
BOOLEAN(NTAPI * PULIB_FORMAT)(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN QuickFormat, IN BOOLEAN BackwardCompatible, IN MEDIA_TYPE MediaType, IN PUNICODE_STRING Label, IN ULONG ClusterSize)
Definition: fmifs.h:232
BOOLEAN(NTAPI * PULIB_CHKDSK)(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PVOID pUnknown1, IN PVOID pUnknown2, IN PVOID pUnknown3, IN PVOID pUnknown4, IN PULONG ExitStatus)
Definition: fmifs.h:216
BOOLEAN(NTAPI * PFMIFSCALLBACK)(IN CALLBACKCOMMAND Command, IN ULONG SubAction, IN PVOID ActionInfo)
Definition: fmifs.h:103
VOID EndCheck(_In_ NTSTATUS Status)
Definition: fmtchk.c:150
VOID EndFormat(_In_ NTSTATUS Status)
Definition: fmtchk.c:97
UCHAR FileSystemToMBRPartitionType(IN PCWSTR FileSystem, IN ULONGLONG StartSector, IN ULONGLONG SectorCount)
Definition: fsrec.c:333
return pTarget Start()
Status
Definition: gdiplustypes.h:25
BOOLEAN NTAPI VfatChkdsk(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PVOID pUnknown1, IN PVOID pUnknown2, IN PVOID pUnknown3, IN PVOID pUnknown4, IN PULONG ExitStatus)
Definition: vfatlib.c:374
BOOLEAN NTAPI VfatFormat(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN QuickFormat, IN BOOLEAN BackwardCompatible, IN MEDIA_TYPE MediaType, IN PUNICODE_STRING Label, IN ULONG ClusterSize)
Definition: vfatlib.c:50
BOOLEAN NTAPI VfatxChkdsk(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PVOID pUnknown1, IN PVOID pUnknown2, IN PVOID pUnknown3, IN PVOID pUnknown4, IN PULONG ExitStatus)
Definition: vfatxlib.c:162
BOOLEAN NTAPI VfatxFormat(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN QuickFormat, IN BOOLEAN BackwardCompatible, IN MEDIA_TYPE MediaType, IN PUNICODE_STRING Label, IN ULONG ClusterSize)
Definition: vfatxlib.c:20
#define C_ASSERT(e)
Definition: intsafe.h:73
#define IsOEMPartition(PartitionType)
Definition: partlist.h:22
@ Formatted
Definition: partlist.h:37
@ Unformatted
Definition: partlist.h:34
UNICODE_STRING Volume
Definition: fltkernel.h:1172
#define ASSERT(a)
Definition: mode.c:44
@ PARTITION_STYLE_MBR
Definition: imports.h:201
#define ULL(a, b)
Definition: format_msg.c:27
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
int Count
Definition: noreturn.cpp:7
#define FSCTL_LOCK_VOLUME
Definition: nt_native.h:832
NTSYSAPI NTSTATUS NTAPI NtWriteFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID WriteBuffer, IN ULONG WriteBufferLength, IN PLARGE_INTEGER FileOffset OPTIONAL, IN PULONG LockOperationKey OPTIONAL)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
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
Definition: nt_native.h:833
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 DEFAULT_UNREACHABLE
enum _MEDIA_TYPE MEDIA_TYPE
@ RemovableMedia
Definition: ntdddisk.h:382
@ FixedMedia
Definition: ntdddisk.h:383
@ F5_320_1024
Definition: ntdddisk.h:379
BOOLEAN NTAPI NtfsChkdsk(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PVOID pUnknown1, IN PVOID pUnknown2, IN PVOID pUnknown3, IN PVOID pUnknown4, IN PULONG ExitStatus)
Definition: ntfslib.c:33
BOOLEAN NTAPI NtfsFormat(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN QuickFormat, IN BOOLEAN BackwardCompatible, IN MEDIA_TYPE MediaType, IN PUNICODE_STRING Label, IN ULONG ClusterSize)
Definition: ntfslib.c:18
#define STATUS_PARTITION_FAILURE
Definition: ntstatus.h:604
NTSTRSAFEAPI RtlStringCbCopyW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:174
#define L(x)
Definition: ntvdm.h:50
CHAR PartitionType
Definition: part_xbox.c:32
unsigned short USHORT
Definition: pedump.c:61
#define __fallthrough
Definition: sal_old.h:314
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
NTSTATUS InstallFat32BootCode(IN PCWSTR SrcPath, IN HANDLE DstPath, IN HANDLE RootPartition)
Definition: fsutil.c:469
struct _BTRFS_BOOTSECTOR * PBTRFS_BOOTSECTOR
NTSTATUS NTAPI FormatFileSystem(_In_ PCWSTR DriveRoot, _In_ PCWSTR FileSystemName, _In_ FMIFS_MEDIA_FLAG MediaFlag, _In_opt_ PCWSTR Label, _In_ BOOLEAN QuickFormat, _In_ ULONG ClusterSize, _In_opt_ PFMIFSCALLBACK Callback)
Definition: fsutil.c:381
static FSVOL_OP DoChecking(_In_ PVOLENTRY Volume, _In_opt_ PVOID Context, _In_opt_ PFSVOL_CALLBACK FsVolCallback)
Definition: fsutil.c:1009
struct _FILE_SYSTEM FILE_SYSTEM
BOOLEAN NTAPI GetRegisteredFileSystems(IN ULONG Index, OUT PCWSTR *FileSystemName)
Definition: fsutil.c:183
static FILE_SYSTEM RegisteredFileSystems[]
Definition: fsutil.c:159
static FSVOL_OP DoFormatting(_In_ PVOLENTRY Volume, _In_opt_ PVOID Context, _In_opt_ PFSVOL_CALLBACK FsVolCallback)
Definition: fsutil.c:951
NTSTATUS NTAPI ChkdskFileSystem(_In_ PCWSTR DriveRoot, _In_ PCWSTR FileSystemName, _In_ BOOLEAN FixErrors, _In_ BOOLEAN Verbose, _In_ BOOLEAN CheckOnlyIfDirty, _In_ BOOLEAN ScanDrive, _In_opt_ PFMIFSCALLBACK Callback)
Definition: fsutil.c:290
struct _BTRFS_BOOTSECTOR BTRFS_BOOTSECTOR
NTSTATUS NTAPI ChkdskVolume(_In_ PVOLINFO Volume, _In_ BOOLEAN FixErrors, _In_ BOOLEAN Verbose, _In_ BOOLEAN CheckOnlyIfDirty, _In_ BOOLEAN ScanDrive, _In_opt_ PFMIFSCALLBACK Callback)
Definition: fsutil.c:763
struct _NTFS_BOOTSECTOR * PNTFS_BOOTSECTOR
NTSTATUS NTAPI FormatFileSystem_UStr(_In_ PUNICODE_STRING DriveRoot, _In_ PCWSTR FileSystemName, _In_ FMIFS_MEDIA_FLAG MediaFlag, _In_opt_ PUNICODE_STRING Label, _In_ BOOLEAN QuickFormat, _In_ ULONG ClusterSize, _In_opt_ PFMIFSCALLBACK Callback)
Definition: fsutil.c:315
NTSTATUS InstallBtrfsBootCode(IN PCWSTR SrcPath, IN HANDLE DstPath, IN HANDLE RootPartition)
Definition: fsutil.c:590
static PVOLENTRY GetNextUnformattedVolume(_In_ PPARTLIST List, _In_opt_ PVOLENTRY Volume)
Definition: fsutil.c:1071
BOOLEAN NTAPI FsVolCommitOpsQueue(_In_ PPARTLIST PartitionList, _In_ PVOLENTRY SystemVolume, _In_ PVOLENTRY InstallVolume, _In_opt_ PFSVOL_CALLBACK FsVolCallback, _In_opt_ PVOID Context)
Definition: fsutil.c:1097
NTSTATUS InstallNtfsBootCode(IN PCWSTR SrcPath, IN HANDLE DstPath, IN HANDLE RootPartition)
Definition: fsutil.c:697
struct _FAT32_BOOTSECTOR * PFAT32_BOOTSECTOR
struct _FILE_SYSTEM * PFILE_SYSTEM
NTSTATUS NTAPI FormatVolume(_In_ PVOLINFO Volume, _In_ PCWSTR FileSystemName, _In_ FMIFS_MEDIA_FLAG MediaFlag, _In_opt_ PCWSTR Label, _In_ BOOLEAN QuickFormat, _In_ ULONG ClusterSize, _In_opt_ PFMIFSCALLBACK Callback)
Definition: fsutil.c:812
struct _FAT32_BOOTSECTOR FAT32_BOOTSECTOR
struct _FAT_BOOTSECTOR * PFAT_BOOTSECTOR
NTSTATUS InstallFatBootCode(IN PCWSTR SrcPath, IN HANDLE DstPath, IN HANDLE RootPartition)
Definition: fsutil.c:411
struct _NTFS_BOOTSECTOR NTFS_BOOTSECTOR
NTSTATUS NTAPI FormatPartition(_In_ PPARTENTRY PartEntry, _In_ PCWSTR FileSystemName, _In_ FMIFS_MEDIA_FLAG MediaFlag, _In_opt_ PCWSTR Label, _In_ BOOLEAN QuickFormat, _In_ ULONG ClusterSize, _In_opt_ PFMIFSCALLBACK Callback)
Definition: fsutil.c:851
static PFILE_SYSTEM GetFileSystemByName(IN PCWSTR FileSystemName)
Definition: fsutil.c:198
NTSTATUS NTAPI ChkdskPartition(_In_ PPARTENTRY PartEntry, _In_ BOOLEAN FixErrors, _In_ BOOLEAN Verbose, _In_ BOOLEAN CheckOnlyIfDirty, _In_ BOOLEAN ScanDrive, _In_opt_ PFMIFSCALLBACK Callback)
Definition: fsutil.c:788
NTSTATUS NTAPI ChkdskFileSystem_UStr(_In_ PUNICODE_STRING DriveRoot, _In_ PCWSTR FileSystemName, _In_ BOOLEAN FixErrors, _In_ BOOLEAN Verbose, _In_ BOOLEAN CheckOnlyIfDirty, _In_ BOOLEAN ScanDrive, _In_opt_ PFMIFSCALLBACK Callback)
Definition: fsutil.c:246
struct _FAT_BOOTSECTOR FAT_BOOTSECTOR
@ FSVOLNOTIFY_STARTCHECK
Definition: fsutil.h:153
@ FSVOLNOTIFY_ENDQUEUE
Definition: fsutil.h:145
@ FSVOLNOTIFY_STARTSUBQUEUE
Definition: fsutil.h:146
@ FSVOLNOTIFY_ENDFORMAT
Definition: fsutil.h:151
@ FSVOLNOTIFY_STARTFORMAT
Definition: fsutil.h:150
@ FSVOLNOTIFY_STARTQUEUE
Definition: fsutil.h:144
@ FSVOLNOTIFY_ENDSUBQUEUE
Definition: fsutil.h:147
@ FSVOLNOTIFY_PARTITIONERROR
Definition: fsutil.h:149
@ FSVOLNOTIFY_CHECKERROR
Definition: fsutil.h:155
@ FSVOLNOTIFY_FORMATERROR
Definition: fsutil.h:152
@ FSVOLNOTIFY_ENDCHECK
Definition: fsutil.h:154
IN HANDLE IN HANDLE RootPartition
Definition: fsutil.h:82
#define NTFS_BOOTSECTOR_SIZE
Definition: fsutil.h:76
enum _FSVOL_OP FSVOL_OP
#define FAT_BOOTSECTOR_SIZE
Definition: fsutil.h:73
@ FSVOL_FORMAT
Definition: fsutil.h:162
@ FSVOL_CHECK
Definition: fsutil.h:163
@ FSVOL_DOIT
Definition: fsutil.h:166
@ FSVOL_ABORT
Definition: fsutil.h:165
@ FSVOL_RETRY
Definition: fsutil.h:167
@ FSVOL_SKIP
Definition: fsutil.h:168
#define FAT32_BOOTSECTOR_SIZE
Definition: fsutil.h:74
#define BTRFS_BOOTSECTOR_SIZE
Definition: fsutil.h:75
IN HANDLE DstPath
Definition: fsutil.h:81
FSVOL_OP(CALLBACK * PFSVOL_CALLBACK)(_In_opt_ PVOID Context, _In_ FSVOLNOTIFY FormatStatus, _In_ ULONG_PTR Param1, _In_ ULONG_PTR Param2)
Definition: fsutil.h:203
BOOLEAN WritePartitionsToDisk(IN PPARTLIST List)
Definition: partlist.c:3753
VOID SetMBRPartitionType(IN PPARTENTRY PartEntry, IN UCHAR PartitionType)
Definition: partlist.c:3899
NTSTATUS WritePartitions(IN PDISKENTRY DiskEntry)
Definition: partlist.c:3590
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
base of all file and directory entries
Definition: entries.h:83
ULONG Length
Definition: bootcode.h:18
PVOID BootCode
Definition: bootcode.h:17
USHORT BootSectorMagic
Definition: fsutil.c:110
UCHAR BootDrive
Definition: fsutil.c:107
UCHAR ChunkMapSize
Definition: fsutil.c:106
UCHAR JumpBoot[3]
Definition: fsutil.c:105
ULONGLONG PartitionStartLBA
Definition: fsutil.c:108
UCHAR Fill[1521]
Definition: fsutil.c:109
BOOLEAN Verbose
Definition: fsutil.h:195
NTSTATUS ErrorStatus
Definition: fsutil.h:191
PVOLENTRY Volume
Definition: fsutil.h:189
PFMIFSCALLBACK Callback
Definition: fsutil.h:198
BOOLEAN CheckOnlyIfDirty
Definition: fsutil.h:196
BOOLEAN FixErrors
Definition: fsutil.h:194
BOOLEAN ScanDrive
Definition: fsutil.h:197
ULONG DiskNumber
Definition: partlist.h:129
PARTITION_STYLE DiskStyle
Definition: partlist.h:139
USHORT BootSectorMagic
Definition: fsutil.c:98
UCHAR BootCodeAndData[420]
Definition: fsutil.c:96
CHAR FileSystemType[8]
Definition: fsutil.c:94
UCHAR MediaDescriptor
Definition: fsutil.c:76
ULONG HiddenSectors
Definition: fsutil.c:80
UCHAR NumberOfFats
Definition: fsutil.c:73
ULONG VolumeSerialNumber
Definition: fsutil.c:92
CHAR VolumeLabel[11]
Definition: fsutil.c:93
USHORT ExtendedFlags
Definition: fsutil.c:83
ULONG SectorsPerFatBig
Definition: fsutil.c:82
UCHAR JumpBoot[3]
Definition: fsutil.c:68
CHAR OemName[8]
Definition: fsutil.c:69
USHORT NumberOfHeads
Definition: fsutil.c:79
USHORT ReservedSectors
Definition: fsutil.c:72
USHORT RootDirEntries
Definition: fsutil.c:74
USHORT FsInfo
Definition: fsutil.c:86
USHORT BytesPerSector
Definition: fsutil.c:70
USHORT FileSystemVersion
Definition: fsutil.c:84
ULONG TotalSectorsBig
Definition: fsutil.c:81
UCHAR BootSignature
Definition: fsutil.c:91
ULONG RootDirStartCluster
Definition: fsutil.c:85
UCHAR DriveNumber
Definition: fsutil.c:89
UCHAR SectorsPerCluster
Definition: fsutil.c:71
USHORT SectorsPerFat
Definition: fsutil.c:77
USHORT SectorsPerTrack
Definition: fsutil.c:78
UCHAR Reserved1
Definition: fsutil.c:90
USHORT BackupBootSector
Definition: fsutil.c:87
USHORT TotalSectors
Definition: fsutil.c:75
ULONG TotalSectorsBig
Definition: fsutil.c:51
UCHAR JumpBoot[3]
Definition: fsutil.c:38
USHORT SectorsPerTrack
Definition: fsutil.c:48
USHORT TotalSectors
Definition: fsutil.c:45
UCHAR NumberOfFats
Definition: fsutil.c:43
CHAR VolumeLabel[11]
Definition: fsutil.c:56
USHORT NumberOfHeads
Definition: fsutil.c:49
USHORT SectorsPerFat
Definition: fsutil.c:47
CHAR OemName[8]
Definition: fsutil.c:39
USHORT ReservedSectors
Definition: fsutil.c:42
ULONG HiddenSectors
Definition: fsutil.c:50
CHAR FileSystemType[8]
Definition: fsutil.c:57
USHORT BytesPerSector
Definition: fsutil.c:40
USHORT RootDirEntries
Definition: fsutil.c:44
ULONG VolumeSerialNumber
Definition: fsutil.c:55
UCHAR MediaDescriptor
Definition: fsutil.c:46
USHORT BootSectorMagic
Definition: fsutil.c:61
UCHAR Reserved1
Definition: fsutil.c:53
UCHAR BootCodeAndData[448]
Definition: fsutil.c:59
UCHAR DriveNumber
Definition: fsutil.c:52
UCHAR BootSignature
Definition: fsutil.c:54
UCHAR SectorsPerCluster
Definition: fsutil.c:41
PULIB_CHKDSK ChkdskFunc
Definition: fsutil.c:155
PCWSTR FileSystemName
Definition: fsutil.c:153
PULIB_FORMAT FormatFunc
Definition: fsutil.c:154
PFMIFSCALLBACK Callback
Definition: fsutil.h:183
BOOLEAN QuickFormat
Definition: fsutil.h:181
NTSTATUS ErrorStatus
Definition: fsutil.h:175
PVOLENTRY Volume
Definition: fsutil.h:173
FMIFS_MEDIA_FLAG MediaFlag
Definition: fsutil.h:179
PCWSTR FileSystemName
Definition: fsutil.h:178
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
USHORT Heads
Definition: fsutil.c:124
ULONGLONG SectorCount
Definition: fsutil.c:128
UCHAR Unused4[3]
Definition: fsutil.c:132
UCHAR Unused3[4]
Definition: fsutil.c:126
UCHAR MediaId
Definition: fsutil.c:121
UCHAR Checksum[4]
Definition: fsutil.c:136
USHORT Unknown[2]
Definition: fsutil.c:127
ULONGLONG SerialNumber
Definition: fsutil.c:135
UCHAR SectorsPerCluster
Definition: fsutil.c:119
CHAR ClustersPerMftRecord
Definition: fsutil.c:131
UCHAR Unused1[2]
Definition: fsutil.c:122
UCHAR Jump[3]
Definition: fsutil.c:116
UCHAR BootCodeAndData[7680]
Definition: fsutil.c:139
USHORT BytesPerSector
Definition: fsutil.c:118
UCHAR Unused0[7]
Definition: fsutil.c:120
UCHAR OEMID[8]
Definition: fsutil.c:117
UCHAR BootStrap[426]
Definition: fsutil.c:137
ULONGLONG MftMirrLocation
Definition: fsutil.c:130
USHORT EndSector
Definition: fsutil.c:138
CHAR ClustersPerIndexRecord
Definition: fsutil.c:133
ULONGLONG MftLocation
Definition: fsutil.c:129
USHORT SectorsPerTrack
Definition: fsutil.c:123
UCHAR Unused2[4]
Definition: fsutil.c:125
UCHAR Unused5[3]
Definition: fsutil.c:134
PVOLENTRY Volume
Definition: partlist.h:95
LARGE_INTEGER StartingOffset
Definition: imports.h:221
LIST_ENTRY VolumesList
Definition: partlist.h:187
uint32_t * PULONG
Definition: typedefs.h:59
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NTAPI
Definition: typedefs.h:36
const char * PCSTR
Definition: typedefs.h:52
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#define OUT
Definition: typedefs.h:40
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
LONGLONG QuadPart
Definition: typedefs.h:114
static PPARTLIST PartitionList
Definition: usetup.c:74
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
unsigned char UCHAR
Definition: xmlstorage.h:181
char CHAR
Definition: xmlstorage.h:175