1 //
2 // Copyright (C) 2018 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_BOOT_IMG_FILESYSTEM_H_
18 #define UPDATE_ENGINE_PAYLOAD_GENERATOR_BOOT_IMG_FILESYSTEM_H_
19 
20 #include "update_engine/payload_generator/filesystem_interface.h"
21 
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 namespace chromeos_update_engine {
27 
28 class BootImgFilesystem : public FilesystemInterface {
29  public:
30   // Creates an BootImgFilesystem from an Android boot.img file.
31   static std::unique_ptr<BootImgFilesystem> CreateFromFile(
32       const std::string& filename);
33   ~BootImgFilesystem() override = default;
34 
35   // FilesystemInterface overrides.
36   size_t GetBlockSize() const override;
37   size_t GetBlockCount() const override;
38 
39   // GetFiles will return one FilesystemInterface::File for kernel and one for
40   // ramdisk.
41   bool GetFiles(std::vector<File>* files) const override;
42 
43  private:
44   friend class BootImgFilesystemTest;
45 
46   BootImgFilesystem() = default;
47 
48   File GetFile(const std::string& name, uint64_t offset, uint64_t size) const;
49 
50   // The boot.img file path.
51   std::string filename_;
52 
53   uint32_t kernel_size_ = 0;    /* size in bytes */
54   uint32_t ramdisk_size_ = 0;   /* size in bytes */
55   uint32_t signature_size_ = 0; /* size in bytes */
56   uint32_t page_size_ = 4096;   /* flash page size we assume */
57 
58   DISALLOW_COPY_AND_ASSIGN(BootImgFilesystem);
59 };
60 
61 }  // namespace chromeos_update_engine
62 
63 #endif  // UPDATE_ENGINE_PAYLOAD_GENERATOR_BOOT_IMG_FILESYSTEM_H_
64