Exemple #1
0
        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();
        }
Exemple #2
0
        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));
            }
        }
Exemple #3
0
        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));
            }
        }
Exemple #4
0
        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();
        }