ReactOS 0.4.16-dev-41-ge8c7597
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 GetRegisteredFileSystems (IN ULONG Index, OUT PCWSTR *FileSystemName)
 
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)
 
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)
 
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)
 
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 ChkdskPartition (_In_ PPARTENTRY PartEntry, _In_ BOOLEAN FixErrors, _In_ BOOLEAN Verbose, _In_ BOOLEAN CheckOnlyIfDirty, _In_ BOOLEAN ScanDrive, _In_opt_ PFMIFSCALLBACK Callback)
 
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)
 
BOOLEAN 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 70 of file fsutil.h.

◆ FAT32_BOOTSECTOR_SIZE

#define FAT32_BOOTSECTOR_SIZE   (1 * SECTORSIZE)

Definition at line 69 of file fsutil.h.

◆ FAT_BOOTSECTOR_SIZE

#define FAT_BOOTSECTOR_SIZE   (1 * SECTORSIZE)

Definition at line 68 of file fsutil.h.

◆ InstallFat12BootCode

#define InstallFat12BootCode   InstallFatBootCode

Definition at line 85 of file fsutil.h.

◆ InstallFat16BootCode

#define InstallFat16BootCode   InstallFatBootCode

Definition at line 86 of file fsutil.h.

◆ NTFS_BOOTSECTOR_SIZE

#define NTFS_BOOTSECTOR_SIZE   (16 * SECTORSIZE)

Definition at line 71 of file fsutil.h.

Typedef Documentation

◆ CHECK_VOLUME_INFO

◆ DstPath

typedef IN HANDLE DstPath

Definition at line 76 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 195 of file fsutil.h.

◆ RootPartition

Definition at line 77 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 152 of file fsutil.h.

153{
154/* Operations ****/
155 FSVOL_FORMAT = 0,
157/* Response actions ****/
158 FSVOL_ABORT = 0,
162} FSVOL_OP;
enum _FSVOL_OP FSVOL_OP
@ FSVOL_FORMAT
Definition: fsutil.h:155
@ FSVOL_CHECK
Definition: fsutil.h:156
@ FSVOL_DOIT
Definition: fsutil.h:159
@ FSVOL_ABORT
Definition: fsutil.h:158
@ FSVOL_RETRY
Definition: fsutil.h:160
@ FSVOL_SKIP
Definition: fsutil.h:161

◆ _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 135 of file fsutil.h.

136{
141// FSVOLNOTIFY_STARTPARTITION, FSVOLNOTIFY_ENDPARTITION,
149 ChangeSystemPartition // FIXME: Deprecate!
@ FSVOLNOTIFY_STARTCHECK
Definition: fsutil.h:146
@ FSVOLNOTIFY_ENDQUEUE
Definition: fsutil.h:138
@ FSVOLNOTIFY_STARTSUBQUEUE
Definition: fsutil.h:139
@ FSVOLNOTIFY_ENDFORMAT
Definition: fsutil.h:144
@ FSVOLNOTIFY_STARTFORMAT
Definition: fsutil.h:143
@ FSVOLNOTIFY_STARTQUEUE
Definition: fsutil.h:137
@ FSVOLNOTIFY_ENDSUBQUEUE
Definition: fsutil.h:140
@ FSVOLNOTIFY_PARTITIONERROR
Definition: fsutil.h:142
@ FSVOLNOTIFY_CHECKERROR
Definition: fsutil.h:148
@ ChangeSystemPartition
Definition: fsutil.h:149
@ FSVOLNOTIFY_FORMATERROR
Definition: fsutil.h:145
@ FSVOLNOTIFY_ENDCHECK
Definition: fsutil.h:147
enum _FSVOLNOTIFY FSVOLNOTIFY

Function Documentation

◆ ChkdskFileSystem()

NTSTATUS 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 287 of file fsutil.c.

295{
296 UNICODE_STRING DriveRootU;
297
298 RtlInitUnicodeString(&DriveRootU, DriveRoot);
299 return ChkdskFileSystem_UStr(&DriveRootU,
300 FileSystemName,
301 FixErrors,
302 Verbose,
303 CheckOnlyIfDirty,
304 ScanDrive,
305 Callback);
306}
BOOL FixErrors
Definition: chkdsk.c:69
BOOL Verbose
Definition: chkdsk.c:72
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
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)
Definition: fsutil.c:244
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458

Referenced by ChkdskVolume().

◆ ChkdskFileSystem_UStr()

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 
)

ChkdskEx()

Definition at line 244 of file fsutil.c.

252{
256
257 FileSystem = GetFileSystemByName(FileSystemName);
258
259 if (!FileSystem || !FileSystem->ChkdskFunc)
260 {
261 // Success = FALSE;
262 // Callback(DONE, 0, &Success);
264 }
265
267 Success = FileSystem->ChkdskFunc(DriveRoot,
268 Callback,
269 FixErrors,
270 Verbose,
271 CheckOnlyIfDirty,
272 ScanDrive,
273 NULL,
274 NULL,
275 NULL,
276 NULL,
277 (PULONG)&Status);
278 if (!Success)
279 DPRINT1("ChkdskFunc() failed with Status 0x%lx\n", Status);
280
281 // Callback(DONE, 0, &Success);
282
283 return Status;
284}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
PWCHAR FileSystem
Definition: format.c:72
#define NULL
Definition: types.h:112
@ Success
Definition: eventcreate.c:712
Status
Definition: gdiplustypes.h:25
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
static PFILE_SYSTEM GetFileSystemByName(IN PCWSTR FileSystemName)
Definition: fsutil.c:197
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t * PULONG
Definition: typedefs.h:59

Referenced by ChkdskFileSystem().

◆ ChkdskPartition()

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

Definition at line 781 of file fsutil.c.

788{
789 ASSERT(PartEntry->IsPartitioned && PartEntry->PartitionNumber != 0);
790 ASSERT(PartEntry->Volume);
791
792 // if (!PartEntry->Volume) { check_raw_sectors(); } else { check_FS(); }
793
794 /* Check the associated volume */
795 return ChkdskVolume(&PartEntry->Volume->Info,
796 FixErrors,
797 Verbose,
798 CheckOnlyIfDirty,
799 ScanDrive,
800 Callback);
801}
#define ASSERT(a)
Definition: mode.c:44
NTSTATUS ChkdskVolume(_In_ PVOLINFO Volume, _In_ BOOLEAN FixErrors, _In_ BOOLEAN Verbose, _In_ BOOLEAN CheckOnlyIfDirty, _In_ BOOLEAN ScanDrive, _In_opt_ PFMIFSCALLBACK Callback)
Definition: fsutil.c:757

◆ FormatFileSystem()

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 
)

Definition at line 376 of file fsutil.c.

384{
385 UNICODE_STRING DriveRootU;
386 UNICODE_STRING LabelU;
387
388 RtlInitUnicodeString(&DriveRootU, DriveRoot);
389 RtlInitUnicodeString(&LabelU, Label);
390
391 return FormatFileSystem_UStr(&DriveRootU,
392 FileSystemName,
393 MediaFlag,
394 &LabelU,
397 Callback);
398}
BOOL QuickFormat
Definition: format.c:66
PWCHAR Label
Definition: format.c:70
DWORD ClusterSize
Definition: format.c:67
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)
Definition: fsutil.c:311

Referenced by FormatVolume(), and InstallFatBootcodeToFloppy().

◆ FormatFileSystem_UStr()

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 
)

FormatEx()

Definition at line 311 of file fsutil.c.

319{
322 BOOLEAN BackwardCompatible = FALSE; // Default to latest FS versions.
323 MEDIA_TYPE MediaType;
324
325 FileSystem = GetFileSystemByName(FileSystemName);
326
327 if (!FileSystem || !FileSystem->FormatFunc)
328 {
329 // Success = FALSE;
330 // Callback(DONE, 0, &Success);
332 }
333
334 /* Set the BackwardCompatible flag in case we format with older FAT12/16 */
335 if (_wcsicmp(FileSystemName, L"FAT") == 0)
336 BackwardCompatible = TRUE;
337 // else if (_wcsicmp(FileSystemName, L"FAT32") == 0)
338 // BackwardCompatible = FALSE;
339
340 /* Convert the FMIFS MediaFlag to a NT MediaType */
341 // FIXME: Actually covert all the possible flags.
342 switch (MediaFlag)
343 {
344 case FMIFS_FLOPPY:
345 MediaType = F5_320_1024; // FIXME: This is hardfixed!
346 break;
347 case FMIFS_REMOVABLE:
348 MediaType = RemovableMedia;
349 break;
350 case FMIFS_HARDDISK:
351 MediaType = FixedMedia;
352 break;
353 default:
354 DPRINT1("Unknown FMIFS MediaFlag %d, converting 1-to-1 to NT MediaType\n",
355 MediaFlag);
356 MediaType = (MEDIA_TYPE)MediaFlag;
357 break;
358 }
359
360 Success = FileSystem->FormatFunc(DriveRoot,
361 Callback,
363 BackwardCompatible,
364 MediaType,
365 Label,
367 if (!Success)
368 DPRINT1("FormatFunc() failed\n");
369
370 // Callback(DONE, 0, &Success);
371
373}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
@ FMIFS_FLOPPY
Definition: fmifs.h:47
@ FMIFS_REMOVABLE
Definition: fmifs.h:50
@ FMIFS_HARDDISK
Definition: fmifs.h:51
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().

◆ FormatPartition()

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 
)

Definition at line 842 of file fsutil.c.

850{
852 PDISKENTRY DiskEntry = PartEntry->DiskEntry;
854
855 ASSERT(PartEntry->IsPartitioned && PartEntry->PartitionNumber != 0);
856
857 if (!FileSystemName || !*FileSystemName)
858 {
859 DPRINT1("No file system specified\n");
861 }
862
863 /*
864 * Prepare the partition for formatting (for MBR disks, reset the
865 * partition type), and adjust the file system name in case of FAT
866 * vs. FAT32, depending on the geometry of the partition.
867 */
868
869// FIXME: Do this only if QuickFormat == FALSE? What about FAT handling?
870
871 /*
872 * Retrieve a partition type as a hint only. It will be used to determine
873 * whether to actually use FAT12/16 or FAT32 file system, depending on the
874 * geometry of the partition. If the partition resides on an MBR disk,
875 * the partition style will be reset to this value as well, unless the
876 * partition is OEM.
877 */
879 PartEntry->StartSector.QuadPart,
880 PartEntry->SectorCount.QuadPart);
882 {
883 /* Unknown file system */
884 DPRINT1("Unknown file system '%S'\n", FileSystemName);
886 }
887
888 /* Reset the MBR partition type, unless this is an OEM partition */
889 if (DiskEntry->DiskStyle == PARTITION_STYLE_MBR)
890 {
891 if (!IsOEMPartition(PartEntry->PartitionType))
893 }
894
895 /*
896 * Adjust the file system name in case of FAT vs. FAT32, according to
897 * the type of partition returned by FileSystemToMBRPartitionType().
898 */
899 if (_wcsicmp(FileSystemName, L"FAT") == 0)
900 {
903 {
904 FileSystemName = L"FAT32";
905 }
906 }
907
908 /* Commit the partition changes to the disk */
909 Status = WritePartitions(DiskEntry);
910 if (!NT_SUCCESS(Status))
911 {
912 DPRINT1("WritePartitions(disk %lu) failed, Status 0x%08lx\n",
913 DiskEntry->DiskNumber, Status);
915 }
916
917 /* We must have an associated volume now */
918 ASSERT(PartEntry->Volume);
919
920 /* Format the associated volume */
921 Status = FormatVolume(&PartEntry->Volume->Info,
922 FileSystemName,
923 MediaFlag,
924 Label,
927 Callback);
928 if (!NT_SUCCESS(Status))
929 return Status;
930
931 PartEntry->Volume->FormatState = Formatted;
932 PartEntry->Volume->New = FALSE;
933 return STATUS_SUCCESS;
934}
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
#define PARTITION_FAT32
Definition: disk.h:95
#define PARTITION_FAT32_XINT13
Definition: disk.h:96
#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 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:804
VOID SetMBRPartitionType(IN PPARTENTRY PartEntry, IN UCHAR PartitionType)
Definition: partlist.c:3834
NTSTATUS WritePartitions(IN PDISKENTRY DiskEntry)
Definition: partlist.c:3525
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 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 1087 of file fsutil.c.

1093{
1094 BOOLEAN Success = TRUE; // Suppose success originally.
1098
1099 /* Machine state for the format step */
1100 typedef enum _FORMATMACHINESTATE
1101 {
1102 Start,
1103 FormatSystemVolume,
1104 FormatInstallVolume,
1105 FormatOtherVolume,
1106 FormatDone
1107 } FORMATMACHINESTATE;
1108 FORMATMACHINESTATE FormatState, OldFormatState;
1109 static const PCSTR FormatStateNames[] = {
1110 "Start",
1111 "FormatSystemVolume",
1112 "FormatInstallVolume",
1113 "FormatOtherVolume",
1114 "FormatDone"
1115 };
1116
1118
1119 /* Commit all partition changes to all the disks */
1121 {
1122 DPRINT("WritePartitionsToDisk() failed\n");
1123 /* Result = */ FsVolCallback(Context,
1125 STATUS_PARTITION_FAILURE, // FIXME
1126 0);
1127 return FALSE;
1128 }
1129
1130//
1131// FIXME: Should we do the following here, or in the caller?
1132//
1133 /*
1134 * In all cases, whether or not we are going to perform a formatting,
1135 * we must perform a file system check of both the system and the
1136 * installation volumes.
1137 */
1138 SystemVolume->NeedsCheck = TRUE;
1139 InstallVolume->NeedsCheck = TRUE;
1140
1143 0, 0);
1144 if (Result == FSVOL_ABORT)
1145 return FALSE;
1146
1147 /*
1148 * Commit the Format queue
1149 */
1150
1154 0);
1155 if (Result == FSVOL_ABORT)
1156 return FALSE;
1158 if (Result == FSVOL_SKIP)
1159 goto StartCheckQueue;
1162 /* Reset the formatter machine state */
1163 FormatState = Start;
1164 Volume = NULL;
1165NextFormat:
1166 OldFormatState = FormatState;
1167 switch (FormatState)
1168 {
1169 case Start:
1170 {
1171 /*
1172 * We start by formatting the system volume in case it is new
1173 * (it didn't exist before) and is not the same as the installation
1174 * volume. Otherwise we just require a file system check on it,
1175 * and start by formatting the installation volume instead.
1176 */
1178 {
1180
1181 if (Volume->FormatState == Unformatted)
1182 {
1183 // TODO: Should we let the user use a custom file system,
1184 // or should we always use FAT(32) for it?
1185 // For "compatibility", FAT(32) would be best indeed.
1186
1187 FormatState = FormatSystemVolume;
1188 DPRINT1("FormatState: %s --> %s\n",
1189 FormatStateNames[OldFormatState], FormatStateNames[FormatState]);
1190 break;
1191 }
1192
1193 /* The system volume is separate, so it had better be formatted! */
1194 ASSERT(Volume->FormatState == Formatted);
1195
1196 /* Require a file system check on the system volume too */
1197 Volume->NeedsCheck = TRUE;
1198 }
1200 }
1201
1202 case FormatSystemVolume:
1203 {
1205
1206 FormatState = FormatInstallVolume;
1207 DPRINT1("FormatState: %s --> %s\n",
1208 FormatStateNames[OldFormatState], FormatStateNames[FormatState]);
1209 break;
1210 }
1211
1212 case FormatInstallVolume:
1213 /* Restart volume enumeration */
1214 Volume = NULL;
1215 case FormatOtherVolume:
1216 {
1218
1219 FormatState = (Volume ? FormatOtherVolume : FormatDone);
1220 DPRINT1("FormatState: %s --> %s\n",
1221 FormatStateNames[OldFormatState], FormatStateNames[FormatState]);
1222 if (Volume)
1223 break;
1225 }
1226
1227 case FormatDone:
1228 {
1229 DPRINT1("FormatState: FormatDone\n");
1230 Success = TRUE;
1231 goto EndFormat;
1232 }
1234 }
1235
1237 if (Result == FSVOL_ABORT)
1238 {
1239 Success = FALSE;
1240 goto Quit;
1241 }
1242 /* Schedule a check for this volume */
1243 Volume->NeedsCheck = TRUE;
1244 /* Go to the next volume to be formatted */
1245 goto NextFormat;
1246
1247EndFormat:
1251 0);
1252
1253
1254 /*
1255 * Commit the CheckFS queue
1256 */
1257
1258StartCheckQueue:
1262 0);
1263 if (Result == FSVOL_ABORT)
1264 return FALSE;
1265
1266 /* Loop through each unchecked volume and do the check */
1269 Entry = Entry->Flink)
1270 {
1271 Volume = CONTAINING_RECORD(Entry, VOLENTRY, ListEntry);
1272 if (!Volume->NeedsCheck)
1273 continue;
1274
1275 /* Found a candidate */
1276 ASSERT(Volume->FormatState == Formatted);
1278 if (Result == FSVOL_ABORT)
1279 {
1280 Success = FALSE;
1281 goto Quit;
1282 }
1283 /* Go to the next volume to be checked */
1284 }
1285 Success = TRUE;
1286
1290 0);
1291
1292
1293Quit:
1294 /* All the queues have been committed */
1297 Success,
1298 0);
1299 return Success;
1300}
static FSVOL_OP CALLBACK FsVolCallback(_In_opt_ PVOID Context, _In_ FSVOLNOTIFY FormatStatus, _In_ ULONG_PTR Param1, _In_ ULONG_PTR Param2)
Definition: reactos.c:1250
#define SystemVolume
Definition: reactos.c:52
#define InstallVolume
Definition: reactos.c:47
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 __fallthrough
Definition: ms_sal.h:2886
#define DEFAULT_UNREACHABLE
static FSVOL_OP DoChecking(_In_ PVOLENTRY Volume, _In_opt_ PVOID Context, _In_opt_ PFSVOL_CALLBACK FsVolCallback)
Definition: fsutil.c:1000
static FSVOL_OP DoFormatting(_In_ PVOLENTRY Volume, _In_opt_ PVOID Context, _In_opt_ PFSVOL_CALLBACK FsVolCallback)
Definition: fsutil.c:942
static PVOLENTRY GetNextUnformattedVolume(_In_ PPARTLIST List, _In_opt_ PVOLENTRY Volume)
Definition: fsutil.c:1062
BOOLEAN WritePartitionsToDisk(IN PPARTLIST List)
Definition: partlist.c:3688
#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:75
_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 GetRegisteredFileSystems ( IN ULONG  Index,
OUT PCWSTR FileSystemName 
)

QueryAvailableFileSystemFormat()

Definition at line 182 of file fsutil.c.

185{
187 return FALSE;
188
189 *FileSystemName = RegisteredFileSystems[Index].FileSystemName;
190
191 return TRUE;
192}
#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 585 of file fsutil.c.

589{
591 NTSTATUS LockStatus;
596 BOOTCODE NewBootSector = {0};
597
598 /* Allocate and read the new bootsector from SrcPath */
599 RtlInitUnicodeString(&Name, SrcPath);
600 Status = ReadBootCodeFromFile(&NewBootSector,
601 &Name,
603 if (!NT_SUCCESS(Status))
604 return Status;
605
606 /*
607 * The BTRFS driver requires the volume to be locked in order to modify
608 * the first sectors of the partition, even though they are outside the
609 * file-system space / in the reserved area (they are situated before
610 * the super-block at 0x1000) and is in principle allowed by the NT
611 * storage stack.
612 * So we lock here in order to write the bootsector at sector 0.
613 * If locking fails, we ignore and continue nonetheless.
614 */
615 LockStatus = NtFsControlFile(DstPath,
616 NULL,
617 NULL,
618 NULL,
621 NULL,
622 0,
623 NULL,
624 0);
625 if (!NT_SUCCESS(LockStatus))
626 {
627 DPRINT1("WARNING: Failed to lock BTRFS volume for writing bootsector! Operations may fail! (Status 0x%lx)\n", LockStatus);
628 }
629
630 /* Obtain partition info and write it to the bootsector */
632 NULL,
633 NULL,
634 NULL,
637 NULL,
638 0,
639 &PartInfo,
640 sizeof(PartInfo));
641 if (!NT_SUCCESS(Status))
642 {
643 DPRINT1("IOCTL_DISK_GET_PARTITION_INFO_EX failed (Status %lx)\n", Status);
644 goto Quit;
645 }
646
647 /* Write new bootsector to RootPath */
648 ((PBTRFS_BOOTSECTOR)NewBootSector.BootCode)->PartitionStartLBA =
650
651 /* Write sector 0 */
652 FileOffset.QuadPart = 0ULL;
654 NULL,
655 NULL,
656 NULL,
658 NewBootSector.BootCode,
659 NewBootSector.Length,
660 &FileOffset,
661 NULL);
662 if (!NT_SUCCESS(Status))
663 {
664 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
665 goto Quit;
666 }
667
668Quit:
669 /* Unlock the volume */
670 LockStatus = NtFsControlFile(DstPath,
671 NULL,
672 NULL,
673 NULL,
676 NULL,
677 0,
678 NULL,
679 0);
680 if (!NT_SUCCESS(LockStatus))
681 {
682 DPRINT1("Failed to unlock BTRFS volume (Status 0x%lx)\n", LockStatus);
683 }
684
685 /* Free the new bootsector */
686 FreeBootCode(&NewBootSector);
687
688 return Status;
689}
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:77
#define BTRFS_BOOTSECTOR_SIZE
Definition: fsutil.h:70
IN HANDLE DstPath
Definition: fsutil.h:76
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 464 of file fsutil.c.

468{
474 BOOTCODE OrigBootSector = {0};
475 BOOTCODE NewBootSector = {0};
476
477 /* Allocate and read the current original partition bootsector */
478 Status = ReadBootCodeByHandle(&OrigBootSector,
481 if (!NT_SUCCESS(Status))
482 return Status;
483
484 /* Allocate and read the new bootsector (2 sectors) from SrcPath */
485 RtlInitUnicodeString(&Name, SrcPath);
486 Status = ReadBootCodeFromFile(&NewBootSector,
487 &Name,
489 if (!NT_SUCCESS(Status))
490 {
491 FreeBootCode(&OrigBootSector);
492 return Status;
493 }
494
495 /* Adjust the bootsector (copy a part of the FAT32 BPB) */
496 RtlCopyMemory(&((PFAT32_BOOTSECTOR)NewBootSector.BootCode)->OemName,
497 &((PFAT32_BOOTSECTOR)OrigBootSector.BootCode)->OemName,
498 FIELD_OFFSET(FAT32_BOOTSECTOR, BootCodeAndData) -
500
501 /*
502 * We know we copy the boot code to a file only when DstPath != RootPartition,
503 * otherwise the boot code is copied to the specified root partition.
504 */
505 if (DstPath != RootPartition)
506 {
507 /* Copy to a file: Disable the backup bootsector */
508 ((PFAT32_BOOTSECTOR)NewBootSector.BootCode)->BackupBootSector = 0;
509 }
510 else
511 {
512 /* Copy to a disk: Get the location of the backup bootsector */
513 BackupBootSector = ((PFAT32_BOOTSECTOR)OrigBootSector.BootCode)->BackupBootSector;
514 }
515
516 /* Free the original bootsector */
517 FreeBootCode(&OrigBootSector);
518
519 /* Write the first sector of the new bootcode to DstPath sector 0 */
520 FileOffset.QuadPart = 0ULL;
522 NULL,
523 NULL,
524 NULL,
526 NewBootSector.BootCode,
528 &FileOffset,
529 NULL);
530 if (!NT_SUCCESS(Status))
531 {
532 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
533 FreeBootCode(&NewBootSector);
534 return Status;
535 }
536
537 if (DstPath == RootPartition)
538 {
539 /* Copy to a disk: Write the backup bootsector */
540 if ((BackupBootSector != 0x0000) && (BackupBootSector != 0xFFFF))
541 {
544 NULL,
545 NULL,
546 NULL,
548 NewBootSector.BootCode,
550 &FileOffset,
551 NULL);
552 if (!NT_SUCCESS(Status))
553 {
554 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
555 FreeBootCode(&NewBootSector);
556 return Status;
557 }
558 }
559 }
560
561 /* Write the second sector of the new bootcode to boot disk sector 14 */
562 // FileOffset.QuadPart = (ULONGLONG)(14 * FAT32_BOOTSECTOR_SIZE);
563 FileOffset.QuadPart = 14 * FAT32_BOOTSECTOR_SIZE;
564 Status = NtWriteFile(DstPath, // or really RootPartition ???
565 NULL,
566 NULL,
567 NULL,
569 ((PUCHAR)NewBootSector.BootCode + FAT32_BOOTSECTOR_SIZE),
571 &FileOffset,
572 NULL);
573 if (!NT_SUCCESS(Status))
574 {
575 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
576 }
577
578 /* Free the new bootsector */
579 FreeBootCode(&NewBootSector);
580
581 return Status;
582}
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:69
#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 406 of file fsutil.c.

410{
415 BOOTCODE OrigBootSector = {0};
416 BOOTCODE NewBootSector = {0};
417
418 /* Allocate and read the current original partition bootsector */
419 Status = ReadBootCodeByHandle(&OrigBootSector,
422 if (!NT_SUCCESS(Status))
423 return Status;
424
425 /* Allocate and read the new bootsector from SrcPath */
426 RtlInitUnicodeString(&Name, SrcPath);
427 Status = ReadBootCodeFromFile(&NewBootSector,
428 &Name,
430 if (!NT_SUCCESS(Status))
431 {
432 FreeBootCode(&OrigBootSector);
433 return Status;
434 }
435
436 /* Adjust the bootsector (copy a part of the FAT12/16 BPB) */
437 RtlCopyMemory(&((PFAT_BOOTSECTOR)NewBootSector.BootCode)->OemName,
438 &((PFAT_BOOTSECTOR)OrigBootSector.BootCode)->OemName,
439 FIELD_OFFSET(FAT_BOOTSECTOR, BootCodeAndData) -
441
442 /* Free the original bootsector */
443 FreeBootCode(&OrigBootSector);
444
445 /* Write the new bootsector to DstPath */
446 FileOffset.QuadPart = 0ULL;
448 NULL,
449 NULL,
450 NULL,
452 NewBootSector.BootCode,
453 NewBootSector.Length,
454 &FileOffset,
455 NULL);
456
457 /* Free the new bootsector */
458 FreeBootCode(&NewBootSector);
459
460 return Status;
461}
#define FAT_BOOTSECTOR_SIZE
Definition: fsutil.h:68

◆ InstallNtfsBootCode()

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

Definition at line 692 of file fsutil.c.

696{
701 BOOTCODE OrigBootSector = {0};
702 BOOTCODE NewBootSector = {0};
703
704 /* Allocate and read the current original partition bootsector */
706 if (!NT_SUCCESS(Status))
707 {
708 DPRINT1("InstallNtfsBootCode: Status %lx\n", Status);
709 return Status;
710 }
711
712 /* Allocate and read the new bootsector (16 sectors) from SrcPath */
713 RtlInitUnicodeString(&Name, SrcPath);
715 if (!NT_SUCCESS(Status))
716 {
717 DPRINT1("InstallNtfsBootCode: Status %lx\n", Status);
718 FreeBootCode(&OrigBootSector);
719 return Status;
720 }
721
722 /* Adjust the bootsector (copy a part of the NTFS BPB) */
723 RtlCopyMemory(&((PNTFS_BOOTSECTOR)NewBootSector.BootCode)->OEMID,
724 &((PNTFS_BOOTSECTOR)OrigBootSector.BootCode)->OEMID,
726
727 /* Write sector 0 */
728 FileOffset.QuadPart = 0ULL;
730 NULL,
731 NULL,
732 NULL,
734 NewBootSector.BootCode,
735 NewBootSector.Length,
736 &FileOffset,
737 NULL);
738 if (!NT_SUCCESS(Status))
739 {
740 DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
741 goto Quit;
742 }
743
744Quit:
745 /* Free the new bootsector */
746 FreeBootCode(&NewBootSector);
747
748 return Status;
749}
#define NTFS_BOOTSECTOR_SIZE
Definition: fsutil.h:71

Referenced by InstallNtfsBootcodeToPartition().

◆ NTSTATUS()

typedef NTSTATUS ( PFS_INSTALL_BOOTCODE)