blob: 186eac439e36ab3d049619f35ea39c1ef04da553 [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_FILESYSTEM_INTERFACE_H_
6#define UPDATE_ENGINE_PAYLOAD_GENERATOR_FILESYSTEM_INTERFACE_H_
7
8// This class is used to abstract a filesystem and iterate the blocks
9// associated with the files and filesystem structures.
10// For the purposes of the update payload generation, a filesystem is a formated
11// partition composed by fixed-size blocks, since that's the interface used in
12// the update payload.
13
14#include <sys/stat.h>
15#include <sys/types.h>
16#include <unistd.h>
17
18#include <memory>
19#include <string>
20#include <vector>
21
22#include <base/macros.h>
Alex Deymo2e9533b2015-06-26 20:57:06 -070023#include <chromeos/key_value_store.h>
Alex Deymo2b19cfb2015-03-26 00:35:07 -070024
25#include "update_engine/update_metadata.pb.h"
26
27namespace chromeos_update_engine {
28
29class FilesystemInterface {
30 public:
31 // This represents a file or pseudo-file in the filesystem. It can include
32 // all sort of files, like symlinks, hardlinks, directories and even a file
33 // entry representing the metadata, free space, journaling data, etc.
34 struct File {
35 File() {
36 memset(&file_stat, 0, sizeof(file_stat));
37 }
38
39 // The stat struct for the file. This is invalid (inode 0) for some
40 // pseudo-files.
41 struct stat file_stat;
42
43 // The absolute path to the file inside the filesystem, for example,
44 // "/usr/bin/bash". For pseudo-files, like blocks associated to internal
45 // filesystem tables or free space, the path doesn't start with a /.
46 std::string name;
47
48 // The list of all physical blocks holding the data of this file in
49 // the same order as the logical data. All the block numbers shall be
50 // between 0 and GetBlockCount() - 1. The blocks are encoded in extents,
51 // indicating the starting block, and the number of consecutive blocks.
52 std::vector<Extent> extents;
53 };
54
55 virtual ~FilesystemInterface() = default;
56
57 // Returns the size of a block in the filesystem.
58 virtual size_t GetBlockSize() const = 0;
59
60 // Returns the number of blocks in the filesystem.
61 virtual size_t GetBlockCount() const = 0;
62
63 // Stores in |files| the list of files and pseudo-files in the filesystem. See
64 // FileInterface for details. The paths returned by this method shall not
65 // be repeated; but the same block could be present in more than one file as
66 // happens for example with hard-linked files, but not limited to those cases.
67 // Returns whether the function succeeded.
68 virtual bool GetFiles(std::vector<File>* files) const = 0;
69
Alex Deymo2e9533b2015-06-26 20:57:06 -070070 // Load the image settings stored in the filesystem in the
71 // /etc/update_engine.conf file. Returns whether the settings were found.
72 virtual bool LoadSettings(chromeos::KeyValueStore* store) const = 0;
73
Alex Deymo2b19cfb2015-03-26 00:35:07 -070074 protected:
75 FilesystemInterface() = default;
76
77 private:
78 DISALLOW_COPY_AND_ASSIGN(FilesystemInterface);
79};
80
81} // namespace chromeos_update_engine
82
83#endif // UPDATE_ENGINE_PAYLOAD_GENERATOR_FILESYSTEM_INTERFACE_H_