| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include <windows.h> | 5 #include <windows.h> |
| 6 #include <setupapi.h> | 6 #include <setupapi.h> |
| 7 #include <winioctl.h> | 7 #include <winioctl.h> |
| 8 | 8 |
| 9 #include "chrome/utility/image_writer/error_messages.h" | 9 #include "chrome/utility/image_writer/error_messages.h" |
| 10 #include "chrome/utility/image_writer/image_writer.h" | 10 #include "chrome/utility/image_writer/image_writer.h" |
| 11 | 11 |
| 12 namespace image_writer { | 12 namespace image_writer { |
| 13 | 13 |
| 14 const size_t kStorageQueryBufferSize = 1024; | 14 const size_t kStorageQueryBufferSize = 1024; |
| 15 | 15 |
| 16 bool ImageWriter::IsValidDevice() { | 16 bool ImageWriter::IsValidDevice() { |
| 17 base::win::ScopedHandle device_handle( | 17 base::win::ScopedHandle device_handle( |
| 18 CreateFile(device_path_.value().c_str(), | 18 CreateFile(device_path_.value().c_str(), |
| 19 GENERIC_READ | GENERIC_WRITE, | 19 GENERIC_READ | GENERIC_WRITE, |
| 20 FILE_SHARE_READ | FILE_SHARE_WRITE, | 20 FILE_SHARE_READ | FILE_SHARE_WRITE, |
| 21 NULL, | 21 NULL, |
| 22 OPEN_EXISTING, | 22 OPEN_EXISTING, |
| 23 FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, | 23 FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, |
| 24 NULL)); | 24 NULL)); |
| 25 if (device_handle == INVALID_HANDLE_VALUE) { | 25 if (!device_handle.IsValid()) { |
| 26 Error(error::kOpenDevice); | 26 Error(error::kOpenDevice); |
| 27 return false; | 27 return false; |
| 28 } | 28 } |
| 29 | 29 |
| 30 STORAGE_PROPERTY_QUERY query = STORAGE_PROPERTY_QUERY(); | 30 STORAGE_PROPERTY_QUERY query = STORAGE_PROPERTY_QUERY(); |
| 31 query.PropertyId = StorageDeviceProperty; | 31 query.PropertyId = StorageDeviceProperty; |
| 32 query.QueryType = PropertyStandardQuery; | 32 query.QueryType = PropertyStandardQuery; |
| 33 DWORD bytes_returned; | 33 DWORD bytes_returned; |
| 34 | 34 |
| 35 scoped_ptr<char[]> output_buf(new char[kStorageQueryBufferSize]); | 35 scoped_ptr<char[]> output_buf(new char[kStorageQueryBufferSize]); |
| 36 BOOL status = DeviceIoControl( | 36 BOOL status = DeviceIoControl( |
| 37 device_handle, // Device handle. | 37 device_handle.Get(), // Device handle. |
| 38 IOCTL_STORAGE_QUERY_PROPERTY, // Flag to request device properties. | 38 IOCTL_STORAGE_QUERY_PROPERTY, // Flag to request device properties. |
| 39 &query, // Query parameters. | 39 &query, // Query parameters. |
| 40 sizeof(STORAGE_PROPERTY_QUERY), // query parameters size. | 40 sizeof(STORAGE_PROPERTY_QUERY), // query parameters size. |
| 41 output_buf.get(), // output buffer. | 41 output_buf.get(), // output buffer. |
| 42 kStorageQueryBufferSize, // Size of buffer. | 42 kStorageQueryBufferSize, // Size of buffer. |
| 43 &bytes_returned, // Number of bytes returned. | 43 &bytes_returned, // Number of bytes returned. |
| 44 // Must not be null. | 44 // Must not be null. |
| 45 NULL); // Optional unused overlapped perameter. | 45 NULL); // Optional unused overlapped perameter. |
| 46 | 46 |
| 47 if (!status) { | 47 if (!status) { |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 190 |
| 191 if (volume_finder != INVALID_HANDLE_VALUE) { | 191 if (volume_finder != INVALID_HANDLE_VALUE) { |
| 192 FindVolumeClose(volume_finder); | 192 FindVolumeClose(volume_finder); |
| 193 } | 193 } |
| 194 | 194 |
| 195 if (success) | 195 if (success) |
| 196 continuation.Run(); | 196 continuation.Run(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 } // namespace image_writer | 199 } // namespace image_writer |
| OLD | NEW |