1 /* 2 * Copyright (C) 2019 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 #pragma once 18 19 #include <map> 20 #include <string> 21 22 #include <android-base/result.h> 23 24 #include "super_vbmeta_format.h" 25 26 namespace android { 27 namespace fs_mgr { 28 29 class SuperVBMetaBuilder { 30 public: 31 SuperVBMetaBuilder(); 32 SuperVBMetaBuilder(const int super_vbmeta_fd, 33 const std::map<std::string, std::string>& images_path); 34 android::base::Result<void> Build(); 35 android::base::Result<std::string> ReadVBMetaImageFromFile(const std::string& file); 36 // It adds the vbmeta image in super_vbmeta and returns the index 37 // (which has the same meaning with vbmeta_index of VBMetaDescriptor). 38 android::base::Result<uint8_t> AddVBMetaImage(const std::string& vbmeta_name); 39 void DeleteVBMetaImage(const std::string& vbmeta_name); 40 std::unique_ptr<VBMetaTable> ExportVBMetaTable(); 41 android::base::Result<void> ExportVBMetaTableToFile(); 42 android::base::Result<void> ExportVBMetaImageToFile(const uint8_t vbmeta_index, 43 const std::string& vbmeta_image); 44 45 private: 46 android::base::Result<uint8_t> GetEmptySlot(); 47 48 int super_vbmeta_fd_; 49 VBMetaTable table_; 50 // Maps vbmeta image name to vbmeta image file path. 51 std::map<std::string, std::string> images_path_; 52 }; 53 54 } // namespace fs_mgr 55 } // namespace android