Remove GetFilesystemSize.
We don't need to get filesystem size now, because the files passed to
delta_generator is already resized properly.
Also moved Is*Filesystem() to delta_diff_utils.
Test: ./update_engine_unittests
Bug: None
Change-Id: I442d69d1820d08c0f3bd63e7f1986fc4b0d6655e
diff --git a/Android.mk b/Android.mk
index fdfcba7..42617c8 100644
--- a/Android.mk
+++ b/Android.mk
@@ -195,8 +195,7 @@
LOCAL_CPPFLAGS := $(ue_common_cppflags)
LOCAL_LDFLAGS := $(ue_common_ldflags)
LOCAL_C_INCLUDES := \
- $(ue_common_c_includes) \
- external/e2fsprogs/lib
+ $(ue_common_c_includes)
LOCAL_STATIC_LIBRARIES := \
update_metadata-protos \
$(ue_libpayload_consumer_exported_static_libraries) \
@@ -219,8 +218,7 @@
LOCAL_CPPFLAGS := $(ue_common_cppflags)
LOCAL_LDFLAGS := $(ue_common_ldflags)
LOCAL_C_INCLUDES := \
- $(ue_common_c_includes) \
- external/e2fsprogs/lib
+ $(ue_common_c_includes)
LOCAL_STATIC_LIBRARIES := \
update_metadata-protos \
$(ue_libpayload_consumer_exported_static_libraries:-host=) \
diff --git a/common/utils.cc b/common/utils.cc
index 2b09560..5f062f5 100644
--- a/common/utils.cc
+++ b/common/utils.cc
@@ -22,7 +22,6 @@
#include <elf.h>
#include <endian.h>
#include <errno.h>
-#include <ext2fs/ext2fs.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@@ -650,141 +649,6 @@
return true;
}
-bool GetFilesystemSize(const string& device,
- int* out_block_count,
- int* out_block_size) {
- int fd = HANDLE_EINTR(open(device.c_str(), O_RDONLY));
- TEST_AND_RETURN_FALSE_ERRNO(fd >= 0);
- ScopedFdCloser fd_closer(&fd);
- return GetFilesystemSizeFromFD(fd, out_block_count, out_block_size);
-}
-
-bool GetFilesystemSizeFromFD(int fd,
- int* out_block_count,
- int* out_block_size) {
- TEST_AND_RETURN_FALSE(fd >= 0);
-
- // Determine the filesystem size by directly reading the block count and
- // block size information from the superblock. Supported FS are ext3 and
- // squashfs.
-
- // Read from the fd only once and detect in memory. The first 2 KiB is enough
- // to read the ext2 superblock (located at offset 1024) and the squashfs
- // superblock (located at offset 0).
- const ssize_t kBufferSize = 2048;
-
- uint8_t buffer[kBufferSize];
- if (HANDLE_EINTR(pread(fd, buffer, kBufferSize, 0)) != kBufferSize) {
- PLOG(ERROR) << "Unable to read the file system header:";
- return false;
- }
-
- if (GetSquashfs4Size(buffer, kBufferSize, out_block_count, out_block_size))
- return true;
- if (GetExt3Size(buffer, kBufferSize, out_block_count, out_block_size))
- return true;
-
- LOG(ERROR) << "Unable to determine file system type.";
- return false;
-}
-
-bool GetExt3Size(const uint8_t* buffer, size_t buffer_size,
- int* out_block_count,
- int* out_block_size) {
- // See include/linux/ext2_fs.h for more details on the structure. We obtain
- // ext2 constants from ext2fs/ext2fs.h header but we don't link with the
- // library.
- if (buffer_size < SUPERBLOCK_OFFSET + SUPERBLOCK_SIZE)
- return false;
-
- const uint8_t* superblock = buffer + SUPERBLOCK_OFFSET;
-
- // ext3_fs.h: ext3_super_block.s_blocks_count
- uint32_t block_count =
- *reinterpret_cast<const uint32_t*>(superblock + 1 * sizeof(int32_t));
-
- // ext3_fs.h: ext3_super_block.s_log_block_size
- uint32_t log_block_size =
- *reinterpret_cast<const uint32_t*>(superblock + 6 * sizeof(int32_t));
-
- // ext3_fs.h: ext3_super_block.s_magic
- uint16_t magic =
- *reinterpret_cast<const uint16_t*>(superblock + 14 * sizeof(int32_t));
-
- block_count = le32toh(block_count);
- log_block_size = le32toh(log_block_size) + EXT2_MIN_BLOCK_LOG_SIZE;
- magic = le16toh(magic);
-
- // Sanity check the parameters.
- TEST_AND_RETURN_FALSE(magic == EXT2_SUPER_MAGIC);
- TEST_AND_RETURN_FALSE(log_block_size >= EXT2_MIN_BLOCK_LOG_SIZE &&
- log_block_size <= EXT2_MAX_BLOCK_LOG_SIZE);
- TEST_AND_RETURN_FALSE(block_count > 0);
-
- if (out_block_count)
- *out_block_count = block_count;
- if (out_block_size)
- *out_block_size = 1 << log_block_size;
- return true;
-}
-
-bool GetSquashfs4Size(const uint8_t* buffer, size_t buffer_size,
- int* out_block_count,
- int* out_block_size) {
- // See fs/squashfs/squashfs_fs.h for format details. We only support
- // Squashfs 4.x little endian.
-
- // sizeof(struct squashfs_super_block)
- const size_t kSquashfsSuperBlockSize = 96;
- if (buffer_size < kSquashfsSuperBlockSize)
- return false;
-
- // Check magic, squashfs_fs.h: SQUASHFS_MAGIC
- if (memcmp(buffer, "hsqs", 4) != 0)
- return false; // Only little endian is supported.
-
- // squashfs_fs.h: struct squashfs_super_block.s_major
- uint16_t s_major = *reinterpret_cast<const uint16_t*>(
- buffer + 5 * sizeof(uint32_t) + 4 * sizeof(uint16_t));
-
- if (s_major != 4) {
- LOG(ERROR) << "Found unsupported squashfs major version " << s_major;
- return false;
- }
-
- // squashfs_fs.h: struct squashfs_super_block.bytes_used
- uint64_t bytes_used = *reinterpret_cast<const int64_t*>(
- buffer + 5 * sizeof(uint32_t) + 6 * sizeof(uint16_t) + sizeof(uint64_t));
-
- const int block_size = 4096;
-
- // The squashfs' bytes_used doesn't need to be aligned with the block boundary
- // so we round up to the nearest blocksize.
- if (out_block_count)
- *out_block_count = (bytes_used + block_size - 1) / block_size;
- if (out_block_size)
- *out_block_size = block_size;
- return true;
-}
-
-bool IsExtFilesystem(const string& device) {
- brillo::Blob header;
- // The first 2 KiB is enough to read the ext2 superblock (located at offset
- // 1024).
- if (!ReadFileChunk(device, 0, 2048, &header))
- return false;
- return GetExt3Size(header.data(), header.size(), nullptr, nullptr);
-}
-
-bool IsSquashfsFilesystem(const string& device) {
- brillo::Blob header;
- // The first 96 is enough to read the squashfs superblock.
- const ssize_t kSquashfsSuperBlockSize = 96;
- if (!ReadFileChunk(device, 0, kSquashfsSuperBlockSize, &header))
- return false;
- return GetSquashfs4Size(header.data(), header.size(), nullptr, nullptr);
-}
-
// Tries to parse the header of an ELF file to obtain a human-readable
// description of it on the |output| string.
static bool GetFileFormatELF(const uint8_t* buffer, size_t size,
diff --git a/common/utils.h b/common/utils.h
index 55d8a80..b935ba7 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -181,44 +181,6 @@
const std::string& fs_mount_options);
bool UnmountFilesystem(const std::string& mountpoint);
-// Returns the block count and the block byte size of the file system on
-// |device| (which may be a real device or a path to a filesystem image) or on
-// an opened file descriptor |fd|. The actual file-system size is |block_count|
-// * |block_size| bytes. Returns true on success, false otherwise.
-bool GetFilesystemSize(const std::string& device,
- int* out_block_count,
- int* out_block_size);
-bool GetFilesystemSizeFromFD(int fd,
- int* out_block_count,
- int* out_block_size);
-
-// Determines the block count and block size of the ext3 fs. At least 2048 bytes
-// are required to parse the first superblock. Returns whether the buffer
-// contains a valid ext3 filesystem and the values were parsed.
-bool GetExt3Size(const uint8_t* buffer, size_t buffer_size,
- int* out_block_count,
- int* out_block_size);
-
-// Determines the block count and block size of the squashfs v4 fs. At least 96
-// bytes are required to parse the header of the filesystem. Since squashfs
-// doesn't define a physical block size, a value of 4096 is used for the block
-// size, which is the default padding when creating the filesystem.
-// Returns whether the buffer contains a valid squashfs v4 header and the size
-// was parsed. Only little endian squashfs is supported.
-bool GetSquashfs4Size(const uint8_t* buffer, size_t buffer_size,
- int* out_block_count,
- int* out_block_size);
-
-// Returns whether the filesystem is an ext[234] filesystem. In case of failure,
-// such as if the file |device| doesn't exists or can't be read, it returns
-// false.
-bool IsExtFilesystem(const std::string& device);
-
-// Returns whether the filesystem is a squashfs filesystem. In case of failure,
-// such as if the file |device| doesn't exists or can't be read, it returns
-// false.
-bool IsSquashfsFilesystem(const std::string& device);
-
// Returns a human-readable string with the file format based on magic constants
// on the header of the file.
std::string GetFileFormat(const std::string& path);
diff --git a/common/utils_unittest.cc b/common/utils_unittest.cc
index 5bc2428..762e891 100644
--- a/common/utils_unittest.cc
+++ b/common/utils_unittest.cc
@@ -16,21 +16,15 @@
#include "update_engine/common/utils.h"
-#include <errno.h>
-#include <fcntl.h>
#include <stdint.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <map>
#include <string>
#include <vector>
#include <base/files/file_path.h>
#include <base/files/file_util.h>
-#include <base/files/scoped_temp_dir.h>
-#include <base/strings/string_util.h>
-#include <base/strings/stringprintf.h>
#include <brillo/message_loops/fake_message_loop.h>
#include <brillo/message_loops/message_loop_utils.h>
#include <gtest/gtest.h>
@@ -38,7 +32,6 @@
#include "update_engine/common/test_utils.h"
using brillo::FakeMessageLoop;
-using std::map;
using std::string;
using std::vector;
@@ -193,95 +186,6 @@
}
}
-TEST(UtilsTest, GetFilesystemSizeTest) {
- string img;
- EXPECT_TRUE(utils::MakeTempFile("img.XXXXXX", &img, nullptr));
- ScopedPathUnlinker img_unlinker(img);
- EXPECT_TRUE(base::CopyFile(
- test_utils::GetBuildArtifactsPath().Append("gen/disk_ext2_4k.img"),
- base::FilePath(img)));
- {
- // Extend the "partition" holding the file system from 4MiB to 10MiB.
- int fd = HANDLE_EINTR(open(img.c_str(), O_WRONLY));
- ASSERT_GT(fd, 0);
- ScopedFdCloser fd_closer(&fd);
- EXPECT_TRUE(utils::PWriteAll(fd, "\0", 1, 10 * 1024 * 1024 - 1));
- }
- EXPECT_EQ(10 * 1024 * 1024, utils::FileSize(img));
- int block_count = 0;
- int block_size = 0;
- EXPECT_TRUE(utils::GetFilesystemSize(img, &block_count, &block_size));
- EXPECT_EQ(4096, block_size);
- EXPECT_EQ(4 * 1024 * 1024 / 4096, block_count);
-}
-
-// Squashfs example filesystem, generated with:
-// echo hola>hola
-// mksquashfs hola hola.sqfs -noappend -nopad
-// hexdump hola.sqfs -e '16/1 "%02x, " "\n"'
-const uint8_t kSquashfsFile[] = {
- 0x68, 0x73, 0x71, 0x73, 0x02, 0x00, 0x00, 0x00, // magic, inodes
- 0x3e, 0x49, 0x61, 0x54, 0x00, 0x00, 0x02, 0x00,
- 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x11, 0x00,
- 0xc0, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, // flags, noids, major, minor
- 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // root_inode
- 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // bytes_used
- 0xe7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xbd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x68, 0x6f, 0x6c, 0x61, 0x0a, 0x2c, 0x00, 0x78,
- 0xda, 0x63, 0x62, 0x58, 0xc2, 0xc8, 0xc0, 0xc0,
- 0xc8, 0xd0, 0x6b, 0x91, 0x18, 0x02, 0x64, 0xa0,
- 0x00, 0x56, 0x06, 0x90, 0xcc, 0x7f, 0xb0, 0xbc,
- 0x9d, 0x67, 0x62, 0x08, 0x13, 0x54, 0x1c, 0x44,
- 0x4b, 0x03, 0x31, 0x33, 0x10, 0x03, 0x00, 0xb5,
- 0x87, 0x04, 0x89, 0x16, 0x00, 0x78, 0xda, 0x63,
- 0x60, 0x80, 0x00, 0x46, 0x28, 0xcd, 0xc4, 0xc0,
- 0xcc, 0x90, 0x91, 0x9f, 0x93, 0x08, 0x00, 0x04,
- 0x70, 0x01, 0xab, 0x10, 0x80, 0x60, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00,
- 0x01, 0x00, 0x00, 0x00, 0x00, 0xab, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x78,
- 0xda, 0x63, 0x60, 0x80, 0x00, 0x05, 0x28, 0x0d,
- 0x00, 0x01, 0x10, 0x00, 0x21, 0xc5, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x80, 0x99,
- 0xcd, 0x02, 0x00, 0x88, 0x13, 0x00, 0x00, 0xdd,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-TEST(UtilsTest, GetSquashfs4Size) {
- uint8_t buffer[sizeof(kSquashfsFile)];
- memcpy(buffer, kSquashfsFile, sizeof(kSquashfsFile));
-
- int block_count = -1;
- int block_size = -1;
- // Not enough bytes passed.
- EXPECT_FALSE(utils::GetSquashfs4Size(buffer, 10, nullptr, nullptr));
-
- // The whole file system is passed, which is enough for parsing.
- EXPECT_TRUE(utils::GetSquashfs4Size(buffer, sizeof(kSquashfsFile),
- &block_count, &block_size));
- EXPECT_EQ(4096, block_size);
- EXPECT_EQ(1, block_count);
-
- // Modify the major version to 5.
- uint16_t* s_major = reinterpret_cast<uint16_t*>(buffer + 0x1c);
- *s_major = 5;
- EXPECT_FALSE(utils::GetSquashfs4Size(buffer, 10, nullptr, nullptr));
- memcpy(buffer, kSquashfsFile, sizeof(kSquashfsFile));
-
- // Modify the bytes_used to have 6 blocks.
- int64_t* bytes_used = reinterpret_cast<int64_t*>(buffer + 0x28);
- *bytes_used = 4096 * 5 + 1; // 6 "blocks".
- EXPECT_TRUE(utils::GetSquashfs4Size(buffer, sizeof(kSquashfsFile),
- &block_count, &block_size));
- EXPECT_EQ(4096, block_size);
- EXPECT_EQ(6, block_count);
-}
-
namespace {
void GetFileFormatTester(const string& expected,
const vector<uint8_t>& contents) {
diff --git a/payload_generator/delta_diff_generator.cc b/payload_generator/delta_diff_generator.cc
index 6143334..d8c4275 100644
--- a/payload_generator/delta_diff_generator.cc
+++ b/payload_generator/delta_diff_generator.cc
@@ -90,9 +90,9 @@
// We don't efficiently support deltas on squashfs. For now, we will
// produce full operations in that case.
if (!old_part.path.empty() &&
- !utils::IsSquashfsFilesystem(new_part.path)) {
+ !diff_utils::IsSquashfs4Filesystem(new_part.path)) {
// Delta update.
- if (utils::IsExtFilesystem(new_part.path)) {
+ if (diff_utils::IsExtFilesystem(new_part.path)) {
LOG_IF(WARNING, old_part.size != new_part.size)
<< "Old and new filesystems have different size.";
// TODO(deymo): Our tools only support growing the filesystem size
diff --git a/payload_generator/delta_diff_utils.cc b/payload_generator/delta_diff_utils.cc
index 88567b2..9206c50 100644
--- a/payload_generator/delta_diff_utils.cc
+++ b/payload_generator/delta_diff_utils.cc
@@ -16,6 +16,9 @@
#include "update_engine/payload_generator/delta_diff_utils.h"
+#include <endian.h>
+#include <ext2fs/ext2fs.h>
+
#include <algorithm>
#include <map>
@@ -717,6 +720,70 @@
return first_dst_start < second_dst_start;
}
+bool IsExtFilesystem(const string& device) {
+ brillo::Blob header;
+ // See include/linux/ext2_fs.h for more details on the structure. We obtain
+ // ext2 constants from ext2fs/ext2fs.h header but we don't link with the
+ // library.
+ if (!utils::ReadFileChunk(
+ device, 0, SUPERBLOCK_OFFSET + SUPERBLOCK_SIZE, &header) ||
+ header.size() < SUPERBLOCK_OFFSET + SUPERBLOCK_SIZE)
+ return false;
+
+ const uint8_t* superblock = header.data() + SUPERBLOCK_OFFSET;
+
+ // ext3_fs.h: ext3_super_block.s_blocks_count
+ uint32_t block_count =
+ *reinterpret_cast<const uint32_t*>(superblock + 1 * sizeof(int32_t));
+
+ // ext3_fs.h: ext3_super_block.s_log_block_size
+ uint32_t log_block_size =
+ *reinterpret_cast<const uint32_t*>(superblock + 6 * sizeof(int32_t));
+
+ // ext3_fs.h: ext3_super_block.s_magic
+ uint16_t magic =
+ *reinterpret_cast<const uint16_t*>(superblock + 14 * sizeof(int32_t));
+
+ block_count = le32toh(block_count);
+ log_block_size = le32toh(log_block_size) + EXT2_MIN_BLOCK_LOG_SIZE;
+ magic = le16toh(magic);
+
+ if (magic != EXT2_SUPER_MAGIC)
+ return false;
+
+ // Sanity check the parameters.
+ TEST_AND_RETURN_FALSE(log_block_size >= EXT2_MIN_BLOCK_LOG_SIZE &&
+ log_block_size <= EXT2_MAX_BLOCK_LOG_SIZE);
+ TEST_AND_RETURN_FALSE(block_count > 0);
+ return true;
+}
+
+bool IsSquashfs4Filesystem(const string& device) {
+ brillo::Blob header;
+ // See fs/squashfs/squashfs_fs.h for format details. We only support
+ // Squashfs 4.x little endian.
+
+ // The first 96 is enough to read the squashfs superblock.
+ const ssize_t kSquashfsSuperBlockSize = 96;
+ if (!utils::ReadFileChunk(device, 0, kSquashfsSuperBlockSize, &header) ||
+ header.size() < kSquashfsSuperBlockSize)
+ return false;
+
+ // Check magic, squashfs_fs.h: SQUASHFS_MAGIC
+ if (memcmp(header.data(), "hsqs", 4) != 0)
+ return false; // Only little endian is supported.
+
+ // squashfs_fs.h: struct squashfs_super_block.s_major
+ uint16_t s_major = *reinterpret_cast<const uint16_t*>(
+ header.data() + 5 * sizeof(uint32_t) + 4 * sizeof(uint16_t));
+
+ if (s_major != 4) {
+ LOG(ERROR) << "Found unsupported squashfs major version " << s_major;
+ return false;
+ }
+ return true;
+}
+
} // namespace diff_utils
} // namespace chromeos_update_engine
diff --git a/payload_generator/delta_diff_utils.h b/payload_generator/delta_diff_utils.h
index 8a02358..b22ff63 100644
--- a/payload_generator/delta_diff_utils.h
+++ b/payload_generator/delta_diff_utils.h
@@ -132,6 +132,16 @@
bool CompareAopsByDestination(AnnotatedOperation first_aop,
AnnotatedOperation second_aop);
+// Returns whether the filesystem is an ext[234] filesystem. In case of failure,
+// such as if the file |device| doesn't exists or can't be read, it returns
+// false.
+bool IsExtFilesystem(const std::string& device);
+
+// Returns whether the filesystem is a squashfs4 filesystem. In case of failure,
+// such as if the file |device| doesn't exists or can't be read, it returns
+// false.
+bool IsSquashfs4Filesystem(const std::string& device);
+
} // namespace diff_utils
} // namespace chromeos_update_engine
diff --git a/payload_generator/delta_diff_utils_unittest.cc b/payload_generator/delta_diff_utils_unittest.cc
index 7aadfdf..c70c70f 100644
--- a/payload_generator/delta_diff_utils_unittest.cc
+++ b/payload_generator/delta_diff_utils_unittest.cc
@@ -40,6 +40,43 @@
namespace {
+// Squashfs example filesystem, generated with:
+// echo hola>hola
+// mksquashfs hola hola.sqfs -noappend -nopad
+// hexdump hola.sqfs -e '16/1 "%02x, " "\n"'
+const uint8_t kSquashfsFile[] = {
+ 0x68, 0x73, 0x71, 0x73, 0x02, 0x00, 0x00, 0x00, // magic, inodes
+ 0x3e, 0x49, 0x61, 0x54, 0x00, 0x00, 0x02, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x11, 0x00,
+ 0xc0, 0x00, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, // flags, noids, major, minor
+ 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // root_inode
+ 0xef, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // bytes_used
+ 0xe7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xbd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x68, 0x6f, 0x6c, 0x61, 0x0a, 0x2c, 0x00, 0x78,
+ 0xda, 0x63, 0x62, 0x58, 0xc2, 0xc8, 0xc0, 0xc0,
+ 0xc8, 0xd0, 0x6b, 0x91, 0x18, 0x02, 0x64, 0xa0,
+ 0x00, 0x56, 0x06, 0x90, 0xcc, 0x7f, 0xb0, 0xbc,
+ 0x9d, 0x67, 0x62, 0x08, 0x13, 0x54, 0x1c, 0x44,
+ 0x4b, 0x03, 0x31, 0x33, 0x10, 0x03, 0x00, 0xb5,
+ 0x87, 0x04, 0x89, 0x16, 0x00, 0x78, 0xda, 0x63,
+ 0x60, 0x80, 0x00, 0x46, 0x28, 0xcd, 0xc4, 0xc0,
+ 0xcc, 0x90, 0x91, 0x9f, 0x93, 0x08, 0x00, 0x04,
+ 0x70, 0x01, 0xab, 0x10, 0x80, 0x60, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0xab, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x78,
+ 0xda, 0x63, 0x60, 0x80, 0x00, 0x05, 0x28, 0x0d,
+ 0x00, 0x01, 0x10, 0x00, 0x21, 0xc5, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x80, 0x99,
+ 0xcd, 0x02, 0x00, 0x88, 0x13, 0x00, 0x00, 0xdd,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
// Writes the |data| in the blocks specified by |extents| on the partition
// |part_path|. The |data| size could be smaller than the size of the blocks
// passed.
@@ -781,4 +818,35 @@
EXPECT_EQ(0, blob_size_);
}
+TEST_F(DeltaDiffUtilsTest, IsExtFilesystemTest) {
+ EXPECT_TRUE(diff_utils::IsExtFilesystem(test_utils::GetBuildArtifactsPath()
+ .Append("gen/disk_ext2_1k.img")
+ .value()));
+ EXPECT_TRUE(diff_utils::IsExtFilesystem(test_utils::GetBuildArtifactsPath()
+ .Append("gen/disk_ext2_4k.img")
+ .value()));
+}
+
+TEST_F(DeltaDiffUtilsTest, IsSquashfs4FilesystemTest) {
+ uint8_t buffer[sizeof(kSquashfsFile)];
+ memcpy(buffer, kSquashfsFile, sizeof(kSquashfsFile));
+ string img;
+ EXPECT_TRUE(utils::MakeTempFile("img.XXXXXX", &img, nullptr));
+ ScopedPathUnlinker img_unlinker(img);
+
+ // Not enough bytes passed.
+ EXPECT_TRUE(utils::WriteFile(img.c_str(), buffer, 10));
+ EXPECT_FALSE(diff_utils::IsSquashfs4Filesystem(img));
+
+ // The whole file system is passed, which is enough for parsing.
+ EXPECT_TRUE(utils::WriteFile(img.c_str(), buffer, sizeof(kSquashfsFile)));
+ EXPECT_TRUE(diff_utils::IsSquashfs4Filesystem(img));
+
+ // Modify the major version to 5.
+ uint16_t* s_major = reinterpret_cast<uint16_t*>(buffer + 0x1c);
+ *s_major = 5;
+ EXPECT_TRUE(utils::WriteFile(img.c_str(), buffer, sizeof(kSquashfsFile)));
+ EXPECT_FALSE(diff_utils::IsSquashfs4Filesystem(img));
+}
+
} // namespace chromeos_update_engine
diff --git a/payload_generator/payload_generation_config.cc b/payload_generator/payload_generation_config.cc
index f93a95a..9ecc682 100644
--- a/payload_generator/payload_generation_config.cc
+++ b/payload_generator/payload_generation_config.cc
@@ -21,6 +21,7 @@
#include "update_engine/common/utils.h"
#include "update_engine/payload_consumer/delta_performer.h"
#include "update_engine/payload_generator/delta_diff_generator.h"
+#include "update_engine/payload_generator/delta_diff_utils.h"
#include "update_engine/payload_generator/ext2_filesystem.h"
#include "update_engine/payload_generator/raw_filesystem.h"
@@ -37,16 +38,6 @@
// The requested size is within the limits of the file.
TEST_AND_RETURN_FALSE(static_cast<off_t>(size) <=
utils::FileSize(path.c_str()));
- // TODO(deymo): The delta generator algorithm doesn't support a block size
- // different than 4 KiB. Remove this check once that's fixed. crbug.com/455045
- int block_count, block_size;
- if (utils::GetFilesystemSize(path, &block_count, &block_size) &&
- block_size != 4096) {
- LOG(ERROR) << "The filesystem provided in " << path
- << " has a block size of " << block_size
- << " but delta_generator only supports 4096.";
- return false;
- }
return true;
}
@@ -54,8 +45,12 @@
if (path.empty())
return true;
fs_interface.reset();
- if (utils::IsExtFilesystem(path)) {
+ if (diff_utils::IsExtFilesystem(path)) {
fs_interface = Ext2Filesystem::CreateFromFile(path);
+ // TODO(deymo): The delta generator algorithm doesn't support a block size
+ // different than 4 KiB. Remove this check once that's fixed. b/26972455
+ if (fs_interface)
+ TEST_AND_RETURN_FALSE(fs_interface->GetBlockSize() == kBlockSize);
}
if (!fs_interface) {