• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
25 #pragma once
26 
27 #include <string>
28 #include <vector>
29 
30 #include <fs_avb/types.h>
31 #include <fstab/fstab.h>
32 #include <libavb/libavb.h>
33 
34 namespace android {
35 namespace fs_mgr {
36 
37 // This class provides C++ bindings to interact with libavb, a small
38 // self-contained piece of code that's intended to be used in bootloaders.
39 // It mainly contains two functions:
40 //   - ReadFromPartition(): to read AVB metadata from a given partition.
41 //     It provides the implementation of AvbOps.read_from_partition() when
42 //     reading metadata through libavb.
43 //   - AvbSlotVerify(): the C++ binding of libavb->avb_slot_verify() to
44 //     read and verify the metadata and store it into the out_data parameter.
45 //     The caller MUST check the integrity of metadata against the
46 //     androidboot.vbmeta.{hash_alg, size, digest} values from /proc/cmdline.
47 //     e.g., see class AvbVerifier for more details.
48 //
49 class FsManagerAvbOps {
50   public:
51     FsManagerAvbOps();
52 
GetInstanceFromAvbOps(AvbOps * ops)53     static FsManagerAvbOps* GetInstanceFromAvbOps(AvbOps* ops) {
54         return reinterpret_cast<FsManagerAvbOps*>(ops->user_data);
55     }
56 
57     AvbIOResult ReadFromPartition(const char* partition, int64_t offset, size_t num_bytes,
58                                   void* buffer, size_t* out_num_read);
59 
60     AvbSlotVerifyResult AvbSlotVerify(const std::string& ab_suffix, AvbSlotVerifyFlags flags,
61                                       std::vector<VBMetaData>* out_vbmeta_images);
62 
63   private:
64     std::string GetLogicalPath(const std::string& partition_name);
65     AvbOps avb_ops_;
66     Fstab fstab_;
67 };
68 
69 }  // namespace fs_mgr
70 }  // namespace android
71