libsnapshot: Fetch device size from header
Now that V3 is enabled, relax the header version check.
For V3, header op_count_max contains the information of the device size.
Bug: 299011882
Test: snapshotctl map-snapshots on Pixel with V3 format
Change-Id: Ia1cb20b24857136a742e20408ee95e56e98b256a
Signed-off-by: Akilesh Kailash <akailash@google.com>
diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp
index cbe8285..e6c4de6 100644
--- a/fs_mgr/libsnapshot/snapshot.cpp
+++ b/fs_mgr/libsnapshot/snapshot.cpp
@@ -508,8 +508,6 @@
// When snapshots are on current slot, we determine the size
// of block device based on the number of COW operations. We cannot
// use base device as it will be from older image.
- size_t num_ops = 0;
- uint64_t dev_sz = 0;
unique_fd fd(open(cow_file.c_str(), O_RDONLY | O_CLOEXEC));
if (fd < 0) {
PLOG(ERROR) << "Failed to open " << cow_file;
@@ -522,13 +520,18 @@
return false;
}
+ uint64_t dev_sz = 0;
const auto& header = reader.GetHeader();
- if (header.prefix.major_version > 2) {
- LOG(ERROR) << "COW format not supported";
- return false;
+ if (header.prefix.major_version == 2) {
+ const size_t num_ops = reader.get_num_total_data_ops();
+ dev_sz = (num_ops * header.block_size);
+ } else {
+ // create_snapshot will skip in-place copy ops. Hence, fetch this
+ // information directly from v3 header.
+ const auto& v3_header = reader.header_v3();
+ dev_sz = v3_header.op_count_max * v3_header.block_size;
}
- num_ops = reader.get_num_total_data_ops();
- dev_sz = (num_ops * header.block_size);
+
base_sectors = dev_sz >> 9;
} else {
// For userspace snapshots, the size of the base device is taken as the