xref: /aosp_15_r20/system/update_engine/payload_generator/erofs_filesystem.h (revision 5a9231315b4521097b8dc3750bc806fcafe0c72f)
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 struct erofs_sb_info;
24 
25 namespace chromeos_update_engine {
26 
27 class ErofsFilesystem final : public FilesystemInterface {
28  public:
29   // Creates an ErofsFilesystem from a erofs formatted filesystem stored in a
30   // file. The file doesn't need to be loop-back mounted. Since erofs-utils
31   // library functions are not concurrency safe(can't be used in multi-threaded
32   // context, can't even work with multiple EROFS images concurrently on 1
33   // thread), this function takes a global mutex.
34   static std::unique_ptr<ErofsFilesystem> CreateFromFile(
35       const std::string& filename,
36       const CompressionAlgorithm& algo =
37           PartitionConfig::GetDefaultCompressionParam());
38   virtual ~ErofsFilesystem() = default;
39 
40   // FilesystemInterface overrides.
GetBlockSize()41   size_t GetBlockSize() const override { return kBlockSize; }
GetBlockCount()42   size_t GetBlockCount() const override { return fs_size_ / kBlockSize; }
43 
44   // GetFiles will return one FilesystemInterface::File for every file and every
45   // directory in the filesystem. Hard-linked files will appear in the list
46   // several times with the same list of blocks.
47   // On addition to actual files, it also returns these pseudo-files:
48   //  <free-space>: With all the unallocated data-blocks.
49   //  <inode-blocks>: Will all the data-blocks for second and third level inodes
50   //    of all the files.
51   //  <group-descriptors>: With the block group descriptor and their reserved
52   //    space.
53   //  <metadata>: With the rest of ext2 metadata blocks, such as superblocks
54   //    and bitmap tables.
55   static bool GetFiles(struct erofs_sb_info* sbi,
56                        const std::string& filename,
57                        std::vector<File>* files,
58                        const CompressionAlgorithm& algo);
59 
60   bool GetFiles(std::vector<File>* files) const override;
61 
62  private:
ErofsFilesystem(std::string filename,size_t fs_size,std::vector<File> files)63   ErofsFilesystem(std::string filename, size_t fs_size, std::vector<File> files)
64       : filename_(filename), fs_size_(fs_size), files_(std::move(files)) {}
65 
66   // The file where the filesystem is stored.
67   const std::string filename_;
68   const size_t fs_size_;
69   const std::vector<File> files_;
70 };  // namespace chromeos_update_engine
71 
72 }  // namespace chromeos_update_engine
73 
74 #endif