blob: 501a6be9332d96e7cda47001a0f207b15c80e20b [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>
23
24#include "update_engine/update_metadata.pb.h"
25
26namespace chromeos_update_engine {
27
28class FilesystemInterface {
29 public:
30 // This represents a file or pseudo-file in the filesystem. It can include
31 // all sort of files, like symlinks, hardlinks, directories and even a file
32 // entry representing the metadata, free space, journaling data, etc.
33 struct File {
34 File() {
35 memset(&file_stat, 0, sizeof(file_stat));
36 }
37
38 // The stat struct for the file. This is invalid (inode 0) for some
39 // pseudo-files.
40 struct stat file_stat;
41
42 // The absolute path to the file inside the filesystem, for example,
43 // "/usr/bin/bash". For pseudo-files, like blocks associated to internal
44 // filesystem tables or free space, the path doesn't start with a /.
45 std::string name;
46
47 // The list of all physical blocks holding the data of this file in
48 // the same order as the logical data. All the block numbers shall be
49 // between 0 and GetBlockCount() - 1. The blocks are encoded in extents,
50 // indicating the starting block, and the number of consecutive blocks.
51 std::vector<Extent> extents;
52 };
53
54 virtual ~FilesystemInterface() = default;
55
56 // Returns the size of a block in the filesystem.
57 virtual size_t GetBlockSize() const = 0;
58
59 // Returns the number of blocks in the filesystem.
60 virtual size_t GetBlockCount() const = 0;
61
62 // Stores in |files| the list of files and pseudo-files in the filesystem. See
63 // FileInterface for details. The paths returned by this method shall not
64 // be repeated; but the same block could be present in more than one file as
65 // happens for example with hard-linked files, but not limited to those cases.
66 // Returns whether the function succeeded.
67 virtual bool GetFiles(std::vector<File>* files) const = 0;
68
69 protected:
70 FilesystemInterface() = default;
71
72 private:
73 DISALLOW_COPY_AND_ASSIGN(FilesystemInterface);
74};
75
76} // namespace chromeos_update_engine
77
78#endif // UPDATE_ENGINE_PAYLOAD_GENERATOR_FILESYSTEM_INTERFACE_H_