206 while (ListEntry != &
List->ListHead)
209 if (
Item->FileSystemName &&
215 ListEntry = ListEntry->
Flink;
335 if (
_wcsicmp(FileSystemName,
L"FAT") == 0)
336 BackwardCompatible =
TRUE;
354 DPRINT1(
"Unknown FMIFS MediaFlag %d, converting 1-to-1 to NT MediaType\n",
368 DPRINT1(
"FormatFunc() failed\n");
627 DPRINT1(
"WARNING: Failed to lock BTRFS volume for writing bootsector! Operations may fail! (Status 0x%lx)\n", LockStatus);
643 DPRINT1(
"IOCTL_DISK_GET_PARTITION_INFO_EX failed (Status %lx)\n",
Status);
682 DPRINT1(
"Failed to unlock BTRFS volume (Status 0x%lx)\n", LockStatus);
789 ASSERT(PartEntry->IsPartitioned && PartEntry->PartitionNumber != 0);
790 ASSERT(PartEntry->Volume);
815 if (!FileSystemName || !*FileSystemName)
817 DPRINT1(
"No file system specified\n");
855 ASSERT(PartEntry->IsPartitioned && PartEntry->PartitionNumber != 0);
857 if (!FileSystemName || !*FileSystemName)
859 DPRINT1(
"No file system specified\n");
879 PartEntry->StartSector.QuadPart,
880 PartEntry->SectorCount.QuadPart);
884 DPRINT1(
"Unknown file system '%S'\n", FileSystemName);
899 if (
_wcsicmp(FileSystemName,
L"FAT") == 0)
904 FileSystemName =
L"FAT32";
912 DPRINT1(
"WritePartitions(disk %lu) failed, Status 0x%08lx\n",
918 ASSERT(PartEntry->Volume);
931 PartEntry->Volume->FormatState =
Formatted;
932 PartEntry->Volume->New =
FALSE;
952 PartEntry =
Volume->PartEntry;
1100 typedef enum _FORMATMACHINESTATE
1104 FormatInstallVolume,
1107 } FORMATMACHINESTATE;
1108 FORMATMACHINESTATE FormatState, OldFormatState;
1109 static const PCSTR FormatStateNames[] = {
1111 "FormatSystemVolume",
1112 "FormatInstallVolume",
1113 "FormatOtherVolume",
1122 DPRINT(
"WritePartitionsToDisk() failed\n");
1159 goto StartCheckQueue;
1163 FormatState =
Start;
1166 OldFormatState = FormatState;
1167 switch (FormatState)
1187 FormatState = FormatSystemVolume;
1188 DPRINT1(
"FormatState: %s --> %s\n",
1189 FormatStateNames[OldFormatState], FormatStateNames[FormatState]);
1202 case FormatSystemVolume:
1206 FormatState = FormatInstallVolume;
1207 DPRINT1(
"FormatState: %s --> %s\n",
1208 FormatStateNames[OldFormatState], FormatStateNames[FormatState]);
1212 case FormatInstallVolume:
1215 case FormatOtherVolume:
1219 FormatState = (
Volume ? FormatOtherVolume : FormatDone);
1220 DPRINT1(
"FormatState: %s --> %s\n",
1221 FormatStateNames[OldFormatState], FormatStateNames[FormatState]);
1229 DPRINT1(
"FormatState: FormatDone\n");
FILESYSTEM_CHKDSK FileSystems[]
static FSVOL_OP CALLBACK FsVolCallback(_In_opt_ PVOID Context, _In_ FSVOLNOTIFY FormatStatus, _In_ ULONG_PTR Param1, _In_ ULONG_PTR Param2)
#define PARTITION_ENTRY_UNUSED
#define PARTITION_FAT32_XINT13
BOOL BackupBootSector(LPCTSTR lpszVolumeName)
VOID FreeBootCode(IN OUT PBOOTCODE BootCodeInfo)
NTSTATUS ReadBootCodeByHandle(IN OUT PBOOTCODE BootCodeInfo, IN HANDLE FileHandle, IN ULONG Length OPTIONAL)
NTSTATUS ReadBootCodeFromFile(IN OUT PBOOTCODE BootCodeInfo, IN PUNICODE_STRING FilePath, IN ULONG Length OPTIONAL)
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
#define NT_SUCCESS(StatCode)
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)
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)
IN PDCB IN POEM_STRING OemName
#define IOCTL_DISK_GET_PARTITION_INFO_EX
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)
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)
BOOLEAN(NTAPI * PFMIFSCALLBACK)(IN CALLBACKCOMMAND Command, IN ULONG SubAction, IN PVOID ActionInfo)
VOID EndCheck(_In_ NTSTATUS Status)
VOID EndFormat(_In_ NTSTATUS Status)
UCHAR FileSystemToMBRPartitionType(IN PCWSTR FileSystem, IN ULONGLONG StartSector, IN ULONGLONG SectorCount)
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)
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)
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)
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)
#define IsOEMPartition(PartitionType)
static OUT PIO_STATUS_BLOCK IoStatusBlock
#define FSCTL_LOCK_VOLUME
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
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
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)
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)
#define STATUS_NOT_SUPPORTED
#define STATUS_PARTITION_FAILURE
NTSTRSAFEAPI RtlStringCbCopyW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
_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)
struct _BTRFS_BOOTSECTOR * PBTRFS_BOOTSECTOR
static FSVOL_OP DoChecking(_In_ PVOLENTRY Volume, _In_opt_ PVOID Context, _In_opt_ PFSVOL_CALLBACK FsVolCallback)
NTSTATUS 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)
struct _FILE_SYSTEM FILE_SYSTEM
static FILE_SYSTEM RegisteredFileSystems[]
NTSTATUS 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)
static FSVOL_OP DoFormatting(_In_ PVOLENTRY Volume, _In_opt_ PVOID Context, _In_opt_ PFSVOL_CALLBACK FsVolCallback)
struct _BTRFS_BOOTSECTOR BTRFS_BOOTSECTOR
struct _NTFS_BOOTSECTOR * PNTFS_BOOTSECTOR
NTSTATUS InstallBtrfsBootCode(IN PCWSTR SrcPath, IN HANDLE DstPath, IN HANDLE RootPartition)
static PVOLENTRY GetNextUnformattedVolume(_In_ PPARTLIST List, _In_opt_ PVOLENTRY Volume)
BOOLEAN GetRegisteredFileSystems(IN ULONG Index, OUT PCWSTR *FileSystemName)
NTSTATUS InstallNtfsBootCode(IN PCWSTR SrcPath, IN HANDLE DstPath, IN HANDLE RootPartition)
struct _FAT32_BOOTSECTOR * PFAT32_BOOTSECTOR
struct _FILE_SYSTEM * PFILE_SYSTEM
NTSTATUS ChkdskPartition(_In_ PPARTENTRY PartEntry, _In_ BOOLEAN FixErrors, _In_ BOOLEAN Verbose, _In_ BOOLEAN CheckOnlyIfDirty, _In_ BOOLEAN ScanDrive, _In_opt_ PFMIFSCALLBACK Callback)
struct _FAT32_BOOTSECTOR FAT32_BOOTSECTOR
NTSTATUS 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)
struct _FAT_BOOTSECTOR * PFAT_BOOTSECTOR
NTSTATUS InstallFatBootCode(IN PCWSTR SrcPath, IN HANDLE DstPath, IN HANDLE RootPartition)
NTSTATUS 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)
NTSTATUS ChkdskFileSystem(_In_ PCWSTR DriveRoot, _In_ PCWSTR FileSystemName, _In_ BOOLEAN FixErrors, _In_ BOOLEAN Verbose, _In_ BOOLEAN CheckOnlyIfDirty, _In_ BOOLEAN ScanDrive, _In_opt_ PFMIFSCALLBACK Callback)
struct _NTFS_BOOTSECTOR NTFS_BOOTSECTOR
BOOLEAN FsVolCommitOpsQueue(_In_ PPARTLIST PartitionList, _In_ PVOLENTRY SystemVolume, _In_ PVOLENTRY InstallVolume, _In_opt_ PFSVOL_CALLBACK FsVolCallback, _In_opt_ PVOID Context)
static PFILE_SYSTEM GetFileSystemByName(IN PCWSTR FileSystemName)
NTSTATUS ChkdskVolume(_In_ PVOLINFO Volume, _In_ BOOLEAN FixErrors, _In_ BOOLEAN Verbose, _In_ BOOLEAN CheckOnlyIfDirty, _In_ BOOLEAN ScanDrive, _In_opt_ PFMIFSCALLBACK Callback)
NTSTATUS 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)
struct _FAT_BOOTSECTOR FAT_BOOTSECTOR
@ FSVOLNOTIFY_STARTSUBQUEUE
@ FSVOLNOTIFY_STARTFORMAT
@ FSVOLNOTIFY_ENDSUBQUEUE
@ FSVOLNOTIFY_PARTITIONERROR
@ FSVOLNOTIFY_FORMATERROR
IN HANDLE IN HANDLE RootPartition
#define NTFS_BOOTSECTOR_SIZE
#define FAT_BOOTSECTOR_SIZE
#define FAT32_BOOTSECTOR_SIZE
#define BTRFS_BOOTSECTOR_SIZE
FSVOL_OP(CALLBACK * PFSVOL_CALLBACK)(_In_opt_ PVOID Context, _In_ FSVOLNOTIFY FormatStatus, _In_ ULONG_PTR Param1, _In_ ULONG_PTR Param2)
BOOLEAN WritePartitionsToDisk(IN PPARTLIST List)
VOID SetMBRPartitionType(IN PPARTENTRY PartEntry, IN UCHAR PartitionType)
NTSTATUS WritePartitions(IN PDISKENTRY DiskEntry)
base of all file and directory entries
ULONGLONG PartitionStartLBA
PARTITION_STYLE DiskStyle
UCHAR BootCodeAndData[420]
ULONG RootDirStartCluster
UCHAR BootCodeAndData[448]
struct _LIST_ENTRY * Flink
CHAR ClustersPerMftRecord
UCHAR BootCodeAndData[7680]
ULONGLONG MftMirrLocation
CHAR ClustersPerIndexRecord
#define FIELD_OFFSET(t, f)
#define RtlCopyMemory(Destination, Source, Length)
#define CONTAINING_RECORD(address, type, field)
#define STATUS_UNRECOGNIZED_VOLUME
#define STATUS_UNSUCCESSFUL
static PPARTLIST PartitionList
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
_Must_inspect_result_ _In_ WDFCMRESLIST List
_Reserved_ PVOID Reserved
_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