ReactOS 0.4.17-dev-1321-g5c122a9
format.c File Reference
#include "diskpart.h"
#include <fmifs/fmifs.h>
#include <debug.h>
Include dependency graph for format.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static BOOL GetFsModule (_In_ PWSTR pszFileSystem, _Out_ HMODULE *phModule)
 
BOOLEAN WINAPI FormatCallback (CALLBACKCOMMAND Command, ULONG Size, PVOID Argument)
 
EXIT_CODE format_main (_In_ INT argc, _In_ PWSTR *argv)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file format.c.

Function Documentation

◆ format_main()

EXIT_CODE format_main ( _In_ INT  argc,
_In_ PWSTR *  argv 
)

Definition at line 95 of file format.c.

98{
99 UNICODE_STRING usDriveRoot;
101 PWSTR pszSuffix = NULL;
102 PWSTR pszFileSystem = NULL;
103 PWSTR pszLabel = NULL;
104 BOOLEAN bQuickFormat = FALSE;
105 ULONG ulClusterSize = 0;
107 PULIB_FORMAT pFormat = NULL;
108// FMIFS_MEDIA_FLAG MediaType = FMIFS_HARDDISK;
109 INT i;
111
112
113 if (CurrentVolume == NULL)
114 {
116 return EXIT_SUCCESS;
117 }
118
119 for (i = 1; i < argc; i++)
120 {
121 if (_wcsicmp(argv[i], L"noerr") == 0)
122 {
123 /* noerr */
124 DPRINT("NoErr\n", pszSuffix);
125 ConPuts(StdOut, L"The NOERR option is not supported yet!\n");
126#if 0
127 bNoErr = TRUE;
128#endif
129 }
130 }
131
132 for (i = 1; i < argc; i++)
133 {
134 if (HasPrefix(argv[i], L"fs=", &pszSuffix))
135 {
136 /* fs=<fs> */
137 pszFileSystem = pszSuffix;
138 }
139 else if (HasPrefix(argv[i], L"revision=", &pszSuffix))
140 {
141 /* revision=<X.XX> */
142 ConPuts(StdOut, L"The REVISION option is not supported yet!\n");
143 }
144 else if (HasPrefix(argv[i], L"label=", &pszSuffix))
145 {
146 /* label=<"label"> */
147 pszLabel = pszSuffix;
148 }
149 else if (HasPrefix(argv[i], L"unit=", &pszSuffix))
150 {
151 /* unit=<N> */
152 ulClusterSize = wcstoul(pszSuffix, NULL, 0);
153 if ((ulClusterSize == 0) && (errno == ERANGE))
154 {
156 goto done;
157 }
158 }
159 else if (_wcsicmp(argv[i], L"recommended") == 0)
160 {
161 /* recommended */
162 ConPuts(StdOut, L"The RECOMMENDED option is not supported yet!\n");
163 }
164 else if (_wcsicmp(argv[i], L"quick") == 0)
165 {
166 /* quick */
167 bQuickFormat = TRUE;
168 }
169 else if (_wcsicmp(argv[i], L"compress") == 0)
170 {
171 /* compress */
172 ConPuts(StdOut, L"The COMPRESS option is not supported yet!\n");
173 }
174 else if (_wcsicmp(argv[i], L"override") == 0)
175 {
176 /* override */
177 ConPuts(StdOut, L"The OVERRIDE option is not supported yet!\n");
178 }
179 else if (_wcsicmp(argv[i], L"duplicate") == 0)
180 {
181 /* duplicate */
182 ConPuts(StdOut, L"The DUPLICATE option is not supported yet!\n");
183 }
184 else if (_wcsicmp(argv[i], L"nowait") == 0)
185 {
186 /* nowait */
187 ConPuts(StdOut, L"The NOWAIT option is not supported yet!\n");
188 }
189 else if (_wcsicmp(argv[i], L"noerr") == 0)
190 {
191 /* noerr - Already handled above */
192 }
193 else
194 {
196 return EXIT_SUCCESS;
197 }
198 }
199
200 DPRINT("VolumeName : %S\n", CurrentVolume->VolumeName);
201 DPRINT("DeviceName : %S\n", CurrentVolume->DeviceName);
202 DPRINT("DriveLetter : %C\n", CurrentVolume->DriveLetter);
203#if 0
204 switch (CurrentVolume->VolumeType)
205 {
207 MediaType = FMIFS_REMOVABLE; // ???
208 break;
209
211 MediaType = FMIFS_HARDDISK;
212 break;
213
215 MediaType = FMIFS_REMOVABLE; // ???
216 break;
217
219 default:
220 MediaType = FMIFS_REMOVABLE; // ???
221 break;
222 }
223#endif
224
225 DPRINT("FileSystem: %S\n", pszFileSystem);
226 DPRINT("Label: %S\n", pszLabel);
227 DPRINT("Quick: %d\n", bQuickFormat);
228 DPRINT("ClusterSize: %lu\n", ulClusterSize);
229
231
232 /* Remove trailing backslash */
233 if (usDriveRoot.Buffer[(usDriveRoot.Length / sizeof(WCHAR)) - 1] == L'\\')
234 {
235 usDriveRoot.Buffer[(usDriveRoot.Length / sizeof(WCHAR)) - 1] = UNICODE_NULL;
236 usDriveRoot.Length -= sizeof(WCHAR);
237 }
238
239 DPRINT("DriveRoot: %wZ\n", &usDriveRoot);
240
241 /* Use the FAT filesystem as default */
242 if (pszFileSystem == NULL)
243 pszFileSystem = L"FAT";
244
245 BOOLEAN bBackwardCompatible = FALSE; // Default to latest FS versions.
246 if (_wcsicmp(pszFileSystem, L"FAT") == 0)
247 bBackwardCompatible = TRUE;
248 // else if (wcsicmp(pszFileSystem, L"FAT32") == 0)
249 // bBackwardCompatible = FALSE;
250
251 if (pszLabel == NULL)
252 pszLabel = L"";
253
255
256 if (!GetFsModule(pszFileSystem, &hModule))
257 {
258 DPRINT1("GetFsModule() failed\n");
259 goto done;
260 }
261
262 pFormat = (PULIB_FORMAT)GetProcAddress(hModule, "Format");
263 if (pFormat)
264 {
265 Success = (pFormat)(&usDriveRoot,
267 bQuickFormat,
268 bBackwardCompatible,
269 FMIFS_HARDDISK, //MediaType,
271 ulClusterSize);
272 }
273
274done:
275 ConPuts(StdOut, L"\n");
276 if (Success)
278 else
280
281 if (hModule)
283
284 RtlFreeUnicodeString(&usDriveRoot);
285
286 return EXIT_SUCCESS;
287}
unsigned char BOOLEAN
Definition: actypes.h:127
#define DPRINT1
Definition: precomp.h:8
static BOOL GetFsModule(_In_ PWSTR pszFileSystem, _Out_ HMODULE *phModule)
Definition: format.c:18
BOOLEAN WINAPI FormatCallback(CALLBACKCOMMAND Command, ULONG Size, PVOID Argument)
Definition: format.c:68
#define IDS_SELECT_NO_VOLUME
Definition: resource.h:132
#define IDS_ERROR_INVALID_ARGS
Definition: resource.h:239
#define IDS_FORMAT_FAIL
Definition: resource.h:89
#define IDS_FORMAT_SUCCESS
Definition: resource.h:90
WCHAR LabelString[12]
Definition: format.c:74
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: conutils_noros.h:8
#define StdOut
Definition: conutils_noros.h:6
void ConResPrintf(FILE *fp, UINT nID,...)
#define StdErr
Definition: conutils_noros.h:7
void ConResPuts(FILE *fp, UINT nID)
@ VOLUME_TYPE_UNKNOWN
Definition: diskpart.h:114
@ VOLUME_TYPE_REMOVABLE
Definition: diskpart.h:113
@ VOLUME_TYPE_CDROM
Definition: diskpart.h:111
@ VOLUME_TYPE_PARTITION
Definition: diskpart.h:112
BOOL HasPrefix(_In_ PWSTR pszString, _In_ PWSTR pszPrefix, _Out_opt_ PWSTR *pszSuffix)
Definition: misc.c:76
PVOLENTRY CurrentVolume
Definition: partlist.c:77
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HMODULE hModule
Definition: animate.c:44
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
MonoAssembly int argc
Definition: metahost.c:107
_ACRTIMP __msvcrt_ulong __cdecl wcstoul(const wchar_t *, wchar_t **, int)
Definition: wcs.c:2917
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:164
#define ERANGE
Definition: errno.h:55
#define errno
Definition: errno.h:120
#define L(x)
Definition: resources.c:13
@ Success
Definition: eventcreate.c:712
@ FMIFS_REMOVABLE
Definition: fmifs.h:65
@ FMIFS_HARDDISK
Definition: fmifs.h:66
BOOLEAN(NTAPI * PULIB_FORMAT)(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: fmifs.h:233
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define argv
Definition: mplay32.c:18
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)
#define UNICODE_NULL
short WCHAR
Definition: pedump.c:58
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
#define DPRINT
Definition: sndvol32.h:73
VOLUME_TYPE VolumeType
Definition: diskpart.h:260
WCHAR VolumeName[MAX_PATH]
Definition: diskpart.h:252
WCHAR DeviceName[MAX_PATH]
Definition: diskpart.h:253
WCHAR DriveLetter
Definition: diskpart.h:256
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59

◆ FormatCallback()

BOOLEAN WINAPI FormatCallback ( CALLBACKCOMMAND  Command,
ULONG  Size,
PVOID  Argument 
)

Definition at line 68 of file format.c.

72{
74
75 switch (Command)
76 {
77 case PROGRESS:
80 break;
81
82 case DONE:
83 break;
84
85 default:
86 DPRINT1("Callback (%u %lu %p)\n", Command, Size, Argument);
87 break;
88 }
89
90 return TRUE;
91}
#define IDS_FORMAT_PROGRESS
Definition: resource.h:91
_Check_return_ _In_ DXGK_EVENT_TYPE _In_ ULONG _In_ PVOID Argument
Definition: dispmprt.h:1288
@ PROGRESS
Definition: fmifs.h:83
DWORD * PDWORD
Definition: pedump.c:68
#define DONE
Definition: rnr20lib.h:14
Definition: shell.h:41
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539

Referenced by format_main().

◆ GetFsModule()

static BOOL GetFsModule ( _In_ PWSTR  pszFileSystem,
_Out_ HMODULE *  phModule 
)
static

Definition at line 18 of file format.c.

21{
22 WCHAR szDllNameBuffer[32];
23 HKEY hKey;
25
26 *phModule = NULL;
27
29 L"SOFTWARE\\ReactOS\\ReactOS\\CurrentVersion\\IFS",
30 0,
32 &hKey);
33 if (dwErr != ERROR_SUCCESS)
34 {
35 DPRINT1("Failed to open!\n");
36 return FALSE;
37 }
38
39 dwLength = sizeof(szDllNameBuffer);
41 pszFileSystem,
42 NULL,
43 NULL,
44 (PBYTE)szDllNameBuffer,
45 &dwLength);
46
48
49 if (dwErr != ERROR_SUCCESS)
50 {
51 DPRINT1("Failed to query!\n");
52 return FALSE;
53 }
54
55 *phModule = LoadLibraryW(szDllNameBuffer);
56 if (*phModule == NULL)
57 {
58 DPRINT1("Failed to load!\n");
59 return FALSE;
60 }
61
62 return TRUE;
63}
DWORD dwErr
Definition: service.c:36
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define LoadLibraryW(x)
Definition: compat.h:747
static DWORD DWORD * dwLength
Definition: fusion.c:86
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
#define KEY_READ
Definition: nt_native.h:1026
BYTE * PBYTE
Definition: pedump.c:66
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by format_main().