2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS VFATx filesystem library
8 * CSH 05/04-2003 Created
13 #include <ndk/obfuncs.h>
19 VfatxFormat(IN PUNICODE_STRING DriveRoot
,
20 IN FMIFS_MEDIA_FLAG MediaFlag
,
21 IN PUNICODE_STRING Label
,
22 IN BOOLEAN QuickFormat
,
24 IN PFMIFSCALLBACK Callback
)
26 OBJECT_ATTRIBUTES ObjectAttributes
;
27 DISK_GEOMETRY DiskGeometry
;
30 PARTITION_INFORMATION PartitionInfo
;
31 FORMAT_CONTEXT Context
;
34 DPRINT("VfatxFormat(DriveRoot '%wZ')\n", DriveRoot
);
36 Context
.TotalSectorCount
= 0;
37 Context
.CurrentSectorCount
= 0;
38 Context
.Callback
= Callback
;
39 Context
.Success
= FALSE
;
42 InitializeObjectAttributes(&ObjectAttributes
,
48 Status
= NtOpenFile(&FileHandle
,
49 FILE_GENERIC_READ
| FILE_GENERIC_WRITE
,
53 FILE_SYNCHRONOUS_IO_ALERT
);
54 if (!NT_SUCCESS(Status
))
56 DPRINT("NtOpenFile() failed with status 0x%.08x\n", Status
);
60 Status
= NtDeviceIoControlFile(FileHandle
,
65 IOCTL_DISK_GET_DRIVE_GEOMETRY
,
69 sizeof(DISK_GEOMETRY
));
70 if (!NT_SUCCESS(Status
))
72 DPRINT("IOCTL_DISK_GET_DRIVE_GEOMETRY failed with status 0x%.08x\n", Status
);
77 if (DiskGeometry
.MediaType
== FixedMedia
)
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
);
89 Status
= NtDeviceIoControlFile(FileHandle
,
94 IOCTL_DISK_GET_PARTITION_INFO
,
98 sizeof(PARTITION_INFORMATION
));
99 if (!NT_SUCCESS(Status
))
101 DPRINT("IOCTL_DISK_GET_PARTITION_INFO failed with status 0x%.08x\n", Status
);
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
;
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
);
131 if (Callback
!= NULL
)
134 Callback(PROGRESS
, 0, (PVOID
)&Context
.Percent
);
137 Status
= FatxFormat(FileHandle
,
144 if (Callback
!= NULL
)
146 Context
.Success
= (BOOLEAN
)(NT_SUCCESS(Status
));
147 Callback(DONE
, 0, (PVOID
)&Context
.Success
);
150 DPRINT("VfatxFormat() done. Status 0x%.08x\n", Status
);
157 VfatxUpdateProgress(IN PFORMAT_CONTEXT Context
,
162 Context
->CurrentSectorCount
+= (ULONGLONG
)Increment
;
164 NewPercent
= (Context
->CurrentSectorCount
* 100ULL) / Context
->TotalSectorCount
;
166 if (NewPercent
> Context
->Percent
)
168 Context
->Percent
= NewPercent
;
169 if (Context
->Callback
!= NULL
)
171 Context
->Callback(PROGRESS
, 0, &Context
->Percent
);