ReactOS 0.4.16-dev-2104-gb84fa49
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 ConPrintf(StdOut, L"%s\n", argv[i]);
135
136 if (HasPrefix(argv[i], L"fs=", &pszSuffix))
137 {
138 /* fs=<fs> */
139 pszFileSystem = pszSuffix;
140 }
141 else if (HasPrefix(argv[i], L"revision=", &pszSuffix))
142 {
143 /* revision=<X.XX> */
144 ConPuts(StdOut, L"The REVISION option is not supported yet!\n");
145 }
146 else if (HasPrefix(argv[i], L"label=", &pszSuffix))
147 {
148 /* label=<"label"> */
149 pszLabel = pszSuffix;
150 }
151 else if (HasPrefix(argv[i], L"unit=", &pszSuffix))
152 {
153 /* unit=<N> */
154 ulClusterSize = wcstoul(pszSuffix, NULL, 0);
155 if ((ulClusterSize == 0) && (errno == ERANGE))
156 {
158 goto done;
159 }
160 }
161 else if (_wcsicmp(argv[i], L"recommended") == 0)
162 {
163 /* recommended */
164 ConPuts(StdOut, L"The RECOMMENDED option is not supported yet!\n");
165 }
166 else if (_wcsicmp(argv[i], L"quick") == 0)
167 {
168 /* quick */
169 bQuickFormat = TRUE;
170 }
171 else if (_wcsicmp(argv[i], L"compress") == 0)
172 {
173 /* compress */
174 ConPuts(StdOut, L"The COMPRESS option is not supported yet!\n");
175 }
176 else if (_wcsicmp(argv[i], L"override") == 0)
177 {
178 /* override */
179 ConPuts(StdOut, L"The OVERRIDE option is not supported yet!\n");
180 }
181 else if (_wcsicmp(argv[i], L"duplicate") == 0)
182 {
183 /* duplicate */
184 ConPuts(StdOut, L"The DUPLICATE option is not supported yet!\n");
185 }
186 else if (_wcsicmp(argv[i], L"nowait") == 0)
187 {
188 /* nowait */
189 ConPuts(StdOut, L"The NOWAIT option is not supported yet!\n");
190 }
191 else if (_wcsicmp(argv[i], L"noerr") == 0)
192 {
193 /* noerr - Already handled above */
194 }
195 else
196 {
198 return EXIT_SUCCESS;
199 }
200 }
201
202 DPRINT("VolumeName : %S\n", CurrentVolume->VolumeName);
203 DPRINT("DeviceName : %S\n", CurrentVolume->DeviceName);
204 DPRINT("DriveLetter : %C\n", CurrentVolume->DriveLetter);
205#if 0
206 switch (CurrentVolume->VolumeType)
207 {
209 MediaType = FMIFS_REMOVABLE; // ???
210 break;
211
213 MediaType = FMIFS_HARDDISK;
214 break;
215
217 MediaType = FMIFS_REMOVABLE; // ???
218 break;
219
221 default:
222 MediaType = FMIFS_REMOVABLE; // ???
223 break;
224 }
225#endif
226
227 DPRINT("FileSystem: %S\n", pszFileSystem);
228 DPRINT("Label: %S\n", pszLabel);
229 DPRINT("Quick: %d\n", bQuickFormat);
230 DPRINT("ClusterSize: %lu\n", ulClusterSize);
231
233
234 /* Remove trailing backslash */
235 if (usDriveRoot.Buffer[(usDriveRoot.Length / sizeof(WCHAR)) - 1] == L'\\')
236 {
237 usDriveRoot.Buffer[(usDriveRoot.Length / sizeof(WCHAR)) - 1] = UNICODE_NULL;
238 usDriveRoot.Length -= sizeof(WCHAR);
239 }
240
241 DPRINT("DriveRoot: %wZ\n", &usDriveRoot);
242
243 /* Use the FAT filesystem as default */
244 if (pszFileSystem == NULL)
245 pszFileSystem = L"FAT";
246
247 BOOLEAN bBackwardCompatible = FALSE; // Default to latest FS versions.
248 if (_wcsicmp(pszFileSystem, L"FAT") == 0)
249 bBackwardCompatible = TRUE;
250 // else if (wcsicmp(pszFileSystem, L"FAT32") == 0)
251 // bBackwardCompatible = FALSE;
252
253 if (pszLabel == NULL)
254 pszLabel = L"";
255
257
258 if (!GetFsModule(pszFileSystem, &hModule))
259 {
260 DPRINT1("GetFsModule() failed\n");
261 goto done;
262 }
263
264 pFormat = (PULIB_FORMAT)GetProcAddress(hModule, "Format");
265 if (pFormat)
266 {
267 Success = (pFormat)(&usDriveRoot,
269 bQuickFormat,
270 bBackwardCompatible,
271 FMIFS_HARDDISK, //MediaType,
273 ulClusterSize);
274 }
275
276done:
277 ConPuts(StdOut, L"\n");
278 if (Success)
280 else
282
283 if (hModule)
285
286 RtlFreeUnicodeString(&usDriveRoot);
287
288 return EXIT_SUCCESS;
289}
unsigned char BOOLEAN
static int argc
Definition: ServiceArgs.c:12
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
#define StdOut
Definition: fc.c:14
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
#define StdErr
Definition: fc.c:15
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
#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:130
#define IDS_ERROR_INVALID_ARGS
Definition: resource.h:229
#define IDS_FORMAT_FAIL
Definition: resource.h:87
#define IDS_FORMAT_SUCCESS
Definition: resource.h:88
WCHAR LabelString[12]
Definition: format.c:75
@ 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:58
PVOLENTRY CurrentVolume
Definition: partlist.c:77
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
_ACRTIMP __msvcrt_ulong __cdecl wcstoul(const wchar_t *, wchar_t **, int)
Definition: wcs.c:2912
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:159
#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)
HMODULE hModule
Definition: netsh.c:17
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define UNICODE_NULL
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
#define DPRINT
Definition: sndvol32.h:73
VOLUME_TYPE VolumeType
Definition: diskpart.h:245
WCHAR VolumeName[MAX_PATH]
Definition: diskpart.h:237
WCHAR DeviceName[MAX_PATH]
Definition: diskpart.h:238
WCHAR DriveLetter
Definition: diskpart.h:241
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ 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:
78 percent = (PDWORD)Argument;
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:89
@ 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().