OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // devguid requires Windows.h be imported first. | 5 // devguid requires Windows.h be imported first. |
6 #include <windows.h> | 6 #include <windows.h> |
7 #include <setupapi.h> | 7 #include <setupapi.h> |
8 #include <winioctl.h> | 8 #include <winioctl.h> |
9 | 9 |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 NULL, // Output buffer. | 28 NULL, // Output buffer. |
29 0, // Output buffer size. | 29 0, // Output buffer size. |
30 &interface_detail_data_size, // Receives the buffer size. | 30 &interface_detail_data_size, // Receives the buffer size. |
31 NULL); // Optional DEVINFO_DATA. | 31 NULL); // Optional DEVINFO_DATA. |
32 | 32 |
33 if (status == FALSE && GetLastError() != ERROR_INSUFFICIENT_BUFFER) { | 33 if (status == FALSE && GetLastError() != ERROR_INSUFFICIENT_BUFFER) { |
34 PLOG(ERROR) << "SetupDiGetDeviceInterfaceDetail failed"; | 34 PLOG(ERROR) << "SetupDiGetDeviceInterfaceDetail failed"; |
35 return false; | 35 return false; |
36 } | 36 } |
37 | 37 |
38 scoped_ptr<char[]> interface_detail_data_buffer( | 38 std::unique_ptr<char[]> interface_detail_data_buffer( |
39 new char[interface_detail_data_size]); | 39 new char[interface_detail_data_size]); |
40 | 40 |
41 SP_DEVICE_INTERFACE_DETAIL_DATA* interface_detail_data = | 41 SP_DEVICE_INTERFACE_DETAIL_DATA* interface_detail_data = |
42 reinterpret_cast<SP_DEVICE_INTERFACE_DETAIL_DATA*>( | 42 reinterpret_cast<SP_DEVICE_INTERFACE_DETAIL_DATA*>( |
43 interface_detail_data_buffer.get()); | 43 interface_detail_data_buffer.get()); |
44 | 44 |
45 interface_detail_data->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA); | 45 interface_detail_data->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA); |
46 | 46 |
47 status = SetupDiGetDeviceInterfaceDetail( | 47 status = SetupDiGetDeviceInterfaceDetail( |
48 interface_enumerator, | 48 interface_enumerator, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 ULONGLONG disk_capacity = geometry.Cylinders.QuadPart * | 95 ULONGLONG disk_capacity = geometry.Cylinders.QuadPart * |
96 geometry.TracksPerCylinder * | 96 geometry.TracksPerCylinder * |
97 geometry.SectorsPerTrack * | 97 geometry.SectorsPerTrack * |
98 geometry.BytesPerSector; | 98 geometry.BytesPerSector; |
99 | 99 |
100 STORAGE_PROPERTY_QUERY query = STORAGE_PROPERTY_QUERY(); | 100 STORAGE_PROPERTY_QUERY query = STORAGE_PROPERTY_QUERY(); |
101 query.PropertyId = StorageDeviceProperty; | 101 query.PropertyId = StorageDeviceProperty; |
102 query.QueryType = PropertyStandardQuery; | 102 query.QueryType = PropertyStandardQuery; |
103 | 103 |
104 scoped_ptr<char[]> output_buf(new char[1024]); | 104 std::unique_ptr<char[]> output_buf(new char[1024]); |
105 status = DeviceIoControl( | 105 status = DeviceIoControl( |
106 device_handle.Get(), // Device handle. | 106 device_handle.Get(), // Device handle. |
107 IOCTL_STORAGE_QUERY_PROPERTY, // Flag to request device properties. | 107 IOCTL_STORAGE_QUERY_PROPERTY, // Flag to request device properties. |
108 &query, // Query parameters. | 108 &query, // Query parameters. |
109 sizeof(STORAGE_PROPERTY_QUERY), // query parameters size. | 109 sizeof(STORAGE_PROPERTY_QUERY), // query parameters size. |
110 output_buf.get(), // output buffer. | 110 output_buf.get(), // output buffer. |
111 1024, // Size of buffer. | 111 1024, // Size of buffer. |
112 &bytes_returned, // Number of bytes returned. | 112 &bytes_returned, // Number of bytes returned. |
113 // Must not be null. | 113 // Must not be null. |
114 NULL); // Optional unused overlapped perameter. | 114 NULL); // Optional unused overlapped perameter. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 PLOG(ERROR) << "SetupDiEnumDeviceInterfaces failed"; | 205 PLOG(ERROR) << "SetupDiEnumDeviceInterfaces failed"; |
206 SetupDiDestroyDeviceInfoList(interface_enumerator); | 206 SetupDiDestroyDeviceInfoList(interface_enumerator); |
207 return false; | 207 return false; |
208 } | 208 } |
209 | 209 |
210 SetupDiDestroyDeviceInfoList(interface_enumerator); | 210 SetupDiDestroyDeviceInfoList(interface_enumerator); |
211 return true; | 211 return true; |
212 } | 212 } |
213 | 213 |
214 } // namespace extensions | 214 } // namespace extensions |
OLD | NEW |