예제 #1
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);
 }
예제 #2
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();
        }
예제 #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);
 }
예제 #4
0
        ///// <summary>
        ///// Task will query provided device for 'Drive geometry' function
        ///// </summary>
        ///// <param name="device"><see cref="SystemDevice"/> to query</param>
        ///// <param name="token">Cancellation token</param>
        ///// <returns>Task that result in Nullable <see cref="DISK_GEOMETRY_EX"/> structure</returns>
        //protected Task<Nullable<DISK_GEOMETRY_EX>> GetDriveGeometry(SystemDevice device, CancellationToken token)
        //{
        //    return Task.Factory.StartNew<Nullable<DISK_GEOMETRY_EX>>(() =>
        //    {
        //        DISK_GEOMETRY_EX diskGeometry;
        //        token.ThrowIfCancellationRequested();
        //        try
        //        {
        //            diskGeometry = base.GetDriveGeometry(device);
        //            return diskGeometry;
        //        }
        //        catch (Exception)
        //        {
        //            return null;
        //        }
        //    }
        //    , token);
        //}
        /// <summary>
        /// Sets the volume information.
        /// </summary>
        /// <param name="device"><see cref="SystemVolume"/> to query</param>
        /// <param name="token">Cancellation token</param>
        /// <returns>Task the will do the job</returns>
        protected Task SetVolumeInformation(SystemVolume device, CancellationToken token)
        {
            return Task.Factory.StartNew(() => {

                token.ThrowIfCancellationRequested();

                base.SetVolumeInformation(device);
            }
            , token);
        }
예제 #5
0
        /// <summary>
        /// Task will query provided device for 'Volume extents' function
        /// </summary>
        /// <param name="device"><see cref="SystemVolume"/> to query</param>
        /// <param name="token">Cancellation token</param>
        /// <returns>Task that result in <c>Nullable</c> <see cref="VOLUME_DISK_EXTENTS"/> structure</returns>
        protected Task<Nullable<VOLUME_DISK_EXTENTS>> GetVolumeDiskExtents(SystemVolume device, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            return Task.Factory.StartNew<Nullable<VOLUME_DISK_EXTENTS>>(() =>
            {
                VOLUME_DISK_EXTENTS? diskExtents;
                try
                {
                    diskExtents = base.GetDiskExtendsForVolume(device);
                    return diskExtents;
                }
                catch (Exception)
                {
                    return null;
                }
            }
            , token);
        }
예제 #6
0
        /// <summary>
        /// Task will query provided device for 'Drive layout' function
        /// </summary>
        /// <param name="device"><see cref="SystemVolume"/> to query</param>
        /// <param name="token">Cancellation token</param>
        /// <returns>Task that result in Nullable <see cref="DRIVE_LAYOUT_INFORMATION_EX"/> structure</returns>
        protected Task<Tuple<DRIVE_LAYOUT_INFORMATION_EX, PARTITION_INFORMATION_EX[]>> GetDriveLayout(SystemVolume device, CancellationToken token)
        {
            return Task.Factory.StartNew<Tuple<DRIVE_LAYOUT_INFORMATION_EX, PARTITION_INFORMATION_EX[]>>(() =>
            {
                Tuple<DRIVE_LAYOUT_INFORMATION_EX, PARTITION_INFORMATION_EX[]> driveLayout;

                token.ThrowIfCancellationRequested();

                try
                {
                    driveLayout = base.GetDriveLayout(device);
                    return driveLayout;
                }
                catch(Exception )
                {
                    return null;
                }
            }
            , token);
        }