Merge "Move ReadCowHeader to CowReader" into main am: f5f0a10541
am: 2457e0b7e8
am: 9d67604c0d
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2781728 Change-Id: I737f6696221edf913cf84d89544c783908732741 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
4156b81180
4 changed files with 31 additions and 31 deletions
|
@ -188,5 +188,7 @@ class CowReader final : public ICowReader {
|
|||
uint8_t compression_type_ = kCowCompressNone;
|
||||
};
|
||||
|
||||
bool ReadCowHeader(android::base::borrowed_fd fd, CowHeader* header);
|
||||
|
||||
} // namespace snapshot
|
||||
} // namespace android
|
||||
|
|
|
@ -34,6 +34,35 @@
|
|||
namespace android {
|
||||
namespace snapshot {
|
||||
|
||||
bool ReadCowHeader(android::base::borrowed_fd fd, CowHeader* header) {
|
||||
if (lseek(fd.get(), 0, SEEK_SET) < 0) {
|
||||
PLOG(ERROR) << "lseek header failed";
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(header, 0, sizeof(*header));
|
||||
|
||||
if (!android::base::ReadFully(fd, &header->prefix, sizeof(header->prefix))) {
|
||||
return false;
|
||||
}
|
||||
if (header->prefix.magic != kCowMagicNumber) {
|
||||
LOG(ERROR) << "Header Magic corrupted. Magic: " << header->prefix.magic
|
||||
<< "Expected: " << kCowMagicNumber;
|
||||
return false;
|
||||
}
|
||||
if (header->prefix.header_size > sizeof(CowHeader)) {
|
||||
LOG(ERROR) << "Unknown CowHeader size (got " << header->prefix.header_size
|
||||
<< " bytes, expected at most " << sizeof(CowHeader) << " bytes)";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (lseek(fd.get(), 0, SEEK_SET) < 0) {
|
||||
PLOG(ERROR) << "lseek header failed";
|
||||
return false;
|
||||
}
|
||||
return android::base::ReadFully(fd, header, header->prefix.header_size);
|
||||
}
|
||||
|
||||
CowReader::CowReader(ReaderFlags reader_flag, bool is_merge)
|
||||
: fd_(-1),
|
||||
header_(),
|
||||
|
|
|
@ -23,35 +23,6 @@ namespace snapshot {
|
|||
|
||||
using android::base::borrowed_fd;
|
||||
|
||||
bool ReadCowHeader(android::base::borrowed_fd fd, CowHeader* header) {
|
||||
if (lseek(fd.get(), 0, SEEK_SET) < 0) {
|
||||
PLOG(ERROR) << "lseek header failed";
|
||||
return false;
|
||||
}
|
||||
|
||||
memset(header, 0, sizeof(*header));
|
||||
|
||||
if (!android::base::ReadFully(fd, &header->prefix, sizeof(header->prefix))) {
|
||||
return false;
|
||||
}
|
||||
if (header->prefix.magic != kCowMagicNumber) {
|
||||
LOG(ERROR) << "Header Magic corrupted. Magic: " << header->prefix.magic
|
||||
<< "Expected: " << kCowMagicNumber;
|
||||
return false;
|
||||
}
|
||||
if (header->prefix.header_size > sizeof(CowHeader)) {
|
||||
LOG(ERROR) << "Unknown CowHeader size (got " << header->prefix.header_size
|
||||
<< " bytes, expected at most " << sizeof(CowHeader) << " bytes)";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (lseek(fd.get(), 0, SEEK_SET) < 0) {
|
||||
PLOG(ERROR) << "lseek header failed";
|
||||
return false;
|
||||
}
|
||||
return android::base::ReadFully(fd, header, header->prefix.header_size);
|
||||
}
|
||||
|
||||
bool CowParserV2::Parse(borrowed_fd fd, const CowHeader& header, std::optional<uint64_t> label) {
|
||||
auto pos = lseek(fd.get(), 0, SEEK_END);
|
||||
if (pos < 0) {
|
||||
|
|
|
@ -49,7 +49,5 @@ class CowParserV2 {
|
|||
std::optional<uint64_t> last_label_;
|
||||
};
|
||||
|
||||
bool ReadCowHeader(android::base::borrowed_fd fd, CowHeader* header);
|
||||
|
||||
} // namespace snapshot
|
||||
} // namespace android
|
||||
|
|
Loading…
Reference in a new issue