avb_ab_ops.h 2.6 KB

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