btrfs.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (C) 2009 Karel Zak <kzak@redhat.com>
  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 btrfs_super_block {
  14. uint8_t csum[32];
  15. uint8_t fsid[16];
  16. uint64_t bytenr;
  17. uint64_t flags;
  18. uint8_t magic[8];
  19. uint64_t generation;
  20. uint64_t root;
  21. uint64_t chunk_root;
  22. uint64_t log_root;
  23. uint64_t log_root_transid;
  24. uint64_t total_bytes;
  25. uint64_t bytes_used;
  26. uint64_t root_dir_objectid;
  27. uint64_t num_devices;
  28. uint32_t sectorsize;
  29. uint32_t nodesize;
  30. uint32_t leafsize;
  31. uint32_t stripesize;
  32. uint32_t sys_chunk_array_size;
  33. uint64_t chunk_root_generation;
  34. uint64_t compat_flags;
  35. uint64_t compat_ro_flags;
  36. uint64_t incompat_flags;
  37. uint16_t csum_type;
  38. uint8_t root_level;
  39. uint8_t chunk_root_level;
  40. uint8_t log_root_level;
  41. struct btrfs_dev_item {
  42. uint64_t devid;
  43. uint64_t total_bytes;
  44. uint64_t bytes_used;
  45. uint32_t io_align;
  46. uint32_t io_width;
  47. uint32_t sector_size;
  48. uint64_t type;
  49. uint64_t generation;
  50. uint64_t start_offset;
  51. uint32_t dev_group;
  52. uint8_t seek_speed;
  53. uint8_t bandwidth;
  54. uint8_t uuid[16];
  55. uint8_t fsid[16];
  56. } __attribute__ ((__packed__)) dev_item;
  57. uint8_t label[256];
  58. } __attribute__ ((__packed__));
  59. static int probe_btrfs(blkid_probe pr, const struct blkid_idmag *mag)
  60. {
  61. struct btrfs_super_block *bfs;
  62. bfs = blkid_probe_get_sb(pr, mag, struct btrfs_super_block);
  63. if (!bfs)
  64. return errno ? -errno : 1;
  65. if (*bfs->label)
  66. blkid_probe_set_label(pr,
  67. (unsigned char *) bfs->label,
  68. sizeof(bfs->label) - 1);
  69. blkid_probe_set_uuid(pr, bfs->fsid);
  70. blkid_probe_set_uuid_as(pr, bfs->dev_item.uuid, "UUID_SUB");
  71. return 0;
  72. }
  73. const struct blkid_idinfo btrfs_idinfo =
  74. {
  75. .name = "btrfs",
  76. .usage = BLKID_USAGE_FILESYSTEM,
  77. .probefunc = probe_btrfs,
  78. .minsz = 1024 * 1024,
  79. .magics =
  80. {
  81. { .magic = "_BHRfS_M", .len = 8, .sboff = 0x40, .kboff = 64 },
  82. { NULL }
  83. }
  84. };