1// 2// Copyright (C) 2016 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// A filesystem parser based on the Android .map files. When generating a 18// filesystem with the Android tools, either squashfs or ext4, a .map file can 19// be generated at the same time with the list of files and the 4K-blocks where 20// the data for those files is located in the filesystem. This class parses this 21// .map text file instead of parsing the structure of the actual filesystem 22// contents. 23 24#ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_MAPFILE_FILESYSTEM_H_ 25#define UPDATE_ENGINE_PAYLOAD_GENERATOR_MAPFILE_FILESYSTEM_H_ 26 27#include "update_engine/payload_generator/filesystem_interface.h" 28 29#include <memory> 30#include <string> 31#include <vector> 32 33namespace chromeos_update_engine { 34 35class MapfileFilesystem : public FilesystemInterface { 36 public: 37 static std::unique_ptr<MapfileFilesystem> CreateFromFile( 38 const std::string& filename, const std::string& mapfile_filename); 39 virtual ~MapfileFilesystem() = default; 40 41 // FilesystemInterface overrides. 42 size_t GetBlockSize() const override; 43 size_t GetBlockCount() const override; 44 45 // All the generated FilesystemInterface::File are reported as regular files. 46 // Files may overlap with other files in the same block. 47 bool GetFiles(std::vector<File>* files) const override; 48 49 bool LoadSettings(brillo::KeyValueStore* store) const override; 50 51 private: 52 MapfileFilesystem(const std::string& mapfile_filename, off_t num_blocks); 53 54 // The file where the map filesystem is stored. 55 std::string mapfile_filename_; 56 57 // The number of blocks in the filesystem. 58 off_t num_blocks_; 59 60 DISALLOW_COPY_AND_ASSIGN(MapfileFilesystem); 61}; 62 63} // namespace chromeos_update_engine 64 65#endif // UPDATE_ENGINE_PAYLOAD_GENERATOR_MAPFILE_FILESYSTEM_H_ 66