bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person |
| 5 | * obtaining a copy of this software and associated documentation |
| 6 | * files (the "Software"), to deal in the Software without |
| 7 | * restriction, including without limitation the rights to use, copy, |
| 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies |
| 9 | * of the Software, and to permit persons to whom the Software is |
| 10 | * furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be |
| 13 | * included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | |
Bowgo Tsai | 20651f6 | 2017-05-08 20:45:50 +0800 | [diff] [blame] | 25 | #ifndef __CORE_FS_MGR_PRIV_AVB_OPS_H |
| 26 | #define __CORE_FS_MGR_PRIV_AVB_OPS_H |
| 27 | |
| 28 | #include <map> |
| 29 | #include <string> |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 30 | |
| 31 | #include <libavb/libavb.h> |
| 32 | |
| 33 | #include "fs_mgr.h" |
| 34 | |
Bowgo Tsai | 95c966a | 2017-03-30 18:42:54 +0800 | [diff] [blame] | 35 | // This class provides C++ bindings to interact with libavb, a small |
| 36 | // self-contained piece of code that's intended to be used in bootloaders. |
| 37 | // It mainly contains two functions: |
| 38 | // - ReadFromPartition(): to read AVB metadata from a given partition. |
| 39 | // It provides the implementation of AvbOps.read_from_partition() when |
| 40 | // reading metadata through libavb. |
| 41 | // - AvbSlotVerify(): the C++ binding of libavb->avb_slot_verify() to |
| 42 | // read and verify the metadata and store it into the out_data parameter. |
| 43 | // The caller MUST check the integrity of metadata against the |
| 44 | // androidboot.vbmeta.{hash_alg, size, digest} values from /proc/cmdline. |
| 45 | // e.g., see class FsManagerAvbVerifier for more details. |
| 46 | // |
| 47 | class FsManagerAvbOps { |
| 48 | public: |
Bowgo Tsai | 20651f6 | 2017-05-08 20:45:50 +0800 | [diff] [blame] | 49 | FsManagerAvbOps(const fstab& fstab); |
| 50 | FsManagerAvbOps(std::map<std::string, std::string>&& by_name_symlink_map); |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 51 | |
Bowgo Tsai | 95c966a | 2017-03-30 18:42:54 +0800 | [diff] [blame] | 52 | static FsManagerAvbOps* GetInstanceFromAvbOps(AvbOps* ops) { |
| 53 | return reinterpret_cast<FsManagerAvbOps*>(ops->user_data); |
| 54 | } |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 55 | |
Bowgo Tsai | 95c966a | 2017-03-30 18:42:54 +0800 | [diff] [blame] | 56 | AvbIOResult ReadFromPartition(const char* partition, int64_t offset, size_t num_bytes, |
| 57 | void* buffer, size_t* out_num_read); |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 58 | |
David Zeuthen | e2e1b67 | 2017-05-10 15:43:37 -0400 | [diff] [blame] | 59 | AvbSlotVerifyResult AvbSlotVerify(const std::string& ab_suffix, AvbSlotVerifyFlags flags, |
Bowgo Tsai | 95c966a | 2017-03-30 18:42:54 +0800 | [diff] [blame] | 60 | AvbSlotVerifyData** out_data); |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 61 | |
Bowgo Tsai | 95c966a | 2017-03-30 18:42:54 +0800 | [diff] [blame] | 62 | private: |
Bowgo Tsai | 20651f6 | 2017-05-08 20:45:50 +0800 | [diff] [blame] | 63 | void InitializeAvbOps(); |
| 64 | |
Bowgo Tsai | 95c966a | 2017-03-30 18:42:54 +0800 | [diff] [blame] | 65 | AvbOps avb_ops_; |
Bowgo Tsai | 20651f6 | 2017-05-08 20:45:50 +0800 | [diff] [blame] | 66 | std::map<std::string, std::string> by_name_symlink_map_; |
Bowgo Tsai | 95c966a | 2017-03-30 18:42:54 +0800 | [diff] [blame] | 67 | }; |
Bowgo Tsai | 20651f6 | 2017-05-08 20:45:50 +0800 | [diff] [blame] | 68 | #endif /* __CORE_FS_MGR_PRIV_AVB_OPS_H */ |