ReactOS  0.4.15-dev-1619-g69dffed
vfatxlib.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS VFATx filesystem library
4  * FILE: vfatxlib.c
5  * PURPOSE: Main API
6  * PROGRAMMERS:
7  * REVISIONS:
8  * CSH 05/04-2003 Created
9  */
10 
11 #include "vfatxlib.h"
12 
13 #include <ndk/obfuncs.h>
14 
15 #define NDEBUG
16 #include <debug.h>
17 
18 BOOLEAN
19 NTAPI
21  IN PUNICODE_STRING DriveRoot,
24  IN BOOLEAN BackwardCompatible,
25  IN MEDIA_TYPE MediaType,
28 {
30  DISK_GEOMETRY DiskGeometry;
36 
37  DPRINT("VfatxFormat(DriveRoot '%wZ')\n", DriveRoot);
38 
39  // FIXME:
40  UNREFERENCED_PARAMETER(MediaType);
41 
42  if (BackwardCompatible)
43  {
44  DPRINT1("BackwardCompatible == TRUE is unsupported!\n");
45  return FALSE;
46  }
47 
48  Context.TotalSectorCount = 0;
49  Context.CurrentSectorCount = 0;
50  Context.Callback = Callback;
51  Context.Success = FALSE;
52  Context.Percent = 0;
53 
55  DriveRoot,
56  0,
57  NULL,
58  NULL);
59 
63  &Iosb,
66  if (!NT_SUCCESS(Status))
67  {
68  DPRINT("NtOpenFile() failed with status 0x%08x\n", Status);
69  return FALSE;
70  }
71 
73  NULL,
74  NULL,
75  NULL,
76  &Iosb,
78  NULL,
79  0,
80  &DiskGeometry,
81  sizeof(DISK_GEOMETRY));
82  if (!NT_SUCCESS(Status))
83  {
84  DPRINT("IOCTL_DISK_GET_DRIVE_GEOMETRY failed with status 0x%08x\n", Status);
86  return FALSE;
87  }
88 
89  if (DiskGeometry.MediaType == FixedMedia)
90  {
91  DPRINT("Cylinders %I64d\n", DiskGeometry.Cylinders.QuadPart);
92  DPRINT("TracksPerCylinder %ld\n", DiskGeometry.TracksPerCylinder);
93  DPRINT("SectorsPerTrack %ld\n", DiskGeometry.SectorsPerTrack);
94  DPRINT("BytesPerSector %ld\n", DiskGeometry.BytesPerSector);
95  DPRINT("DiskSize %I64d\n",
96  DiskGeometry.Cylinders.QuadPart *
97  (ULONGLONG)DiskGeometry.TracksPerCylinder *
98  (ULONGLONG)DiskGeometry.SectorsPerTrack *
99  (ULONGLONG)DiskGeometry.BytesPerSector);
100 
102  NULL,
103  NULL,
104  NULL,
105  &Iosb,
107  NULL,
108  0,
109  &PartitionInfo,
110  sizeof(PARTITION_INFORMATION));
111  if (!NT_SUCCESS(Status))
112  {
113  DPRINT("IOCTL_DISK_GET_PARTITION_INFO failed with status 0x%08x\n", Status);
115  return FALSE;
116  }
117  }
118  else
119  {
120  PartitionInfo.PartitionType = 0;
121  PartitionInfo.StartingOffset.QuadPart = 0ULL;
122  PartitionInfo.PartitionLength.QuadPart =
123  DiskGeometry.Cylinders.QuadPart *
124  (ULONGLONG)DiskGeometry.TracksPerCylinder *
125  (ULONGLONG)DiskGeometry.SectorsPerTrack *
126  (ULONGLONG)DiskGeometry.BytesPerSector;
127  PartitionInfo.HiddenSectors = 0;
128  PartitionInfo.PartitionNumber = 0;
129  PartitionInfo.BootIndicator = FALSE;
130  PartitionInfo.RewritePartition = FALSE;
131  PartitionInfo.RecognizedPartition = FALSE;
132  }
133 
134  DPRINT("PartitionType 0x%x\n", PartitionInfo.PartitionType);
135  DPRINT("StartingOffset %I64d\n", PartitionInfo.StartingOffset.QuadPart);
136  DPRINT("PartitionLength %I64d\n", PartitionInfo.PartitionLength.QuadPart);
137  DPRINT("HiddenSectors %lu\n", PartitionInfo.HiddenSectors);
138  DPRINT("PartitionNumber %d\n", PartitionInfo.PartitionNumber);
139  DPRINT("BootIndicator 0x%x\n", PartitionInfo.BootIndicator);
140  DPRINT("RewritePartition %d\n", PartitionInfo.RewritePartition);
141  DPRINT("RecognizedPartition %d\n", PartitionInfo.RecognizedPartition);
142 
143  if (Callback != NULL)
144  {
145  Context.Percent = 0;
146  Callback(PROGRESS, 0, (PVOID)&Context.Percent);
147  }
148 
150  &PartitionInfo,
151  &DiskGeometry,
152  QuickFormat,
153  &Context);
155 
156  DPRINT("VfatxFormat() done. Status 0x%08x\n", Status);
157  return NT_SUCCESS(Status);
158 }
159 
160 BOOLEAN
161 NTAPI
163  IN PUNICODE_STRING DriveRoot,
167  IN BOOLEAN CheckOnlyIfDirty,
168  IN BOOLEAN ScanDrive,
169  IN PVOID pUnknown1,
170  IN PVOID pUnknown2,
171  IN PVOID pUnknown3,
172  IN PVOID pUnknown4,
174 {
177  return TRUE;
178 }
179 
180 VOID
183 {
184  ULONG NewPercent;
185 
186  Context->CurrentSectorCount += (ULONGLONG)Increment;
187 
188  NewPercent = (Context->CurrentSectorCount * 100ULL) / Context->TotalSectorCount;
189 
190  if (NewPercent > Context->Percent)
191  {
192  Context->Percent = NewPercent;
193  if (Context->Callback != NULL)
194  {
195  Context->Callback(PROGRESS, 0, &Context->Percent);
196  }
197  }
198 }
199 
200 /* EOF */
#define FILE_GENERIC_READ
Definition: nt_native.h:653
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define IN
Definition: typedefs.h:39
BOOL Verbose
Definition: chkdsk.c:72
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
LONG NTSTATUS
Definition: precomp.h:26
Definition: fmifs.h:68
enum _MEDIA_TYPE MEDIA_TYPE
ULONG BytesPerSector
Definition: ntdddisk.h:409
ULONG TracksPerCylinder
Definition: ntdddisk.h:407
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define FILE_SHARE_READ
Definition: compat.h:136
HANDLE FileHandle
Definition: stats.c:38
#define FILE_SYNCHRONOUS_IO_ALERT
Definition: from_kernel.h:30
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
NTSTATUS FatxFormat(IN HANDLE FileHandle, IN PPARTITION_INFORMATION PartitionInfo, IN PDISK_GEOMETRY DiskGeometry, IN BOOLEAN QuickFormat, IN OUT PFORMAT_CONTEXT Context)
Definition: fatx.c:343
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
BOOL QuickFormat
Definition: format.c:66
#define ULL(a, b)
Definition: format_msg.c:27
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
if(!(yy_init))
Definition: macro.lex.yy.c:714
return Iosb
Definition: create.c:4402
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:67
VOID VfatxUpdateProgress(IN PFORMAT_CONTEXT Context, IN ULONG Increment)
Definition: vfatxlib.c:181
LARGE_INTEGER Cylinders
Definition: ntdddisk.h:405
ULONG SectorsPerTrack
Definition: ntdddisk.h:408
DWORD ClusterSize
Definition: format.c:67
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2101
MEDIA_TYPE MediaType
Definition: ntdddisk.h:406
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:106
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:456
#define FILE_GENERIC_WRITE
Definition: nt_native.h:660
BOOLEAN(NTAPI * PFMIFSCALLBACK)(IN CALLBACKCOMMAND Command, IN ULONG SubAction, IN PVOID ActionInfo)
Definition: fmifs.h:89
BOOLEAN NTAPI VfatxChkdsk(IN PUNICODE_STRING DriveRoot, IN PFMIFSCALLBACK Callback, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PVOID pUnknown1, IN PVOID pUnknown2, IN PVOID pUnknown3, IN PVOID pUnknown4, IN PULONG ExitStatus)
Definition: vfatxlib.c:162
_In_ NTSTATUS ExitStatus
Definition: psfuncs.h:859
BOOLEAN NTAPI VfatxFormat(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: vfatxlib.c:20
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
BOOL FixErrors
Definition: chkdsk.c:69
#define DPRINT1
Definition: precomp.h:8
struct tagContext Context
Definition: acpixf.h:1034
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:115
PWCHAR Label
Definition: format.c:70
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define STATUS_SUCCESS
Definition: shellext.h:65
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:42
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
LONGLONG QuadPart
Definition: typedefs.h:114