ext2_filesystem.h revision 2e9533be9eb2e022d653400f47a354a7f06bf9db
1// 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  bool LoadSettings(chromeos::KeyValueStore* store) const override;
44
45 private:
46  Ext2Filesystem() = default;
47
48  // The ext2 main data structure holding the filesystem.
49  ext2_filsys filsys_ = nullptr;
50
51  // The file where the filesystem is stored.
52  std::string filename_;
53
54  DISALLOW_COPY_AND_ASSIGN(Ext2Filesystem);
55};
56
57}  // namespace chromeos_update_engine
58
59#endif  // UPDATE_ENGINE_PAYLOAD_GENERATOR_EXT2_FILESYSTEM_H_
60