public RawDisk(DiskNumberType type, int number, FileAccess access = FileAccess.Read) { if (number < 0) { throw new ArgumentException("Invalid number"); } if ((access & FileAccess.Read) == 0) { throw new ArgumentException("Access must include read"); } string path; switch (type) { case DiskNumberType.PhysicalDisk: path = $@"\\.\GLOBALROOT\Device\Harddisk{number}\Partition0"; break; case DiskNumberType.Volume: path = $@"\\.\GLOBALROOT\Device\HarddiskVolume{number}"; break; default: throw new ArgumentOutOfRangeException(nameof(type)); } InitiateCommon(path, access); InitateDevice(); }
public static IEnumerable<int> GetAllAvailableDrives(DiskNumberType type) { string[] drives = Win32Helper.GetAllDevices(); if (type == DiskNumberType.PhysicalDisk) { foreach (string drive in drives) { if (RgxHarddisk.IsMatch(drive)) yield return int.Parse(drive.Substring("PhysicalDrive".Length)); } } else if (type == DiskNumberType.Volume) { foreach (string drive in drives) { if (RgxPartition.IsMatch(drive)) yield return int.Parse(drive.Substring("HarddiskVolume".Length)); } } else { throw new ArgumentOutOfRangeException(nameof(type)); } }
public static IEnumerable <int> GetAllAvailableDrives(DiskNumberType type) { string[] drives = Win32Helper.GetAllDevices(); if (type == DiskNumberType.PhysicalDisk) { foreach (string drive in drives) { if (RgxHarddisk.IsMatch(drive)) { yield return(int.Parse(drive.Substring("PhysicalDrive".Length))); } } } else if (type == DiskNumberType.Volume) { foreach (string drive in drives) { if (RgxPartition.IsMatch(drive)) { yield return(int.Parse(drive.Substring("HarddiskVolume".Length))); } } } else { throw new ArgumentOutOfRangeException(nameof(type)); } }
public RawDisk(DiskNumberType type, int number, FileAccess access = FileAccess.Read) { if (number < 0) throw new ArgumentException("Invalid number"); if ((access & FileAccess.Read) == 0) throw new ArgumentException("Access must include read"); string path; switch (type) { case DiskNumberType.PhysicalDisk: path = $@"\\.\GLOBALROOT\Device\Harddisk{number}\Partition0"; break; case DiskNumberType.Volume: path = $@"\\.\GLOBALROOT\Device\HarddiskVolume{number}"; break; default: throw new ArgumentOutOfRangeException(nameof(type)); } InitiateCommon(path, access); InitateDevice(); }