reiserfs.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #include "volume_id_internal.h"
  22. struct reiserfs_super_block {
  23. uint32_t blocks_count;
  24. uint32_t free_blocks;
  25. uint32_t root_block;
  26. uint32_t journal_block;
  27. uint32_t journal_dev;
  28. uint32_t orig_journal_size;
  29. uint32_t dummy2[5];
  30. uint16_t blocksize;
  31. uint16_t dummy3[3];
  32. uint8_t magic[12];
  33. uint32_t dummy4[5];
  34. uint8_t uuid[16];
  35. uint8_t label[16];
  36. } __attribute__((__packed__));
  37. struct reiser4_super_block {
  38. uint8_t magic[16];
  39. uint16_t dummy[2];
  40. uint8_t uuid[16];
  41. uint8_t label[16];
  42. uint64_t dummy2;
  43. } __attribute__((__packed__));
  44. #define REISERFS1_SUPERBLOCK_OFFSET 0x2000
  45. #define REISERFS_SUPERBLOCK_OFFSET 0x10000
  46. int volume_id_probe_reiserfs(struct volume_id *id, uint64_t off)
  47. {
  48. struct reiserfs_super_block *rs;
  49. struct reiser4_super_block *rs4;
  50. dbg("reiserfs: probing at offset 0x%llx", (unsigned long long) off);
  51. rs = volume_id_get_buffer(id, off + REISERFS_SUPERBLOCK_OFFSET, 0x200);
  52. if (rs == NULL)
  53. return -1;
  54. if (memcmp(rs->magic, "ReIsErFs", 8) == 0) {
  55. dbg("reiserfs: ReIsErFs, no label");
  56. // strcpy(id->type_version, "3.5");
  57. goto found;
  58. }
  59. if (memcmp(rs->magic, "ReIsEr2Fs", 9) == 0) {
  60. dbg("reiserfs: ReIsEr2Fs");
  61. // strcpy(id->type_version, "3.6");
  62. goto found_label;
  63. }
  64. if (memcmp(rs->magic, "ReIsEr3Fs", 9) == 0) {
  65. dbg("reiserfs: ReIsEr3Fs");
  66. // strcpy(id->type_version, "JR");
  67. goto found_label;
  68. }
  69. rs4 = (struct reiser4_super_block *) rs;
  70. if (memcmp(rs4->magic, "ReIsEr4", 7) == 0) {
  71. // strcpy(id->type_version, "4");
  72. // volume_id_set_label_raw(id, rs4->label, 16);
  73. volume_id_set_label_string(id, rs4->label, 16);
  74. volume_id_set_uuid(id, rs4->uuid, UUID_DCE);
  75. dbg("reiserfs: ReIsEr4, label '%s' uuid '%s'", id->label, id->uuid);
  76. goto found;
  77. }
  78. rs = volume_id_get_buffer(id, off + REISERFS1_SUPERBLOCK_OFFSET, 0x200);
  79. if (rs == NULL)
  80. return -1;
  81. if (memcmp(rs->magic, "ReIsErFs", 8) == 0) {
  82. dbg("reiserfs: ReIsErFs, no label");
  83. // strcpy(id->type_version, "3.5");
  84. goto found;
  85. }
  86. dbg("reiserfs: no signature found");
  87. return -1;
  88. found_label:
  89. // volume_id_set_label_raw(id, rs->label, 16);
  90. volume_id_set_label_string(id, rs->label, 16);
  91. volume_id_set_uuid(id, rs->uuid, UUID_DCE);
  92. dbg("reiserfs: label '%s' uuid '%s'", id->label, id->uuid);
  93. found:
  94. // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
  95. // id->type = "reiserfs";
  96. return 0;
  97. }