image-sparse.h 836 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright 2014 Broadcom Corporation.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <part.h>
  7. #include <sparse_format.h>
  8. #define ROUNDUP(x, y) (((x) + ((y) - 1)) & ~((y) - 1))
  9. struct sparse_storage {
  10. lbaint_t blksz;
  11. lbaint_t start;
  12. lbaint_t size;
  13. void *priv;
  14. lbaint_t (*write)(struct sparse_storage *info,
  15. lbaint_t blk,
  16. lbaint_t blkcnt,
  17. const void *buffer);
  18. lbaint_t (*reserve)(struct sparse_storage *info,
  19. lbaint_t blk,
  20. lbaint_t blkcnt);
  21. };
  22. static inline int is_sparse_image(void *buf)
  23. {
  24. sparse_header_t *s_header = (sparse_header_t *)buf;
  25. if ((le32_to_cpu(s_header->magic) == SPARSE_HEADER_MAGIC) &&
  26. (le16_to_cpu(s_header->major_version) == 1))
  27. return 1;
  28. return 0;
  29. }
  30. void write_sparse_image(struct sparse_storage *info, const char *part_name,
  31. void *data, unsigned sz);