reiserfs.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * volume_id - reads filesystem label and uuid
  3. *
  4. * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
  5. * Copyright (C) 2005 Tobias Klauser <tklauser@access.unizh.ch>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. //config:config FEATURE_VOLUMEID_REISERFS
  22. //config: bool "Reiser filesystem"
  23. //config: default y
  24. //config: depends on VOLUMEID
  25. //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_REISERFS) += reiserfs.o
  26. #include "volume_id_internal.h"
  27. struct reiserfs_super_block {
  28. uint32_t blocks_count;
  29. uint32_t free_blocks;
  30. uint32_t root_block;
  31. uint32_t journal_block;
  32. uint32_t journal_dev;
  33. uint32_t orig_journal_size;
  34. uint32_t dummy2[5];
  35. uint16_t blocksize;
  36. uint16_t dummy3[3];
  37. uint8_t magic[12];
  38. uint32_t dummy4[5];
  39. uint8_t uuid[16];
  40. uint8_t label[16];
  41. } PACKED;
  42. struct reiser4_super_block {
  43. uint8_t magic[16];
  44. uint16_t dummy[2];
  45. uint8_t uuid[16];
  46. uint8_t label[16];
  47. uint64_t dummy2;
  48. } PACKED;
  49. #define REISERFS1_SUPERBLOCK_OFFSET 0x2000
  50. #define REISERFS_SUPERBLOCK_OFFSET 0x10000
  51. int FAST_FUNC volume_id_probe_reiserfs(struct volume_id *id /*,uint64_t off*/)
  52. {
  53. #define off ((uint64_t)0)
  54. struct reiserfs_super_block *rs;
  55. struct reiser4_super_block *rs4;
  56. dbg("reiserfs: probing at offset 0x%llx", (unsigned long long) off);
  57. rs = volume_id_get_buffer(id, off + REISERFS_SUPERBLOCK_OFFSET, 0x200);
  58. if (rs == NULL)
  59. return -1;
  60. if (memcmp(rs->magic, "ReIsErFs", 8) == 0) {
  61. dbg("reiserfs: ReIsErFs, no label");
  62. // strcpy(id->type_version, "3.5");
  63. goto found;
  64. }
  65. if (memcmp(rs->magic, "ReIsEr2Fs", 9) == 0) {
  66. dbg("reiserfs: ReIsEr2Fs");
  67. // strcpy(id->type_version, "3.6");
  68. goto found_label;
  69. }
  70. if (memcmp(rs->magic, "ReIsEr3Fs", 9) == 0) {
  71. dbg("reiserfs: ReIsEr3Fs");
  72. // strcpy(id->type_version, "JR");
  73. goto found_label;
  74. }
  75. rs4 = (struct reiser4_super_block *) rs;
  76. if (memcmp(rs4->magic, "ReIsEr4", 7) == 0) {
  77. // strcpy(id->type_version, "4");
  78. // volume_id_set_label_raw(id, rs4->label, 16);
  79. volume_id_set_label_string(id, rs4->label, 16);
  80. volume_id_set_uuid(id, rs4->uuid, UUID_DCE);
  81. dbg("reiserfs: ReIsEr4, label '%s' uuid '%s'", id->label, id->uuid);
  82. goto found;
  83. }
  84. rs = volume_id_get_buffer(id, off + REISERFS1_SUPERBLOCK_OFFSET, 0x200);
  85. if (rs == NULL)
  86. return -1;
  87. if (memcmp(rs->magic, "ReIsErFs", 8) == 0) {
  88. dbg("reiserfs: ReIsErFs, no label");
  89. // strcpy(id->type_version, "3.5");
  90. goto found;
  91. }
  92. dbg("reiserfs: no signature found");
  93. return -1;
  94. found_label:
  95. // volume_id_set_label_raw(id, rs->label, 16);
  96. volume_id_set_label_string(id, rs->label, 16);
  97. volume_id_set_uuid(id, rs->uuid, UUID_DCE);
  98. dbg("reiserfs: label '%s' uuid '%s'", id->label, id->uuid);
  99. found:
  100. // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
  101. IF_FEATURE_BLKID_TYPE(id->type = "reiserfs";)
  102. return 0;
  103. }