blob: 0863b50f69500a1437afccc147bc7131a6f5af2a [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
23namespace chromeos_update_engine {
24
25class ErofsFilesystem final : public FilesystemInterface {
26 public:
Kelvin Zhang8389dfe2022-01-13 12:47:11 -080027 // 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.
Kelvin Zhang446989a2021-12-08 13:49:07 -080032 static std::unique_ptr<ErofsFilesystem> CreateFromFile(
Kelvin Zhang8389dfe2022-01-13 12:47:11 -080033 const std::string& filename,
34 const CompressionAlgorithm& algo =
35 PartitionConfig::GetDefaultCompressionParam());
Kelvin Zhang446989a2021-12-08 13:49:07 -080036 virtual ~ErofsFilesystem() = default;
37
38 // FilesystemInterface overrides.
39 size_t GetBlockSize() const override { return kBlockSize; }
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.
Kelvin Zhang8389dfe2022-01-13 12:47:11 -080053 static bool GetFiles(const std::string& filename,
54 std::vector<File>* files,
55 const CompressionAlgorithm& algo);
Kelvin Zhang446989a2021-12-08 13:49:07 -080056
57 bool GetFiles(std::vector<File>* files) const override;
58
59 bool LoadSettings(
60 [[maybe_unused]] brillo::KeyValueStore* store) const override {
61 return true;
62 }
63
64 private:
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