Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_EXTENT_WRITER_H__ | 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_EXTENT_WRITER_H__ |
| 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_EXTENT_WRITER_H__ | 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_EXTENT_WRITER_H__ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 #include "chromeos/obsolete_logging.h" | 9 #include "chromeos/obsolete_logging.h" |
| 10 #include "update_engine/update_metadata.pb.h" | 10 #include "update_engine/update_metadata.pb.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 class ExtentWriter { | 22 class ExtentWriter { |
| 23 public: | 23 public: |
| 24 ExtentWriter() : end_called_(false) {} | 24 ExtentWriter() : end_called_(false) {} |
| 25 virtual ~ExtentWriter() { | 25 virtual ~ExtentWriter() { |
| 26 LOG_IF(ERROR, !end_called_) << "End() not called on ExtentWriter."; | 26 LOG_IF(ERROR, !end_called_) << "End() not called on ExtentWriter."; |
| 27 } | 27 } |
| 28 | 28 |
| 29 // Returns true on success. | 29 // Returns true on success. |
| 30 virtual bool Init(int fd, | 30 virtual bool Init(int fd, |
| 31 const std::vector<Extent>& extents, | 31 const std::vector<Extent>& extents, |
| 32 size_t block_size) = 0; | 32 uint32 block_size) = 0; |
|
Daniel Erat
2010/04/15 00:55:47
switch this to uint32_t
| |
| 33 | 33 |
| 34 // Returns true on success. | 34 // Returns true on success. |
| 35 virtual bool Write(const void* bytes, size_t count) = 0; | 35 virtual bool Write(const void* bytes, size_t count) = 0; |
| 36 | 36 |
| 37 // Should be called when all writing is complete. Returns true on success. | 37 // Should be called when all writing is complete. Returns true on success. |
| 38 // The fd is not closed. Caller is responsible for closing it. | 38 // The fd is not closed. Caller is responsible for closing it. |
| 39 bool End() { | 39 bool End() { |
| 40 end_called_ = true; | 40 end_called_ = true; |
| 41 return EndImpl(); | 41 return EndImpl(); |
| 42 } | 42 } |
| 43 virtual bool EndImpl() = 0; | 43 virtual bool EndImpl() = 0; |
| 44 private: | 44 private: |
| 45 bool end_called_; | 45 bool end_called_; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 // DirectExtentWriter is probably the simplest ExtentWriter implementation. | 48 // DirectExtentWriter is probably the simplest ExtentWriter implementation. |
| 49 // It writes the data directly into the extents. | 49 // It writes the data directly into the extents. |
| 50 | 50 |
| 51 class DirectExtentWriter : public ExtentWriter { | 51 class DirectExtentWriter : public ExtentWriter { |
| 52 public: | 52 public: |
| 53 DirectExtentWriter() | 53 DirectExtentWriter() |
| 54 : fd_(-1), | 54 : fd_(-1), |
| 55 block_size_(0), | 55 block_size_(0), |
| 56 extent_bytes_written_(0), | 56 extent_bytes_written_(0), |
| 57 next_extent_index_(0) {} | 57 next_extent_index_(0) {} |
| 58 ~DirectExtentWriter() {} | 58 ~DirectExtentWriter() {} |
| 59 | 59 |
| 60 bool Init(int fd, const std::vector<Extent>& extents, size_t block_size) { | 60 bool Init(int fd, const std::vector<Extent>& extents, uint32 block_size) { |
|
Daniel Erat
2010/04/15 00:55:47
this too
| |
| 61 fd_ = fd; | 61 fd_ = fd; |
| 62 block_size_ = block_size; | 62 block_size_ = block_size; |
| 63 extents_ = extents; | 63 extents_ = extents; |
| 64 return true; | 64 return true; |
| 65 } | 65 } |
| 66 bool Write(const void* bytes, size_t count); | 66 bool Write(const void* bytes, size_t count); |
| 67 bool EndImpl() { | 67 bool EndImpl() { |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| 70 | 70 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 85 // to pad as needed. | 85 // to pad as needed. |
| 86 | 86 |
| 87 class ZeroPadExtentWriter : public ExtentWriter { | 87 class ZeroPadExtentWriter : public ExtentWriter { |
| 88 public: | 88 public: |
| 89 ZeroPadExtentWriter(ExtentWriter* underlying_extent_writer) | 89 ZeroPadExtentWriter(ExtentWriter* underlying_extent_writer) |
| 90 : underlying_extent_writer_(underlying_extent_writer), | 90 : underlying_extent_writer_(underlying_extent_writer), |
| 91 block_size_(0), | 91 block_size_(0), |
| 92 bytes_written_mod_block_size_(0) {} | 92 bytes_written_mod_block_size_(0) {} |
| 93 ~ZeroPadExtentWriter() {} | 93 ~ZeroPadExtentWriter() {} |
| 94 | 94 |
| 95 bool Init(int fd, const std::vector<Extent>& extents, size_t block_size) { | 95 bool Init(int fd, const std::vector<Extent>& extents, uint32 block_size) { |
|
Daniel Erat
2010/04/15 00:55:47
and this
| |
| 96 block_size_ = block_size; | 96 block_size_ = block_size; |
| 97 return underlying_extent_writer_->Init(fd, extents, block_size); | 97 return underlying_extent_writer_->Init(fd, extents, block_size); |
| 98 } | 98 } |
| 99 bool Write(const void* bytes, size_t count) { | 99 bool Write(const void* bytes, size_t count) { |
| 100 if (underlying_extent_writer_->Write(bytes, count)) { | 100 if (underlying_extent_writer_->Write(bytes, count)) { |
| 101 bytes_written_mod_block_size_ += count; | 101 bytes_written_mod_block_size_ += count; |
| 102 bytes_written_mod_block_size_ %= block_size_; | 102 bytes_written_mod_block_size_ %= block_size_; |
| 103 return true; | 103 return true; |
| 104 } | 104 } |
| 105 return false; | 105 return false; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 116 | 116 |
| 117 private: | 117 private: |
| 118 ExtentWriter* underlying_extent_writer_; // The underlying ExtentWriter. | 118 ExtentWriter* underlying_extent_writer_; // The underlying ExtentWriter. |
| 119 size_t block_size_; | 119 size_t block_size_; |
| 120 size_t bytes_written_mod_block_size_; | 120 size_t bytes_written_mod_block_size_; |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 } // namespace chromeos_update_engine | 123 } // namespace chromeos_update_engine |
| 124 | 124 |
| 125 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_EXTENT_WRITER_H__ | 125 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_EXTENT_WRITER_H__ |
| OLD | NEW |