• 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 #if !defined(AVB_INSIDE_LIBAVB_AB_H) && !defined(AVB_COMPILATION)
26 #error \
27     "Never include this file directly, include libavb_ab/libavb_ab.h instead."
28 #endif
29 
30 #ifndef AVB_AB_OPS_H_
31 #define AVB_AB_OPS_H_
32 
33 #include <libavb/libavb.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 struct AvbABOps;
40 typedef struct AvbABOps AvbABOps;
41 
42 struct AvbABData;
43 
44 /* High-level operations/functions/methods for A/B that are platform
45  * dependent.
46  */
47 struct AvbABOps {
48   /* Operations from libavb. */
49   AvbOps* ops;
50 
51   /* Reads A/B metadata from persistent storage. Returned data is
52    * properly byteswapped. Returns AVB_IO_RESULT_OK on success, error
53    * code otherwise.
54    *
55    * If the data read is invalid (e.g. wrong magic or CRC checksum
56    * failure), the metadata shoule be reset using avb_ab_data_init()
57    * and then written to persistent storage.
58    *
59    * Implementations will typically want to use avb_ab_data_read()
60    * here to use the 'misc' partition for persistent storage.
61    */
62   AvbIOResult (*read_ab_metadata)(AvbABOps* ab_ops, struct AvbABData* data);
63 
64   /* Writes A/B metadata to persistent storage. This will byteswap and
65    * update the CRC as needed. Returns AVB_IO_RESULT_OK on success,
66    * error code otherwise.
67    *
68    * Implementations will typically want to use avb_ab_data_write()
69    * here to use the 'misc' partition for persistent storage.
70    */
71   AvbIOResult (*write_ab_metadata)(AvbABOps* ab_ops,
72                                    const struct AvbABData* data);
73 };
74 
75 #ifdef __cplusplus
76 }
77 #endif
78 
79 #endif /* AVB_AB_OPS_H_ */
80