ubi.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (C) 2017 Rafał Miłecki <rafal@milecki.pl>
  3. *
  4. * This file may be redistributed under the terms of the
  5. * GNU Lesser General Public License.
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10. #include <string.h>
  11. #include <stdint.h>
  12. #include "superblocks.h"
  13. struct ubi_ec_hdr {
  14. uint32_t magic;
  15. uint8_t version;
  16. uint8_t padding1[3];
  17. uint64_t ec;
  18. uint32_t vid_hdr_offset;
  19. uint32_t data_offset;
  20. uint32_t image_seq;
  21. uint8_t padding2[32];
  22. uint32_t hdr_crc;
  23. } __attribute__((packed));
  24. static int probe_ubi(blkid_probe pr, const struct blkid_idmag *mag)
  25. {
  26. struct ubi_ec_hdr *hdr;
  27. hdr = blkid_probe_get_sb(pr, mag, struct ubi_ec_hdr);
  28. if (!hdr)
  29. return -1;
  30. blkid_probe_sprintf_version(pr, "%u", hdr->version);
  31. blkid_probe_sprintf_uuid(pr, (unsigned char *)&hdr->image_seq, 4, "%u",
  32. be32_to_cpu(hdr->image_seq));
  33. return 0;
  34. }
  35. const struct blkid_idinfo ubi_idinfo =
  36. {
  37. .name = "ubi",
  38. .usage = BLKID_USAGE_RAID,
  39. .probefunc = probe_ubi,
  40. .magics =
  41. {
  42. { .magic = "UBI#", .len = 4 },
  43. { NULL }
  44. }
  45. };