示例#1
0
        private void AddStorageDevice(IDictionary <string, ResultOrError <VolumeDeviceQuery> > dictionary, string path, XmlElement node)
        {
            if (node == null)
            {
                return;
            }
            if (dictionary.ContainsKey(path))
            {
                return;
            }

            // Because this is a complex type, The XML will always return the default value.
            ResultOrError <VolumeDeviceQuery> result = GetResultOrError <VolumeDeviceQuery>(node);

            if (result != null)
            {
                dictionary.Add(path, result);
                return;
            }

            string            removableMedia = node["RemovableMedia"].Attributes["result"].Value;
            string            cmdQueuing     = node["CommandQueueing"].Attributes["result"].Value;
            string            scsiDevType    = node["ScsiDeviceType"].Attributes["result"].Value;
            string            scsiDevMod     = node["ScsiModifier"].Attributes["result"].Value;
            string            busType        = node["BusType"].Attributes["result"].Value;
            VolumeDeviceQuery devQuery       = new VolumeDeviceQuery()
            {
                VendorId           = node["VendorId"].Attributes["result"].Value,
                DeviceSerialNumber = node["DeviceSerialNumber"].Attributes["result"].Value,
                ProductId          = node["ProductId"].Attributes["result"].Value,
                ProductRevision    = node["ProductRevision"].Attributes["result"].Value,
                RemovableMedia     = bool.Parse(removableMedia),
                CommandQueueing    = bool.Parse(cmdQueuing),
                ScsiDeviceType     = (ScsiDeviceType)int.Parse(scsiDevType, CultureInfo.InvariantCulture),
                ScsiDeviceModifier = int.Parse(scsiDevMod, CultureInfo.InvariantCulture),
                BusType            = (BusType)int.Parse(busType, CultureInfo.InvariantCulture)
            };

            dictionary.Add(path, new ResultOrError <VolumeDeviceQuery>(devQuery));
        }
示例#2
0
        public VolumeDeviceQuery GetStorageDeviceProperty(SafeHandle hDevice)
        {
            VolumeDeviceQuery volumeDeviceQuery = new VolumeDeviceQuery();

            SafeAllocHandle <STORAGE_PROPERTY_QUERY>    storagePropertyQueryPtr    = null;
            SafeAllocHandle <STORAGE_DESCRIPTOR_HEADER> storageDescriptorHeaderPtr = null;
            SafeAllocHandle <STORAGE_DEVICE_DESCRIPTOR> storageDeviceDescriptorPtr = null;

            try {
                STORAGE_PROPERTY_QUERY storagePropertyQuery = new STORAGE_PROPERTY_QUERY {
                    PropertyId = (uint)STORAGE_PROPERTY_ID.StorageDeviceProperty,
                    QueryType  = (uint)STORAGE_QUERY_TYPE.PropertyStandardQuery
                };
                storagePropertyQueryPtr = new SafeAllocHandle <STORAGE_PROPERTY_QUERY>(storagePropertyQuery);

                // Get the necessary output buffer size
                STORAGE_DESCRIPTOR_HEADER storageDescriptorHeader = new STORAGE_DESCRIPTOR_HEADER {
                    Version = 0,
                    Size    = 0
                };
                storageDescriptorHeaderPtr = new SafeAllocHandle <STORAGE_DESCRIPTOR_HEADER>(storageDescriptorHeader);

                bool success = DeviceIoControl(hDevice, IOCTL_STORAGE_QUERY_PROPERTY,
                                               storagePropertyQueryPtr, storagePropertyQueryPtr.SizeOf,
                                               storageDescriptorHeaderPtr, storageDescriptorHeaderPtr.SizeOf,
                                               out uint bytesReturns, IntPtr.Zero);
                if (!success || bytesReturns == 0)
                {
                    m_Win32Error = Marshal.GetLastWin32Error();
                    return(null);
                }

                STORAGE_DESCRIPTOR_HEADER storageDescriptorHeaderResult = storageDescriptorHeaderPtr.ToStructure();

                storageDeviceDescriptorPtr = new SafeAllocHandle <STORAGE_DEVICE_DESCRIPTOR>((int)storageDescriptorHeaderResult.Size);
                success = DeviceIoControl(hDevice, IOCTL_STORAGE_QUERY_PROPERTY,
                                          storagePropertyQueryPtr, storagePropertyQueryPtr.SizeOf,
                                          storageDeviceDescriptorPtr, storageDeviceDescriptorPtr.SizeOf,
                                          out bytesReturns, IntPtr.Zero);
                if (!success || bytesReturns == 0)
                {
                    m_Win32Error = Marshal.GetLastWin32Error();
                    return(null);
                }

                STORAGE_DEVICE_DESCRIPTOR storageDeviceDescriptor = storageDeviceDescriptorPtr.ToStructure();
                if (storageDeviceDescriptor.VendorIdOffset != 0)
                {
                    volumeDeviceQuery.VendorId = storageDeviceDescriptorPtr.ToStringAnsi((int)storageDeviceDescriptor.VendorIdOffset);
                }
                if (storageDeviceDescriptor.SerialNumberOffset != 0)
                {
                    volumeDeviceQuery.DeviceSerialNumber = storageDeviceDescriptorPtr.ToStringAnsi((int)storageDeviceDescriptor.SerialNumberOffset);
                }
                if (storageDeviceDescriptor.ProductIdOffset != 0)
                {
                    volumeDeviceQuery.ProductId = storageDeviceDescriptorPtr.ToStringAnsi((int)storageDeviceDescriptor.ProductIdOffset);
                }
                if (storageDeviceDescriptor.ProductRevisionOffset != 0)
                {
                    volumeDeviceQuery.ProductRevision = storageDeviceDescriptorPtr.ToStringAnsi((int)storageDeviceDescriptor.ProductRevisionOffset);
                }
                volumeDeviceQuery.RemovableMedia     = storageDeviceDescriptor.RemovableMedia;
                volumeDeviceQuery.CommandQueueing    = storageDeviceDescriptor.CommandQueueing;
                volumeDeviceQuery.ScsiDeviceType     = (ScsiDeviceType)storageDeviceDescriptor.DeviceType;
                volumeDeviceQuery.ScsiDeviceModifier = storageDeviceDescriptor.DeviceTypeModifier;
                volumeDeviceQuery.BusType            = (BusType)storageDeviceDescriptor.BusType;
            } finally {
                if (storagePropertyQueryPtr != null)
                {
                    storagePropertyQueryPtr.Close();
                }
                if (storageDescriptorHeaderPtr != null)
                {
                    storageDescriptorHeaderPtr.Close();
                }
                if (storageDeviceDescriptorPtr != null)
                {
                    storageDeviceDescriptorPtr.Close();
                }
            }

            return(volumeDeviceQuery);
        }