blob: c87849ca663875f8f236131ad038ab40d2156962 [file] [log] [blame]
Alex Deymo2b19cfb2015-03-26 00:35:07 -07001// Copyright 2015 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_EXT2_FILESYSTEM_H_
6#define UPDATE_ENGINE_PAYLOAD_GENERATOR_EXT2_FILESYSTEM_H_
7
8#include "update_engine/payload_generator/filesystem_interface.h"
9
10#include <memory>
11#include <string>
12#include <vector>
13
14#include <ext2fs/ext2fs.h>
15
16namespace chromeos_update_engine {
17
18class Ext2Filesystem : public FilesystemInterface {
19 public:
20 // Creates an Ext2Filesystem from a ext2 formatted filesystem stored in a
21 // file. The file doesn't need to be loop-back mounted.
22 static std::unique_ptr<Ext2Filesystem> CreateFromFile(
23 const std::string& filename);
24 virtual ~Ext2Filesystem();
25
26 // FilesystemInterface overrides.
27 size_t GetBlockSize() const override;
28 size_t GetBlockCount() const override;
29
30 // GetFiles will return one FilesystemInterface::File for every file and every
31 // directory in the filesystem. Hard-linked files will appear in the list
32 // several times with the same list of blocks.
33 // On addition to actual files, it also returns these pseudo-files:
34 // <free-space>: With all the unallocated data-blocks.
35 // <inode-blocks>: Will all the data-blocks for second and third level inodes
36 // of all the files.
37 // <group-descriptors>: With the block group descriptor and their reserved
38 // space.
39 // <metadata>: With the rest of ext2 metadata blocks, such as superblocks
40 // and bitmap tables.
41 bool GetFiles(std::vector<File>* files) const override;
42
43 private:
44 Ext2Filesystem() = default;
45
46 // The ext2 main data structure holding the filesystem.
47 ext2_filsys filsys_ = nullptr;
48
49 DISALLOW_COPY_AND_ASSIGN(Ext2Filesystem);
50};
51
52} // namespace chromeos_update_engine
53
54#endif // UPDATE_ENGINE_PAYLOAD_GENERATOR_EXT2_FILESYSTEM_H_