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 it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
26 #include "libvolume_id.h"
29 /* Common gfs/gfs2 constants: */
30 #define GFS_MAGIC 0x01161970
31 #define GFS_DEFAULT_BSIZE 4096
32 #define GFS_SUPERBLOCK_OFFSET (0x10 * GFS_DEFAULT_BSIZE)
33 #define GFS_METATYPE_SB 1
34 #define GFS_FORMAT_SB 100
35 #define GFS_LOCKNAME_LEN 64
38 #define GFS_FORMAT_FS 1309
39 #define GFS_FORMAT_MULTI 1401
41 #define GFS2_FORMAT_FS 1801
42 #define GFS2_FORMAT_MULTI 1900
44 struct gfs2_meta_header {
47 uint64_t __pad0; /* Was generation number in gfs1 */
49 uint32_t __pad1; /* Was incarnation number in gfs1 */
53 uint64_t no_formal_ino;
58 struct gfs2_meta_header sb_header;
60 uint32_t sb_fs_format;
61 uint32_t sb_multihost_format;
62 uint32_t __pad0; /* Was superblock flags in gfs1 */
65 uint32_t sb_bsize_shift;
66 uint32_t __pad1; /* Was journal segment size in gfs1 */
68 struct gfs2_inum sb_master_dir; /* Was jindex dinode in gfs1 */
69 struct gfs2_inum __pad2; /* Was rindex dinode in gfs1 */
70 struct gfs2_inum sb_root_dir;
72 char sb_lockproto[GFS_LOCKNAME_LEN];
73 char sb_locktable[GFS_LOCKNAME_LEN];
74 /* In gfs1, quota and license dinodes followed */
77 static int volume_id_probe_gfs_generic(struct volume_id *id, uint64_t off, int vers)
81 info("probing at offset 0x%llx", (unsigned long long) off);
83 sbd = (struct gfs2_sb *)
84 volume_id_get_buffer(id, off + GFS_SUPERBLOCK_OFFSET, sizeof(struct gfs2_sb));
88 if (be32_to_cpu(sbd->sb_header.mh_magic) == GFS_MAGIC &&
89 be32_to_cpu(sbd->sb_header.mh_type) == GFS_METATYPE_SB &&
90 be32_to_cpu(sbd->sb_header.mh_format) == GFS_FORMAT_SB) {
92 if (be32_to_cpu(sbd->sb_fs_format) != GFS_FORMAT_FS ||
93 be32_to_cpu(sbd->sb_multihost_format) != GFS_FORMAT_MULTI)
94 return -1; /* not gfs1 */
98 if (be32_to_cpu(sbd->sb_fs_format) != GFS2_FORMAT_FS ||
99 be32_to_cpu(sbd->sb_multihost_format) != GFS2_FORMAT_MULTI)
100 return -1; /* not gfs2 */
105 strcpy(id->type_version, "1");
106 volume_id_set_usage(id, VOLUME_ID_FILESYSTEM);
112 int volume_id_probe_gfs(struct volume_id *id, uint64_t off, uint64_t size)
114 return volume_id_probe_gfs_generic(id, off, 1);
117 int volume_id_probe_gfs2(struct volume_id *id, uint64_t off, uint64_t size)
119 return volume_id_probe_gfs_generic(id, off, 2);