Remove extra error logs when parsing non-EROFS images
When running delta_generator, it will first attempt to parse input as
EROFS images, and try other image format it that failed. delta_generator
will print an ERROR message when parsing EROFS failed, but that should
not be regarded as an "ERROR" by developers looking at the logs. To
avoid confusion, check for EROFS magic and return silently before
performing actual parsing.
Test: th
Change-Id: I23f5fe49ca109231b85b21e1d6ffa6b97f96b9fb
diff --git a/payload_generator/erofs_filesystem.cc b/payload_generator/erofs_filesystem.cc
index c2c3979..508c9a1 100644
--- a/payload_generator/erofs_filesystem.cc
+++ b/payload_generator/erofs_filesystem.cc
@@ -16,14 +16,18 @@
#include "update_engine/payload_generator/erofs_filesystem.h"
+#include <endian.h>
+#include <fcntl.h>
#include <time.h>
+#include <array>
#include <string>
#include <mutex>
-#include <erofs/internal.h>
+#include <android-base/unique_fd.h>
#include <erofs/dir.h>
#include <erofs/io.h>
+#include <erofs_fs.h>
#include "erofs_iterate.h"
#include "lz4diff/lz4diff.pb.h"
@@ -151,12 +155,24 @@
return;
}
+bool IsErofsImage(const char* path) {
+ android::base::unique_fd fd(open(path, O_RDONLY));
+ uint32_t buf{};
+ if (pread(fd.get(), &buf, 4, EROFS_SUPER_OFFSET) < 0) {
+ return false;
+ }
+ return le32toh(buf) == EROFS_SUPER_MAGIC_V1;
+}
+
} // namespace
static_assert(kBlockSize == EROFS_BLKSIZ);
std::unique_ptr<ErofsFilesystem> ErofsFilesystem::CreateFromFile(
const std::string& filename, const CompressionAlgorithm& algo) {
+ if (!IsErofsImage(filename.c_str())) {
+ return {};
+ }
// erofs-utils makes heavy use of global variables. Hence its functions aren't
// thread safe. For example, it stores a global int holding file descriptors
// to the opened EROFS image. It doesn't even support opening more than 1