2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS VFAT filesystem library
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * CSH 05/04-2003 Created
12 #define NTOS_MODE_USER
14 #include <ddk/ntddscsi.h>
15 #include <fslib/vfatlib.h>
22 DPRINT("VfatInitialize()\n");
24 return STATUS_SUCCESS;
30 PUNICODE_STRING DriveRoot,
32 PUNICODE_STRING Label,
35 PFMIFSCALLBACK Callback)
37 OBJECT_ATTRIBUTES ObjectAttributes;
38 DISK_GEOMETRY DiskGeometry;
41 PARTITION_INFORMATION PartitionInfo;
44 DPRINT("VfatFormat(DriveRoot '%wZ')\n", DriveRoot);
46 InitializeObjectAttributes(&ObjectAttributes,
52 Status = NtOpenFile(&FileHandle,
53 FILE_WRITE_ACCESS | FILE_WRITE_ATTRIBUTES,
57 FILE_SYNCHRONOUS_IO_ALERT);
58 if (!NT_SUCCESS(Status))
60 DPRINT("NtOpenFile() failed with status 0x%.08x\n", Status);
64 Status = NtDeviceIoControlFile(FileHandle,
69 IOCTL_DISK_GET_DRIVE_GEOMETRY,
73 sizeof(DISK_GEOMETRY));
74 if (!NT_SUCCESS(Status))
76 DPRINT("IOCTL_DISK_GET_DRIVE_GEOMETRY failed with status 0x%.08x\n", Status);
81 if (DiskGeometry.MediaType == FixedMedia)
83 DPRINT("Cylinders %I64d\n", DiskGeometry.Cylinders.QuadPart);
84 DPRINT("TracksPerCylinder %ld\n", DiskGeometry.TracksPerCylinder);
85 DPRINT("SectorsPerTrack %ld\n", DiskGeometry.SectorsPerTrack);
86 DPRINT("BytesPerSector %ld\n", DiskGeometry.BytesPerSector);
87 DPRINT("DiskSize %I64d\n",
88 DiskGeometry.Cylinders.QuadPart *
89 (ULONGLONG)DiskGeometry.TracksPerCylinder *
90 (ULONGLONG)DiskGeometry.SectorsPerTrack *
91 (ULONGLONG)DiskGeometry.BytesPerSector);
93 Status = NtDeviceIoControlFile(FileHandle,
98 IOCTL_DISK_GET_PARTITION_INFO,
102 sizeof(PARTITION_INFORMATION));
103 if (!NT_SUCCESS(Status))
105 DPRINT("IOCTL_DISK_GET_PARTITION_INFO failed with status 0x%.08x\n", Status);
111 * FIXME: This is a hack!
112 * Partitioning software MUST set the correct number of hidden sectors!
114 PartitionInfo.HiddenSectors = DiskGeometry.SectorsPerTrack;
118 PartitionInfo.PartitionType = 0;
119 PartitionInfo.StartingOffset.QuadPart = 0ULL;
120 PartitionInfo.PartitionLength.QuadPart =
121 DiskGeometry.Cylinders.QuadPart *
122 (ULONGLONG)DiskGeometry.TracksPerCylinder *
123 (ULONGLONG)DiskGeometry.SectorsPerTrack *
124 (ULONGLONG)DiskGeometry.BytesPerSector;
125 PartitionInfo.HiddenSectors = 0;
126 PartitionInfo.PartitionNumber = 0;
127 PartitionInfo.BootIndicator = FALSE;
128 PartitionInfo.RewritePartition = FALSE;
129 PartitionInfo.RecognizedPartition = FALSE;
132 DPRINT("PartitionType 0x%x\n", PartitionInfo.PartitionType);
133 DPRINT("StartingOffset %I64d\n", PartitionInfo.StartingOffset.QuadPart);
134 DPRINT("PartitionLength %I64d\n", PartitionInfo.PartitionLength.QuadPart);
135 DPRINT("HiddenSectors %lu\n", PartitionInfo.HiddenSectors);
136 DPRINT("PartitionNumber %d\n", PartitionInfo.PartitionNumber);
137 DPRINT("BootIndicator 0x%x\n", PartitionInfo.BootIndicator);
138 DPRINT("RewritePartition %d\n", PartitionInfo.RewritePartition);
139 DPRINT("RecognizedPartition %d\n", PartitionInfo.RecognizedPartition);
141 if (PartitionInfo.PartitionLength.QuadPart < (4200ULL * 1024ULL))
143 /* FAT12 (volume is smaller than 4.1MB) */
144 Status = Fat12Format (FileHandle,
152 else if (PartitionInfo.PartitionLength.QuadPart < (512ULL * 1024ULL * 1024ULL))
154 /* FAT16 (volume is smaller than 512MB) */
155 Status = Fat16Format (FileHandle,
165 /* FAT32 (volume is 512MB or larger) */
166 Status = Fat32Format (FileHandle,
177 DPRINT("VfatFormat() done. Status 0x%.08x\n", Status);
186 DPRINT("VfatCleanup()\n");
188 return STATUS_SUCCESS;