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; } }
/// <summary> /// Initializes a new instance of the <see cref="VolumeDeviceInfo"/> class, specifically for abstracting the OS /// and testing. /// </summary> /// <param name="os">The object that simulates the OS calls.</param> /// <param name="pathName">Path to the volume that should be queried.</param> /// <exception cref="PlatformNotSupportedException">This software only supports Windows NT.</exception> /// <exception cref="ArgumentNullException"> /// The parameter <paramref name="pathName"/> is <see langword="null"/>. /// </exception> /// <exception cref="ArgumentException">The parameter <paramref name="pathName"/> is empty.</exception> /// <remarks> /// This method is used to provide an implementation on how to access the Operating System, so this class isn't /// required to do this directly, making it testable for different OS behaviors. /// </remarks> internal VolumeDeviceInfoWin32(IOSVolumeDeviceInfo os, string pathName) { if (os == null) { throw new ArgumentNullException(nameof(os)); } if (pathName == null) { throw new ArgumentNullException(nameof(pathName)); } if (string.IsNullOrEmpty(pathName)) { throw new ArgumentException("Path is empty", nameof(pathName)); } if (!Native.Platform.IsWinNT()) { throw new PlatformNotSupportedException(); } m_OS = os; Path = pathName; ResolveDevicePathNames(pathName); GetDeviceInformation(); InitializeProperties(); }
private T QueryApi <T>(XmlElement parent, string elementName, IOSVolumeDeviceInfo vinfo, bool errorIfFalse, Func <T> method, out XmlElement node) { T result; try { result = method(); } catch { node = WriteApiResult(parent, elementName, null, vinfo.GetLastWin32Error(), true); return(default);
private void QueryDeviceNumber(XmlElement pathNode, IOSVolumeDeviceInfo vinfo, SafeHandle hDevice) { StorageDeviceNumber device = QueryApi(pathNode, "StorageDeviceNumber", vinfo, () => { return(vinfo.GetDeviceNumber(hDevice)); }, out XmlElement deviceNode); if (device == null) { return; } WriteApiResult(deviceNode, "DeviceType", (int)device.DeviceType); WriteApiResult(deviceNode, "DeviceNumber", device.DeviceNumber); WriteApiResult(deviceNode, "DevicePartition", device.PartitionNumber); }
private void QueryVolumeInfo(XmlElement pathNode, IOSVolumeDeviceInfo vinfo, string pathName) { VolumeInfo info = QueryApi(pathNode, "VolumeInformation", vinfo, () => { return(vinfo.GetVolumeInformation(pathName)); }, out XmlElement volumeInfoNode); if (info == null) { return; } WriteApiResult(volumeInfoNode, "Label", info.VolumeLabel); WriteApiResult(volumeInfoNode, "SerialNumber", info.VolumeSerial); WriteApiResult(volumeInfoNode, "FileSystem", info.FileSystem); WriteApiResult(volumeInfoNode, "Flags", (int)info.Flags); }
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); }
private void QueryDiskAlignment(XmlElement pathNode, IOSVolumeDeviceInfo vinfo, SafeHandle hDevice) { StorageAccessAlignment diskAlignment = QueryApi(pathNode, "StorageAlignment", vinfo, () => { return(vinfo.GetAlignment(hDevice)); }, out XmlElement alignNode); if (diskAlignment == null) { return; } WriteApiResult(alignNode, "BytesPerCacheLine", diskAlignment.BytesPerCacheLine); WriteApiResult(alignNode, "BytesOffsetForCacheAlignment", diskAlignment.BytesOffsetForCacheAlignment); WriteApiResult(alignNode, "BytesPerLogicalSector", diskAlignment.BytesPerLogicalSector); WriteApiResult(alignNode, "BytesPerPhysicalSector", diskAlignment.BytesPerPhysicalSector); WriteApiResult(alignNode, "BytesOffsetForSectorAlignment", diskAlignment.BytesOffsetForSectorAlignment); }
private void QueryDiskGeometry(XmlElement pathNode, IOSVolumeDeviceInfo vinfo, SafeHandle hDevice) { DiskGeometry diskGeo = QueryApi(pathNode, "DiskGeometry", vinfo, () => { return(vinfo.GetDiskGeometry(hDevice)); }, out XmlElement geoNode); if (diskGeo == null) { return; } WriteApiResult(geoNode, "MediaType", (int)diskGeo.MediaType); WriteApiResult(geoNode, "Cylinders", diskGeo.Cylinders); WriteApiResult(geoNode, "TracksPerCylinder", diskGeo.TracksPerCylinder); WriteApiResult(geoNode, "SectorsPerTrack", diskGeo.SectorsPerTrack); WriteApiResult(geoNode, "BytesPerSector", diskGeo.BytesPerSector); }
private void QueryDiskExtents(XmlElement pathNode, IOSVolumeDeviceInfo vinfo, SafeHandle hDevice) { DiskExtent[] extents = QueryApi(pathNode, "DiskExtents", vinfo, () => { return(vinfo.GetDiskExtents(hDevice)); }, out XmlElement extNode); if (extents == null) { return; } foreach (DiskExtent extent in extents) { XmlElement entry = WriteApiResult(extNode, "DiskExtent", string.Empty); WriteApiResult(entry, "Device", extent.Device); WriteApiResult(entry, "Offset", extent.StartingOffset); WriteApiResult(entry, "Length", extent.ExtentLength); } }
private void QueryStorageProperty(XmlElement pathNode, IOSVolumeDeviceInfo vinfo, SafeHandle hDevice) { VolumeDeviceQuery query = QueryApi(pathNode, "StorageDeviceProperty", vinfo, () => { return(vinfo.GetStorageDeviceProperty(hDevice)); }, out XmlElement storageNode); if (query == null) { return; } WriteApiResult(storageNode, "VendorId", query.VendorId); WriteApiResult(storageNode, "DeviceSerialNumber", query.DeviceSerialNumber); WriteApiResult(storageNode, "ProductId", query.ProductId); WriteApiResult(storageNode, "ProductRevision", query.ProductRevision); WriteApiResult(storageNode, "RemovableMedia", query.RemovableMedia); WriteApiResult(storageNode, "CommandQueueing", query.CommandQueueing); WriteApiResult(storageNode, "ScsiDeviceType", (int)query.ScsiDeviceType); WriteApiResult(storageNode, "ScsiModifier", query.ScsiDeviceModifier); WriteApiResult(storageNode, "BusType", (int)query.BusType); }
private T QueryApi <T>(XmlElement parent, string elementName, IOSVolumeDeviceInfo vinfo, bool errorIfFalse, Func <T> method) { return(QueryApi(parent, elementName, vinfo, errorIfFalse, method, out _)); }
private T QueryApi <T>(XmlElement parent, string elementName, IOSVolumeDeviceInfo vinfo, Func <T> method, out XmlElement node) { return(QueryApi(parent, elementName, vinfo, false, method, out node)); }