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];
79 /* In gfs1, quota and license dinodes followed */
82 static int volume_id_probe_gfs_generic(struct volume_id *id, uint64_t off, int vers)
86 info("probing at offset 0x%" PRIx64 "\n", off);
88 sbd = (struct gfs2_sb *)
89 volume_id_get_buffer(id, off + GFS_SUPERBLOCK_OFFSET, sizeof(struct gfs2_sb));
93 if (be32_to_cpu(sbd->sb_header.mh_magic) == GFS_MAGIC &&
94 be32_to_cpu(sbd->sb_header.mh_type) == GFS_METATYPE_SB) {
96 if (be32_to_cpu(sbd->sb_fs_format) != GFS_FORMAT_FS ||
97 be32_to_cpu(sbd->sb_multihost_format) != GFS_FORMAT_MULTI)
98 return -1; /* not gfs1 */
101 else if (vers == 2) {
102 if (be32_to_cpu(sbd->sb_fs_format) != GFS2_FORMAT_FS ||
103 be32_to_cpu(sbd->sb_multihost_format) != GFS2_FORMAT_MULTI)
104 return -1; /* not gfs2 */
110 if (strlen(sbd->sb_locktable)) {
111 uint8_t *label = (uint8_t *) sbd->sb_locktable;
113 volume_id_set_label_raw(id, label, GFS_LOCKNAME_LEN);
114 volume_id_set_label_string(id, label, GFS_LOCKNAME_LEN);
116 strcpy(id->type_version, "1");
117 volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
123 int volume_id_probe_gfs(struct volume_id *id, uint64_t off, uint64_t size)
125 return volume_id_probe_gfs_generic(id, off, 1);
128 int volume_id_probe_gfs2(struct volume_id *id, uint64_t off, uint64_t size)
130 return volume_id_probe_gfs_generic(id, off, 2);