ReactOS 0.4.16-dev-338-g34e76ad
fsutil.h File Reference
#include <fmifs/fmifs.h>
Include dependency graph for fsutil.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _FORMAT_VOLUME_INFO
 
struct  _CHECK_VOLUME_INFO
 

Macros

#define FAT_BOOTSECTOR_SIZE   (1 * SECTORSIZE)
 
#define FAT32_BOOTSECTOR_SIZE   (1 * SECTORSIZE)
 
#define BTRFS_BOOTSECTOR_SIZE   (3 * SECTORSIZE)
 
#define NTFS_BOOTSECTOR_SIZE   (16 * SECTORSIZE)
 
#define InstallFat12BootCode   InstallFatBootCode
 
#define InstallFat16BootCode   InstallFatBootCode
 

Typedefs

typedef IN HANDLE DstPath
 
typedef IN HANDLE IN HANDLE RootPartition
 
typedef enum _FSVOLNOTIFY FSVOLNOTIFY
 
typedef enum _FSVOL_OP FSVOL_OP
 
typedef struct _FORMAT_VOLUME_INFO FORMAT_VOLUME_INFO
 
typedef struct _FORMAT_VOLUME_INFOPFORMAT_VOLUME_INFO
 
typedef struct _CHECK_VOLUME_INFO CHECK_VOLUME_INFO
 
typedef struct _CHECK_VOLUME_INFOPCHECK_VOLUME_INFO
 
typedef FSVOL_OP(CALLBACKPFSVOL_CALLBACK) (_In_opt_ PVOID Context, _In_ FSVOLNOTIFY FormatStatus, _In_ ULONG_PTR Param1, _In_ ULONG_PTR Param2)
 

Enumerations

enum  _FSVOLNOTIFY {
  FSVOLNOTIFY_STARTQUEUE = 0 , FSVOLNOTIFY_ENDQUEUE , FSVOLNOTIFY_STARTSUBQUEUE , FSVOLNOTIFY_ENDSUBQUEUE ,
  FSVOLNOTIFY_PARTITIONERROR , FSVOLNOTIFY_STARTFORMAT , FSVOLNOTIFY_ENDFORMAT , FSVOLNOTIFY_FORMATERROR ,
  FSVOLNOTIFY_STARTCHECK , FSVOLNOTIFY_ENDCHECK , FSVOLNOTIFY_CHECKERROR , ChangeSystemPartition
}
 
enum  _FSVOL_OP {
  FSVOL_FORMAT = 0 , FSVOL_CHECK , FSVOL_ABORT = 0 , FSVOL_DOIT ,
  FSVOL_RETRY = FSVOL_DOIT , FSVOL_SKIP
}
 

Functions

BOOLEAN NTAPI GetRegisteredFileSystems (IN ULONG Index, OUT PCWSTR *FileSystemName)
 
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)
 
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)
 
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)
 
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)
 
typedef NTSTATUS (*PFS_INSTALL_BOOTCODE)(IN PCWSTR SrcPath
 
NTSTATUS InstallFatBootCode (IN PCWSTR SrcPath, IN HANDLE DstPath, IN HANDLE RootPartition)
 
NTSTATUS InstallFat32BootCode (IN PCWSTR SrcPath, IN HANDLE DstPath, IN HANDLE RootPartition)
 
NTSTATUS InstallBtrfsBootCode (IN PCWSTR SrcPath, IN HANDLE DstPath, IN HANDLE RootPartition)
 
NTSTATUS InstallNtfsBootCode (IN PCWSTR SrcPath, IN HANDLE DstPath, IN HANDLE RootPartition)
 
NTSTATUS NTAPI ChkdskPartition (_In_ PPARTENTRY PartEntry, _In_ BOOLEAN FixErrors, _In_ BOOLEAN Verbose, _In_ BOOLEAN CheckOnlyIfDirty, _In_ BOOLEAN ScanDrive, _In_opt_ PFMIFSCALLBACK Callback)
 
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)
 
BOOLEAN NTAPI FsVolCommitOpsQueue (_In_ PPARTLIST PartitionList, _In_ PVOLENTRY SystemVolume, _In_ PVOLENTRY InstallVolume, _In_opt_ PFSVOL_CALLBACK FsVolCallback, _In_opt_ PVOID Context)
 

Macro Definition Documentation

◆ BTRFS_BOOTSECTOR_SIZE

#define BTRFS_BOOTSECTOR_SIZE   (3 * SECTORSIZE)

Definition at line 75 of file fsutil.h.

◆ FAT32_BOOTSECTOR_SIZE

#define FAT32_BOOTSECTOR_SIZE   (1 * SECTORSIZE)

Definition at line 74 of file fsutil.h.

◆ FAT_BOOTSECTOR_SIZE

#define FAT_BOOTSECTOR_SIZE   (1 * SECTORSIZE)

Definition at line 73 of file fsutil.h.

◆ InstallFat12BootCode

#define InstallFat12BootCode   InstallFatBootCode

Definition at line 90 of file fsutil.h.

◆ InstallFat16BootCode

#define InstallFat16BootCode   InstallFatBootCode

Definition at line 91 of file fsutil.h.

◆ NTFS_BOOTSECTOR_SIZE

#define NTFS_BOOTSECTOR_SIZE   (16 * SECTORSIZE)

Definition at line 76 of file fsutil.h.

Typedef Documentation

◆ CHECK_VOLUME_INFO

◆ DstPath

typedef IN HANDLE DstPath

Definition at line 81 of file fsutil.h.

◆ FORMAT_VOLUME_INFO

◆ FSVOL_OP

◆ FSVOLNOTIFY

◆ PCHECK_VOLUME_INFO

◆ PFORMAT_VOLUME_INFO

◆ PFSVOL_CALLBACK

typedef FSVOL_OP(CALLBACK * PFSVOL_CALLBACK) (_In_opt_ PVOID Context, _In_ FSVOLNOTIFY FormatStatus, _In_ ULONG_PTR Param1, _In_ ULONG_PTR Param2)

Definition at line 202 of file fsutil.h.

◆ RootPartition

Definition at line 82 of file fsutil.h.

Enumeration Type Documentation

◆ _FSVOL_OP

Enumerator
FSVOL_FORMAT 
FSVOL_CHECK 
FSVOL_ABORT 
FSVOL_DOIT 
FSVOL_RETRY 
FSVOL_SKIP 

Definition at line 159 of file fsutil.h.

160{
161/* Operations ****/
162 FSVOL_FORMAT = 0,
164/* Response actions ****/
165 FSVOL_ABORT = 0,
169} FSVOL_OP;
enum _FSVOL_OP FSVOL_OP
@ 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

◆ _FSVOLNOTIFY

Enumerator
FSVOLNOTIFY_STARTQUEUE 
FSVOLNOTIFY_ENDQUEUE 
FSVOLNOTIFY_STARTSUBQUEUE 
FSVOLNOTIFY_ENDSUBQUEUE 
FSVOLNOTIFY_PARTITIONERROR 
FSVOLNOTIFY_STARTFORMAT 
FSVOLNOTIFY_ENDFORMAT 
FSVOLNOTIFY_FORMATERROR 
FSVOLNOTIFY_STARTCHECK 
FSVOLNOTIFY_ENDCHECK 
FSVOLNOTIFY_CHECKERROR 
ChangeSystemPartition 

Definition at line 142 of file fsutil.h.

143{
148// FSVOLNOTIFY_STARTPARTITION, FSVOLNOTIFY_ENDPARTITION,
156 ChangeSystemPartition // FIXME: Deprecate!
@ 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
@ ChangeSystemPartition
Definition: fsutil.h:156
@ FSVOLNOTIFY_FORMATERROR
Definition: fsutil.h:152
@ FSVOLNOTIFY_ENDCHECK
Definition: fsutil.h:154
enum _FSVOLNOTIFY FSVOLNOTIFY

Function Documentation

◆ ChkdskFileSystem()

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 at line 290 of file fsutil.c.

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}
BOOL FixErrors
Definition: chkdsk.c:69
BOOL Verbose
Definition: chkdsk.c:72
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
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
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458

Referenced by ChkdskVolume().

◆ ChkdskFileSystem_UStr()

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 
)

ChkdskEx()

Definition at line 246 of file fsutil.c.

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}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
PWCHAR FileSystem
Definition: format.c:72
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define NULL
Definition: types.h:112
@ Success
Definition: eventcreate.c:712
Status
Definition: gdiplustypes.h:25
static PFILE_SYSTEM GetFileSystemByName(IN PCWSTR FileSystemName)
Definition: fsutil.c:198
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t * PULONG
Definition: typedefs.h:59

Referenced by ChkdskFileSystem().

◆ ChkdskPartition()

NTSTATUS NTAPI ChkdskPartition ( _In_ PPARTENTRY  PartEntry,
_In_ BOOLEAN  FixErrors,
_In_ BOOLEAN  Verbose,
_In_ BOOLEAN  CheckOnlyIfDirty,
_In_ BOOLEAN  ScanDrive,
_In_opt_ PFMIFSCALLBACK  Callback 
)

Definition at line 788 of file fsutil.c.

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}
#define ASSERT(a)
Definition: mode.c:44
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

◆ FormatFileSystem()

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 at line 381 of file fsutil.c.

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}
BOOL QuickFormat
Definition: format.c:66
PWCHAR Label
Definition: format.c:70
DWORD ClusterSize
Definition: format.c:67
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

Referenced by FormatVolume().

◆ FormatFileSystem_UStr()

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 
)

FormatEx()

Definition at line 315 of file fsutil.c.

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}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
@ FMIFS_FLOPPY
Definition: fmifs.h:61
@ FMIFS_REMOVABLE
Definition: fmifs.h:64
@ FMIFS_HARDDISK
Definition: fmifs.h:65
enum _MEDIA_TYPE MEDIA_TYPE
@ RemovableMedia
Definition: ntdddisk.h:382
@ FixedMedia
Definition: ntdddisk.h:383
@ F5_320_1024
Definition: ntdddisk.h:379
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by FormatFileSystem(), and InstallBootcodeToRemovable().

◆ FormatPartition()

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 at line 851 of file fsutil.c.

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}
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:87
#define PARTITION_FAT32
Definition: disk.h:96
#define PARTITION_FAT32_XINT13
Definition: disk.h:97
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
UCHAR FileSystemToMBRPartitionType(IN PCWSTR FileSystem, IN ULONGLONG StartSector, IN ULONGLONG SectorCount)
Definition: fsrec.c:333
#define IsOEMPartition(PartitionType)
Definition: partlist.h:22
@ Formatted
Definition: partlist.h:37
@ PARTITION_STYLE_MBR
Definition: imports.h:201
#define STATUS_PARTITION_FAILURE
Definition: ntstatus.h:604
CHAR PartitionType
Definition: part_xbox.c:32
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
VOID SetMBRPartitionType(IN PPARTENTRY PartEntry, IN UCHAR PartitionType)
Definition: partlist.c:3899
NTSTATUS WritePartitions(IN PDISKENTRY DiskEntry)
Definition: partlist.c:3590
ULONG DiskNumber
Definition: partlist.h:129
PARTITION_STYLE DiskStyle
Definition: partlist.h:139
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by DoFormatting().

◆ FsVolCommitOpsQueue()

BOOLEAN NTAPI FsVolCommitOpsQueue ( _In_ PPARTLIST  PartitionList,
_In_ PVOLENTRY  SystemVolume,
_In_ PVOLENTRY  InstallVolume,
_In_opt_ PFSVOL_CALLBACK  FsVolCallback,
_In_opt_ PVOID  Context 
)

HACK!!

END HACK!!

Definition at line 1097 of file fsutil.c.

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}
static FSVOL_OP CALLBACK FsVolCallback(_In_opt_ PVOID Context, _In_ FSVOLNOTIFY FormatStatus, _In_ ULONG_PTR Param1, _In_ ULONG_PTR Param2)
Definition: reactos.c:1251
#define SystemVolume
Definition: reactos.c:51
#define InstallVolume
Definition: reactos.c:46
VOID EndFormat(_In_ NTSTATUS Status)
Definition: fmtchk.c:97
return pTarget Start()
@ Unformatted
Definition: partlist.h:34
UNICODE_STRING Volume
Definition: fltkernel.h:1172
#define DEFAULT_UNREACHABLE
#define __fallthrough
Definition: sal_old.h:314
static FSVOL_OP DoChecking(_In_ PVOLENTRY Volume, _In_opt_ PVOID Context, _In_opt_ PFSVOL_CALLBACK FsVolCallback)
Definition: fsutil.c:1009
static FSVOL_OP DoFormatting(_In_ PVOLENTRY Volume, _In_opt_ PVOID Context, _In_opt_ PFSVOL_CALLBACK FsVolCallback)
Definition: fsutil.c:951
static PVOLENTRY GetNextUnformattedVolume(_In_ PPARTLIST List, _In_opt_ PVOLENTRY Volume)
Definition: fsutil.c:1071
BOOLEAN WritePartitionsToDisk(IN PPARTLIST List)
Definition: partlist.c:3753
#define DPRINT
Definition: sndvol32.h:73
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LIST_ENTRY VolumesList
Definition: partlist.h:187
const char * PCSTR
Definition: typedefs.h:52
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
static PPARTLIST PartitionList
Definition: usetup.c:74
_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

Referenced by PrepareAndDoCopyThread(), and StartPartitionOperationsPage().

◆ GetRegisteredFileSystems()

BOOLEAN NTAPI GetRegisteredFileSystems ( IN ULONG  Index,
OUT PCWSTR FileSystemName 
)

QueryAvailableFileSystemFormat()

Definition at line 183 of file fsutil.c.

186{
188 return FALSE;
189
190 *FileSystemName = RegisteredFileSystems[Index].FileSystemName;
191
192 return TRUE;
193}
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
static FILE_SYSTEM RegisteredFileSystems[]
Definition: fsutil.c:159
PCWSTR FileSystemName
Definition: fsutil.c:153
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by FormatDlgProcWorker(), and InitializeFileSystemList().

◆ InstallBtrfsBootCode()

NTSTATUS InstallBtrfsBootCode ( IN PCWSTR  SrcPath,
IN HANDLE  DstPath,
IN HANDLE  RootPartition 
)

Definition at line 590 of file fsutil.c.

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}
struct NameRec_ * Name
Definition: cdprocs.h:460
VOID FreeBootCode(IN OUT PBOOTCODE BootCodeInfo)
Definition: bootcode.c:104
NTSTATUS ReadBootCodeFromFile(IN OUT PBOOTCODE BootCodeInfo, IN PUNICODE_STRING FilePath, IN ULONG Length OPTIONAL)
Definition: bootcode.c:69
#define SECTORSIZE
Definition: bootcode.h:13
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
#define IOCTL_DISK_GET_PARTITION_INFO_EX
Definition: ntddk_ex.h:206
#define ULL(a, b)
Definition: format_msg.c:27
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#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 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)
struct _BTRFS_BOOTSECTOR * PBTRFS_BOOTSECTOR
IN HANDLE IN HANDLE RootPartition
Definition: fsutil.h:82
#define BTRFS_BOOTSECTOR_SIZE
Definition: fsutil.h:75
IN HANDLE DstPath
Definition: fsutil.h:81
ULONG Length
Definition: bootcode.h:18
PVOID BootCode
Definition: bootcode.h:17
LARGE_INTEGER StartingOffset
Definition: imports.h:221
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by InstallBtrfsBootcodeToPartition().

◆ InstallFat32BootCode()

NTSTATUS InstallFat32BootCode ( IN PCWSTR  SrcPath,
IN HANDLE  DstPath,
IN HANDLE  RootPartition 
)

Definition at line 469 of file fsutil.c.

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}
BOOL BackupBootSector(LPCTSTR lpszVolumeName)
Definition: install.c:61
NTSTATUS ReadBootCodeByHandle(IN OUT PBOOTCODE BootCodeInfo, IN HANDLE FileHandle, IN ULONG Length OPTIONAL)
Definition: bootcode.c:21
IN PDCB IN POEM_STRING OemName
Definition: fatprocs.h:1305
unsigned short USHORT
Definition: pedump.c:61
struct _FAT32_BOOTSECTOR * PFAT32_BOOTSECTOR
#define FAT32_BOOTSECTOR_SIZE
Definition: fsutil.h:74
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67

Referenced by InstallFatBootcodeToPartition().

◆ InstallFatBootCode()

NTSTATUS InstallFatBootCode ( IN PCWSTR  SrcPath,
IN HANDLE  DstPath,
IN HANDLE  RootPartition 
)

Definition at line 411 of file fsutil.c.

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}
#define FAT_BOOTSECTOR_SIZE
Definition: fsutil.h:73

◆ InstallNtfsBootCode()

NTSTATUS InstallNtfsBootCode ( IN PCWSTR  SrcPath,
IN HANDLE  DstPath,
IN HANDLE  RootPartition 
)

Definition at line 697 of file fsutil.c.

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}
#define NTFS_BOOTSECTOR_SIZE
Definition: fsutil.h:76

Referenced by InstallNtfsBootcodeToPartition().

◆ NTSTATUS()

typedef NTSTATUS ( PFS_INSTALL_BOOTCODE)