blob: 1a4e1a1edaaf0785b885451fbf220f0c0cf8732c [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2015 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//
Alex Deymo2b19cfb2015-03-26 00:35:07 -070016
17#ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_EXT2_FILESYSTEM_H_
18#define UPDATE_ENGINE_PAYLOAD_GENERATOR_EXT2_FILESYSTEM_H_
19
20#include "update_engine/payload_generator/filesystem_interface.h"
21
22#include <memory>
23#include <string>
24#include <vector>
25
Christopher Ferrisdcb18612017-02-24 10:13:06 -080026// TODO: Remove these pragmas when b/35721782 is fixed.
27#pragma clang diagnostic push
28#pragma clang diagnostic ignored "-Wmacro-redefined"
Alex Deymo2b19cfb2015-03-26 00:35:07 -070029#include <ext2fs/ext2fs.h>
Christopher Ferrisdcb18612017-02-24 10:13:06 -080030#pragma clang diagnostic pop
Alex Deymo2b19cfb2015-03-26 00:35:07 -070031
32namespace chromeos_update_engine {
33
34class Ext2Filesystem : public FilesystemInterface {
35 public:
36 // Creates an Ext2Filesystem from a ext2 formatted filesystem stored in a
37 // file. The file doesn't need to be loop-back mounted.
38 static std::unique_ptr<Ext2Filesystem> CreateFromFile(
39 const std::string& filename);
40 virtual ~Ext2Filesystem();
41
42 // FilesystemInterface overrides.
43 size_t GetBlockSize() const override;
44 size_t GetBlockCount() const override;
45
46 // GetFiles will return one FilesystemInterface::File for every file and every
47 // directory in the filesystem. Hard-linked files will appear in the list
48 // several times with the same list of blocks.
49 // On addition to actual files, it also returns these pseudo-files:
50 // <free-space>: With all the unallocated data-blocks.
51 // <inode-blocks>: Will all the data-blocks for second and third level inodes
52 // of all the files.
53 // <group-descriptors>: With the block group descriptor and their reserved
54 // space.
55 // <metadata>: With the rest of ext2 metadata blocks, such as superblocks
56 // and bitmap tables.
57 bool GetFiles(std::vector<File>* files) const override;
58
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070059 bool LoadSettings(brillo::KeyValueStore* store) const override;
Alex Deymo2e9533b2015-06-26 20:57:06 -070060
Alex Deymo2b19cfb2015-03-26 00:35:07 -070061 private:
62 Ext2Filesystem() = default;
63
64 // The ext2 main data structure holding the filesystem.
65 ext2_filsys filsys_ = nullptr;
66
Alex Deymo2e9533b2015-06-26 20:57:06 -070067 // The file where the filesystem is stored.
68 std::string filename_;
69
Alex Deymo2b19cfb2015-03-26 00:35:07 -070070 DISALLOW_COPY_AND_ASSIGN(Ext2Filesystem);
71};
72
73} // namespace chromeos_update_engine
74
75#endif // UPDATE_ENGINE_PAYLOAD_GENERATOR_EXT2_FILESYSTEM_H_