Exemplo n.º 1
0
        /// <summary>
        /// Retrieves virtual storage type.
        /// </summary>
        /// <param name="deviceId">Device type identifier.</param>
        /// <param name="vendorId">Vendor-unique identifier.</param>
        public void GetVirtualStorageType(out int deviceId, out Guid vendorId)
        {
            var info = new NativeMethods.GET_VIRTUAL_DISK_INFO();
            info.Version = NativeMethods.GET_VIRTUAL_DISK_INFO_VERSION.GET_VIRTUAL_DISK_INFO_VIRTUAL_STORAGE_TYPE;

            int size = Marshal.SizeOf(info);
            int sizeUsed = 0;
            int res = NativeMethods.GetVirtualDiskInformation(this._handle, ref size, ref info, ref sizeUsed);

            if (res == NativeMethods.ERROR_SUCCESS) {

                deviceId = info.Union.VirtualStorageType.DeviceId;
                vendorId = info.Union.VirtualStorageType.VendorId;

            } else if (res == NativeMethods.ERROR_DEV_NOT_EXIST) {
                throw new IOException("Device could not be accessed.");
            } else {
                throw new Win32Exception(res);
            }
        }
Exemplo n.º 2
0
        public int GetProviderSubtype()
        {
            var info = new NativeMethods.GET_VIRTUAL_DISK_INFO();
            info.Version = NativeMethods.GET_VIRTUAL_DISK_INFO_VERSION.GET_VIRTUAL_DISK_INFO_PROVIDER_SUBTYPE;

            int size = Marshal.SizeOf(info);
            int sizeUsed = 0;
            int res = NativeMethods.GetVirtualDiskInformation(this._handle, ref size, ref info, ref sizeUsed);

            if (res == NativeMethods.ERROR_SUCCESS) {

                return info.Union.ProviderSubtype;

            } else if (res == NativeMethods.ERROR_DEV_NOT_EXIST) {
                throw new IOException("Device could not be accessed.");
            } else {
                throw new Win32Exception(res);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves size information.
        /// </summary>
        /// <param name="virtualSize">Virtual size of the VHD, in bytes.</param>
        /// <param name="physicalSize">Physical size of the VHD on disk, in bytes.</param>
        /// <param name="blockSize">Block size of the VHD, in bytes.</param>
        /// <param name="sectorSize">Sector size of the VHD, in bytes.</param>
        public void GetSize(out long virtualSize, out long physicalSize, out int blockSize, out int sectorSize)
        {
            var info = new NativeMethods.GET_VIRTUAL_DISK_INFO();
            info.Version = NativeMethods.GET_VIRTUAL_DISK_INFO_VERSION.GET_VIRTUAL_DISK_INFO_SIZE;

            int size = Marshal.SizeOf(info);
            int sizeUsed = 0;
            int res = NativeMethods.GetVirtualDiskInformation(this._handle, ref size, ref info, ref sizeUsed);

            if (res == NativeMethods.ERROR_SUCCESS) {

                virtualSize = info.Union.Size.VirtualSize;
                physicalSize = info.Union.Size.PhysicalSize;
                blockSize = info.Union.Size.BlockSize;
                sectorSize = info.Union.Size.SectorSize;

            } else if (res == NativeMethods.ERROR_DEV_NOT_EXIST) {
                throw new IOException("Device could not be accessed.");
            } else {
                throw new Win32Exception(res);
            }
        }
Exemplo n.º 4
0
        public Guid GetIdentifier()
        {
            var info = new NativeMethods.GET_VIRTUAL_DISK_INFO();
            info.Version = NativeMethods.GET_VIRTUAL_DISK_INFO_VERSION.GET_VIRTUAL_DISK_INFO_IDENTIFIER;

            int size = Marshal.SizeOf(info);
            int sizeUsed = 0;
            int res = NativeMethods.GetVirtualDiskInformation(this._handle, ref size, ref info, ref sizeUsed);

            if (res == NativeMethods.ERROR_SUCCESS) {

                return info.Union.Identifier;

            } else if (res == NativeMethods.ERROR_DEV_NOT_EXIST) {
                throw new IOException("Device could not be accessed.");
            } else {
                throw new Win32Exception(res);
            }
        }