blob: d1ef2e91d363ef562f1305001d205c8049b5cc11 [file] [log] [blame]
bowgotsaib51722b2017-01-11 22:21:38 +08001/*
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 Tsai20651f62017-05-08 20:45:50 +080025#ifndef __CORE_FS_MGR_PRIV_AVB_OPS_H
26#define __CORE_FS_MGR_PRIV_AVB_OPS_H
27
28#include <map>
29#include <string>
bowgotsaib51722b2017-01-11 22:21:38 +080030
31#include <libavb/libavb.h>
32
33#include "fs_mgr.h"
34
Bowgo Tsai95c966a2017-03-30 18:42:54 +080035// 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//
47class FsManagerAvbOps {
48 public:
Bowgo Tsai20651f62017-05-08 20:45:50 +080049 FsManagerAvbOps(const fstab& fstab);
50 FsManagerAvbOps(std::map<std::string, std::string>&& by_name_symlink_map);
bowgotsaib51722b2017-01-11 22:21:38 +080051
Bowgo Tsai95c966a2017-03-30 18:42:54 +080052 static FsManagerAvbOps* GetInstanceFromAvbOps(AvbOps* ops) {
53 return reinterpret_cast<FsManagerAvbOps*>(ops->user_data);
54 }
bowgotsaib51722b2017-01-11 22:21:38 +080055
Bowgo Tsai95c966a2017-03-30 18:42:54 +080056 AvbIOResult ReadFromPartition(const char* partition, int64_t offset, size_t num_bytes,
57 void* buffer, size_t* out_num_read);
bowgotsaib51722b2017-01-11 22:21:38 +080058
David Zeuthene2e1b672017-05-10 15:43:37 -040059 AvbSlotVerifyResult AvbSlotVerify(const std::string& ab_suffix, AvbSlotVerifyFlags flags,
Bowgo Tsai95c966a2017-03-30 18:42:54 +080060 AvbSlotVerifyData** out_data);
bowgotsaib51722b2017-01-11 22:21:38 +080061
Bowgo Tsai95c966a2017-03-30 18:42:54 +080062 private:
Bowgo Tsai20651f62017-05-08 20:45:50 +080063 void InitializeAvbOps();
64
Bowgo Tsai95c966a2017-03-30 18:42:54 +080065 AvbOps avb_ops_;
Bowgo Tsai20651f62017-05-08 20:45:50 +080066 std::map<std::string, std::string> by_name_symlink_map_;
Bowgo Tsai95c966a2017-03-30 18:42:54 +080067};
Bowgo Tsai20651f62017-05-08 20:45:50 +080068#endif /* __CORE_FS_MGR_PRIV_AVB_OPS_H */