blob: b10fc98b1402d51952df22cb12cbed953e9f3d1a [file] [log] [blame]
Kelvin Zhang446989a2021-12-08 13:49:07 -08001//
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
Kelvin Zhang18e97e02023-09-25 09:54:16 -070023struct erofs_sb_info;
24
Kelvin Zhang446989a2021-12-08 13:49:07 -080025namespace chromeos_update_engine {
26
27class ErofsFilesystem final : public FilesystemInterface {
28 public:
Kelvin Zhang8389dfe2022-01-13 12:47:11 -080029 // 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.
Kelvin Zhang446989a2021-12-08 13:49:07 -080034 static std::unique_ptr<ErofsFilesystem> CreateFromFile(
Kelvin Zhang8389dfe2022-01-13 12:47:11 -080035 const std::string& filename,
36 const CompressionAlgorithm& algo =
37 PartitionConfig::GetDefaultCompressionParam());
Kelvin Zhang446989a2021-12-08 13:49:07 -080038 virtual ~ErofsFilesystem() = default;
39
40 // FilesystemInterface overrides.
41 size_t GetBlockSize() const override { return kBlockSize; }
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.
Kelvin Zhang18e97e02023-09-25 09:54:16 -070055 static bool GetFiles(struct erofs_sb_info* sbi,
56 const std::string& filename,
Kelvin Zhang8389dfe2022-01-13 12:47:11 -080057 std::vector<File>* files,
58 const CompressionAlgorithm& algo);
Kelvin Zhang446989a2021-12-08 13:49:07 -080059
60 bool GetFiles(std::vector<File>* files) const override;
61
Kelvin Zhang446989a2021-12-08 13:49:07 -080062 private:
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