ReactOS 0.4.16-dev-250-g3ecd236
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
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,
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
151 &DiskGeometry,
153 &Context);
155
156 DPRINT("VfatxFormat() done. Status 0x%08x\n", Status);
157 return NT_SUCCESS(Status);
158}
159
161NTAPI
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
180VOID
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 */
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
BOOL FixErrors
Definition: chkdsk.c:69
BOOL Verbose
Definition: chkdsk.c:72
BOOL QuickFormat
Definition: format.c:66
PWCHAR Label
Definition: format.c:70
DWORD ClusterSize
Definition: format.c:67
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#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 FILE_SHARE_READ
Definition: compat.h:136
return Iosb
Definition: create.c:4402
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:46
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
@ PROGRESS
Definition: fmifs.h:82
BOOLEAN(NTAPI * PFMIFSCALLBACK)(IN CALLBACKCOMMAND Command, IN ULONG SubAction, IN PVOID ActionInfo)
Definition: fmifs.h:103
#define FILE_SYNCHRONOUS_IO_ALERT
Definition: from_kernel.h:30
Status
Definition: gdiplustypes.h:25
if(dx< 0)
Definition: linetemp.h:194
#define ULL(a, b)
Definition: format_msg.c:27
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_In_ NTSTATUS ExitStatus
Definition: psfuncs.h:867
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:3952
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)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define FILE_GENERIC_READ
Definition: nt_native.h:653
#define FILE_GENERIC_WRITE
Definition: nt_native.h:660
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
enum _MEDIA_TYPE MEDIA_TYPE
@ FixedMedia
Definition: ntdddisk.h:383
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:106
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
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
MEDIA_TYPE MediaType
Definition: ntdddisk.h:401
LARGE_INTEGER Cylinders
Definition: ntdddisk.h:400
ULONG TracksPerCylinder
Definition: ntdddisk.h:402
ULONG SectorsPerTrack
Definition: ntdddisk.h:403
ULONG BytesPerSector
Definition: ntdddisk.h:404
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
LONGLONG QuadPart
Definition: typedefs.h:114
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
VOID VfatxUpdateProgress(IN PFORMAT_CONTEXT Context, IN ULONG Increment)
Definition: vfatxlib.c:181
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
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2105