ReactOS 0.4.16-dev-197-g92996da
format.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: File Management IFS Utility functions
4 * FILE: reactos/dll/win32/fmifs/format.c
5 * PURPOSE: Volume format
6 *
7 * PROGRAMMERS: Emanuele Aliberti
8 * Hervé Poussineau (hpoussin@reactos.org)
9 */
10
11#include "precomp.h"
12#include <ntstrsafe.h>
13
14#define NDEBUG
15#include <debug.h>
16
17/* FMIFS.6 */
20 IN PWCHAR DriveRoot,
21 IN FMIFS_MEDIA_FLAG MediaFlag,
26{
27 FormatEx(DriveRoot,
28 MediaFlag,
29 Format,
30 Label,
32 0,
33 Callback);
34}
35
36/* FMIFS.7 */
37VOID
40 IN PWCHAR DriveRoot,
41 IN FMIFS_MEDIA_FLAG MediaFlag,
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}
136
137/* EOF */
unsigned char BOOLEAN
#define DPRINT1
Definition: precomp.h:8
BOOL QuickFormat
Definition: format.c:66
PWCHAR Label
Definition: format.c:70
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
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
@ Success
Definition: eventcreate.c:712
_Must_inspect_result_ _Inout_opt_ PUNICODE_STRING VolumeName
Definition: fltkernel.h:1117
FMIFS_MEDIA_FLAG
Definition: fmifs.h:52
@ FMIFS_FLOPPY
Definition: fmifs.h:61
@ FMIFS_REMOVABLE
Definition: fmifs.h:64
@ FMIFS_HARDDISK
Definition: fmifs.h:65
BOOLEAN(NTAPI * PFMIFSCALLBACK)(IN CALLBACKCOMMAND Command, IN ULONG SubAction, IN PVOID ActionInfo)
Definition: fmifs.h:103
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
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
__wchar_t WCHAR
Definition: xmlstorage.h:180