| 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 "chrome/utility/image_writer/image_writer.h" | 5 #include "chrome/utility/image_writer/image_writer.h" |
| 6 | 6 |
| 7 #include "base/memory/aligned_memory.h" | 7 #include "base/memory/aligned_memory.h" |
| 8 #include "chrome/utility/image_writer/error_messages.h" | 8 #include "chrome/utility/image_writer/error_messages.h" |
| 9 #include "chrome/utility/image_writer/image_writer_handler.h" | 9 #include "chrome/utility/image_writer/image_writer_handler.h" |
| 10 #include "content/public/utility/utility_thread.h" | 10 #include "content/public/utility/utility_thread.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 memset(buffer.get(), 0, kBurningBlockSize); | 118 memset(buffer.get(), 0, kBurningBlockSize); |
| 119 | 119 |
| 120 int bytes_read = image_file_.Read(bytes_processed_, buffer.get(), | 120 int bytes_read = image_file_.Read(bytes_processed_, buffer.get(), |
| 121 kBurningBlockSize); | 121 kBurningBlockSize); |
| 122 | 122 |
| 123 if (bytes_read > 0) { | 123 if (bytes_read > 0) { |
| 124 // Always attempt to write a whole block, as writing DASD requires sector- | 124 // Always attempt to write a whole block, as writing DASD requires sector- |
| 125 // aligned writes to devices. | 125 // aligned writes to devices. |
| 126 int bytes_to_write = bytes_read + (kMemoryAlignment - 1) - | 126 int bytes_to_write = bytes_read + (kMemoryAlignment - 1) - |
| 127 (bytes_read - 1) % kMemoryAlignment; | 127 (bytes_read - 1) % kMemoryAlignment; |
| 128 DCHECK_EQ(0, bytes_to_write % kMemoryAlignment); |
| 128 int bytes_written = | 129 int bytes_written = |
| 129 device_file_.Write(bytes_processed_, buffer.get(), bytes_to_write); | 130 device_file_.Write(bytes_processed_, buffer.get(), bytes_to_write); |
| 130 | 131 |
| 131 if (bytes_written < bytes_read) { | 132 if (bytes_written < bytes_read) { |
| 132 Error(error::kWriteImage); | 133 Error(error::kWriteImage); |
| 133 return; | 134 return; |
| 134 } | 135 } |
| 135 | 136 |
| 136 bytes_processed_ += bytes_read; | 137 bytes_processed_ += bytes_read; |
| 137 PostProgress(bytes_processed_); | 138 PostProgress(bytes_processed_); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 running_ = false; | 189 running_ = false; |
| 189 } else { | 190 } else { |
| 190 // Unable to read entire file. | 191 // Unable to read entire file. |
| 191 LOG(ERROR) << "Failed to read " << kBurningBlockSize << " bytes of image " | 192 LOG(ERROR) << "Failed to read " << kBurningBlockSize << " bytes of image " |
| 192 << "at offset " << bytes_processed_; | 193 << "at offset " << bytes_processed_; |
| 193 Error(error::kReadImage); | 194 Error(error::kReadImage); |
| 194 } | 195 } |
| 195 } | 196 } |
| 196 | 197 |
| 197 } // namespace image_writer | 198 } // namespace image_writer |
| OLD | NEW |