File: fs_mgr_priv_avb_ops.h

package info (click to toggle)
android-platform-system-core 1%3A8.1.0%2Br23-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 19,480 kB
  • sloc: cpp: 137,841; ansic: 30,813; asm: 3,504; python: 1,754; makefile: 235; sh: 225; xml: 73
file content (68 lines) | stat: -rw-r--r-- 2,819 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef __CORE_FS_MGR_PRIV_AVB_OPS_H
#define __CORE_FS_MGR_PRIV_AVB_OPS_H

#include <map>
#include <string>

#include <libavb/libavb.h>

#include "fs_mgr.h"

// This class provides C++ bindings to interact with libavb, a small
// self-contained piece of code that's intended to be used in bootloaders.
// It mainly contains two functions:
//   - ReadFromPartition(): to read AVB metadata from a given partition.
//     It provides the implementation of AvbOps.read_from_partition() when
//     reading metadata through libavb.
//   - AvbSlotVerify(): the C++ binding of libavb->avb_slot_verify() to
//     read and verify the metadata and store it into the out_data parameter.
//     The caller MUST check the integrity of metadata against the
//     androidboot.vbmeta.{hash_alg, size, digest} values from /proc/cmdline.
//     e.g., see class FsManagerAvbVerifier for more details.
//
class FsManagerAvbOps {
  public:
    FsManagerAvbOps(const fstab& fstab);
    FsManagerAvbOps(std::map<std::string, std::string>&& by_name_symlink_map);

    static FsManagerAvbOps* GetInstanceFromAvbOps(AvbOps* ops) {
        return reinterpret_cast<FsManagerAvbOps*>(ops->user_data);
    }

    AvbIOResult ReadFromPartition(const char* partition, int64_t offset, size_t num_bytes,
                                  void* buffer, size_t* out_num_read);

    AvbSlotVerifyResult AvbSlotVerify(const std::string& ab_suffix, AvbSlotVerifyFlags flags,
                                      AvbSlotVerifyData** out_data);

  private:
    void InitializeAvbOps();

    AvbOps avb_ops_;
    std::map<std::string, std::string> by_name_symlink_map_;
};
#endif /* __CORE_FS_MGR_PRIV_AVB_OPS_H */