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 <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/aligned_memory.h" | 10 #include "base/memory/aligned_memory.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 112 |
113 return true; | 113 return true; |
114 } | 114 } |
115 | 115 |
116 void ImageWriter::WriteChunk() { | 116 void ImageWriter::WriteChunk() { |
117 if (!IsRunning()) { | 117 if (!IsRunning()) { |
118 return; | 118 return; |
119 } | 119 } |
120 | 120 |
121 // DASD buffers require memory alignment on some systems. | 121 // DASD buffers require memory alignment on some systems. |
122 scoped_ptr<char, base::AlignedFreeDeleter> buffer(static_cast<char*>( | 122 std::unique_ptr<char, base::AlignedFreeDeleter> buffer(static_cast<char*>( |
123 base::AlignedAlloc(kBurningBlockSize, kMemoryAlignment))); | 123 base::AlignedAlloc(kBurningBlockSize, kMemoryAlignment))); |
124 memset(buffer.get(), 0, kBurningBlockSize); | 124 memset(buffer.get(), 0, kBurningBlockSize); |
125 | 125 |
126 int bytes_read = image_file_.Read(bytes_processed_, buffer.get(), | 126 int bytes_read = image_file_.Read(bytes_processed_, buffer.get(), |
127 kBurningBlockSize); | 127 kBurningBlockSize); |
128 | 128 |
129 if (bytes_read > 0) { | 129 if (bytes_read > 0) { |
130 // Always attempt to write a whole block, as writing DASD requires sector- | 130 // Always attempt to write a whole block, as writing DASD requires sector- |
131 // aligned writes to devices. | 131 // aligned writes to devices. |
132 int bytes_to_write = bytes_read + (kMemoryAlignment - 1) - | 132 int bytes_to_write = bytes_read + (kMemoryAlignment - 1) - |
(...skipping 20 matching lines...) Expand all Loading... |
153 // Unable to read entire file. | 153 // Unable to read entire file. |
154 Error(error::kReadImage); | 154 Error(error::kReadImage); |
155 } | 155 } |
156 } | 156 } |
157 | 157 |
158 void ImageWriter::VerifyChunk() { | 158 void ImageWriter::VerifyChunk() { |
159 if (!IsRunning()) { | 159 if (!IsRunning()) { |
160 return; | 160 return; |
161 } | 161 } |
162 | 162 |
163 scoped_ptr<char[]> image_buffer(new char[kBurningBlockSize]); | 163 std::unique_ptr<char[]> image_buffer(new char[kBurningBlockSize]); |
164 // DASD buffers require memory alignment on some systems. | 164 // DASD buffers require memory alignment on some systems. |
165 scoped_ptr<char, base::AlignedFreeDeleter> device_buffer(static_cast<char*>( | 165 std::unique_ptr<char, base::AlignedFreeDeleter> device_buffer( |
166 base::AlignedAlloc(kBurningBlockSize, kMemoryAlignment))); | 166 static_cast<char*>( |
| 167 base::AlignedAlloc(kBurningBlockSize, kMemoryAlignment))); |
167 | 168 |
168 int bytes_read = image_file_.Read(bytes_processed_, image_buffer.get(), | 169 int bytes_read = image_file_.Read(bytes_processed_, image_buffer.get(), |
169 kBurningBlockSize); | 170 kBurningBlockSize); |
170 | 171 |
171 if (bytes_read > 0) { | 172 if (bytes_read > 0) { |
172 if (device_file_.Read(bytes_processed_, | 173 if (device_file_.Read(bytes_processed_, |
173 device_buffer.get(), | 174 device_buffer.get(), |
174 kBurningBlockSize) < bytes_read) { | 175 kBurningBlockSize) < bytes_read) { |
175 LOG(ERROR) << "Failed to read " << bytes_read << " bytes of " | 176 LOG(ERROR) << "Failed to read " << bytes_read << " bytes of " |
176 << "device at offset " << bytes_processed_; | 177 << "device at offset " << bytes_processed_; |
(...skipping 18 matching lines...) Expand all Loading... |
195 running_ = false; | 196 running_ = false; |
196 } else { | 197 } else { |
197 // Unable to read entire file. | 198 // Unable to read entire file. |
198 LOG(ERROR) << "Failed to read " << kBurningBlockSize << " bytes of image " | 199 LOG(ERROR) << "Failed to read " << kBurningBlockSize << " bytes of image " |
199 << "at offset " << bytes_processed_; | 200 << "at offset " << bytes_processed_; |
200 Error(error::kReadImage); | 201 Error(error::kReadImage); |
201 } | 202 } |
202 } | 203 } |
203 | 204 |
204 } // namespace image_writer | 205 } // namespace image_writer |
OLD | NEW |