예제 #1
0
        public StorageAccessAlignment GetAlignment(SafeHandle hDevice)
        {
            StorageAccessAlignment alignment = new StorageAccessAlignment();

            SafeAllocHandle <STORAGE_PROPERTY_QUERY> storagePropertyQueryPtr          = null;
            SafeAllocHandle <STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR> storageAlignmentPtr = null;

            try {
                STORAGE_PROPERTY_QUERY storagePropertyQuery = new STORAGE_PROPERTY_QUERY {
                    PropertyId = (uint)STORAGE_PROPERTY_ID.StorageAccessAlignmentProperty,
                    QueryType  = (uint)STORAGE_QUERY_TYPE.PropertyStandardQuery
                };
                storagePropertyQueryPtr = new SafeAllocHandle <STORAGE_PROPERTY_QUERY>(storagePropertyQuery);
                storageAlignmentPtr     = new SafeAllocHandle <STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR>();
                bool success = DeviceIoControl(hDevice, IOCTL_STORAGE_QUERY_PROPERTY,
                                               storagePropertyQueryPtr, storagePropertyQueryPtr.SizeOf,
                                               storageAlignmentPtr, storageAlignmentPtr.SizeOf,
                                               out uint bytesReturns, IntPtr.Zero);
                if (!success || bytesReturns == 0)
                {
                    // Windows XP returns success, byte bytesReturns == 0.
                    m_Win32Error = Marshal.GetLastWin32Error();
                    return(null);
                }

                STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR storageAlignment = storageAlignmentPtr.ToStructure();
                alignment.BytesPerCacheLine             = (int)storageAlignment.BytesPerCacheLine;
                alignment.BytesOffsetForCacheAlignment  = (int)storageAlignment.BytesOffsetForCacheAlignment;
                alignment.BytesPerLogicalSector         = (int)storageAlignment.BytesPerLogicalSector;
                alignment.BytesPerPhysicalSector        = (int)storageAlignment.BytesPerPhysicalSector;
                alignment.BytesOffsetForSectorAlignment = (int)storageAlignment.BytesOffsetForSectorAlignment;
            } finally {
                if (storagePropertyQueryPtr != null)
                {
                    storagePropertyQueryPtr.Close();
                }
                if (storageAlignmentPtr != null)
                {
                    storageAlignmentPtr.Close();
                }
            }

            return(alignment);
        }
예제 #2
0
        private void AddAlignment(IDictionary <string, ResultOrError <StorageAccessAlignment> > 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 <StorageAccessAlignment> result = GetResultOrError <StorageAccessAlignment>(node);

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

            string bytesPerCacheLine             = node["BytesPerCacheLine"].Attributes["result"].Value;
            string bytesOffsetForCacheAlignment  = node["BytesOffsetForCacheAlignment"].Attributes["result"].Value;
            string bytesPerLogicalSector         = node["BytesPerLogicalSector"].Attributes["result"].Value;
            string bytesPerPhysicalSector        = node["BytesPerPhysicalSector"].Attributes["result"].Value;
            string bytesOffsetForSectorAlignment = node["BytesOffsetForSectorAlignment"].Attributes["result"].Value;
            StorageAccessAlignment diskAlignment = new StorageAccessAlignment()
            {
                BytesPerCacheLine             = int.Parse(bytesPerCacheLine, CultureInfo.InvariantCulture),
                BytesOffsetForCacheAlignment  = int.Parse(bytesOffsetForCacheAlignment, CultureInfo.InvariantCulture),
                BytesPerLogicalSector         = int.Parse(bytesPerLogicalSector, CultureInfo.InvariantCulture),
                BytesPerPhysicalSector        = int.Parse(bytesPerPhysicalSector, CultureInfo.InvariantCulture),
                BytesOffsetForSectorAlignment = int.Parse(bytesOffsetForSectorAlignment, CultureInfo.InvariantCulture),
            };

            dictionary.Add(path, new ResultOrError <StorageAccessAlignment>(diskAlignment));
        }