ReactOS 0.4.16-dev-555-g690643f
fsutil.c File Reference
#include "precomp.h"
#include "partlist.h"
#include "fsrec.h"
#include "bootcode.h"
#include "fsutil.h"
#include <fslib/vfatlib.h>
#include <fslib/btrfslib.h>
#include <debug.h>
#include <pshpack1.h>
#include <poppack.h>
Include dependency graph for fsutil.c:

Go to the source code of this file.

Classes

struct  _FAT_BOOTSECTOR
 
struct  _FAT32_BOOTSECTOR
 
struct  _BTRFS_BOOTSECTOR
 
struct  _NTFS_BOOTSECTOR
 
struct  _FILE_SYSTEM
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _FAT_BOOTSECTOR FAT_BOOTSECTOR
 
typedef struct _FAT_BOOTSECTORPFAT_BOOTSECTOR
 
typedef struct _FAT32_BOOTSECTOR FAT32_BOOTSECTOR
 
typedef struct _FAT32_BOOTSECTORPFAT32_BOOTSECTOR
 
typedef struct _BTRFS_BOOTSECTOR BTRFS_BOOTSECTOR
 
typedef struct _BTRFS_BOOTSECTORPBTRFS_BOOTSECTOR
 
typedef struct _NTFS_BOOTSECTOR NTFS_BOOTSECTOR
 
typedef struct _NTFS_BOOTSECTORPNTFS_BOOTSECTOR
 
typedef struct _FILE_SYSTEM FILE_SYSTEM
 
typedef struct _FILE_SYSTEMPFILE_SYSTEM
 

Functions

 C_ASSERT (sizeof(FAT_BOOTSECTOR)==FAT_BOOTSECTOR_SIZE)
 
 C_ASSERT (sizeof(FAT32_BOOTSECTOR)==FAT32_BOOTSECTOR_SIZE)
 
 C_ASSERT (sizeof(BTRFS_BOOTSECTOR)==BTRFS_BOOTSECTOR_SIZE)
 
 C_ASSERT (sizeof(NTFS_BOOTSECTOR)==NTFS_BOOTSECTOR_SIZE)
 
BOOLEAN NTAPI GetRegisteredFileSystems (IN ULONG Index, OUT PCWSTR *FileSystemName)
 
static PFILE_SYSTEM GetFileSystemByName (IN 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)
 
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 ChkdskVolume (_In_ PVOLINFO Volume, _In_ BOOLEAN FixErrors, _In_ BOOLEAN Verbose, _In_ BOOLEAN CheckOnlyIfDirty, _In_ BOOLEAN ScanDrive, _In_opt_ PFMIFSCALLBACK Callback)
 
NTSTATUS NTAPI ChkdskPartition (_In_ PPARTENTRY PartEntry, _In_ BOOLEAN FixErrors, _In_ BOOLEAN Verbose, _In_ BOOLEAN CheckOnlyIfDirty, _In_ BOOLEAN ScanDrive, _In_opt_ PFMIFSCALLBACK Callback)
 
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)
 
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)
 
static FSVOL_OP DoFormatting (_In_ PVOLENTRY Volume, _In_opt_ PVOID Context, _In_opt_ PFSVOL_CALLBACK FsVolCallback)
 
static FSVOL_OP DoChecking (_In_ PVOLENTRY Volume, _In_opt_ PVOID Context, _In_opt_ PFSVOL_CALLBACK FsVolCallback)
 
static PVOLENTRY GetNextUnformattedVolume (_In_ PPARTLIST List, _In_opt_ PVOLENTRY Volume)
 
BOOLEAN NTAPI FsVolCommitOpsQueue (_In_ PPARTLIST PartitionList, _In_ PVOLENTRY SystemVolume, _In_ PVOLENTRY InstallVolume, _In_opt_ PFSVOL_CALLBACK FsVolCallback, _In_opt_ PVOID Context)
 

Variables

static FILE_SYSTEM RegisteredFileSystems []
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 29 of file fsutil.c.

Typedef Documentation

◆ BTRFS_BOOTSECTOR

◆ FAT32_BOOTSECTOR

◆ FAT_BOOTSECTOR

◆ FILE_SYSTEM

IFS_PROVIDER

◆ NTFS_BOOTSECTOR

◆ PBTRFS_BOOTSECTOR

◆ PFAT32_BOOTSECTOR

◆ PFAT_BOOTSECTOR

◆ PFILE_SYSTEM

◆ PNTFS_BOOTSECTOR

Function Documentation

◆ C_ASSERT() [1/4]

◆ C_ASSERT() [2/4]

◆ C_ASSERT() [3/4]

◆ C_ASSERT() [4/4]

◆ 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

◆ ChkdskVolume()

NTSTATUS NTAPI ChkdskVolume ( _In_ PVOLINFO  Volume,
_In_ BOOLEAN  FixErrors,
_In_ BOOLEAN  Verbose,
_In_ BOOLEAN  CheckOnlyIfDirty,
_In_ BOOLEAN  ScanDrive,
_In_opt_ PFMIFSCALLBACK  Callback 
)

Definition at line 763 of file fsutil.c.

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}
UNICODE_STRING Volume
Definition: fltkernel.h:1172
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
#define DPRINT
Definition: sndvol32.h:73
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173

Referenced by ChkdskPartition(), and DoChecking().

◆ DoChecking()

static FSVOL_OP DoChecking ( _In_ PVOLENTRY  Volume,
_In_opt_ PVOID  Context,
_In_opt_ PFSVOL_CALLBACK  FsVolCallback 
)
static

Definition at line 1009 of file fsutil.c.

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}
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 FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
VOID EndCheck(_In_ NTSTATUS Status)
Definition: fmtchk.c:150
@ FSVOLNOTIFY_STARTCHECK
Definition: fsutil.h:153
@ FSVOLNOTIFY_CHECKERROR
Definition: fsutil.h:155
@ FSVOLNOTIFY_ENDCHECK
Definition: fsutil.h:154
enum _FSVOL_OP FSVOL_OP
@ FSVOL_CHECK
Definition: fsutil.h:163
@ FSVOL_DOIT
Definition: fsutil.h:166
@ FSVOL_RETRY
Definition: fsutil.h:167
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
uint32_t ULONG_PTR
Definition: typedefs.h:65
_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 FsVolCommitOpsQueue().

◆ DoFormatting()

static FSVOL_OP DoFormatting ( _In_ PVOLENTRY  Volume,
_In_opt_ PVOID  Context,
_In_opt_ PFSVOL_CALLBACK  FsVolCallback 
)
static

Definition at line 951 of file fsutil.c.

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}
VOID EndFormat(_In_ NTSTATUS Status)
Definition: fmtchk.c:97
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
@ FSVOLNOTIFY_ENDFORMAT
Definition: fsutil.h:151
@ FSVOLNOTIFY_STARTFORMAT
Definition: fsutil.h:150
@ FSVOLNOTIFY_FORMATERROR
Definition: fsutil.h:152
@ FSVOL_FORMAT
Definition: fsutil.h:162
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
PVOLENTRY Volume
Definition: partlist.h:95

Referenced by FsVolCommitOpsQueue().

◆ 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
@ 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
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
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by DoFormatting().

◆ FormatVolume()

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

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}
NTSTRSAFEAPI RtlStringCbCopyW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:174
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

Referenced by FormatPartition().

◆ 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}
#define SystemVolume
Definition: reactos.c:51
#define InstallVolume
Definition: reactos.c:46
return pTarget Start()
@ Unformatted
Definition: partlist.h:34
#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
@ FSVOLNOTIFY_ENDQUEUE
Definition: fsutil.h:145
@ FSVOLNOTIFY_STARTSUBQUEUE
Definition: fsutil.h:146
@ FSVOLNOTIFY_STARTQUEUE
Definition: fsutil.h:144
@ FSVOLNOTIFY_ENDSUBQUEUE
Definition: fsutil.h:147
@ FSVOLNOTIFY_PARTITIONERROR
Definition: fsutil.h:149
@ FSVOL_ABORT
Definition: fsutil.h:165
@ FSVOL_SKIP
Definition: fsutil.h:168
BOOLEAN WritePartitionsToDisk(IN PPARTLIST List)
Definition: partlist.c:3753
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

Referenced by PrepareAndDoCopyThread(), and StartPartitionOperationsPage().

◆ GetFileSystemByName()

static PFILE_SYSTEM GetFileSystemByName ( IN PCWSTR  FileSystemName)
static

GetProvider()

Definition at line 198 of file fsutil.c.

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}
FILESYSTEM_CHKDSK FileSystems[]
Definition: autochk.c:47
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
int Count
Definition: noreturn.cpp:7
static FILE_SYSTEM RegisteredFileSystems[]
Definition: fsutil.c:159
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFCOLLECTION _In_ WDFOBJECT Item
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550

Referenced by ChkdskFileSystem_UStr(), and FormatFileSystem_UStr().

◆ GetNextUnformattedVolume()

static PVOLENTRY GetNextUnformattedVolume ( _In_ PPARTLIST  List,
_In_opt_ PVOLENTRY  Volume 
)
static

Definition at line 1071 of file fsutil.c.

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}

Referenced by FsVolCommitOpsQueue().

◆ 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}
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
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().

Variable Documentation

◆ RegisteredFileSystems

FILE_SYSTEM RegisteredFileSystems[]
static
Initial value:
=
{
{ L"FAT" , VfatFormat, VfatChkdsk },
{ L"FAT32", VfatFormat, VfatChkdsk },
{ L"BTRFS", BtrfsFormat, BtrfsChkdsk },
}
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)
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

Definition at line 159 of file fsutil.c.

Referenced by BlImgStartBootApplication(), GetFileSystemByName(), and GetRegisteredFileSystems().