Kelvin Zhang | 446989a | 2021-12-08 13:49:07 -0800 | [diff] [blame^] | 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 Ext2Filesystem from a ext2 formatted filesystem stored in a |
| 28 | // file. The file doesn't need to be loop-back mounted. |
| 29 | static std::unique_ptr<ErofsFilesystem> CreateFromFile( |
| 30 | const std::string& filename); |
| 31 | virtual ~ErofsFilesystem() = default; |
| 32 | |
| 33 | // FilesystemInterface overrides. |
| 34 | size_t GetBlockSize() const override { return kBlockSize; } |
| 35 | size_t GetBlockCount() const override { return fs_size_ / kBlockSize; } |
| 36 | |
| 37 | // GetFiles will return one FilesystemInterface::File for every file and every |
| 38 | // directory in the filesystem. Hard-linked files will appear in the list |
| 39 | // several times with the same list of blocks. |
| 40 | // On addition to actual files, it also returns these pseudo-files: |
| 41 | // <free-space>: With all the unallocated data-blocks. |
| 42 | // <inode-blocks>: Will all the data-blocks for second and third level inodes |
| 43 | // of all the files. |
| 44 | // <group-descriptors>: With the block group descriptor and their reserved |
| 45 | // space. |
| 46 | // <metadata>: With the rest of ext2 metadata blocks, such as superblocks |
| 47 | // and bitmap tables. |
| 48 | static bool GetFiles(const std::string& filename, std::vector<File>* files); |
| 49 | |
| 50 | bool GetFiles(std::vector<File>* files) const override; |
| 51 | |
| 52 | bool LoadSettings( |
| 53 | [[maybe_unused]] brillo::KeyValueStore* store) const override { |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | private: |
| 58 | ErofsFilesystem(std::string filename, size_t fs_size, std::vector<File> files) |
| 59 | : filename_(filename), fs_size_(fs_size), files_(std::move(files)) {} |
| 60 | |
| 61 | // The file where the filesystem is stored. |
| 62 | const std::string filename_; |
| 63 | const size_t fs_size_; |
| 64 | const std::vector<File> files_; |
| 65 | }; // namespace chromeos_update_engine |
| 66 | |
| 67 | } // namespace chromeos_update_engine |
| 68 | |
| 69 | #endif |