| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 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 | // | 
| Alex Deymo | 2b19cfb | 2015-03-26 00:35:07 -0700 | [diff] [blame] | 16 |  | 
|  | 17 | #ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_EXT2_FILESYSTEM_H_ | 
|  | 18 | #define UPDATE_ENGINE_PAYLOAD_GENERATOR_EXT2_FILESYSTEM_H_ | 
|  | 19 |  | 
|  | 20 | #include "update_engine/payload_generator/filesystem_interface.h" | 
|  | 21 |  | 
|  | 22 | #include <memory> | 
|  | 23 | #include <string> | 
|  | 24 | #include <vector> | 
|  | 25 |  | 
| Amin Hassani | fca4775 | 2017-06-16 14:05:46 -0700 | [diff] [blame] | 26 | #if defined(__clang__) | 
| Christopher Ferris | dcb1861 | 2017-02-24 10:13:06 -0800 | [diff] [blame] | 27 | // TODO: Remove these pragmas when b/35721782 is fixed. | 
|  | 28 | #pragma clang diagnostic push | 
|  | 29 | #pragma clang diagnostic ignored "-Wmacro-redefined" | 
| Amin Hassani | fca4775 | 2017-06-16 14:05:46 -0700 | [diff] [blame] | 30 | #endif | 
| Alex Deymo | 2b19cfb | 2015-03-26 00:35:07 -0700 | [diff] [blame] | 31 | #include <ext2fs/ext2fs.h> | 
| Amin Hassani | fca4775 | 2017-06-16 14:05:46 -0700 | [diff] [blame] | 32 | #if defined(__clang__) | 
| Christopher Ferris | dcb1861 | 2017-02-24 10:13:06 -0800 | [diff] [blame] | 33 | #pragma clang diagnostic pop | 
| Amin Hassani | fca4775 | 2017-06-16 14:05:46 -0700 | [diff] [blame] | 34 | #endif | 
| Alex Deymo | 2b19cfb | 2015-03-26 00:35:07 -0700 | [diff] [blame] | 35 |  | 
|  | 36 | namespace chromeos_update_engine { | 
|  | 37 |  | 
|  | 38 | class Ext2Filesystem : public FilesystemInterface { | 
|  | 39 | public: | 
|  | 40 | // Creates an Ext2Filesystem from a ext2 formatted filesystem stored in a | 
|  | 41 | // file. The file doesn't need to be loop-back mounted. | 
|  | 42 | static std::unique_ptr<Ext2Filesystem> CreateFromFile( | 
|  | 43 | const std::string& filename); | 
|  | 44 | virtual ~Ext2Filesystem(); | 
|  | 45 |  | 
|  | 46 | // FilesystemInterface overrides. | 
|  | 47 | size_t GetBlockSize() const override; | 
|  | 48 | size_t GetBlockCount() const override; | 
|  | 49 |  | 
|  | 50 | // GetFiles will return one FilesystemInterface::File for every file and every | 
|  | 51 | // directory in the filesystem. Hard-linked files will appear in the list | 
|  | 52 | // several times with the same list of blocks. | 
|  | 53 | // On addition to actual files, it also returns these pseudo-files: | 
|  | 54 | //  <free-space>: With all the unallocated data-blocks. | 
|  | 55 | //  <inode-blocks>: Will all the data-blocks for second and third level inodes | 
|  | 56 | //    of all the files. | 
|  | 57 | //  <group-descriptors>: With the block group descriptor and their reserved | 
|  | 58 | //    space. | 
|  | 59 | //  <metadata>: With the rest of ext2 metadata blocks, such as superblocks | 
|  | 60 | //    and bitmap tables. | 
|  | 61 | bool GetFiles(std::vector<File>* files) const override; | 
|  | 62 |  | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 63 | bool LoadSettings(brillo::KeyValueStore* store) const override; | 
| Alex Deymo | 2e9533b | 2015-06-26 20:57:06 -0700 | [diff] [blame] | 64 |  | 
| Alex Deymo | 2b19cfb | 2015-03-26 00:35:07 -0700 | [diff] [blame] | 65 | private: | 
|  | 66 | Ext2Filesystem() = default; | 
|  | 67 |  | 
|  | 68 | // The ext2 main data structure holding the filesystem. | 
|  | 69 | ext2_filsys filsys_ = nullptr; | 
|  | 70 |  | 
| Alex Deymo | 2e9533b | 2015-06-26 20:57:06 -0700 | [diff] [blame] | 71 | // The file where the filesystem is stored. | 
|  | 72 | std::string filename_; | 
|  | 73 |  | 
| Alex Deymo | 2b19cfb | 2015-03-26 00:35:07 -0700 | [diff] [blame] | 74 | DISALLOW_COPY_AND_ASSIGN(Ext2Filesystem); | 
|  | 75 | }; | 
|  | 76 |  | 
|  | 77 | }  // namespace chromeos_update_engine | 
|  | 78 |  | 
|  | 79 | #endif  // UPDATE_ENGINE_PAYLOAD_GENERATOR_EXT2_FILESYSTEM_H_ |