{"id":104391,"date":"2020-10-22T07:00:00","date_gmt":"2020-10-22T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=104391"},"modified":"2020-10-22T06:50:12","modified_gmt":"2020-10-22T13:50:12","slug":"20201022-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20201022-00\/?p=104391","title":{"rendered":"Taking a shortcut: You can query properties from a volume, and it will forward to the physical drive"},"content":{"rendered":"<p>If you have the handle to a volume, you can issue certain disk ioctls to the volume, and it will forward them to the underlying disk. We saw this earlier when we used <code>IOCTL_<\/code><code>STORAGE_<\/code><code>GET_<\/code><code>DEVICE_<\/code><code>NUMBER<\/code> to obtain the physical drive number from a volume. The name of the ioctl is <code>IOCTL_<\/code><code>STORAGE<\/code>, but we issued it against a volume anyway.<\/p>\n<p>And as we saw earlier, if the volume does not have a unique physical disk, then the call will fail.<\/p>\n<p>This feature is particularly handy with storage property queries. For example, you can ask what how the drive is connected to the system by querying the volume:<\/p>\n<pre>wil::unique_hfile volume = GetVolumeHandleForFile(L\"C:\\\\\");\r\n\r\nSTORAGE_PROPERTY_QUERY query{};\r\nquery.PropertyId = StorageAdapterProperty;\r\nquery.QueryType = PropertyStandardQuery;\r\nDWORD bytesWritten;\r\nSTORAGE_ADAPTER_DESCRIPTOR result{};\r\n\r\nif (DeviceIoControl(volume.get(), IOCTL_STORAGE_QUERY_PROPERTY,\r\n    &amp;query, sizeof(query),\r\n    &amp;result, sizeof(result),\r\n    &amp;bytesWritten, nullptr)) {\r\n    \/* result.BusType tells you how the drive is connected *\/\r\n}\r\n<\/pre>\n<p>Next time, we&#8217;ll use this to answer a commonly-asked question.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Saving a little extra trip.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-104391","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Saving a little extra trip.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/104391","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=104391"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/104391\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=104391"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=104391"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=104391"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}