ReactOS  0.4.15-dev-1206-g731eddf
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.

Macros

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

Typedefs

typedef IN HANDLE DstPath
 
typedef IN HANDLE IN HANDLE RootPartition
 

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 PFMIFSCALLBACK Callback)
 
NTSTATUS ChkdskFileSystem (IN PCWSTR DriveRoot, IN PCWSTR FileSystemName, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PFMIFSCALLBACK Callback)
 
NTSTATUS FormatFileSystem_UStr (IN PUNICODE_STRING DriveRoot, IN PCWSTR FileSystemName, IN FMIFS_MEDIA_FLAG MediaFlag, IN PUNICODE_STRING Label, IN BOOLEAN QuickFormat, IN ULONG ClusterSize, IN PFMIFSCALLBACK Callback)
 
NTSTATUS FormatFileSystem (IN PCWSTR DriveRoot, IN PCWSTR FileSystemName, IN FMIFS_MEDIA_FLAG MediaFlag, IN PCWSTR Label, IN BOOLEAN QuickFormat, IN ULONG ClusterSize, IN 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)
 
BOOLEAN PreparePartitionForFormatting (IN struct _PARTENTRY *PartEntry, IN PCWSTR FileSystemName)
 

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 84 of file fsutil.h.

◆ InstallFat16BootCode

#define InstallFat16BootCode   InstallFatBootCode

Definition at line 85 of file fsutil.h.

Typedef Documentation

◆ DstPath

typedef IN HANDLE DstPath

Definition at line 75 of file fsutil.h.

◆ RootPartition

Definition at line 75 of file fsutil.h.

Function Documentation

◆ ChkdskFileSystem()

NTSTATUS ChkdskFileSystem ( IN PCWSTR  DriveRoot,
IN PCWSTR  FileSystemName,
IN BOOLEAN  FixErrors,
IN BOOLEAN  Verbose,
IN BOOLEAN  CheckOnlyIfDirty,
IN BOOLEAN  ScanDrive,
IN PFMIFSCALLBACK  Callback 
)

Definition at line 246 of file fsutil.c.

254 {
255  UNICODE_STRING DriveRootU;
256 
257  RtlInitUnicodeString(&DriveRootU, DriveRoot);
258  return ChkdskFileSystem_UStr(&DriveRootU,
259  FileSystemName,
260  FixErrors,
261  Verbose,
262  CheckOnlyIfDirty,
263  ScanDrive,
264  Callback);
265 }
BOOL Verbose
Definition: chkdsk.c:72
NTSTATUS ChkdskFileSystem_UStr(IN PUNICODE_STRING DriveRoot, IN PCWSTR FileSystemName, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PFMIFSCALLBACK Callback)
Definition: fsutil.c:217
BOOL FixErrors
Definition: chkdsk.c:69
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
LPFNPSPCALLBACK Callback
Definition: desk.c:112

◆ 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 PFMIFSCALLBACK  Callback 
)

ChkdskEx()

Definition at line 217 of file fsutil.c.

225 {
227 
228  FileSystem = GetFileSystemByName(FileSystemName);
229 
230  if (!FileSystem || !FileSystem->ChkdskFunc)
231  {
232  // BOOLEAN Argument = FALSE;
233  // Callback(DONE, 0, &Argument);
234  return STATUS_NOT_SUPPORTED;
235  }
236 
237  return FileSystem->ChkdskFunc(DriveRoot,
238  FixErrors,
239  Verbose,
240  CheckOnlyIfDirty,
241  ScanDrive,
242  Callback);
243 }
PWCHAR FileSystem
Definition: format.c:72
BOOL Verbose
Definition: chkdsk.c:72
static PFILE_SYSTEM GetFileSystemByName(IN PCWSTR FileSystemName)
Definition: fsutil.c:170
BOOL FixErrors
Definition: chkdsk.c:69
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
LPFNPSPCALLBACK Callback
Definition: desk.c:112

Referenced by ChkdskFileSystem(), and ChkdskPartition().

◆ FormatFileSystem()

NTSTATUS FormatFileSystem ( IN PCWSTR  DriveRoot,
IN PCWSTR  FileSystemName,
IN FMIFS_MEDIA_FLAG  MediaFlag,
IN PCWSTR  Label,
IN BOOLEAN  QuickFormat,
IN ULONG  ClusterSize,
IN PFMIFSCALLBACK  Callback 
)

Definition at line 299 of file fsutil.c.

307 {
308  UNICODE_STRING DriveRootU;
309  UNICODE_STRING LabelU;
310 
311  RtlInitUnicodeString(&DriveRootU, DriveRoot);
312  RtlInitUnicodeString(&LabelU, Label);
313 
314  return FormatFileSystem_UStr(&DriveRootU,
315  FileSystemName,
316  MediaFlag,
317  &LabelU,
318  QuickFormat,
319  ClusterSize,
320  Callback);
321 }
BOOL QuickFormat
Definition: format.c:66
DWORD ClusterSize
Definition: format.c:67
NTSTATUS FormatFileSystem_UStr(IN PUNICODE_STRING DriveRoot, IN PCWSTR FileSystemName, IN FMIFS_MEDIA_FLAG MediaFlag, IN PUNICODE_STRING Label, IN BOOLEAN QuickFormat, IN ULONG ClusterSize, IN PFMIFSCALLBACK Callback)
Definition: fsutil.c:270
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
PWCHAR Label
Definition: format.c:70
LPFNPSPCALLBACK Callback
Definition: desk.c:112

Referenced by InstallFatBootcodeToFloppy().

◆ FormatFileSystem_UStr()

NTSTATUS FormatFileSystem_UStr ( IN PUNICODE_STRING  DriveRoot,
IN PCWSTR  FileSystemName,
IN FMIFS_MEDIA_FLAG  MediaFlag,
IN PUNICODE_STRING  Label,
IN BOOLEAN  QuickFormat,
IN ULONG  ClusterSize,
IN PFMIFSCALLBACK  Callback 
)

FormatEx()

Definition at line 270 of file fsutil.c.

278 {
280 
281  FileSystem = GetFileSystemByName(FileSystemName);
282 
283  if (!FileSystem || !FileSystem->FormatFunc)
284  {
285  // BOOLEAN Argument = FALSE;
286  // Callback(DONE, 0, &Argument);
287  return STATUS_NOT_SUPPORTED;
288  }
289 
290  return FileSystem->FormatFunc(DriveRoot,
291  MediaFlag,
292  Label,
293  QuickFormat,
294  ClusterSize,
295  Callback);
296 }
PWCHAR FileSystem
Definition: format.c:72
BOOL QuickFormat
Definition: format.c:66
DWORD ClusterSize
Definition: format.c:67
static PFILE_SYSTEM GetFileSystemByName(IN PCWSTR FileSystemName)
Definition: fsutil.c:170
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
PWCHAR Label
Definition: format.c:70
LPFNPSPCALLBACK Callback
Definition: desk.c:112

Referenced by FormatFileSystem(), and FormatPartition().

◆ GetRegisteredFileSystems()

BOOLEAN GetRegisteredFileSystems ( IN ULONG  Index,
OUT PCWSTR FileSystemName 
)

QueryAvailableFileSystemFormat()

Definition at line 155 of file fsutil.c.

158 {
160  return FALSE;
161 
162  *FileSystemName = RegisteredFileSystems[Index].FileSystemName;
163 
164  return TRUE;
165 }
#define TRUE
Definition: types.h:120
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define FALSE
Definition: types.h:117
static FILE_SYSTEM RegisteredFileSystems[]
Definition: fsutil.c:130
static const UCHAR Index[8]
Definition: usbohci.c:18
PCWSTR FileSystemName
Definition: fsutil.c:124

Referenced by InitializeFileSystemList().

◆ InstallBtrfsBootCode()

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

Definition at line 508 of file fsutil.c.

512 {
514  NTSTATUS LockStatus;
518  PARTITION_INFORMATION_EX PartInfo;
519  BOOTCODE NewBootSector = {0};
520 
521  /* Allocate and read the new bootsector from SrcPath */
522  RtlInitUnicodeString(&Name, SrcPath);
523  Status = ReadBootCodeFromFile(&NewBootSector,
524  &Name,
526  if (!NT_SUCCESS(Status))
527  return Status;
528 
529  /*
530  * The BTRFS driver requires the volume to be locked in order to modify
531  * the first sectors of the partition, even though they are outside the
532  * file-system space / in the reserved area (they are situated before
533  * the super-block at 0x1000) and is in principle allowed by the NT
534  * storage stack.
535  * So we lock here in order to write the bootsector at sector 0.
536  * If locking fails, we ignore and continue nonetheless.
537  */
538  LockStatus = NtFsControlFile(DstPath,
539  NULL,
540  NULL,
541  NULL,
542  &IoStatusBlock,
544  NULL,
545  0,
546  NULL,
547  0);
548  if (!NT_SUCCESS(LockStatus))
549  {
550  DPRINT1("WARNING: Failed to lock BTRFS volume for writing bootsector! Operations may fail! (Status 0x%lx)\n", LockStatus);
551  }
552 
553  /* Obtain partition info and write it to the bootsector */
555  NULL,
556  NULL,
557  NULL,
558  &IoStatusBlock,
560  NULL,
561  0,
562  &PartInfo,
563  sizeof(PartInfo));
564  if (!NT_SUCCESS(Status))
565  {
566  DPRINT1("IOCTL_DISK_GET_PARTITION_INFO_EX failed (Status %lx)\n", Status);
567  goto Quit;
568  }
569 
570  /* Write new bootsector to RootPath */
571  ((PBTRFS_BOOTSECTOR)NewBootSector.BootCode)->PartitionStartLBA =
573 
574  /* Write sector 0 */
575  FileOffset.QuadPart = 0ULL;
577  NULL,
578  NULL,
579  NULL,
580  &IoStatusBlock,
581  NewBootSector.BootCode,
582  NewBootSector.Length,
583  &FileOffset,
584  NULL);
585  if (!NT_SUCCESS(Status))
586  {
587  DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
588  goto Quit;
589  }
590 
591 Quit:
592  /* Unlock the volume */
593  LockStatus = NtFsControlFile(DstPath,
594  NULL,
595  NULL,
596  NULL,
597  &IoStatusBlock,
599  NULL,
600  0,
601  NULL,
602  0);
603  if (!NT_SUCCESS(LockStatus))
604  {
605  DPRINT1("Failed to unlock BTRFS volume (Status 0x%lx)\n", LockStatus);
606  }
607 
608  /* Free the new bootsector */
609  FreeBootCode(&NewBootSector);
610 
611  return Status;
612 }
#define FSCTL_UNLOCK_VOLUME
Definition: nt_native.h:833
#define BTRFS_BOOTSECTOR_SIZE
Definition: fsutil.h:70
LONG NTSTATUS
Definition: precomp.h:26
ULONG Length
Definition: bootcode.h:18
NTSTATUS ReadBootCodeFromFile(IN OUT PBOOTCODE BootCodeInfo, IN PUNICODE_STRING FilePath, IN ULONG Length OPTIONAL)
Definition: bootcode.c:69
NTSYSCALLAPI NTSTATUS NTAPI NtFsControlFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG FsControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength)
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)
struct _BTRFS_BOOTSECTOR * PBTRFS_BOOTSECTOR
IN HANDLE DstPath
Definition: fsutil.h:75
struct NameRec_ * Name
Definition: cdprocs.h:459
smooth NULL
Definition: ftsmooth.c:416
#define ULL(a, b)
Definition: format_msg.c:27
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PVOID BootCode
Definition: bootcode.h:17
IN HANDLE IN HANDLE RootPartition
Definition: fsutil.h:75
LARGE_INTEGER StartingOffset
Definition: imports.h:221
Status
Definition: gdiplustypes.h:24
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)
VOID FreeBootCode(IN OUT PBOOTCODE BootCodeInfo)
Definition: bootcode.c:104
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define DPRINT1
Definition: precomp.h:8
#define FSCTL_LOCK_VOLUME
Definition: nt_native.h:832
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define SECTORSIZE
Definition: bootcode.h:13
#define IOCTL_DISK_GET_PARTITION_INFO_EX
Definition: ntddk_ex.h:206
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by InstallBtrfsBootcodeToPartition().

◆ InstallFat32BootCode()

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

Definition at line 387 of file fsutil.c.

391 {
397  BOOTCODE OrigBootSector = {0};
398  BOOTCODE NewBootSector = {0};
399 
400  /* Allocate and read the current original partition bootsector */
401  Status = ReadBootCodeByHandle(&OrigBootSector,
404  if (!NT_SUCCESS(Status))
405  return Status;
406 
407  /* Allocate and read the new bootsector (2 sectors) from SrcPath */
408  RtlInitUnicodeString(&Name, SrcPath);
409  Status = ReadBootCodeFromFile(&NewBootSector,
410  &Name,
412  if (!NT_SUCCESS(Status))
413  {
414  FreeBootCode(&OrigBootSector);
415  return Status;
416  }
417 
418  /* Adjust the bootsector (copy a part of the FAT32 BPB) */
419  RtlCopyMemory(&((PFAT32_BOOTSECTOR)NewBootSector.BootCode)->OemName,
420  &((PFAT32_BOOTSECTOR)OrigBootSector.BootCode)->OemName,
421  FIELD_OFFSET(FAT32_BOOTSECTOR, BootCodeAndData) -
423 
424  /*
425  * We know we copy the boot code to a file only when DstPath != RootPartition,
426  * otherwise the boot code is copied to the specified root partition.
427  */
428  if (DstPath != RootPartition)
429  {
430  /* Copy to a file: Disable the backup bootsector */
431  ((PFAT32_BOOTSECTOR)NewBootSector.BootCode)->BackupBootSector = 0;
432  }
433  else
434  {
435  /* Copy to a disk: Get the location of the backup bootsector */
436  BackupBootSector = ((PFAT32_BOOTSECTOR)OrigBootSector.BootCode)->BackupBootSector;
437  }
438 
439  /* Free the original bootsector */
440  FreeBootCode(&OrigBootSector);
441 
442  /* Write the first sector of the new bootcode to DstPath sector 0 */
443  FileOffset.QuadPart = 0ULL;
445  NULL,
446  NULL,
447  NULL,
448  &IoStatusBlock,
449  NewBootSector.BootCode,
451  &FileOffset,
452  NULL);
453  if (!NT_SUCCESS(Status))
454  {
455  DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
456  FreeBootCode(&NewBootSector);
457  return Status;
458  }
459 
460  if (DstPath == RootPartition)
461  {
462  /* Copy to a disk: Write the backup bootsector */
463  if ((BackupBootSector != 0x0000) && (BackupBootSector != 0xFFFF))
464  {
467  NULL,
468  NULL,
469  NULL,
470  &IoStatusBlock,
471  NewBootSector.BootCode,
473  &FileOffset,
474  NULL);
475  if (!NT_SUCCESS(Status))
476  {
477  DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
478  FreeBootCode(&NewBootSector);
479  return Status;
480  }
481  }
482  }
483 
484  /* Write the second sector of the new bootcode to boot disk sector 14 */
485  // FileOffset.QuadPart = (ULONGLONG)(14 * FAT32_BOOTSECTOR_SIZE);
486  FileOffset.QuadPart = 14 * FAT32_BOOTSECTOR_SIZE;
487  Status = NtWriteFile(DstPath, // or really RootPartition ???
488  NULL,
489  NULL,
490  NULL,
491  &IoStatusBlock,
492  ((PUCHAR)NewBootSector.BootCode + FAT32_BOOTSECTOR_SIZE),
494  &FileOffset,
495  NULL);
496  if (!NT_SUCCESS(Status))
497  {
498  DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
499  }
500 
501  /* Free the new bootsector */
502  FreeBootCode(&NewBootSector);
503 
504  return Status;
505 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS ReadBootCodeFromFile(IN OUT PBOOTCODE BootCodeInfo, IN PUNICODE_STRING FilePath, IN ULONG Length OPTIONAL)
Definition: bootcode.c:69
BOOL BackupBootSector(LPCTSTR lpszVolumeName)
Definition: install.c:61
IN HANDLE DstPath
Definition: fsutil.h:75
struct NameRec_ * Name
Definition: cdprocs.h:459
smooth NULL
Definition: ftsmooth.c:416
struct _FAT32_BOOTSECTOR * PFAT32_BOOTSECTOR
#define ULL(a, b)
Definition: format_msg.c:27
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:67
PVOID BootCode
Definition: bootcode.h:17
IN HANDLE IN HANDLE RootPartition
Definition: fsutil.h:75
Status
Definition: gdiplustypes.h:24
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)
NTSTATUS ReadBootCodeByHandle(IN OUT PBOOTCODE BootCodeInfo, IN HANDLE FileHandle, IN ULONG Length OPTIONAL)
Definition: bootcode.c:21
VOID FreeBootCode(IN OUT PBOOTCODE BootCodeInfo)
Definition: bootcode.c:104
unsigned short USHORT
Definition: pedump.c:61
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define FAT32_BOOTSECTOR_SIZE
Definition: fsutil.h:69
IN PDCB IN POEM_STRING OemName
Definition: fatprocs.h:1303

Referenced by InstallFatBootcodeToPartition().

◆ InstallFatBootCode()

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

Definition at line 329 of file fsutil.c.

333 {
338  BOOTCODE OrigBootSector = {0};
339  BOOTCODE NewBootSector = {0};
340 
341  /* Allocate and read the current original partition bootsector */
342  Status = ReadBootCodeByHandle(&OrigBootSector,
345  if (!NT_SUCCESS(Status))
346  return Status;
347 
348  /* Allocate and read the new bootsector from SrcPath */
349  RtlInitUnicodeString(&Name, SrcPath);
350  Status = ReadBootCodeFromFile(&NewBootSector,
351  &Name,
353  if (!NT_SUCCESS(Status))
354  {
355  FreeBootCode(&OrigBootSector);
356  return Status;
357  }
358 
359  /* Adjust the bootsector (copy a part of the FAT12/16 BPB) */
360  RtlCopyMemory(&((PFAT_BOOTSECTOR)NewBootSector.BootCode)->OemName,
361  &((PFAT_BOOTSECTOR)OrigBootSector.BootCode)->OemName,
362  FIELD_OFFSET(FAT_BOOTSECTOR, BootCodeAndData) -
364 
365  /* Free the original bootsector */
366  FreeBootCode(&OrigBootSector);
367 
368  /* Write the new bootsector to DstPath */
369  FileOffset.QuadPart = 0ULL;
371  NULL,
372  NULL,
373  NULL,
374  &IoStatusBlock,
375  NewBootSector.BootCode,
376  NewBootSector.Length,
377  &FileOffset,
378  NULL);
379 
380  /* Free the new bootsector */
381  FreeBootCode(&NewBootSector);
382 
383  return Status;
384 }
#define FAT_BOOTSECTOR_SIZE
Definition: fsutil.h:68
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
LONG NTSTATUS
Definition: precomp.h:26
ULONG Length
Definition: bootcode.h:18
NTSTATUS ReadBootCodeFromFile(IN OUT PBOOTCODE BootCodeInfo, IN PUNICODE_STRING FilePath, IN ULONG Length OPTIONAL)
Definition: bootcode.c:69
IN HANDLE DstPath
Definition: fsutil.h:75
struct NameRec_ * Name
Definition: cdprocs.h:459
smooth NULL
Definition: ftsmooth.c:416
#define ULL(a, b)
Definition: format_msg.c:27
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PVOID BootCode
Definition: bootcode.h:17
IN HANDLE IN HANDLE RootPartition
Definition: fsutil.h:75
Status
Definition: gdiplustypes.h:24
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)
NTSTATUS ReadBootCodeByHandle(IN OUT PBOOTCODE BootCodeInfo, IN HANDLE FileHandle, IN ULONG Length OPTIONAL)
Definition: bootcode.c:21
VOID FreeBootCode(IN OUT PBOOTCODE BootCodeInfo)
Definition: bootcode.c:104
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
IN PDCB IN POEM_STRING OemName
Definition: fatprocs.h:1303

◆ NTSTATUS()

typedef NTSTATUS ( PFS_INSTALL_BOOTCODE)

◆ PreparePartitionForFormatting()

BOOLEAN PreparePartitionForFormatting ( IN struct _PARTENTRY PartEntry,
IN PCWSTR  FileSystemName 
)

Definition at line 620 of file fsutil.c.

623 {
625 
626  if (!FileSystemName || !*FileSystemName)
627  {
628  DPRINT1("No file system specified?\n");
629  return FALSE;
630  }
631 
632  PartitionType = FileSystemToPartitionType(FileSystemName,
633  &PartEntry->StartSector,
634  &PartEntry->SectorCount);
636  {
637  /* Unknown file system */
638  DPRINT1("Unknown file system '%S'\n", FileSystemName);
639  return FALSE;
640  }
641 
642  SetPartitionType(PartEntry, PartitionType);
643 
644  /*
645  * Adjust the filesystem name in case of FAT vs. FAT32, according to
646  * the type of partition set by FileSystemToPartitionType().
647  */
648  if (wcsicmp(FileSystemName, L"FAT") == 0)
649  {
650  if ((/*PartEntry->*/PartitionType == PARTITION_FAT32) ||
651  (/*PartEntry->*/PartitionType == PARTITION_FAT32_XINT13))
652  {
653  FileSystemName = L"FAT32";
654  }
655  }
656 
657 //
658 // FIXME: Do this now, or after the partition was actually formatted??
659 //
660  /* Set the new partition's file system proper */
661  RtlStringCbCopyW(PartEntry->FileSystem,
662  sizeof(PartEntry->FileSystem),
663  FileSystemName);
664 
665  return TRUE;
666 }
#define PARTITION_FAT32
Definition: disk.h:95
NTSTRSAFEAPI RtlStringCbCopyW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:174
UCHAR FileSystemToPartitionType(IN PCWSTR FileSystem, IN PULARGE_INTEGER StartSector, IN PULARGE_INTEGER SectorCount)
Definition: fsrec.c:234
#define TRUE
Definition: types.h:120
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
#define FALSE
Definition: types.h:117
#define wcsicmp
Definition: compat.h:15
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
VOID SetPartitionType(IN PPARTENTRY PartEntry, IN UCHAR PartitionType)
Definition: partlist.c:4108
#define DPRINT1
Definition: precomp.h:8
CHAR PartitionType
Definition: part_xbox.c:32
#define PARTITION_FAT32_XINT13
Definition: disk.h:96

Referenced by FormatPartitionPage().