3
0

erofs.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * volume_id - reads filesystem label and uuid
  3. *
  4. * Copyright (C) 2020 Norbert Lange <nolange79@gmail.com>
  5. *
  6. * Licensed under GPLv2, see file LICENSE in this source tree.
  7. */
  8. //config:config FEATURE_VOLUMEID_EROFS
  9. //config: bool "erofs filesystem"
  10. //config: default y
  11. //config: depends on VOLUMEID
  12. //config: help
  13. //config: Erofs is a compressed readonly filesystem for Linux.
  14. //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_EROFS) += erofs.o
  15. #include "volume_id_internal.h"
  16. #define EROFS_SUPER_MAGIC_V1 0xE0F5E1E2
  17. #define EROFS_SUPER_OFFSET 1024
  18. #define EROFS_FEATURE_COMPAT_SB_CHKSUM 0x00000001
  19. /* 128-byte erofs on-disk super block */
  20. struct erofs_super_block {
  21. uint32_t magic; /* file system magic number */
  22. uint32_t checksum; /* crc32c(super_block) */
  23. uint32_t feature_compat;
  24. uint8_t blkszbits; /* support block_size == PAGE_SIZE only */
  25. uint8_t reserved;
  26. uint16_t root_nid; /* nid of root directory */
  27. uint64_t inos; /* total valid ino # (== f_files - f_favail) */
  28. uint64_t build_time; /* inode v1 time derivation */
  29. uint32_t build_time_nsec; /* inode v1 time derivation in nano scale */
  30. uint32_t blocks; /* used for statfs */
  31. uint32_t meta_blkaddr; /* start block address of metadata area */
  32. uint32_t xattr_blkaddr; /* start block address of shared xattr area */
  33. uint8_t uuid[16]; /* 128-bit uuid for volume */
  34. uint8_t volume_name[16]; /* volume name */
  35. uint32_t feature_incompat;
  36. uint8_t reserved2[44];
  37. } PACKED;
  38. int FAST_FUNC volume_id_probe_erofs(struct volume_id *id /*,uint64_t off*/)
  39. {
  40. struct erofs_super_block *sb;
  41. BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
  42. dbg("erofs: probing at offset 0x%llx", EROFS_SUPER_OFFSET);
  43. sb = volume_id_get_buffer(id, EROFS_SUPER_OFFSET, sizeof(*sb));
  44. if (!sb)
  45. return -1;
  46. if (sb->magic != cpu_to_le32(EROFS_SUPER_MAGIC_V1))
  47. return -1;
  48. IF_FEATURE_BLKID_TYPE(id->type = "erofs");
  49. volume_id_set_label_string(id, sb->volume_name,
  50. MIN(sizeof(sb->volume_name), VOLUME_ID_LABEL_SIZE));
  51. volume_id_set_uuid(id, sb->uuid, UUID_DCE);
  52. return 0;
  53. }