Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 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 | */ |
Sven-Göran Bergh | 15d0a86 | 2013-07-31 15:57:59 +0200 | [diff] [blame] | 21 | //config:config FEATURE_VOLUMEID_REISERFS |
| 22 | //config: bool "Reiser filesystem" |
| 23 | //config: default y |
| 24 | //config: depends on VOLUMEID |
Sven-Göran Bergh | 15d0a86 | 2013-07-31 15:57:59 +0200 | [diff] [blame] | 25 | |
Denys Vlasenko | 0c4dbd4 | 2017-09-18 16:28:43 +0200 | [diff] [blame] | 26 | //kbuild:lib-$(CONFIG_FEATURE_VOLUMEID_REISERFS) += reiserfs.o |
| 27 | |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 28 | #include "volume_id_internal.h" |
| 29 | |
| 30 | struct reiserfs_super_block { |
| 31 | uint32_t blocks_count; |
| 32 | uint32_t free_blocks; |
| 33 | uint32_t root_block; |
| 34 | uint32_t journal_block; |
| 35 | uint32_t journal_dev; |
| 36 | uint32_t orig_journal_size; |
| 37 | uint32_t dummy2[5]; |
| 38 | uint16_t blocksize; |
| 39 | uint16_t dummy3[3]; |
| 40 | uint8_t magic[12]; |
| 41 | uint32_t dummy4[5]; |
| 42 | uint8_t uuid[16]; |
| 43 | uint8_t label[16]; |
Denys Vlasenko | 8dc0e19 | 2009-09-16 00:58:11 +0200 | [diff] [blame] | 44 | } PACKED; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 45 | |
| 46 | struct reiser4_super_block { |
| 47 | uint8_t magic[16]; |
| 48 | uint16_t dummy[2]; |
| 49 | uint8_t uuid[16]; |
| 50 | uint8_t label[16]; |
| 51 | uint64_t dummy2; |
Denys Vlasenko | 8dc0e19 | 2009-09-16 00:58:11 +0200 | [diff] [blame] | 52 | } PACKED; |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 53 | |
| 54 | #define REISERFS1_SUPERBLOCK_OFFSET 0x2000 |
| 55 | #define REISERFS_SUPERBLOCK_OFFSET 0x10000 |
| 56 | |
Denys Vlasenko | 8930096 | 2009-11-01 23:07:18 +0100 | [diff] [blame] | 57 | int FAST_FUNC volume_id_probe_reiserfs(struct volume_id *id /*,uint64_t off*/) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 58 | { |
Denis Vlasenko | 28ea429 | 2009-02-15 05:51:19 +0000 | [diff] [blame] | 59 | #define off ((uint64_t)0) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 60 | struct reiserfs_super_block *rs; |
| 61 | struct reiser4_super_block *rs4; |
| 62 | |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 63 | dbg("reiserfs: probing at offset 0x%llx", (unsigned long long) off); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 64 | |
| 65 | rs = volume_id_get_buffer(id, off + REISERFS_SUPERBLOCK_OFFSET, 0x200); |
| 66 | if (rs == NULL) |
| 67 | return -1; |
| 68 | |
| 69 | if (memcmp(rs->magic, "ReIsErFs", 8) == 0) { |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 70 | dbg("reiserfs: ReIsErFs, no label"); |
| 71 | // strcpy(id->type_version, "3.5"); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 72 | goto found; |
| 73 | } |
| 74 | if (memcmp(rs->magic, "ReIsEr2Fs", 9) == 0) { |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 75 | dbg("reiserfs: ReIsEr2Fs"); |
| 76 | // strcpy(id->type_version, "3.6"); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 77 | goto found_label; |
| 78 | } |
| 79 | if (memcmp(rs->magic, "ReIsEr3Fs", 9) == 0) { |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 80 | dbg("reiserfs: ReIsEr3Fs"); |
| 81 | // strcpy(id->type_version, "JR"); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 82 | goto found_label; |
| 83 | } |
| 84 | |
| 85 | rs4 = (struct reiser4_super_block *) rs; |
| 86 | if (memcmp(rs4->magic, "ReIsEr4", 7) == 0) { |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 87 | // strcpy(id->type_version, "4"); |
| 88 | // volume_id_set_label_raw(id, rs4->label, 16); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 89 | volume_id_set_label_string(id, rs4->label, 16); |
| 90 | volume_id_set_uuid(id, rs4->uuid, UUID_DCE); |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 91 | dbg("reiserfs: ReIsEr4, label '%s' uuid '%s'", id->label, id->uuid); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 92 | goto found; |
| 93 | } |
| 94 | |
| 95 | rs = volume_id_get_buffer(id, off + REISERFS1_SUPERBLOCK_OFFSET, 0x200); |
| 96 | if (rs == NULL) |
| 97 | return -1; |
| 98 | |
| 99 | if (memcmp(rs->magic, "ReIsErFs", 8) == 0) { |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 100 | dbg("reiserfs: ReIsErFs, no label"); |
| 101 | // strcpy(id->type_version, "3.5"); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 102 | goto found; |
| 103 | } |
| 104 | |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 105 | dbg("reiserfs: no signature found"); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 106 | return -1; |
| 107 | |
| 108 | found_label: |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 109 | // volume_id_set_label_raw(id, rs->label, 16); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 110 | volume_id_set_label_string(id, rs->label, 16); |
| 111 | volume_id_set_uuid(id, rs->uuid, UUID_DCE); |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 112 | dbg("reiserfs: label '%s' uuid '%s'", id->label, id->uuid); |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 113 | |
| 114 | found: |
Denis Vlasenko | c5b7372 | 2008-03-17 09:21:26 +0000 | [diff] [blame] | 115 | // volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); |
Denys Vlasenko | 90615a0 | 2010-12-30 00:40:11 +0100 | [diff] [blame] | 116 | IF_FEATURE_BLKID_TYPE(id->type = "reiserfs";) |
Denis Vlasenko | de7684a | 2008-02-18 21:08:49 +0000 | [diff] [blame] | 117 | |
| 118 | return 0; |
| 119 | } |