1 // 2 // Copyright (C) 2021 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_EROFS_FILESYSTEM_H_ 18 #define UPDATE_ENGINE_PAYLOAD_GENERATOR_EROFS_FILESYSTEM_H_ 19 20 #include "update_engine/payload_generator/filesystem_interface.h" 21 #include "update_engine/payload_generator/delta_diff_generator.h" 22 23 namespace chromeos_update_engine { 24 25 class ErofsFilesystem final : public FilesystemInterface { 26 public: 27 // Creates an ErofsFilesystem from a erofs formatted filesystem stored in a 28 // file. The file doesn't need to be loop-back mounted. Since erofs-utils 29 // library functions are not concurrency safe(can't be used in multi-threaded 30 // context, can't even work with multiple EROFS images concurrently on 1 31 // thread), this function takes a global mutex. 32 static std::unique_ptr<ErofsFilesystem> CreateFromFile( 33 const std::string& filename, 34 const CompressionAlgorithm& algo = 35 PartitionConfig::GetDefaultCompressionParam()); 36 virtual ~ErofsFilesystem() = default; 37 38 // FilesystemInterface overrides. GetBlockSize()39 size_t GetBlockSize() const override { return kBlockSize; } GetBlockCount()40 size_t GetBlockCount() const override { return fs_size_ / kBlockSize; } 41 42 // GetFiles will return one FilesystemInterface::File for every file and every 43 // directory in the filesystem. Hard-linked files will appear in the list 44 // several times with the same list of blocks. 45 // On addition to actual files, it also returns these pseudo-files: 46 // <free-space>: With all the unallocated data-blocks. 47 // <inode-blocks>: Will all the data-blocks for second and third level inodes 48 // of all the files. 49 // <group-descriptors>: With the block group descriptor and their reserved 50 // space. 51 // <metadata>: With the rest of ext2 metadata blocks, such as superblocks 52 // and bitmap tables. 53 static bool GetFiles(const std::string& filename, 54 std::vector<File>* files, 55 const CompressionAlgorithm& algo); 56 57 bool GetFiles(std::vector<File>* files) const override; 58 LoadSettings(brillo::KeyValueStore * store)59 bool LoadSettings( 60 [[maybe_unused]] brillo::KeyValueStore* store) const override { 61 return true; 62 } 63 64 private: ErofsFilesystem(std::string filename,size_t fs_size,std::vector<File> files)65 ErofsFilesystem(std::string filename, size_t fs_size, std::vector<File> files) 66 : filename_(filename), fs_size_(fs_size), files_(std::move(files)) {} 67 68 // The file where the filesystem is stored. 69 const std::string filename_; 70 const size_t fs_size_; 71 const std::vector<File> files_; 72 }; // namespace chromeos_update_engine 73 74 } // namespace chromeos_update_engine 75 76 #endif