Used in conjunction with the IOCTL_STORAGE_QUERY_PROPERTY control code to retrieve the storage access alignment descriptor data for a device.
Syntax
1 2 3 4 5 6 7 8 9 |
<span style="color: blue;">typedef</span> <span style="color: blue;">struct</span> _STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR { DWORD Version; DWORD Size; DWORD BytesPerCacheLine; DWORD BytesOffsetForCacheAlignment; DWORD BytesPerLogicalSector; DWORD BytesPerPhysicalSector; DWORD BytesOffsetForSectorAlignment; } STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR, *PSTORAGE_ACCESS_ALIGNMENT_DESCRIPTOR; |
Members
Version
Contains the size of this structure, in bytes. The value of this member will change as members are added to the structure.
Size
Specifies the total size of the data returned, in bytes. This may include data that follows this structure.
BytesPerCacheLine
The number of bytes in a cache line of the device.
BytesOffsetForCacheAlignment
The address offset necessary for proper cache access alignment, in bytes.
BytesPerLogicalSector
The number of bytes in a logical sector of the device.
BytesPerPhysicalSector
The number of bytes in a physical sector of the device.
BytesOffsetForSectorAlignment
The logical sector offset within the first physical sector where the first logical sector is placed, in bytes.
Example: Offset = 3 Logical sectors
1 2 3 4 5 6 |
+---------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |LBA |##|##|##|00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17| +---------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |Physical | | | ... |Sector | 0 | 1 | 2 +---------+-----------------------+-----------------------+--------------- |
In this example, BytesOffsetForSectorAlignment = 3 * BytesPerLogicalSector.
Examples
The following sample code retrieves a STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR structure and displays the physical sector size and the logical sector size if it differs from the physical sector size.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
#include <windows.h> #include <stdio.h> DWORD DetectSectorSize( WCHAR * devName, PSTORAGE_ACCESS_ALIGNMENT_DESCRIPTOR pAlignmentDescriptor); DWORD wmain() { DWORD Error = NO_ERROR; STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR Alignment = {0}; WCHAR szDisk[] = L<span style="color: #a31515;">"\\\\.\\PhysicalDrive0"</span>; Error = DetectSectorSize(szDisk, &Alignment); <span style="color: blue;">if</span> (Error) { wprintf(L<span style="color: #a31515;">"Error %lu encountered while querying alignment.\n"</span>, Error); <span style="color: blue;">return</span> Error; } wprintf(L<span style="color: #a31515;">"Disk %s Properties\n"</span>, (WCHAR*) szDisk); <span style="color: blue;">if</span> (Alignment.BytesPerLogicalSector < Alignment.BytesPerPhysicalSector) { wprintf(L<span style="color: #a31515;">" Emulated sector size is %lu bytes.\n"</span>, Alignment.BytesPerLogicalSector); wprintf(L<span style="color: #a31515;">" Physical sector size is %lu bytes.\n"</span>, Alignment.BytesPerPhysicalSector); } <span style="color: blue;">else</span> { wprintf(L<span style="color: #a31515;">" Physical sector size is %lu bytes.\n"</span>, Alignment.BytesPerPhysicalSector); } <span style="color: blue;">return</span> 0; } DWORD DetectSectorSize( WCHAR * devName, PSTORAGE_ACCESS_ALIGNMENT_DESCRIPTOR pAlignmentDescriptor) { DWORD Bytes = 0; BOOL bReturn = FALSE; DWORD Error = NO_ERROR; STORAGE_PROPERTY_QUERY Query; ZeroMemory(&Query, <span style="color: blue;">sizeof</span>(Query)); HANDLE hFile = CreateFileW( devName, STANDARD_RIGHTS_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); <span style="color: blue;">if</span> (hFile==INVALID_HANDLE_VALUE) { Error=GetLastError(); <span style="color: blue;">return</span> Error; } Query.QueryType = PropertyStandardQuery; Query.PropertyId = StorageAccessAlignmentProperty; bReturn = DeviceIoControl( hFile, IOCTL_STORAGE_QUERY_PROPERTY, &Query, <span style="color: blue;">sizeof</span>(STORAGE_PROPERTY_QUERY), pAlignmentDescriptor, <span style="color: blue;">sizeof</span>(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR), &Bytes, NULL); <span style="color: blue;">if</span> (bReturn == FALSE) { Error=GetLastError(); } CloseHandle(hFile); <span style="color: blue;">return</span> Error; } |
Requirements
Minimum supported client |
Windows Vista [desktop apps only] |
---|---|
Minimum supported server |
Windows Server 2008 [desktop apps only] |
Header |
WinIoCtl.h (include Windows.h) |