Add parser for EROFS file data

This CL parses file names and compression info from input EROFS image,
so that OTA generation can use it later.

Test: th
Test: Generate an incremental OTA with erofs images, make sure we see
file lists.
Bug: 206729162

Change-Id: I70536d7762acc19a6977460738065d5557338532
diff --git a/payload_generator/erofs_filesystem.h b/payload_generator/erofs_filesystem.h
new file mode 100644
index 0000000..473c609
--- /dev/null
+++ b/payload_generator/erofs_filesystem.h
@@ -0,0 +1,69 @@
+//
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+#ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_EROFS_FILESYSTEM_H_
+#define UPDATE_ENGINE_PAYLOAD_GENERATOR_EROFS_FILESYSTEM_H_
+
+#include "update_engine/payload_generator/filesystem_interface.h"
+#include "update_engine/payload_generator/delta_diff_generator.h"
+
+namespace chromeos_update_engine {
+
+class ErofsFilesystem final : public FilesystemInterface {
+ public:
+  // Creates an Ext2Filesystem from a ext2 formatted filesystem stored in a
+  // file. The file doesn't need to be loop-back mounted.
+  static std::unique_ptr<ErofsFilesystem> CreateFromFile(
+      const std::string& filename);
+  virtual ~ErofsFilesystem() = default;
+
+  // FilesystemInterface overrides.
+  size_t GetBlockSize() const override { return kBlockSize; }
+  size_t GetBlockCount() const override { return fs_size_ / kBlockSize; }
+
+  // GetFiles will return one FilesystemInterface::File for every file and every
+  // directory in the filesystem. Hard-linked files will appear in the list
+  // several times with the same list of blocks.
+  // On addition to actual files, it also returns these pseudo-files:
+  //  <free-space>: With all the unallocated data-blocks.
+  //  <inode-blocks>: Will all the data-blocks for second and third level inodes
+  //    of all the files.
+  //  <group-descriptors>: With the block group descriptor and their reserved
+  //    space.
+  //  <metadata>: With the rest of ext2 metadata blocks, such as superblocks
+  //    and bitmap tables.
+  static bool GetFiles(const std::string& filename, std::vector<File>* files);
+
+  bool GetFiles(std::vector<File>* files) const override;
+
+  bool LoadSettings(
+      [[maybe_unused]] brillo::KeyValueStore* store) const override {
+    return true;
+  }
+
+ private:
+  ErofsFilesystem(std::string filename, size_t fs_size, std::vector<File> files)
+      : filename_(filename), fs_size_(fs_size), files_(std::move(files)) {}
+
+  // The file where the filesystem is stored.
+  const std::string filename_;
+  const size_t fs_size_;
+  const std::vector<File> files_;
+};  // namespace chromeos_update_engine
+
+}  // namespace chromeos_update_engine
+
+#endif
\ No newline at end of file