ext2_filesystem.h 2.6 KB

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