ReactOS  0.4.15-dev-3173-g40ee59d
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 
13 #define NDEBUG
14 #include <debug.h>
15 
16 /* FMIFS.6 */
17 VOID NTAPI
19  IN PWCHAR DriveRoot,
20  IN FMIFS_MEDIA_FLAG MediaFlag,
22  IN PWCHAR Label,
25 {
26  FormatEx(DriveRoot,
27  MediaFlag,
28  Format,
29  Label,
31  0,
32  Callback);
33 }
34 
35 /* FMIFS.7 */
36 VOID
37 NTAPI
39  IN PWCHAR DriveRoot,
40  IN FMIFS_MEDIA_FLAG MediaFlag,
42  IN PWCHAR Label,
46 {
48  UNICODE_STRING usDriveRoot;
49  UNICODE_STRING usLabel;
51  BOOLEAN BackwardCompatible = FALSE; // Default to latest FS versions.
52  MEDIA_TYPE MediaType;
54  //CURDIR CurDir;
55 
56 //
57 // TODO: Convert filesystem Format into ULIB format string.
58 //
59 
61  if (!Provider)
62  {
63  /* Unknown file system */
64  Callback(DONE, 0, &Success);
65  return;
66  }
67 
68 #if 1
69  DPRINT1("Warning: use GetVolumeNameForVolumeMountPointW() instead!\n");
70  swprintf(VolumeName, L"\\??\\%c:", towupper(DriveRoot[0]));
71  RtlCreateUnicodeString(&usDriveRoot, VolumeName);
72  /* Code disabled as long as our storage stack doesn't understand IOCTL_MOUNTDEV_QUERY_DEVICE_NAME */
73 #else
75  !RtlDosPathNameToNtPathName_U(VolumeName, &usDriveRoot, NULL, &CurDir))
76  {
77  /* Report an error */
78  Callback(DONE, 0, &Success);
79  return;
80  }
81 #endif
82 
83  RtlInitUnicodeString(&usLabel, Label);
84 
85  /* Set the BackwardCompatible flag in case we format with older FAT12/16 */
86  if (wcsicmp(Format, L"FAT") == 0)
87  BackwardCompatible = TRUE;
88  // else if (wcsicmp(Format, L"FAT32") == 0)
89  // BackwardCompatible = FALSE;
90 
91  /* Convert the FMIFS MediaFlag to a NT MediaType */
92  // FIXME: Actually covert all the possible flags.
93  switch (MediaFlag)
94  {
95  case FMIFS_FLOPPY:
96  MediaType = F5_320_1024; // FIXME: This is hardfixed!
97  break;
98  case FMIFS_REMOVABLE:
99  MediaType = RemovableMedia;
100  break;
101  case FMIFS_HARDDISK:
102  MediaType = FixedMedia;
103  break;
104  default:
105  DPRINT1("Unknown FMIFS MediaFlag %d, converting 1-to-1 to NT MediaType\n",
106  MediaFlag);
107  MediaType = (MEDIA_TYPE)MediaFlag;
108  break;
109  }
110 
111  DPRINT("Format() - %S\n", Format);
112  Success = Provider->Format(&usDriveRoot,
113  Callback,
114  QuickFormat,
115  BackwardCompatible,
116  MediaType,
117  &usLabel,
118  ClusterSize);
119  if (!Success)
120  DPRINT1("Format() failed\n");
121 
122  /* Report success */
123  Callback(DONE, 0, &Success);
124 
125  RtlFreeUnicodeString(&usDriveRoot);
126 }
127 
128 /* EOF */
#define IN
Definition: typedefs.h:39
#define TRUE
Definition: types.h:120
enum _MEDIA_TYPE MEDIA_TYPE
uint16_t * PWCHAR
Definition: typedefs.h:56
#define swprintf
Definition: precomp.h:40
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
BOOL QuickFormat
Definition: format.c:66
__wchar_t WCHAR
Definition: xmlstorage.h:180
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:38
#define MAX_PATH
Definition: compat.h:34
DWORD ClusterSize
Definition: format.c:67
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define wcsicmp
Definition: compat.h:15
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
static const WCHAR L[]
Definition: oid.c:1250
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:456
BOOLEAN(NTAPI * PFMIFSCALLBACK)(IN CALLBACKCOMMAND Command, IN ULONG SubAction, IN PVOID ActionInfo)
Definition: fmifs.h:89
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _Inout_opt_ PUNICODE_STRING VolumeName
Definition: fltkernel.h:1117
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
PWCHAR Label
Definition: format.c:70
#define DONE
Definition: rnr20lib.h:14
#define towupper(c)
Definition: wctype.h:99
BOOL WINAPI GetVolumeNameForVolumeMountPointW(IN LPCWSTR VolumeMountPoint, OUT LPWSTR VolumeName, IN DWORD VolumeNameLength)
Definition: mntpoint.c:496
#define DPRINT
Definition: sndvol32.h:71
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)
VOID NTAPI Format(IN PWCHAR DriveRoot, IN FMIFS_MEDIA_FLAG MediaFlag, IN PWCHAR Format, IN PWCHAR Label, IN BOOLEAN QuickFormat, IN PFMIFSCALLBACK Callback)
Definition: format.c:18
FMIFS_MEDIA_FLAG
Definition: fmifs.h:37
PIFS_PROVIDER GetProvider(IN PWCHAR FileSystem)
Definition: init.c:23