2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) 2004 Andre Masella <andre@masella.no-ip.org>
5 * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation version 2 of the License.
27 #include "volume_id.h"
33 struct ocfs1_super_block_header {
34 uint32_t minor_version;
35 uint32_t major_version;
36 uint8_t signature[128];
37 uint8_t mount_point[128];
44 uint64_t root_bitmap_off;
45 uint64_t data_start_off;
46 uint64_t root_bitmap_size;
49 uint64_t cluster_size;
51 uint64_t num_clusters;
52 uint64_t dir_node_size;
53 uint64_t file_node_size;
54 uint64_t internal_off;
55 uint64_t node_cfg_off;
56 uint64_t node_cfg_size;
60 } __attribute__((__packed__));
62 struct ocfs1_super_block_label {
63 struct ocfs1_disk_lock {
66 uint8_t compat_pad[3];
67 uint64_t last_write_time;
68 uint64_t last_read_time;
69 uint32_t writer_node_num;
70 uint32_t reader_node_num;
71 uint64_t oin_node_map;
72 uint64_t dlock_seq_num;
73 } disk_lock __attribute__((__packed__));
78 uint8_t cluster_name[64];
79 uint16_t cluster_name_len;
80 } __attribute__((__packed__));
82 struct ocfs2_super_block {
83 uint8_t i_signature[8];
84 uint32_t i_generation;
85 int16_t i_suballoc_slot;
86 uint16_t i_suballoc_bit;
93 uint16_t i_links_count;
100 uint64_t i_last_eb_blk;
101 uint32_t i_fs_generation;
102 uint32_t i_atime_nsec;
103 uint32_t i_ctime_nsec;
104 uint32_t i_mtime_nsec;
105 uint64_t i_reserved1[9];
107 uint16_t s_major_rev_level;
108 uint16_t s_minor_rev_level;
109 uint16_t s_mnt_count;
110 int16_t s_max_mnt_count;
113 uint32_t s_checkinterval;
114 uint64_t s_lastcheck;
115 uint32_t s_creator_os;
116 uint32_t s_feature_compat;
117 uint32_t s_feature_incompat;
118 uint32_t s_feature_ro_compat;
119 uint64_t s_root_blkno;
120 uint64_t s_system_dir_blkno;
121 uint32_t s_blocksize_bits;
122 uint32_t s_clustersize_bits;
123 uint16_t s_max_slots;
124 uint16_t s_reserved1;
125 uint32_t s_reserved2;
126 uint64_t s_first_cluster_group;
129 } __attribute__((__packed__));
131 int volume_id_probe_ocfs1(struct volume_id *id, uint64_t off)
134 struct ocfs1_super_block_header *osh;
135 struct ocfs1_super_block_label *osl;
137 buf = volume_id_get_buffer(id, off, 0x200);
141 osh = (struct ocfs1_super_block_header *) buf;
142 if (memcmp(osh->signature, "OracleCFS", 9) != 0)
144 snprintf(id->type_version, sizeof(id->type_version)-1,
145 "%u.%u", osh->major_version, osh->minor_version);
147 dbg("found OracleCFS signature, now reading label");
148 buf = volume_id_get_buffer(id, off + 0x200, 0x200);
152 osl = (struct ocfs1_super_block_label *) buf;
153 volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
154 if (osl->label_len <= 64) {
155 volume_id_set_label_raw(id, osl->label, 64);
156 volume_id_set_label_string(id, osl->label, 64);
158 if (osl->vol_id_len == 16)
159 volume_id_set_uuid(id, osl->vol_id, UUID_DCE);
164 #define OCFS2_MAX_BLOCKSIZE 0x1000
165 #define OCFS2_SUPER_BLOCK_BLKNO 2
167 int volume_id_probe_ocfs2(struct volume_id *id, uint64_t off)
170 struct ocfs2_super_block *os;
173 dbg("probing at offset 0x%llx", (unsigned long long) off);
175 for (blksize = 0x200; blksize <= OCFS2_MAX_BLOCKSIZE; blksize <<= 1) {
176 buf = volume_id_get_buffer(id, off + OCFS2_SUPER_BLOCK_BLKNO * blksize, 0x200);
180 os = (struct ocfs2_super_block *) buf;
181 if (memcmp(os->i_signature, "OCFSV2", 6) != 0)
184 volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
185 volume_id_set_label_raw(id, os->s_label, 64);
186 volume_id_set_label_string(id, os->s_label, 64);
187 volume_id_set_uuid(id, os->s_uuid, UUID_DCE);
188 snprintf(id->type_version, sizeof(id->type_version)-1,
189 "%u.%u", os->s_major_rev_level, os->s_minor_rev_level);