コード例 #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();
        }
コード例 #2
0
ファイル: Utils.cs プロジェクト: LordMike/RawDiskLib
        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));
            }
        }
コード例 #3
0
ファイル: Utils.cs プロジェクト: waldeilton/RawDiskLib
        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));
            }
        }
コード例 #4
0
ファイル: RawDisk.cs プロジェクト: LordMike/RawDiskLib
        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();
        }