{"id":139,"date":"2013-09-15T16:12:20","date_gmt":"2013-09-15T08:12:20","guid":{"rendered":"http:\/\/www.datarelab.com\/blog\/?p=139"},"modified":"2015-01-18T19:40:18","modified_gmt":"2015-01-18T11:40:18","slug":"vc%e8%8e%b7%e5%8f%96%e7%a1%ac%e7%9b%98%e7%89%a9%e7%90%86%e6%89%87%e5%8c%ba%e4%b8%8e%e9%80%bb%e8%be%91%e6%89%87%e5%8c%ba%e5%a4%a7%e5%b0%8f","status":"publish","type":"post","link":"https:\/\/www.datarelab.com\/blog\/Technical_literature\/139.html","title":{"rendered":"VC\u83b7\u53d6\u786c\u76d8\u7269\u7406\u6247\u533a\u4e0e\u903b\u8f91\u6247\u533a\u5927\u5c0f"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p style=\"color: #454545; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 14px;\">Used in conjunction with the\u00a0<strong>IOCTL_STORAGE_QUERY_PROPERTY<\/strong>\u00a0control code to retrieve the storage access alignment descriptor data for a device.<\/p>\n<h3 style=\"color: #454545; font-family: 'Segoe UI bold', 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 1em !important;\">Syntax<\/h3>\n<div id=\"code-snippet-1\" class=\"codeSnippetContainer\" style=\"color: #454545; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 14px;\">\n<div class=\"codeSnippetContainerTabs\" style=\"vertical-align: middle;\">\n<div class=\"codeSnippetContainerTabSingle\" style=\"font-size: 12px; padding: 0px 8px; vertical-align: baseline; color: #707070; background-color: #ffffff;\"><a>C++<\/a><\/div>\n<\/div>\n<div class=\"codeSnippetContainerCodeContainer\" style=\"border: 1px solid #939393;\">\n<div class=\"codeSnippetToolBar\"><\/div>\n<div id=\"CodeSnippetContainerCode_c0a19707-e960-4002-a6ba-0f0c4286a212\" class=\"codeSnippetContainerCode\" style=\"margin: 0px; padding: 10px 21px;\">\n<div style=\"padding: 0px; margin: 0px; color: black;\">\n<pre><span style=\"color: blue;\">typedef<\/span> <span style=\"color: blue;\">struct<\/span> _STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR {\r\n  DWORD Version;\r\n  DWORD Size;\r\n  DWORD BytesPerCacheLine;\r\n  DWORD BytesOffsetForCacheAlignment;\r\n  DWORD BytesPerLogicalSector;\r\n  DWORD BytesPerPhysicalSector;\r\n  DWORD BytesOffsetForSectorAlignment;\r\n} STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR, *PSTORAGE_ACCESS_ALIGNMENT_DESCRIPTOR;\r\n\r\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h3 style=\"color: #454545; font-family: 'Segoe UI bold', 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 1em !important;\">Members<\/h3>\n<p><strong>Version<\/strong><\/p>\n<p>Contains the size of this structure, in bytes. The value of this member will change as members are added to the structure.<\/p>\n<p><strong>Size<\/strong><\/p>\n<p>Specifies the total size of the data returned, in bytes. This may include data that follows this structure.<\/p>\n<p><strong>BytesPerCacheLine<\/strong><\/p>\n<p>The number of bytes in a cache line of the device.<\/p>\n<p><strong>BytesOffsetForCacheAlignment<\/strong><\/p>\n<p>The address offset necessary for proper cache access alignment, in bytes.<\/p>\n<p><strong>BytesPerLogicalSector<\/strong><\/p>\n<p>The number of bytes in a logical sector of the device.<\/p>\n<p><strong>BytesPerPhysicalSector<\/strong><\/p>\n<p>The number of bytes in a physical sector of the device.<\/p>\n<p><strong>BytesOffsetForSectorAlignment<\/strong><\/p>\n<p>The logical sector offset within the first physical sector where the first logical sector is placed, in bytes.<\/p>\n<p>Example: Offset = 3 Logical sectors<\/p>\n<div id=\"code-snippet-2\" class=\"codeSnippetContainer\">\n<div class=\"codeSnippetContainerTabs\" style=\"vertical-align: middle;\"><\/div>\n<div class=\"codeSnippetContainerCodeContainer\" style=\"border: 1px solid #939393;\">\n<div class=\"codeSnippetToolBar\"><\/div>\n<div id=\"CodeSnippetContainerCode_63f78f82-f411-48d5-8a20-c0963108ae0b\" class=\"codeSnippetContainerCode\" style=\"margin: 0px; padding: 10px 21px;\">\n<div style=\"padding: 0px; margin: 0px; color: black;\">\n<pre>+---------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\r\n|LBA      |##|##|##|00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15|16|17|\r\n+---------+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+\r\n|Physical |                       |                       |                ...\r\n|Sector   |           0           |           1           |           2\r\n+---------+-----------------------+-----------------------+---------------\r\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>In this example,\u00a0BytesOffsetForSectorAlignment = 3 * BytesPerLogicalSector.<\/p>\n<h3 style=\"color: #454545; font-family: 'Segoe UI bold', 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 1em !important;\">Examples<\/h3>\n<p style=\"color: #454545; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 14px;\">The following sample code retrieves a\u00a0<strong>STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR<\/strong>\u00a0structure and displays the physical sector size and the logical sector size if it differs from the physical sector size.<\/p>\n<div id=\"code-snippet-3\" class=\"codeSnippetContainer\" style=\"color: #454545; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 14px;\">\n<div class=\"codeSnippetContainerTabs\" style=\"vertical-align: middle;\">\n<div class=\"codeSnippetContainerTabSingle\" style=\"font-size: 12px; padding: 0px 8px; vertical-align: baseline; color: #707070; background-color: #ffffff;\"><a>C++<\/a><\/div>\n<\/div>\n<div class=\"codeSnippetContainerCodeContainer\" style=\"border: 1px solid #939393;\">\n<div class=\"codeSnippetToolBar\"><\/div>\n<div id=\"CodeSnippetContainerCode_dd698e42-86ea-4e7f-85a4-a8246498b311\" class=\"codeSnippetContainerCode\" style=\"margin: 0px; padding: 10px 21px;\">\n<div style=\"padding: 0px; margin: 0px; color: black;\">\n<pre>#include &lt;windows.h&gt;\r\n#include &lt;stdio.h&gt;\r\n\r\nDWORD DetectSectorSize( WCHAR * devName, PSTORAGE_ACCESS_ALIGNMENT_DESCRIPTOR pAlignmentDescriptor);\r\n\r\nDWORD wmain()\r\n {\r\n  DWORD                               Error     = NO_ERROR;\r\n  STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR Alignment = {0};\r\n  WCHAR                               szDisk[]  = L<span style=\"color: #a31515;\">\"\\\\\\\\.\\\\PhysicalDrive0\"<\/span>;\r\n\r\n  Error = DetectSectorSize(szDisk, &amp;Alignment); <span style=\"color: blue;\">if<\/span> (Error)\r\n   {\r\n    wprintf(L<span style=\"color: #a31515;\">\"Error %lu encountered while querying alignment.\\n\"<\/span>, Error); <span style=\"color: blue;\">return<\/span> Error;\r\n   }\r\n\r\n  wprintf(L<span style=\"color: #a31515;\">\"Disk %s Properties\\n\"<\/span>, (WCHAR*) szDisk); <span style=\"color: blue;\">if<\/span> (Alignment.BytesPerLogicalSector &lt; Alignment.BytesPerPhysicalSector)\r\n   {\r\n    wprintf(L<span style=\"color: #a31515;\">\"  Emulated sector size is %lu bytes.\\n\"<\/span>, Alignment.BytesPerLogicalSector);\r\n    wprintf(L<span style=\"color: #a31515;\">\"  Physical sector size is %lu bytes.\\n\"<\/span>, Alignment.BytesPerPhysicalSector);\r\n   } <span style=\"color: blue;\">else<\/span> {\r\n    wprintf(L<span style=\"color: #a31515;\">\"  Physical sector size is %lu bytes.\\n\"<\/span>, Alignment.BytesPerPhysicalSector);\r\n   } <span style=\"color: blue;\">return<\/span> 0;\r\n }\r\n\r\nDWORD DetectSectorSize( WCHAR * devName, PSTORAGE_ACCESS_ALIGNMENT_DESCRIPTOR pAlignmentDescriptor)\r\n {\r\n  DWORD                  Bytes   = 0;\r\n  BOOL                   bReturn = FALSE;\r\n  DWORD                  Error   = NO_ERROR;\r\n  STORAGE_PROPERTY_QUERY Query;\r\n  \r\n  ZeroMemory(&amp;Query, <span style=\"color: blue;\">sizeof<\/span>(Query));\r\n\r\n  HANDLE  hFile = CreateFileW( devName,\r\n                               STANDARD_RIGHTS_READ, \r\n                               FILE_SHARE_READ | FILE_SHARE_WRITE,\r\n                               NULL, \r\n                               OPEN_EXISTING, \r\n                               FILE_ATTRIBUTE_NORMAL,\r\n                               NULL); <span style=\"color: blue;\">if<\/span> (hFile==INVALID_HANDLE_VALUE)\r\n   {\r\n    Error=GetLastError(); <span style=\"color: blue;\">return<\/span> Error;\r\n   }\r\n\r\n  Query.QueryType  = PropertyStandardQuery;\r\n  Query.PropertyId = StorageAccessAlignmentProperty;\r\n      \r\n  bReturn = DeviceIoControl( hFile, \r\n                             IOCTL_STORAGE_QUERY_PROPERTY, \r\n                             &amp;Query, <span style=\"color: blue;\">sizeof<\/span>(STORAGE_PROPERTY_QUERY), \r\n                             pAlignmentDescriptor, <span style=\"color: blue;\">sizeof<\/span>(STORAGE_ACCESS_ALIGNMENT_DESCRIPTOR), \r\n                             &amp;Bytes,\r\n                             NULL); <span style=\"color: blue;\">if<\/span> (bReturn == FALSE)\r\n   {\r\n    Error=GetLastError();\r\n   }\r\n\r\n  CloseHandle(hFile); <span style=\"color: blue;\">return<\/span> Error;\r\n\r\n }\r\n\r\n\r\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<h3 style=\"color: #454545; font-family: 'Segoe UI bold', 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 1em !important;\">Requirements<\/h3>\n<table style=\"width: 740px; color: #454545; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 14px; text-align: start;\">\n<tbody>\n<tr>\n<th style=\"background-color: inherit; color: #636363;\">\n<p style=\"color: #454545;\">Minimum supported client<\/p>\n<\/th>\n<td style=\"color: #2a2a2a; vertical-align: top;\">Windows\u00a0Vista [desktop apps only]<\/td>\n<\/tr>\n<tr>\n<th style=\"background-color: inherit; color: #636363;\">\n<p style=\"color: #454545;\">Minimum supported server<\/p>\n<\/th>\n<td style=\"color: #2a2a2a; vertical-align: top;\">Windows Server\u00a02008 [desktop apps only]<\/td>\n<\/tr>\n<tr>\n<th style=\"background-color: inherit; color: #636363;\">\n<p style=\"color: #454545;\">Header<\/p>\n<\/th>\n<td style=\"color: #2a2a2a; vertical-align: top;\">WinIoCtl.h (include Windows.h)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Used in conjunction with the\u00a0IOCTL_STORAGE_QUERY [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[168],"class_list":["post-139","post","type-post","status-publish","format-standard","hentry","category-Technical_literature","tag-vc"],"views":1936,"_links":{"self":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/comments?post=139"}],"version-history":[{"count":0,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts\/139\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/media?parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/categories?post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/tags?post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}