ReactOS 0.4.16-dev-188-g678aa63
format.c File Reference
#include "precomp.h"
#include <ntstrsafe.h>
#include <debug.h>
Include dependency graph for format.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI Format (IN PWCHAR DriveRoot, IN FMIFS_MEDIA_FLAG MediaFlag, IN PWCHAR Format, IN PWCHAR Label, IN BOOLEAN QuickFormat, IN PFMIFSCALLBACK Callback)
 
VOID NTAPI FormatEx (IN PWCHAR DriveRoot, IN FMIFS_MEDIA_FLAG MediaFlag, IN PWCHAR Format, IN PWCHAR Label, IN BOOLEAN QuickFormat, IN ULONG ClusterSize, IN PFMIFSCALLBACK Callback)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file format.c.

Function Documentation

◆ Format()

VOID NTAPI Format ( IN PWCHAR  DriveRoot,
IN FMIFS_MEDIA_FLAG  MediaFlag,
IN PWCHAR  Format,
IN PWCHAR  Label,
IN BOOLEAN  QuickFormat,
IN PFMIFSCALLBACK  Callback 
)

Definition at line 19 of file format.c.

26{
27 FormatEx(DriveRoot,
28 MediaFlag,
29 Format,
30 Label,
32 0,
33 Callback);
34}
BOOL QuickFormat
Definition: format.c:66
PWCHAR Label
Definition: format.c:70
VOID NTAPI FormatEx(IN PWCHAR DriveRoot, IN FMIFS_MEDIA_FLAG MediaFlag, IN PWCHAR Format, IN PWCHAR Label, IN BOOLEAN QuickFormat, IN ULONG ClusterSize, IN PFMIFSCALLBACK Callback)
Definition: format.c:39
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458

◆ FormatEx()

VOID NTAPI FormatEx ( IN PWCHAR  DriveRoot,
IN FMIFS_MEDIA_FLAG  MediaFlag,
IN PWCHAR  Format,
IN PWCHAR  Label,
IN BOOLEAN  QuickFormat,
IN ULONG  ClusterSize,
IN PFMIFSCALLBACK  Callback 
)

Definition at line 39 of file format.c.

47{
49 UNICODE_STRING usDriveRoot;
50 UNICODE_STRING usLabel;
52 BOOLEAN BackwardCompatible = FALSE; // Default to latest FS versions.
53 MEDIA_TYPE MediaType;
54 WCHAR DriveName[MAX_PATH];
56
57//
58// TODO: Convert filesystem Format into ULIB format string.
59//
60
62 if (!Provider)
63 {
64 /* Unknown file system */
65 goto Quit;
66 }
67
68 if (!NT_SUCCESS(RtlStringCchCopyW(DriveName, ARRAYSIZE(DriveName), DriveRoot)))
69 goto Quit;
70
71 if (DriveName[wcslen(DriveName) - 1] != L'\\')
72 {
73 /* Append the trailing backslash for GetVolumeNameForVolumeMountPointW */
74 if (!NT_SUCCESS(RtlStringCchCatW(DriveName, ARRAYSIZE(DriveName), L"\\")))
75 goto Quit;
76 }
77
79 {
80 /* Couldn't get a volume GUID path, try formatting using a parameter provided path */
81 DPRINT1("Couldn't get a volume GUID path for drive %S\n", DriveName);
82 wcscpy(VolumeName, DriveName);
83 }
84
86 goto Quit;
87
88 /* Trim the trailing backslash since we will work with a device object */
89 usDriveRoot.Length -= sizeof(WCHAR);
90
91 RtlInitUnicodeString(&usLabel, Label);
92
93 /* Set the BackwardCompatible flag in case we format with older FAT12/16 */
94 if (_wcsicmp(Format, L"FAT") == 0)
95 BackwardCompatible = TRUE;
96 // else if (wcsicmp(Format, L"FAT32") == 0)
97 // BackwardCompatible = FALSE;
98
99 /* Convert the FMIFS MediaFlag to a NT MediaType */
100 // FIXME: Actually covert all the possible flags.
101 switch (MediaFlag)
102 {
103 case FMIFS_FLOPPY:
104 MediaType = F5_320_1024; // FIXME: This is hardfixed!
105 break;
106 case FMIFS_REMOVABLE:
107 MediaType = RemovableMedia;
108 break;
109 case FMIFS_HARDDISK:
110 MediaType = FixedMedia;
111 break;
112 default:
113 DPRINT1("Unknown FMIFS MediaFlag %d, converting 1-to-1 to NT MediaType\n",
114 MediaFlag);
115 MediaType = (MEDIA_TYPE)MediaFlag;
116 break;
117 }
118
119 DPRINT("Format() - %S\n", Format);
120 Success = Provider->Format(&usDriveRoot,
121 Callback,
123 BackwardCompatible,
124 MediaType,
125 &usLabel,
127 if (!Success)
128 DPRINT1("Format() failed\n");
129
130 RtlFreeUnicodeString(&usDriveRoot);
131
132Quit:
133 /* Report result */
134 Callback(DONE, 0, &Success);
135}
unsigned char BOOLEAN
#define DPRINT1
Definition: precomp.h:8
DWORD ClusterSize
Definition: format.c:67
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define MAX_PATH
Definition: compat.h:34
@ Success
Definition: eventcreate.c:712
_Must_inspect_result_ _Inout_opt_ PUNICODE_STRING VolumeName
Definition: fltkernel.h:1117
@ FMIFS_FLOPPY
Definition: fmifs.h:61
@ FMIFS_REMOVABLE
Definition: fmifs.h:64
@ FMIFS_HARDDISK
Definition: fmifs.h:65
return pInstance GetProvider() -> GetHandle()
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
BOOL WINAPI GetVolumeNameForVolumeMountPointW(IN LPCWSTR VolumeMountPoint, OUT LPWSTR VolumeName, IN DWORD VolumeNameLength)
Definition: mntpoint.c:496
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToNtPathName_U(_In_opt_z_ PCWSTR DosPathName, _Out_ PUNICODE_STRING NtPathName, _Out_opt_ PCWSTR *NtFileNamePart, _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
enum _MEDIA_TYPE MEDIA_TYPE
@ RemovableMedia
Definition: ntdddisk.h:382
@ FixedMedia
Definition: ntdddisk.h:383
@ F5_320_1024
Definition: ntdddisk.h:379
NTSTRSAFEAPI RtlStringCchCopyW(_Out_writes_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:127
NTSTRSAFEAPI RtlStringCchCatW(_Inout_updates_(cchDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cchDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:601
#define L(x)
Definition: ntvdm.h:50
#define DONE
Definition: rnr20lib.h:14
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define DPRINT
Definition: sndvol32.h:73
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by Format(), FormatDrive(), and wmain().