Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: chrome/utility/image_writer/image_writer_win.cc

Issue 294163008: Adds USB writing for OS X. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@list-devices
Patch Set: Fixes windows compilation. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/utility/image_writer/image_writer_stub.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 PLOG(ERROR) << "Storage property query failed"; 48 PLOG(ERROR) << "Storage property query failed";
49 return false; 49 return false;
50 } 50 }
51 51
52 STORAGE_DEVICE_DESCRIPTOR* device_descriptor = 52 STORAGE_DEVICE_DESCRIPTOR* device_descriptor =
53 reinterpret_cast<STORAGE_DEVICE_DESCRIPTOR*>(output_buf.get()); 53 reinterpret_cast<STORAGE_DEVICE_DESCRIPTOR*>(output_buf.get());
54 54
55 return device_descriptor->RemovableMedia == TRUE; 55 return device_descriptor->RemovableMedia == TRUE;
56 } 56 }
57 57
58 bool ImageWriter::UnmountVolumes() { 58 bool ImageWriter::OpenDevice() {
59 // Windows requires that device files be opened with FILE_FLAG_NO_BUFFERING
60 // and FILE_FLAG_WRITE_THROUGH. These two flags are not part of base::File.
61 device_file_ =
62 base::File(CreateFile(device_path_.value().c_str(),
63 GENERIC_READ | GENERIC_WRITE,
64 FILE_SHARE_READ | FILE_SHARE_WRITE,
65 NULL,
66 OPEN_EXISTING,
67 FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH,
68 NULL));
69 return device_file_.IsValid();
70 }
71
72 void ImageWriter::UnmountVolumes(const base::Closure& continuation) {
59 if (!InitializeFiles()) { 73 if (!InitializeFiles()) {
60 return false; 74 return;
61 } 75 }
62 76
63 STORAGE_DEVICE_NUMBER sdn = {0}; 77 STORAGE_DEVICE_NUMBER sdn = {0};
64 DWORD bytes_returned; 78 DWORD bytes_returned;
65 79
66 BOOL status = DeviceIoControl( 80 BOOL status = DeviceIoControl(
67 device_file_.GetPlatformFile(), 81 device_file_.GetPlatformFile(),
68 IOCTL_STORAGE_GET_DEVICE_NUMBER, 82 IOCTL_STORAGE_GET_DEVICE_NUMBER,
69 NULL, // Unused, must be NULL. 83 NULL, // Unused, must be NULL.
70 0, // Unused, must be 0. 84 0, // Unused, must be 0.
71 &sdn, // An input buffer to hold the STORAGE_DEVICE_NUMBER 85 &sdn, // An input buffer to hold the STORAGE_DEVICE_NUMBER
72 sizeof(sdn), // The size of the input buffer. 86 sizeof(sdn), // The size of the input buffer.
73 &bytes_returned, // the actual number of bytes returned. 87 &bytes_returned, // the actual number of bytes returned.
74 NULL); // Unused overlap. 88 NULL); // Unused overlap.
75 if (!status) { 89 if (!status) {
76 PLOG(ERROR) << "Unable to get device number."; 90 PLOG(ERROR) << "Unable to get device number.";
77 return false; 91 return;
78 } 92 }
79 93
80 ULONG device_number = sdn.DeviceNumber; 94 ULONG device_number = sdn.DeviceNumber;
81 95
82 TCHAR volume_path[MAX_PATH + 1]; 96 TCHAR volume_path[MAX_PATH + 1];
83 HANDLE volume_finder = FindFirstVolume(volume_path, MAX_PATH + 1); 97 HANDLE volume_finder = FindFirstVolume(volume_path, MAX_PATH + 1);
84 if (volume_finder == INVALID_HANDLE_VALUE) { 98 if (volume_finder == INVALID_HANDLE_VALUE) {
85 return false; 99 return;
86 } 100 }
87 101
88 HANDLE volume_handle; 102 HANDLE volume_handle;
89 bool first_volume = true; 103 bool first_volume = true;
90 bool success = true; 104 bool success = true;
91 105
92 while (first_volume || 106 while (first_volume ||
93 FindNextVolume(volume_finder, volume_path, MAX_PATH + 1)) { 107 FindNextVolume(volume_finder, volume_path, MAX_PATH + 1)) {
94 first_volume = false; 108 first_volume = false;
95 109
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 success = false; 184 success = false;
171 break; 185 break;
172 } 186 }
173 } 187 }
174 } 188 }
175 189
176 if (volume_finder != INVALID_HANDLE_VALUE) { 190 if (volume_finder != INVALID_HANDLE_VALUE) {
177 FindVolumeClose(volume_finder); 191 FindVolumeClose(volume_finder);
178 } 192 }
179 193
180 return success; 194 if (success)
195 continuation.Run();
181 } 196 }
182 197
183 } // namespace image_writer 198 } // namespace image_writer
OLDNEW
« no previous file with comments | « chrome/utility/image_writer/image_writer_stub.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698