ReactOS 0.4.17-dev-1321-g5c122a9
format.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS DiskPart
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/system/diskpart/format.c
5 * PURPOSE: Manages all the partitions of the OS in an interactive way.
6 * PROGRAMMERS: Lee Schroeder
7 */
8
9#include "diskpart.h"
10
11#include <fmifs/fmifs.h>
12
13#define NDEBUG
14#include <debug.h>
15
16static
17BOOL
19 _In_ PWSTR pszFileSystem,
20 _Out_ HMODULE *phModule)
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}
64
65
70 ULONG Size,
72{
73 PDWORD percent;
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}
92
93
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
DWORD dwErr
Definition: service.c:36
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
EXIT_CODE format_main(_In_ INT argc, _In_ PWSTR *argv)
Definition: format.c:95
#define IDS_SELECT_NO_VOLUME
Definition: resource.h:132
#define IDS_FORMAT_PROGRESS
Definition: resource.h:91
#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
#define RegCloseKey(hKey)
Definition: registry.h:49
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)
#define ERROR_SUCCESS
Definition: deptool.c:10
@ 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
enum _EXIT_CODE EXIT_CODE
PVOLENTRY CurrentVolume
Definition: partlist.c:77
_Check_return_ _In_ DXGK_EVENT_TYPE _In_ ULONG _In_ PVOID Argument
Definition: dispmprt.h:1288
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
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
HMODULE hModule
Definition: animate.c:44
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define LoadLibraryW(x)
Definition: compat.h:747
static DWORD DWORD * dwLength
Definition: fusion.c:86
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
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
@ 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
CALLBACKCOMMAND
Definition: fmifs.h:82
@ PROGRESS
Definition: fmifs.h:83
FxAutoRegKey hKey
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)
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define KEY_READ
Definition: nt_native.h:1026
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define UNICODE_NULL
BYTE * PBYTE
Definition: pedump.c:66
short WCHAR
Definition: pedump.c:58
DWORD * PDWORD
Definition: pedump.c:68
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
#define DONE
Definition: rnr20lib.h:14
#define DPRINT
Definition: sndvol32.h:73
Definition: shell.h:41
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
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
#define WINAPI
Definition: msvc.h:6
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12