예제 #1
0
        private void GetDeviceInformation()
        {
            if (m_VolumeData.VolumeDevicePath == null && IsDriveLetter(m_VolumeData.VolumeDrive))
            {
                string drive = string.Format("{0}{1}",
                                             m_VolumeData.VolumeDrive.TrimEnd(new[] { System.IO.Path.DirectorySeparatorChar, System.IO.Path.AltDirectorySeparatorChar }),
                                             System.IO.Path.DirectorySeparatorChar);
                m_VolumeData.DriveType = m_OS.GetDriveType(drive);
                return;
            }

            m_VolumeData.DriveType   = m_OS.GetDriveType(m_VolumeData.VolumeDevicePathSlash);
            m_VolumeData.VolumeQuery = m_OS.GetVolumeInformation(m_VolumeData.VolumeDevicePathSlash);
            m_VolumeData.FreeSpace   = m_OS.GetDiskFreeSpace(m_VolumeData.VolumeDevicePathSlash);

            // For floppy drives, m_OS.GetMediaPresent is false, even if media is present. Looking into the sources from
            // .NET, the DriveInfo class checks if the file attribute directory bit is set instead. So use that first,
            // and only if it fails, then use the IOCTL later.
            System.IO.FileAttributes attr = m_OS.GetFileAttributes(m_VolumeData.VolumeDevicePathSlash);
            if ((int)attr != -1)
            {
                m_VolumeData.MediaPresent = (attr & System.IO.FileAttributes.Directory) != 0;
            }

            SafeHandle hDevice = m_OS.CreateFileFromDevice(m_VolumeData.VolumeDevicePath);

            try {
                m_OS.RefreshVolume(hDevice);
                m_VolumeData.Extents     = m_OS.GetDiskExtents(hDevice);
                m_VolumeData.DeviceQuery = m_OS.GetStorageDeviceProperty(hDevice);
                if ((int)attr == -1)
                {
                    m_VolumeData.MediaPresent = m_OS.GetMediaPresent(hDevice);
                }
                m_VolumeData.HasSeekPenalty = m_OS.IncursSeekPenalty(hDevice);
                m_VolumeData.DeviceNumber   = m_OS.GetDeviceNumberEx(hDevice);
                if (m_VolumeData.DeviceNumber == null)
                {
                    m_VolumeData.DeviceNumber = m_OS.GetDeviceNumber(hDevice);
                }
                m_VolumeData.PartitionInfo = m_OS.GetPartitionInfo(hDevice);
                m_VolumeData.DiskGeometry  = m_OS.GetDiskGeometry(hDevice);
                m_VolumeData.Alignment     = m_OS.GetAlignment(hDevice);
                m_VolumeData.DiskReadOnly  = m_OS.IsReadOnly(hDevice);
            } finally {
                hDevice.Close();
            }
        }
예제 #2
0
        private void QueryFreeSpace(XmlElement pathNode, IOSVolumeDeviceInfo vinfo, string pathName)
        {
            DiskFreeSpace space = QueryApi(pathNode, "DiskFreeSpace", vinfo, () => {
                return(vinfo.GetDiskFreeSpace(pathName));
            }, out XmlElement spaceInfo);

            if (space == null)
            {
                return;
            }
            WriteApiResult(spaceInfo, "SectorsPerCluster", space.SectorsPerCluster);
            WriteApiResult(spaceInfo, "BytesPerSector", space.BytesPerSector);
            WriteApiResult(spaceInfo, "TotalBytes", space.TotalBytes);
            WriteApiResult(spaceInfo, "TotalBytesFree", space.TotalBytesFree);
            WriteApiResult(spaceInfo, "UserBytesFree", space.UserBytesFree);
        }