2 * volume_id - reads filesystem label and uuid
4 * Copyright (C) 2006 Red Hat, Inc. <redhat.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #include "libvolume_id.h"
32 #include "libvolume_id-private.h"
34 /* Common gfs/gfs2 constants: */
35 #define GFS_MAGIC 0x01161970
36 #define GFS_DEFAULT_BSIZE 4096
37 #define GFS_SUPERBLOCK_OFFSET (0x10 * GFS_DEFAULT_BSIZE)
38 #define GFS_METATYPE_SB 1
39 #define GFS_FORMAT_SB 100
40 #define GFS_LOCKNAME_LEN 64
43 #define GFS_FORMAT_FS 1309
44 #define GFS_FORMAT_MULTI 1401
46 #define GFS2_FORMAT_FS 1801
47 #define GFS2_FORMAT_MULTI 1900
49 struct gfs2_meta_header {
52 uint64_t __pad0; /* Was generation number in gfs1 */
54 uint32_t __pad1; /* Was incarnation number in gfs1 */
58 uint64_t no_formal_ino;
63 struct gfs2_meta_header sb_header;
65 uint32_t sb_fs_format;
66 uint32_t sb_multihost_format;
67 uint32_t __pad0; /* Was superblock flags in gfs1 */
70 uint32_t sb_bsize_shift;
71 uint32_t __pad1; /* Was journal segment size in gfs1 */
73 struct gfs2_inum sb_master_dir; /* Was jindex dinode in gfs1 */
74 struct gfs2_inum __pad2; /* Was rindex dinode in gfs1 */
75 struct gfs2_inum sb_root_dir;
77 char sb_lockproto[GFS_LOCKNAME_LEN];
78 char sb_locktable[GFS_LOCKNAME_LEN];
80 struct gfs2_inum __pad3; /* Was quota inode in gfs1 */
81 struct gfs2_inum __pad4; /* Was licence inode in gfs1 */
82 uint8_t sb_uuid[16]; /* The UUID maybe 0 for backwards compat */
85 static int uuid_non_zero(const uint8_t *p)
88 for (i = 0; i < 16; i++) {
95 static int volume_id_probe_gfs_generic(struct volume_id *id, uint64_t off, int vers)
99 info("probing at offset 0x%" PRIx64 "\n", off);
101 sbd = (struct gfs2_sb *)
102 volume_id_get_buffer(id, off + GFS_SUPERBLOCK_OFFSET, sizeof(struct gfs2_sb));
106 if (be32_to_cpu(sbd->sb_header.mh_magic) == GFS_MAGIC &&
107 be32_to_cpu(sbd->sb_header.mh_type) == GFS_METATYPE_SB) {
109 if (be32_to_cpu(sbd->sb_fs_format) != GFS_FORMAT_FS ||
110 be32_to_cpu(sbd->sb_multihost_format) != GFS_FORMAT_MULTI)
111 return -1; /* not gfs1 */
114 else if (vers == 2) {
115 if (be32_to_cpu(sbd->sb_fs_format) != GFS2_FORMAT_FS ||
116 be32_to_cpu(sbd->sb_multihost_format) != GFS2_FORMAT_MULTI)
117 return -1; /* not gfs2 */
123 if (strlen(sbd->sb_locktable)) {
124 uint8_t *label = (uint8_t *) sbd->sb_locktable;
126 volume_id_set_label_raw(id, label, GFS_LOCKNAME_LEN);
127 volume_id_set_label_string(id, label, GFS_LOCKNAME_LEN);
129 if (vers == 2 && uuid_non_zero(sbd->sb_uuid))
130 volume_id_set_uuid(id, sbd->sb_uuid, 0, UUID_DCE);
131 strcpy(id->type_version, "1");
132 volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
138 int volume_id_probe_gfs(struct volume_id *id, uint64_t off, uint64_t size)
140 return volume_id_probe_gfs_generic(id, off, 1);
143 int volume_id_probe_gfs2(struct volume_id *id, uint64_t off, uint64_t size)
145 return volume_id_probe_gfs_generic(id, off, 2);