Commit e06a8c6b authored by jackhou's avatar jackhou Committed by Commit bot

[Mac] Use raw disks (/dev/rdisk#) in image_writer_mac.

For some USB drives, writes on Mac are much slower than using the old image
creator. This is most likely because the implementation in Chrome uses
/dev/disk# whereas the old implementation used /dev/rdisk# whenever
possible.

The main requirement is that writes are in multiples of the block size, but
since ImageWriter::WriteChunk always writes in multiples of
kMemoryAlignment (4096), it should be fine to always use the raw disk.

My brief tests using a Lexar JumpDrive 16GB and a 1.6GB image:
before: ~6.5 minutes to write, same to verify
after: ~5 minutes to write, ~1.5 minutes to verify

BUG=415891

Review URL: https://codereview.chromium.org/599853002

Cr-Commit-Position: refs/heads/master@{#296875}
parent a23b072d
...@@ -125,6 +125,7 @@ void ImageWriter::WriteChunk() { ...@@ -125,6 +125,7 @@ void ImageWriter::WriteChunk() {
// aligned writes to devices. // aligned writes to devices.
int bytes_to_write = bytes_read + (kMemoryAlignment - 1) - int bytes_to_write = bytes_read + (kMemoryAlignment - 1) -
(bytes_read - 1) % kMemoryAlignment; (bytes_read - 1) % kMemoryAlignment;
DCHECK_EQ(0, bytes_to_write % kMemoryAlignment);
int bytes_written = int bytes_written =
device_file_.Write(bytes_processed_, buffer.get(), bytes_to_write); device_file_.Write(bytes_processed_, buffer.get(), bytes_to_write);
......
...@@ -95,9 +95,15 @@ bool ImageWriter::OpenDevice() { ...@@ -95,9 +95,15 @@ bool ImageWriter::OpenDevice() {
// Find the file path to open. // Find the file path to open.
base::FilePath real_device_path; base::FilePath real_device_path;
if (device_path_.IsAbsolute()) { if (device_path_.IsAbsolute()) {
// This only occurs for tests where the device path is mocked with a
// temporary file.
real_device_path = device_path_; real_device_path = device_path_;
} else { } else {
real_device_path = base::FilePath("/dev").Append(device_path_); // Get the raw device file. Writes need to be in multiples of
// DAMediaBlockSize (usually 512). This is fine since WriteChunk() writes in
// multiples of kMemoryAlignment.
real_device_path =
base::FilePath("/dev").Append("r" + device_path_.BaseName().value());
} }
// Build the command line. // Build the command line.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment