+
+//
+// Formatting routines
+//
+
+BOOLEAN
+PreparePartitionForFormatting(
+ IN struct _PARTENTRY* PartEntry,
+ IN PFILE_SYSTEM FileSystem)
+{
+ if (!FileSystem)
+ {
+ DPRINT1("No file system specified?\n");
+ return FALSE;
+ }
+
+ if (wcscmp(FileSystem->FileSystemName, L"FAT") == 0)
+ {
+ if (PartEntry->SectorCount.QuadPart < 8192)
+ {
+ /* FAT12 CHS partition (disk is smaller than 4.1MB) */
+ SetPartitionType(PartEntry, PARTITION_FAT_12);
+ }
+ else if (PartEntry->StartSector.QuadPart < 1450560)
+ {
+ /* Partition starts below the 8.4GB boundary ==> CHS partition */
+
+ if (PartEntry->SectorCount.QuadPart < 65536)
+ {
+ /* FAT16 CHS partition (partition size < 32MB) */
+ SetPartitionType(PartEntry, PARTITION_FAT_16);
+ }
+ else if (PartEntry->SectorCount.QuadPart < 1048576)
+ {
+ /* FAT16 CHS partition (partition size < 512MB) */
+ SetPartitionType(PartEntry, PARTITION_HUGE);
+ }
+ else
+ {
+ /* FAT32 CHS partition (partition size >= 512MB) */
+ SetPartitionType(PartEntry, PARTITION_FAT32);
+ }
+ }
+ else
+ {
+ /* Partition starts above the 8.4GB boundary ==> LBA partition */
+
+ if (PartEntry->SectorCount.QuadPart < 1048576)
+ {
+ /* FAT16 LBA partition (partition size < 512MB) */
+ SetPartitionType(PartEntry, PARTITION_XINT13);
+ }
+ else
+ {
+ /* FAT32 LBA partition (partition size >= 512MB) */
+ SetPartitionType(PartEntry, PARTITION_FAT32_XINT13);
+ }
+ }
+ }
+#if 0
+ else if (wcscmp(FileSystem->FileSystemName, L"EXT2") == 0)
+ {
+ SetPartitionType(PartEntry, PARTITION_EXT2);
+ }
+ else if (wcscmp(FileSystem->FileSystemName, L"NTFS") == 0)
+ {
+ SetPartitionType(PartEntry, PARTITION_IFS);
+ }
+#endif
+ else
+ {
+ /* Unknown file system? */
+ DPRINT1("Unknown file system \"%S\"?\n", FileSystem->FileSystemName);
+ return FALSE;
+ }
+
+//
+// FIXME: Do this now, or after the partition was actually formatted??
+//
+ /* Set the new partition's file system proper */
+ PartEntry->FormatState = Formatted; // Well... This may be set after the real formatting takes place (in which case we should change the FormatState to another value)
+ PartEntry->FileSystem = FileSystem;
+
+ return TRUE;
+}
+