ubifs.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * volume_id - reads filesystem label and uuid
  3. *
  4. * Copyright (C) 2012 S-G Bergh <sgb@systemasis.org>
  5. *
  6. * Licensed under GPLv2, see file LICENSE in this source tree.
  7. */
  8. //config:config FEATURE_VOLUMEID_UBIFS
  9. //config: bool "UBIFS filesystem"
  10. //config: default y
  11. //config: depends on VOLUMEID
  12. //config: help
  13. //config: UBIFS (Unsorted Block Image File System) is a file
  14. //config: system for use with raw flash memory media.
  15. //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_UBIFS) += ubifs.o
  16. #include "volume_id_internal.h"
  17. #define UBIFS_NODE_MAGIC 0x06101831
  18. /*
  19. * struct ubifs_ch - common header node.
  20. * @magic: UBIFS node magic number (%UBIFS_NODE_MAGIC)
  21. * @crc: CRC-32 checksum of the node header
  22. * @sqnum: sequence number
  23. * @len: full node length
  24. * @node_type: node type
  25. * @group_type: node group type
  26. * @padding: reserved for future, zeroes
  27. *
  28. * Every UBIFS node starts with this common part. If the node has a key, the
  29. * key always goes next.
  30. */
  31. struct ubifs_ch {
  32. uint32_t magic;
  33. uint32_t crc;
  34. uint64_t sqnum;
  35. uint32_t len;
  36. uint8_t node_type;
  37. uint8_t group_type;
  38. uint8_t padding[2];
  39. } PACKED;
  40. /*
  41. * struct ubifs_sb_node - superblock node.
  42. * @ch: common header
  43. * @padding: reserved for future, zeroes
  44. * @key_hash: type of hash function used in keys
  45. * @key_fmt: format of the key
  46. * @flags: file-system flags (%UBIFS_FLG_BIGLPT, etc)
  47. * @min_io_size: minimal input/output unit size
  48. * @leb_size: logical eraseblock size in bytes
  49. * @leb_cnt: count of LEBs used by file-system
  50. * @max_leb_cnt: maximum count of LEBs used by file-system
  51. * @max_bud_bytes: maximum amount of data stored in buds
  52. * @log_lebs: log size in logical eraseblocks
  53. * @lpt_lebs: number of LEBs used for lprops table
  54. * @orph_lebs: number of LEBs used for recording orphans
  55. * @jhead_cnt: count of journal heads
  56. * @fanout: tree fanout (max. number of links per indexing node)
  57. * @lsave_cnt: number of LEB numbers in LPT's save table
  58. * @fmt_version: UBIFS on-flash format version
  59. * @default_compr: default compression algorithm (%UBIFS_COMPR_LZO, etc)
  60. * @padding1: reserved for future, zeroes
  61. * @rp_uid: reserve pool UID
  62. * @rp_gid: reserve pool GID
  63. * @rp_size: size of the reserved pool in bytes
  64. * @padding2: reserved for future, zeroes
  65. * @time_gran: time granularity in nanoseconds
  66. * @uuid: UUID generated when the file system image was created
  67. * @ro_compat_version: UBIFS R/O compatibility version
  68. */
  69. struct ubifs_sb_node {
  70. struct ubifs_ch ch;
  71. uint8_t padding[2];
  72. uint8_t key_hash;
  73. uint8_t key_fmt;
  74. uint32_t flags;
  75. uint32_t min_io_size;
  76. uint32_t leb_size;
  77. uint32_t leb_cnt;
  78. uint32_t max_leb_cnt;
  79. uint64_t max_bud_bytes;
  80. uint32_t log_lebs;
  81. uint32_t lpt_lebs;
  82. uint32_t orph_lebs;
  83. uint32_t jhead_cnt;
  84. uint32_t fanout;
  85. uint32_t lsave_cnt;
  86. uint32_t fmt_version;
  87. uint16_t default_compr;
  88. uint8_t padding1[2];
  89. uint32_t rp_uid;
  90. uint32_t rp_gid;
  91. uint64_t rp_size;
  92. uint32_t time_gran;
  93. uint8_t uuid[16];
  94. uint32_t ro_compat_version;
  95. /*
  96. uint8_t padding2[3968];
  97. */
  98. } PACKED;
  99. int FAST_FUNC volume_id_probe_ubifs(struct volume_id *id /*,uint64_t off*/)
  100. {
  101. #define off ((uint64_t)0)
  102. struct ubifs_sb_node *sb;
  103. dbg("UBIFS: probing at offset 0x%llx", (unsigned long long) off);
  104. sb = volume_id_get_buffer(id, off, sizeof(struct ubifs_sb_node));
  105. if (!sb)
  106. return -1;
  107. if (le32_to_cpu(sb->ch.magic) != UBIFS_NODE_MAGIC)
  108. return -1;
  109. IF_FEATURE_BLKID_TYPE(id->type = "ubifs";)
  110. volume_id_set_uuid(id, sb->uuid, UUID_DCE);
  111. return 0;
  112. }