bcache.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (C) 2013 Rolf Fokkens <rolf@fokkens.nl>
  3. *
  4. * This file may be redistributed under the terms of the
  5. * GNU Lesser General Public License.
  6. *
  7. * Based on code fragments from bcache-tools by Kent Overstreet:
  8. * http://evilpiepirate.org/git/bcache-tools.git
  9. */
  10. //config:config FEATURE_VOLUMEID_BCACHE
  11. //config: bool "bcache filesystem"
  12. //config: default y
  13. //config: depends on VOLUMEID
  14. //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_BCACHE) += bcache.o
  15. #include "volume_id_internal.h"
  16. #define SB_LABEL_SIZE 32
  17. #define SB_JOURNAL_BUCKETS 256U
  18. static const char bcache_magic[] ALIGN1 = {
  19. 0xc6, 0x85, 0x73, 0xf6, 0x4e, 0x1a, 0x45, 0xca,
  20. 0x82, 0x65, 0xf5, 0x7f, 0x48, 0xba, 0x6d, 0x81
  21. };
  22. struct bcache_super_block {
  23. uint64_t csum;
  24. uint64_t offset; /* sector where this sb was written */
  25. uint64_t version;
  26. uint8_t magic[16];
  27. uint8_t uuid[16];
  28. union {
  29. uint8_t set_uuid[16];
  30. uint64_t set_magic;
  31. };
  32. uint8_t label[SB_LABEL_SIZE];
  33. uint64_t flags;
  34. uint64_t seq;
  35. uint64_t pad[8];
  36. union {
  37. struct {
  38. /* Cache devices */
  39. uint64_t nbuckets; /* device size */
  40. uint16_t block_size; /* sectors */
  41. uint16_t bucket_size; /* sectors */
  42. uint16_t nr_in_set;
  43. uint16_t nr_this_dev;
  44. };
  45. struct {
  46. /* Backing devices */
  47. uint64_t data_offset;
  48. /*
  49. * block_size from the cache device section is still used by
  50. * backing devices, so don't add anything here until we fix
  51. * things to not need it for backing devices anymore
  52. */
  53. };
  54. };
  55. uint32_t last_mount; /* time_t */
  56. uint16_t first_bucket;
  57. union {
  58. uint16_t njournal_buckets;
  59. uint16_t keys;
  60. };
  61. uint64_t d[SB_JOURNAL_BUCKETS]; /* journal buckets */
  62. };
  63. /* magic string */
  64. #define BCACHE_SB_MAGIC bcache_magic
  65. /* magic string len */
  66. #define BCACHE_SB_MAGIC_LEN sizeof (bcache_magic)
  67. /* super block offset */
  68. #define BCACHE_SB_OFF 0x1000
  69. /* supper block offset in kB */
  70. #define BCACHE_SB_KBOFF (BCACHE_SB_OFF >> 10)
  71. /* magic string offset within super block */
  72. #define BCACHE_SB_MAGIC_OFF offsetof (struct bcache_super_block, magic)
  73. int FAST_FUNC volume_id_probe_bcache(struct volume_id *id /*,uint64_t off*/)
  74. {
  75. struct bcache_super_block *sb;
  76. sb = volume_id_get_buffer(id, BCACHE_SB_OFF, sizeof(*sb));
  77. if (sb == NULL)
  78. return -1;
  79. if (memcmp(sb->magic, BCACHE_SB_MAGIC, BCACHE_SB_MAGIC_LEN) != 0)
  80. return -1;
  81. volume_id_set_label_string(id, sb->label, SB_LABEL_SIZE);
  82. volume_id_set_uuid(id, sb->uuid, UUID_DCE);
  83. IF_FEATURE_BLKID_TYPE(id->type = "bcache";)
  84. return 0;
  85. }