ReactOS  0.4.14-dev-55-g2da92ac
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 
20  IN FMIFS_MEDIA_FLAG MediaFlag,
25 {
27  DISK_GEOMETRY DiskGeometry;
33 
34  DPRINT("VfatxFormat(DriveRoot '%wZ')\n", DriveRoot);
35 
36  Context.TotalSectorCount = 0;
37  Context.CurrentSectorCount = 0;
38  Context.Callback = Callback;
39  Context.Success = FALSE;
40  Context.Percent = 0;
41 
43  DriveRoot,
44  0,
45  NULL,
46  NULL);
47 
51  &Iosb,
54  if (!NT_SUCCESS(Status))
55  {
56  DPRINT("NtOpenFile() failed with status 0x%.08x\n", Status);
57  return Status;
58  }
59 
61  NULL,
62  NULL,
63  NULL,
64  &Iosb,
66  NULL,
67  0,
68  &DiskGeometry,
69  sizeof(DISK_GEOMETRY));
70  if (!NT_SUCCESS(Status))
71  {
72  DPRINT("IOCTL_DISK_GET_DRIVE_GEOMETRY failed with status 0x%.08x\n", Status);
74  return Status;
75  }
76 
77  if (DiskGeometry.MediaType == FixedMedia)
78  {
79  DPRINT("Cylinders %I64d\n", DiskGeometry.Cylinders.QuadPart);
80  DPRINT("TracksPerCylinder %ld\n", DiskGeometry.TracksPerCylinder);
81  DPRINT("SectorsPerTrack %ld\n", DiskGeometry.SectorsPerTrack);
82  DPRINT("BytesPerSector %ld\n", DiskGeometry.BytesPerSector);
83  DPRINT("DiskSize %I64d\n",
84  DiskGeometry.Cylinders.QuadPart *
85  (ULONGLONG)DiskGeometry.TracksPerCylinder *
86  (ULONGLONG)DiskGeometry.SectorsPerTrack *
87  (ULONGLONG)DiskGeometry.BytesPerSector);
88 
90  NULL,
91  NULL,
92  NULL,
93  &Iosb,
95  NULL,
96  0,
98  sizeof(PARTITION_INFORMATION));
99  if (!NT_SUCCESS(Status))
100  {
101  DPRINT("IOCTL_DISK_GET_PARTITION_INFO failed with status 0x%.08x\n", Status);
103  return Status;
104  }
105  }
106  else
107  {
108  PartitionInfo.PartitionType = 0;
109  PartitionInfo.StartingOffset.QuadPart = 0ULL;
110  PartitionInfo.PartitionLength.QuadPart =
111  DiskGeometry.Cylinders.QuadPart *
112  (ULONGLONG)DiskGeometry.TracksPerCylinder *
113  (ULONGLONG)DiskGeometry.SectorsPerTrack *
114  (ULONGLONG)DiskGeometry.BytesPerSector;
115  PartitionInfo.HiddenSectors = 0;
116  PartitionInfo.PartitionNumber = 0;
117  PartitionInfo.BootIndicator = FALSE;
118  PartitionInfo.RewritePartition = FALSE;
119  PartitionInfo.RecognizedPartition = FALSE;
120  }
121 
122  DPRINT("PartitionType 0x%x\n", PartitionInfo.PartitionType);
123  DPRINT("StartingOffset %I64d\n", PartitionInfo.StartingOffset.QuadPart);
124  DPRINT("PartitionLength %I64d\n", PartitionInfo.PartitionLength.QuadPart);
125  DPRINT("HiddenSectors %lu\n", PartitionInfo.HiddenSectors);
126  DPRINT("PartitionNumber %d\n", PartitionInfo.PartitionNumber);
127  DPRINT("BootIndicator 0x%x\n", PartitionInfo.BootIndicator);
128  DPRINT("RewritePartition %d\n", PartitionInfo.RewritePartition);
129  DPRINT("RecognizedPartition %d\n", PartitionInfo.RecognizedPartition);
130 
131  if (Callback != NULL)
132  {
133  Context.Percent = 0;
134  Callback(PROGRESS, 0, (PVOID)&Context.Percent);
135  }
136 
138  &PartitionInfo,
139  &DiskGeometry,
140  QuickFormat,
141  &Context);
143 
144  if (Callback != NULL)
145  {
146  Context.Success = (BOOLEAN)(NT_SUCCESS(Status));
147  Callback(DONE, 0, (PVOID)&Context.Success);
148  }
149 
150  DPRINT("VfatxFormat() done. Status 0x%.08x\n", Status);
151 
152  return Status;
153 }
154 
159  IN BOOLEAN CheckOnlyIfDirty,
160  IN BOOLEAN ScanDrive,
162 {
164  return STATUS_SUCCESS;
165 }
166 
167 VOID
170 {
171  ULONG NewPercent;
172 
173  Context->CurrentSectorCount += (ULONGLONG)Increment;
174 
175  NewPercent = (Context->CurrentSectorCount * 100ULL) / Context->TotalSectorCount;
176 
177  if (NewPercent > Context->Percent)
178  {
179  Context->Percent = NewPercent;
180  if (Context->Callback != NULL)
181  {
182  Context->Callback(PROGRESS, 0, &Context->Percent);
183  }
184  }
185 }
186 
187 /* EOF */
#define FILE_GENERIC_READ
Definition: nt_native.h:653
NTSTATUS NTAPI VfatxChkdsk(IN PUNICODE_STRING DriveRoot, IN BOOLEAN FixErrors, IN BOOLEAN Verbose, IN BOOLEAN CheckOnlyIfDirty, IN BOOLEAN ScanDrive, IN PFMIFSCALLBACK Callback)
Definition: vfatxlib.c:156
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define IN
Definition: typedefs.h:38
BOOL Verbose
Definition: chkdsk.c:72
LONG NTSTATUS
Definition: precomp.h:26
Definition: fmifs.h:68
ULONG BytesPerSector
Definition: ntdddisk.h:376
ULONG TracksPerCylinder
Definition: ntdddisk.h:374
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:125
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
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
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
BOOL QuickFormat
Definition: format.c:66
#define ULL(a, b)
Definition: format_msg.c:27
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:4426
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
uint64_t ULONGLONG
Definition: typedefs.h:65
VOID VfatxUpdateProgress(IN PFORMAT_CONTEXT Context, IN ULONG Increment)
Definition: vfatxlib.c:168
LARGE_INTEGER Cylinders
Definition: ntdddisk.h:372
ULONG SectorsPerTrack
Definition: ntdddisk.h:375
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:373
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:88
Status
Definition: gdiplustypes.h:24
#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
NTSTATUS NTAPI VfatxFormat(IN PUNICODE_STRING DriveRoot, IN FMIFS_MEDIA_FLAG MediaFlag, IN PUNICODE_STRING Label, IN BOOLEAN QuickFormat, IN ULONG ClusterSize, IN PFMIFSCALLBACK Callback)
Definition: vfatxlib.c:19
BOOL FixErrors
Definition: chkdsk.c:69
#define BOOLEAN
Definition: pedump.c:73
struct tagContext Context
Definition: acpixf.h:1024
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:114
PWCHAR Label
Definition: format.c:70
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define DONE
Definition: rnr20lib.h:14
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG Increment
Definition: CrNtStubs.h:42
return STATUS_SUCCESS
Definition: btrfs.c:2966
LPFNPSPCALLBACK Callback
Definition: desk.c:111
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
LONGLONG QuadPart
Definition: typedefs.h:112
FMIFS_MEDIA_FLAG
Definition: fmifs.h:37