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 20 VfatxFormat( 21 IN PUNICODE_STRING DriveRoot, 22 IN PFMIFSCALLBACK Callback, 23 IN BOOLEAN QuickFormat, 24 IN BOOLEAN BackwardCompatible, 25 IN MEDIA_TYPE MediaType, 26 IN PUNICODE_STRING Label, 27 IN ULONG ClusterSize) 28 { 29 OBJECT_ATTRIBUTES ObjectAttributes; 30 DISK_GEOMETRY DiskGeometry; 31 IO_STATUS_BLOCK Iosb; 32 HANDLE FileHandle; 33 PARTITION_INFORMATION PartitionInfo; 34 FORMAT_CONTEXT Context; 35 NTSTATUS Status; 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 54 InitializeObjectAttributes(&ObjectAttributes, 55 DriveRoot, 56 0, 57 NULL, 58 NULL); 59 60 Status = NtOpenFile(&FileHandle, 61 FILE_GENERIC_READ | FILE_GENERIC_WRITE, 62 &ObjectAttributes, 63 &Iosb, 64 FILE_SHARE_READ, 65 FILE_SYNCHRONOUS_IO_ALERT); 66 if (!NT_SUCCESS(Status)) 67 { 68 DPRINT("NtOpenFile() failed with status 0x%08x\n", Status); 69 return FALSE; 70 } 71 72 Status = NtDeviceIoControlFile(FileHandle, 73 NULL, 74 NULL, 75 NULL, 76 &Iosb, 77 IOCTL_DISK_GET_DRIVE_GEOMETRY, 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); 85 NtClose(FileHandle); 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 101 Status = NtDeviceIoControlFile(FileHandle, 102 NULL, 103 NULL, 104 NULL, 105 &Iosb, 106 IOCTL_DISK_GET_PARTITION_INFO, 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); 114 NtClose(FileHandle); 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 149 Status = FatxFormat(FileHandle, 150 &PartitionInfo, 151 &DiskGeometry, 152 QuickFormat, 153 &Context); 154 NtClose(FileHandle); 155 156 DPRINT("VfatxFormat() done. Status 0x%08x\n", Status); 157 return NT_SUCCESS(Status); 158 } 159 160 BOOLEAN 161 NTAPI 162 VfatxChkdsk( 163 IN PUNICODE_STRING DriveRoot, 164 IN PFMIFSCALLBACK Callback, 165 IN BOOLEAN FixErrors, 166 IN BOOLEAN Verbose, 167 IN BOOLEAN CheckOnlyIfDirty, 168 IN BOOLEAN ScanDrive, 169 IN PVOID pUnknown1, 170 IN PVOID pUnknown2, 171 IN PVOID pUnknown3, 172 IN PVOID pUnknown4, 173 IN PULONG ExitStatus) 174 { 175 UNIMPLEMENTED; 176 *ExitStatus = (ULONG)STATUS_SUCCESS; 177 return TRUE; 178 } 179 180 VOID 181 VfatxUpdateProgress(IN PFORMAT_CONTEXT Context, 182 IN ULONG Increment) 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 */ 201