#define COSMOSDEBUG
using System;
using System.Collections.Generic;
using System.Text;
using Cosmos.System.FileSystem.VFS;
namespace Cosmos.System.FileSystem
{
///
/// DiskManager class. Used to manage drives.
///
public class DiskManager
{
///
/// Get drive name.
///
public string Name {get; }
///
/// Create new instance of class.
///
/// A drive name assinged to the disk.
/// Thrown if aDriveName is null.
/// Thrown if aDriveName length is smaller then 2, or greater than Int32.MaxValue.
/// Thrown if aDriveName is invalid drive identifier / not a root dir.
public DiskManager(string aDriveName)
{
if (aDriveName == null)
{
throw new ArgumentNullException(nameof(aDriveName));
}
if (!VFSManager.IsValidDriveId(aDriveName))
{
throw new ArgumentException("Argument must be drive identifier or root dir");
}
Global.mFileSystemDebugger.SendInternal($"Creating DriskManager for drive {aDriveName}");
Name = aDriveName;
}
///
/// Format drive. (delete all)
///
/// A drive format.
/// Quick format.
///
///
/// - Thrown when formating to different filesystem format then current format.
/// - aQuick is false.
/// - Thrown when FAT type is unknown.
///
///
///
///
/// - Thrown when the data length is 0 or greater then Int32.MaxValue.
/// - Entrys matadata offset value is invalid.
/// - Fatal error (contact support).
///
///
/// Thrown when filesystem is null / memory error.
///
///
/// - Thrown when drive name is null or empty.
/// - Data length is 0.
/// - Root path is null or empty.
/// - Memory error.
///
///
///
///
/// - Unable to determine filesystem for path: + drive name.
/// - Thrown when data size invalid.
/// - Thrown on unknown file system type.
/// - Thrown on fatal error (contact support).
///
///
/// Thrown when data lenght is greater then Int32.MaxValue.
/// Thrown on memory error.
/// Thrown on fatal error (contact support).
/// Thrown on fatal error (contact support).
/// Thrown when the data in aData is corrupted.
/// Thrown when FAT type is unknown.
public void Format(string aDriveFormat, bool aQuick = true)
{
/* For now we do the more easy thing: quick format of a drive with the same filesystem */
if (VFSManager.GetFileSystemType(Name) != aDriveFormat)
{
throw new NotImplementedException($"Formatting in {aDriveFormat} drive {Name} with Filesystem {VFSManager.GetFileSystemType(Name)} not yet supported");
}
if (aQuick == false)
{
throw new NotImplementedException("Slow format not implemented yet");
}
VFSManager.Format(Name, aDriveFormat, aQuick);
}
///
/// Change drive letter.
///
/// A new name to be set.
/// Thrown when aNewName is null.
/// Thrown if aNewName length is smaller then 2, or greater than Int32.MaxValue.
/// Thrown if aNewName is invalid drive identifier / not a root dir.
/// Thrown always.
public void ChangeDriveLetter(string aNewName)
{
if (aNewName == null)
{
throw new ArgumentNullException(nameof(aNewName));
}
if (!VFSManager.IsValidDriveId(aNewName))
{
throw new ArgumentException("Argument must be drive identifier or root dir");
}
/*
* 1. Add new method in VFSManager to change identifier of a drive
* 2. Update 'Name' to be 'aNewName'
*/
throw new NotImplementedException("ChangeDriveLetter");
}
///
/// Create Partition.
///
/// Start.
/// End.
/// Thrown if start / end is smaller then 0.
/// Thrown if end is smaller or equal to start.
/// Thrown always.
public void CreatePartion(long start, long end)
{
if (start < 0)
{
throw new ArgumentOutOfRangeException(nameof(start));
}
if (end < 0)
{
throw new ArgumentOutOfRangeException(nameof(start));
}
if (end <= start)
{
throw new ArgumentException("end is <= start");
}
throw new NotImplementedException("CreatePartion");
}
}
}