Skip to content

Commit 63e875c

Browse files
committed
Disk formatting type as enum
1 parent 1f3bb52 commit 63e875c

File tree

4 files changed

+11
-21
lines changed

4 files changed

+11
-21
lines changed

source/Cosmos.System2/FileSystem/Disk.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,21 +263,14 @@ public void Clear()
263263
}
264264
}
265265

266-
public void FormatPartition(int index, string format, bool quick = true)
266+
public void FormatPartition(int index, FileSystemType format, bool quick = true)
267267
{
268268
var part = Partitions[index];
269269

270270
var xSize = (long)(Host.BlockCount * Host.BlockSize / 1024 / 1024);
271271

272-
if (format.StartsWith("FAT"))
273-
{
274-
FatFileSystem.CreateFatFileSystem(part.Host, VFSManager.GetNextFilesystemLetter() + ":\\", xSize, format);
275-
Mount();
276-
}
277-
else
278-
{
279-
throw new NotImplementedException(format + " formatting not supported.");
280-
}
272+
FatFileSystem.CreateFatFileSystem(part.Host, VFSManager.GetNextFilesystemLetter() + ":\\", xSize, format);
273+
Mount();
281274
}
282275

283276
private readonly FileSystem[] mountedPartitions = new FileSystem[4];

source/Cosmos.System2/FileSystem/FAT/FatFileSystem.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ public FatFileSystem(Partition aDevice, string aRootPath, long aSize, bool fileS
766766
/// </list>
767767
/// </exception>
768768
/// <exception cref="ArgumentOutOfRangeException">Thrown on fatal error.</exception>
769-
public static FatFileSystem CreateFatFileSystem(Partition aDevice, string aRootPath, long aSize, string aDriveFormat)
769+
public static FatFileSystem CreateFatFileSystem(Partition aDevice, string aRootPath, long aSize, FileSystemType aDriveFormat)
770770
{
771771
if (aDevice == null)
772772
{
@@ -1465,30 +1465,26 @@ internal enum FatTypeEnum
14651465
/// <exception cref="ArrayTypeMismatchException">Thrown on fatal error.</exception>
14661466
/// <exception cref="InvalidCastException">Thrown when the data in aData is corrupted.</exception>
14671467
/// <exception cref="NotSupportedException">Thrown when FAT type is unknown.</exception>
1468-
public override void Format(string aDriveFormat, bool aQuick)
1468+
public override void Format(FileSystemType aDriveFormat, bool aQuick)
14691469
{
14701470
/* Parmaters check */
14711471
if (Device == null)
14721472
{
14731473
throw new ArgumentNullException(nameof(Device));
14741474
}
14751475

1476-
if (aDriveFormat == "FAT32")
1476+
if (aDriveFormat == FileSystemType.FAT32)
14771477
{
14781478
mFatType = FatTypeEnum.Fat32;
14791479
}
1480-
else if (aDriveFormat == "FAT16")
1480+
else if (aDriveFormat == FileSystemType.FAT16)
14811481
{
14821482
throw new NotImplementedException("FAT16 formatting not supported yet.");
14831483
}
1484-
else if (aDriveFormat == "FAT12")
1484+
else if (aDriveFormat == FileSystemType.FAT12)
14851485
{
14861486
throw new NotImplementedException("FAT12 formatting not supported yet.");
14871487
}
1488-
else
1489-
{
1490-
throw new Exception("Unknown FAT type.");
1491-
}
14921488

14931489
/* FAT Configuration */
14941490
BytesPerSector = (uint)Device.BlockSize;

source/Cosmos.System2/FileSystem/FileSystem.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ protected FileSystem(Partition aDevice, string aRootPath, long aSize)
252252
/// <exception cref="ArrayTypeMismatchException">Thrown on fatal error.</exception>
253253
/// <exception cref="InvalidCastException">Thrown when the data in aData is corrupted.</exception>
254254
/// <exception cref="NotSupportedException">Thrown when FAT type is unknown.</exception>
255-
public abstract void Format(string aDriveFormat, bool aQuick);
255+
public abstract void Format(FileSystemType aDriveFormat, bool aQuick);
256256
}
257+
public enum FileSystemType { FAT12, FAT16, FAT32 }
257258
}

source/Cosmos.System2/FileSystem/ISO9660/ISO9660FileSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public override void DeleteFile(DirectoryEntry aPath)
243243
{
244244
throw new NotImplementedException("Read only file system");
245245
}
246-
public override void Format(string aDriveFormat, bool aQuick)
246+
public override void Format(FileSystemType aDriveFormat, bool aQuick)
247247
{
248248
throw new NotImplementedException();
249249
}

0 commit comments

Comments
 (0)