Home | History | Annotate | Download | only in payload_generator
      1 //
      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 //
     16 
     17 #ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_FILESYSTEM_INTERFACE_H_
     18 #define UPDATE_ENGINE_PAYLOAD_GENERATOR_FILESYSTEM_INTERFACE_H_
     19 
     20 // This class is used to abstract a filesystem and iterate the blocks
     21 // associated with the files and filesystem structures.
     22 // For the purposes of the update payload generation, a filesystem is a formated
     23 // partition composed by fixed-size blocks, since that's the interface used in
     24 // the update payload.
     25 
     26 #include <sys/stat.h>
     27 #include <sys/types.h>
     28 #include <unistd.h>
     29 
     30 #include <memory>
     31 #include <string>
     32 #include <vector>
     33 
     34 #include <base/macros.h>
     35 #include <brillo/key_value_store.h>
     36 #include <puffin/utils.h>
     37 
     38 #include "update_engine/update_metadata.pb.h"
     39 
     40 namespace chromeos_update_engine {
     41 
     42 class FilesystemInterface {
     43  public:
     44   // This represents a file or pseudo-file in the filesystem. It can include
     45   // all sort of files, like symlinks, hardlinks, directories and even a file
     46   // entry representing the metadata, free space, journaling data, etc.
     47   struct File {
     48     File() {
     49       memset(&file_stat, 0, sizeof(file_stat));
     50     }
     51 
     52     // The stat struct for the file. This is invalid (inode 0) for some
     53     // pseudo-files.
     54     struct stat file_stat;
     55 
     56     // The absolute path to the file inside the filesystem, for example,
     57     // "/usr/bin/bash". For pseudo-files, like blocks associated to internal
     58     // filesystem tables or free space, the path doesn't start with a /.
     59     std::string name;
     60 
     61     // The list of all physical blocks holding the data of this file in
     62     // the same order as the logical data. All the block numbers shall be
     63     // between 0 and GetBlockCount() - 1. The blocks are encoded in extents,
     64     // indicating the starting block, and the number of consecutive blocks.
     65     std::vector<Extent> extents;
     66 
     67     // All the deflate locations in the file. These locations are not relative
     68     // to the extents. They are relative to the file system itself.
     69     std::vector<puffin::BitExtent> deflates;
     70   };
     71 
     72   virtual ~FilesystemInterface() = default;
     73 
     74   // Returns the size of a block in the filesystem.
     75   virtual size_t GetBlockSize() const = 0;
     76 
     77   // Returns the number of blocks in the filesystem.
     78   virtual size_t GetBlockCount() const = 0;
     79 
     80   // Stores in |files| the list of files and pseudo-files in the filesystem. See
     81   // FileInterface for details. The paths returned by this method shall not
     82   // be repeated; but the same block could be present in more than one file as
     83   // happens for example with hard-linked files, but not limited to those cases.
     84   // Returns whether the function succeeded.
     85   virtual bool GetFiles(std::vector<File>* files) const = 0;
     86 
     87   // Load the image settings stored in the filesystem in the
     88   // /etc/update_engine.conf file. Returns whether the settings were found.
     89   virtual bool LoadSettings(brillo::KeyValueStore* store) const = 0;
     90 
     91  protected:
     92   FilesystemInterface() = default;
     93 
     94  private:
     95   DISALLOW_COPY_AND_ASSIGN(FilesystemInterface);
     96 };
     97 
     98 }  // namespace chromeos_update_engine
     99 
    100 #endif  // UPDATE_ENGINE_PAYLOAD_GENERATOR_FILESYSTEM_INTERFACE_H_
    101