Esempio n. 1
0
        /// <summary>
        /// Sets the volume information.
        /// </summary>
        /// <param name="device"><see cref="SystemVolume"/> to query</param>
        /// <exception cref="System.ComponentModel.Win32Exception">
        /// Could not acquire volume information
        /// </exception>
        internal virtual void SetVolumeInformation(SystemVolume device)
        {
            StringBuilder volumeName               = new StringBuilder(UnsafeNativeMethods.MAX_PATH + 1);
            uint          lpVolumeSerialNumber     = 0;
            uint          lpMaximumComponentLength = 0;
            //FileSystemFlags lpFileSystemFlags = 0;
            uint          lpFileSystemFlags      = 0;
            StringBuilder lpFileSystemNameBuffer = new StringBuilder(UnsafeNativeMethods.MAX_PATH + 1);
            bool          functionResult         = false;

            if (string.IsNullOrEmpty(device.DevicePath))
            {
                return;
            }

            if (DeviceIoControl <int> .IsAccessible(device) == false)
            {
                // Device is not accessible
                return;
            }

            functionResult = UnsafeNativeMethods.GetVolumeInformation(device.DevicePath,
                                                                      volumeName,
                                                                      Convert.ToUInt32(volumeName.Capacity),
                                                                      out lpVolumeSerialNumber,
                                                                      out lpMaximumComponentLength,
                                                                      out lpFileSystemFlags,
                                                                      lpFileSystemNameBuffer,
                                                                      Convert.ToUInt32(lpFileSystemNameBuffer.Capacity));

            if (functionResult == false)
            {
                throw new Win32Exception("Could not acquire volume information", new Win32Exception(Marshal.GetLastWin32Error()));
            }

            device.SerialNumber   = lpVolumeSerialNumber;
            device.FileSystemName = lpFileSystemNameBuffer.ToString();
        }
Esempio n. 2
0
        /// <summary>
        /// Retrieves the device type, device number, and, for a partitionable device, the partition number of a device.
        /// </summary>
        /// <param name="device"><see cref="SystemVolume"/> to query</param>
        /// <returns><see cref="STORAGE_DEVICE_NUMBER"/> structure</returns>
        internal virtual STORAGE_DEVICE_NUMBER GetDeviceNumber(DeviceHandle device)
        {
            DeviceIoControl <STORAGE_DEVICE_NUMBER> deviceControl = new DeviceIoControl <STORAGE_DEVICE_NUMBER>();

            return(deviceControl.GetDataForDevice(device, IoControlCode.IOCTL_STORAGE_GET_DEVICE_NUMBER));
        }
Esempio n. 3
0
        /// <summary>
        /// Function will calculate/read 'Layout information' for provided <see cref="SystemVolume"/>
        /// </summary>
        /// <param name="device"><see cref="SystemVolume"/> to query</param>
        /// <returns>Tuple of <see cref="DRIVE_LAYOUT_INFORMATION_EX"/> and array of <see cref="PARTITION_INFORMATION_EX"/></returns>
        /// <remarks>MSDN: http://msdn.microsoft.com/en-us/library/aa365174(v=vs.85).aspx </remarks>
        internal virtual Tuple <DRIVE_LAYOUT_INFORMATION_EX, PARTITION_INFORMATION_EX[]> GetDriveLayout(SystemVolume device)
        {
            DeviceIoControl <DRIVE_LAYOUT_INFORMATION_EX> deviceControl = new DeviceIoControl <DRIVE_LAYOUT_INFORMATION_EX>();

            return(deviceControl.GetDriveLayout(device));
        }
Esempio n. 4
0
        /// <summary>
        /// Function will calculate/read 'Disk geometry' for provided <see cref="SystemVolume"/>
        /// </summary>
        /// <param name="device"><see cref="SystemVolume"/> to query</param>
        /// <returns>Disk geometry information</returns>
        internal virtual DISK_GEOMETRY_EX GetDriveGeometry(DeviceHandle device)
        {
            DeviceIoControl <DISK_GEOMETRY_EX> deviceControl = new DeviceIoControl <DISK_GEOMETRY_EX>();

            return(deviceControl.GetDiskGeometryEx(device));
        }
Esempio n. 5
0
        /// <summary>
        /// Function will all physical disk that 'volume' is extended/spanned on it
        /// </summary>
        /// <remarks>MSDN: http://msdn.microsoft.com/en-us/library/aa365194(v=vs.85).aspx </remarks>
        /// <param name="device"><see cref="SystemVolume"/> to query</param>
        /// <returns><see cref="VOLUME_DISK_EXTENTS"/> structure that volume extends on</returns>
        internal virtual Nullable <VOLUME_DISK_EXTENTS> GetDiskExtendsForVolume(SystemVolume device)
        {
            DeviceIoControl <VOLUME_DISK_EXTENTS> deviceControl = new DeviceIoControl <VOLUME_DISK_EXTENTS>();

            return(deviceControl.GetDataForDevice(device, IoControlCode.IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS));
        }