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 <CoreFoundation/CoreFoundation.h> | 5 #include <CoreFoundation/CoreFoundation.h> |
6 #include <IOKit/IOBSD.h> | 6 #include <IOKit/IOBSD.h> |
7 #include <IOKit/IOKitLib.h> | 7 #include <IOKit/IOKitLib.h> |
8 #include <IOKit/storage/IOBlockStorageDevice.h> | 8 #include <IOKit/storage/IOBlockStorageDevice.h> |
9 #include <IOKit/storage/IOMedia.h> | 9 #include <IOKit/storage/IOMedia.h> |
10 #include <IOKit/storage/IOStorageProtocolCharacteristics.h> | 10 #include <IOKit/storage/IOStorageProtocolCharacteristics.h> |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 base::ScopedFD child_socket(sockets[1]); | 88 base::ScopedFD child_socket(sockets[1]); |
89 | 89 |
90 // Map the client socket to the client's STDOUT. | 90 // Map the client socket to the client's STDOUT. |
91 base::FileHandleMappingVector fd_map; | 91 base::FileHandleMappingVector fd_map; |
92 fd_map.push_back(std::pair<int, int>(child_socket.get(), STDOUT_FILENO)); | 92 fd_map.push_back(std::pair<int, int>(child_socket.get(), STDOUT_FILENO)); |
93 options.fds_to_remap = &fd_map; | 93 options.fds_to_remap = &fd_map; |
94 | 94 |
95 // Find the file path to open. | 95 // Find the file path to open. |
96 base::FilePath real_device_path; | 96 base::FilePath real_device_path; |
97 if (device_path_.IsAbsolute()) { | 97 if (device_path_.IsAbsolute()) { |
98 // This only occurs for tests where the device path is mocked with a | |
99 // temporary file. | |
98 real_device_path = device_path_; | 100 real_device_path = device_path_; |
99 } else { | 101 } else { |
100 real_device_path = base::FilePath("/dev").Append(device_path_); | 102 // Get the raw device file. Writes need to be in multiples of |
103 // DAMediaBlockSize (usually 512). This is fine since WriteChunk() writes in | |
104 // multiples of kMemoryAlignment. | |
Avi (use Gerrit)
2014/09/24 15:31:36
I'm not familiar with WriteChunk. Can we DCHECK in
jackhou1
2014/09/24 23:58:42
Added a DCHECK. I'm not sure if there's an easy wa
| |
105 real_device_path = | |
106 base::FilePath("/dev").Append("r" + device_path_.BaseName().value()); | |
101 } | 107 } |
102 | 108 |
103 // Build the command line. | 109 // Build the command line. |
104 std::string rdwr = base::StringPrintf("%d", O_RDWR); | 110 std::string rdwr = base::StringPrintf("%d", O_RDWR); |
105 | 111 |
106 base::CommandLine cmd_line = base::CommandLine(base::FilePath(kAuthOpenPath)); | 112 base::CommandLine cmd_line = base::CommandLine(base::FilePath(kAuthOpenPath)); |
107 cmd_line.AppendSwitch("-stdoutpipe"); | 113 cmd_line.AppendSwitch("-stdoutpipe"); |
108 // Using AppendSwitchNative will use an equal-symbol which we don't want. | 114 // Using AppendSwitchNative will use an equal-symbol which we don't want. |
109 cmd_line.AppendArg("-o"); | 115 cmd_line.AppendArg("-o"); |
110 cmd_line.AppendArg(rdwr); | 116 cmd_line.AppendArg(rdwr); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 | 164 |
159 if (child_exit_status) { | 165 if (child_exit_status) { |
160 LOG(ERROR) << "Child process returned failure."; | 166 LOG(ERROR) << "Child process returned failure."; |
161 return false; | 167 return false; |
162 } | 168 } |
163 | 169 |
164 return device_file_.IsValid(); | 170 return device_file_.IsValid(); |
165 } | 171 } |
166 | 172 |
167 } // namespace image_writer | 173 } // namespace image_writer |
OLD | NEW |