private void QueryPartition(XmlElement pathNode, IOSVolumeDeviceInfo vinfo, SafeHandle hDevice) { PartitionInformation partInfo = QueryApi(pathNode, "PartitionInformation", vinfo, () => { return(vinfo.GetPartitionInfo(hDevice)); }, out XmlElement partNode); if (partInfo == null) { return; } WriteApiResult(partNode, "Style", (int)partInfo.Style); WriteApiResult(partNode, "Number", partInfo.Number); WriteApiResult(partNode, "Offset", partInfo.Offset); WriteApiResult(partNode, "Length", partInfo.Length); switch (partInfo.Style) { case PartitionStyle.MasterBootRecord: MbrPartition mbrInfo = (MbrPartition)partInfo; WriteApiResult(partNode, "MbrType", mbrInfo.Type); WriteApiResult(partNode, "MbrBootable", mbrInfo.Bootable); WriteApiResult(partNode, "MbrOffset", mbrInfo.HiddenSectors); break; case PartitionStyle.GuidPartitionTable: GptPartition gptInfo = (GptPartition)partInfo; WriteApiResult(partNode, "GptAttributes", (long)gptInfo.Attributes); WriteApiResult(partNode, "GptId", gptInfo.Id.ToString()); WriteApiResult(partNode, "GptType", gptInfo.Type.ToString()); WriteApiResult(partNode, "GptName", gptInfo.Name); break; } }
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(); } }