Blame gfs2/libgfs2/meta.c

Packit 6ef888
#include <stdint.h>
Packit 6ef888
#include <string.h>
Packit 6ef888
#include "libgfs2.h"
Packit 6ef888
#include "clusterautoconfig.h"
Packit 6ef888
Packit 6ef888
#ifdef GFS2_HAS_UUID
Packit 6ef888
#include <uuid.h>
Packit 6ef888
#endif
Packit 6ef888
Packit 6ef888
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
Packit 6ef888
#define SYM(x) { x, #x },
Packit 6ef888
Packit 6ef888
const struct lgfs2_symbolic lgfs2_metatypes[] = {
Packit 6ef888
SYM(GFS2_METATYPE_NONE)
Packit 6ef888
SYM(GFS2_METATYPE_SB)
Packit 6ef888
SYM(GFS2_METATYPE_RG)
Packit 6ef888
SYM(GFS2_METATYPE_RB)
Packit 6ef888
SYM(GFS2_METATYPE_DI)
Packit 6ef888
SYM(GFS2_METATYPE_IN)
Packit 6ef888
SYM(GFS2_METATYPE_LF)
Packit 6ef888
SYM(GFS2_METATYPE_JD)
Packit 6ef888
SYM(GFS2_METATYPE_LH)
Packit 6ef888
SYM(GFS2_METATYPE_LD)
Packit 6ef888
SYM(GFS2_METATYPE_LB)
Packit 6ef888
SYM(GFS2_METATYPE_EA)
Packit 6ef888
SYM(GFS2_METATYPE_ED)
Packit 6ef888
SYM(GFS2_METATYPE_QC)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
const unsigned lgfs2_metatype_size = ARRAY_SIZE(lgfs2_metatypes);
Packit 6ef888
Packit 6ef888
const struct lgfs2_symbolic lgfs2_metaformats[] = {
Packit 6ef888
SYM(GFS2_FORMAT_NONE)
Packit 6ef888
SYM(GFS2_FORMAT_SB)
Packit 6ef888
SYM(GFS2_FORMAT_RG)
Packit 6ef888
SYM(GFS2_FORMAT_RB)
Packit 6ef888
SYM(GFS2_FORMAT_DI)
Packit 6ef888
SYM(GFS2_FORMAT_IN)
Packit 6ef888
SYM(GFS2_FORMAT_LF)
Packit 6ef888
SYM(GFS2_FORMAT_JD)
Packit 6ef888
SYM(GFS2_FORMAT_LH)
Packit 6ef888
SYM(GFS2_FORMAT_LD)
Packit 6ef888
SYM(GFS2_FORMAT_LB)
Packit 6ef888
SYM(GFS2_FORMAT_EA)
Packit 6ef888
SYM(GFS2_FORMAT_ED)
Packit 6ef888
SYM(GFS2_FORMAT_QC)
Packit 6ef888
SYM(GFS2_FORMAT_RI)
Packit 6ef888
SYM(GFS2_FORMAT_DE)
Packit 6ef888
SYM(GFS2_FORMAT_QU)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
const unsigned lgfs2_metaformat_size = ARRAY_SIZE(lgfs2_metaformats);
Packit 6ef888
Packit 6ef888
const struct lgfs2_symbolic lgfs2_di_flags[] = {
Packit 6ef888
SYM(GFS2_DIF_JDATA)
Packit 6ef888
SYM(GFS2_DIF_EXHASH)
Packit 6ef888
SYM(GFS2_DIF_UNUSED)
Packit 6ef888
SYM(GFS2_DIF_EA_INDIRECT)
Packit 6ef888
SYM(GFS2_DIF_DIRECTIO)
Packit 6ef888
SYM(GFS2_DIF_IMMUTABLE)
Packit 6ef888
SYM(GFS2_DIF_APPENDONLY)
Packit 6ef888
SYM(GFS2_DIF_NOATIME)
Packit 6ef888
SYM(GFS2_DIF_SYNC)
Packit 6ef888
SYM(GFS2_DIF_SYSTEM)
Packit 6ef888
SYM(GFS2_DIF_TRUNC_IN_PROG)
Packit 6ef888
SYM(GFS2_DIF_INHERIT_DIRECTIO)
Packit 6ef888
SYM(GFS2_DIF_INHERIT_JDATA)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
const unsigned lgfs2_di_flag_size = ARRAY_SIZE(lgfs2_di_flags);
Packit 6ef888
Packit 6ef888
const struct lgfs2_symbolic lgfs2_lh_flags[] = {
Packit 6ef888
SYM(GFS2_LOG_HEAD_UNMOUNT)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
const unsigned int lgfs2_lh_flag_size = ARRAY_SIZE(lgfs2_lh_flags);
Packit 6ef888
Packit 6ef888
const struct lgfs2_symbolic lgfs2_ld_types[] = {
Packit 6ef888
SYM(GFS2_LOG_DESC_METADATA)
Packit 6ef888
SYM(GFS2_LOG_DESC_REVOKE)
Packit 6ef888
SYM(GFS2_LOG_DESC_JDATA)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
const unsigned int lgfs2_ld_type_size = ARRAY_SIZE(lgfs2_ld_types);
Packit 6ef888
Packit 6ef888
const struct lgfs2_symbolic lgfs2_ld1_types[] = {
Packit 6ef888
SYM(GFS_LOG_DESC_METADATA)
Packit 6ef888
SYM(GFS_LOG_DESC_IUL)
Packit 6ef888
SYM(GFS_LOG_DESC_IDA)
Packit 6ef888
SYM(GFS_LOG_DESC_Q)
Packit 6ef888
SYM(GFS_LOG_DESC_LAST)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
const unsigned int lgfs2_ld1_type_size = ARRAY_SIZE(lgfs2_ld1_types);
Packit 6ef888
Packit 6ef888
#undef SYM
Packit 6ef888
Packit 6ef888
Packit 6ef888
Packit 6ef888
Packit 6ef888
#define F(f,...)  { .name = #f, \
Packit 6ef888
		    .offset = offsetof(struct STRUCT, f), \
Packit 6ef888
		    .length = sizeof(((struct STRUCT *)(0))->f), \
Packit 6ef888
		    __VA_ARGS__ },
Packit 6ef888
#define FP(f,...) F(f, .flags = LGFS2_MFF_POINTER, __VA_ARGS__)
Packit 6ef888
#define RF(f) F(f, .flags = LGFS2_MFF_RESERVED)
Packit 6ef888
#define RFP(f,...) F(f, .flags = LGFS2_MFF_POINTER|LGFS2_MFF_RESERVED, __VA_ARGS__)
Packit 6ef888
Packit 6ef888
Packit 6ef888
#define MH(f) F(f.mh_magic) \
Packit 6ef888
	      F(f.mh_type, .flags = LGFS2_MFF_ENUM, .symtab=lgfs2_metatypes, .nsyms=ARRAY_SIZE(lgfs2_metatypes)) \
Packit 6ef888
	      RF(f.__pad0) \
Packit 6ef888
	      F(f.mh_format, .flags = LGFS2_MFF_ENUM, .symtab=lgfs2_metaformats, .nsyms=ARRAY_SIZE(lgfs2_metaformats)) \
Packit 6ef888
	      F(f.mh_jid)
Packit 6ef888
Packit 6ef888
#define IN(f,...) F(f.no_formal_ino) \
Packit 6ef888
		  FP(f.no_addr, __VA_ARGS__)
Packit 6ef888
Packit 6ef888
#define INR(f,...) RF(f.no_formal_ino) \
Packit 6ef888
		   RFP(f.no_addr, __VA_ARGS__)
Packit 6ef888
#define ANY_COMMON_BLOCK (1 << LGFS2_MT_DIR_LEAF) | \
Packit 6ef888
			 (1 << LGFS2_MT_JRNL_DATA) | \
Packit 6ef888
			 (1 << LGFS2_MT_EA_ATTR) | \
Packit 6ef888
			 (1 << LGFS2_MT_EA_DATA) | \
Packit 6ef888
			 (1 << LGFS2_MT_DATA)
Packit 6ef888
Packit 6ef888
#define ANY_GFS2_BLOCK (1 << LGFS2_MT_GFS2_DINODE) | \
Packit 6ef888
		       (1 << LGFS2_MT_GFS2_INDIRECT) | \
Packit 6ef888
		       (1 << LGFS2_MT_GFS2_LOG_HEADER) | \
Packit 6ef888
		       (1 << LGFS2_MT_GFS2_LOG_DESC) | \
Packit 6ef888
		       (1 << LGFS2_MT_GFS2_LOG_BLOCK) | \
Packit 6ef888
		       ANY_COMMON_BLOCK
Packit 6ef888
Packit 6ef888
#define ANY_GFS_BLOCK (1 << LGFS2_MT_GFS_DINODE) | \
Packit 6ef888
		      (1 << LGFS2_MT_GFS_INDIRECT) | \
Packit 6ef888
		      ANY_COMMON_BLOCK
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs2_sb
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_sb_fields[] = {
Packit 6ef888
MH(sb_header)
Packit 6ef888
F(sb_fs_format)
Packit 6ef888
F(sb_multihost_format)
Packit 6ef888
RF(__pad0)
Packit 6ef888
F(sb_bsize, .flags = LGFS2_MFF_BYTES)
Packit 6ef888
F(sb_bsize_shift, .flags = LGFS2_MFF_BYTES|LGFS2_MFF_SHIFT)
Packit 6ef888
RF(__pad1)
Packit 6ef888
IN(sb_master_dir, .points_to = (1 << LGFS2_MT_GFS2_DINODE))
Packit 6ef888
INR(__pad2, .points_to = (1 << LGFS2_MT_GFS2_DINODE))
Packit 6ef888
IN(sb_root_dir, .points_to = (1 << LGFS2_MT_GFS2_DINODE))
Packit 6ef888
F(sb_lockproto, .flags = LGFS2_MFF_STRING)
Packit 6ef888
F(sb_locktable, .flags = LGFS2_MFF_STRING)
Packit 6ef888
INR(__pad3, .points_to = (1 << LGFS2_MT_GFS2_DINODE))
Packit 6ef888
INR(__pad4, .points_to = (1 << LGFS2_MT_GFS2_DINODE))
Packit 6ef888
#ifdef GFS2_HAS_UUID
Packit 6ef888
F(sb_uuid, .flags = LGFS2_MFF_UUID)
Packit 6ef888
#endif
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs_sb
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs_sb_fields[] = {
Packit 6ef888
MH(sb_header)
Packit 6ef888
F(sb_fs_format)
Packit 6ef888
F(sb_multihost_format)
Packit 6ef888
F(sb_flags)
Packit 6ef888
F(sb_bsize, .flags = LGFS2_MFF_BYTES)
Packit 6ef888
F(sb_bsize_shift, .flags = LGFS2_MFF_BYTES|LGFS2_MFF_SHIFT)
Packit 6ef888
F(sb_seg_size, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
IN(sb_jindex_di, .points_to = (1 << LGFS2_MT_GFS_DINODE))
Packit 6ef888
IN(sb_rindex_di, .points_to = (1 << LGFS2_MT_GFS_DINODE))
Packit 6ef888
IN(sb_root_di, .points_to = (1 << LGFS2_MT_GFS_DINODE))
Packit 6ef888
F(sb_lockproto, .flags = LGFS2_MFF_STRING)
Packit 6ef888
F(sb_locktable, .flags = LGFS2_MFF_STRING)
Packit 6ef888
IN(sb_quota_di, .points_to = (1 << LGFS2_MT_GFS_DINODE))
Packit 6ef888
IN(sb_license_di, .points_to = (1 << LGFS2_MT_GFS_DINODE))
Packit 6ef888
RF(sb_reserved)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs2_rindex
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_rindex_fields[] = {
Packit 6ef888
FP(ri_addr, .points_to = (1 << LGFS2_MT_GFS2_RGRP))
Packit 6ef888
F(ri_length, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
RF(__pad)
Packit 6ef888
FP(ri_data0, .points_to = ANY_GFS2_BLOCK|(1 << LGFS2_MT_FREE))
Packit 6ef888
F(ri_data, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
F(ri_bitbytes, .flags = LGFS2_MFF_BYTES)
Packit 6ef888
F(ri_reserved)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs2_rgrp
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_rgrp_fields[] = {
Packit 6ef888
MH(rg_header)
Packit 6ef888
F(rg_flags)
Packit 6ef888
F(rg_free, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
F(rg_dinodes, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
#ifdef GFS2_HAS_RG_SKIP
Packit 6ef888
FP(rg_skip, .points_to = (1 << LGFS2_MT_GFS2_RGRP))
Packit 6ef888
#else
Packit 6ef888
RF(__pad)
Packit 6ef888
#endif
Packit 6ef888
F(rg_igeneration)
Packit 6ef888
#ifdef GFS2_HAS_RG_RI_FIELDS
Packit 6ef888
FP(rg_data0, .points_to = ANY_GFS2_BLOCK|(1 << LGFS2_MT_FREE))
Packit 6ef888
F(rg_data, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
F(rg_bitbytes, .flags = LGFS2_MFF_BYTES)
Packit 6ef888
F(rg_crc, .flags = LGFS2_MFF_CHECK)
Packit 6ef888
#endif
Packit 6ef888
RF(rg_reserved)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs_rgrp
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs_rgrp_fields[] = {
Packit 6ef888
MH(rg_header)
Packit 6ef888
F(rg_flags)
Packit 6ef888
F(rg_free, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
F(rg_useddi, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
F(rg_freedi, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
IN(rg_freedi_list, .points_to = (1 << LGFS2_MT_GFS_DINODE))
Packit 6ef888
F(rg_usedmeta, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
F(rg_freemeta, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
RF(rg_reserved)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
struct gfs2_rgrp_bitmap { struct gfs2_meta_header rb_header; };
Packit 6ef888
#define STRUCT gfs2_rgrp_bitmap
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_rgrp_bitmap_fields[] = {
Packit 6ef888
MH(rb_header)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs2_dinode
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_dinode_fields[] = {
Packit 6ef888
MH(di_header)
Packit 6ef888
IN(di_num, .points_to = (1 << LGFS2_MT_GFS2_DINODE))
Packit 6ef888
F(di_mode, .flags = LGFS2_MFF_MODE)
Packit 6ef888
F(di_uid, .flags = LGFS2_MFF_UID)
Packit 6ef888
F(di_gid, .flags = LGFS2_MFF_GID)
Packit 6ef888
F(di_nlink)
Packit 6ef888
F(di_size, .flags = LGFS2_MFF_BYTES)
Packit 6ef888
F(di_blocks, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
F(di_atime, .flags = LGFS2_MFF_SECS)
Packit 6ef888
F(di_mtime, .flags = LGFS2_MFF_SECS)
Packit 6ef888
F(di_ctime, .flags = LGFS2_MFF_SECS)
Packit 6ef888
F(di_major, .flags = LGFS2_MFF_MAJOR)
Packit 6ef888
F(di_minor, .flags = LGFS2_MFF_MINOR)
Packit 6ef888
FP(di_goal_meta, .points_to = ANY_GFS2_BLOCK | (1 << LGFS2_MT_FREE))
Packit 6ef888
FP(di_goal_data, .points_to = ANY_GFS2_BLOCK | (1 << LGFS2_MT_FREE))
Packit 6ef888
F(di_generation)
Packit 6ef888
F(di_flags, .flags = LGFS2_MFF_MASK, .symtab=lgfs2_di_flags, .nsyms=ARRAY_SIZE(lgfs2_di_flags))
Packit 6ef888
F(di_payload_format)
Packit 6ef888
RF(__pad1)
Packit 6ef888
F(di_height)
Packit 6ef888
RF(__pad2)
Packit 6ef888
RF(__pad3)
Packit 6ef888
F(di_depth)
Packit 6ef888
F(di_entries)
Packit 6ef888
INR(__pad4, .points_to = (1 << LGFS2_MT_GFS2_DINODE))
Packit 6ef888
FP(di_eattr, .points_to = (1 << LGFS2_MT_EA_ATTR)|(1 << LGFS2_MT_GFS2_INDIRECT))
Packit 6ef888
F(di_atime_nsec, .flags = LGFS2_MFF_NSECS)
Packit 6ef888
F(di_mtime_nsec, .flags = LGFS2_MFF_NSECS)
Packit 6ef888
F(di_ctime_nsec, .flags = LGFS2_MFF_NSECS)
Packit 6ef888
RF(di_reserved)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs_dinode
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs_dinode_fields[] = {
Packit 6ef888
MH(di_header)
Packit 6ef888
IN(di_num, .points_to = (1 << LGFS2_MT_GFS_DINODE))
Packit 6ef888
F(di_mode, .flags = LGFS2_MFF_MODE)
Packit 6ef888
F(di_uid, .flags = LGFS2_MFF_UID)
Packit 6ef888
F(di_gid, .flags = LGFS2_MFF_GID)
Packit 6ef888
F(di_nlink)
Packit 6ef888
F(di_size, .flags = LGFS2_MFF_BYTES)
Packit 6ef888
F(di_blocks, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
F(di_atime, .flags = LGFS2_MFF_SECS)
Packit 6ef888
F(di_mtime, .flags = LGFS2_MFF_SECS)
Packit 6ef888
F(di_ctime, .flags = LGFS2_MFF_SECS)
Packit 6ef888
F(di_major, .flags = LGFS2_MFF_MAJOR)
Packit 6ef888
F(di_minor, .flags = LGFS2_MFF_MINOR)
Packit 6ef888
FP(di_rgrp, .points_to = LGFS2_MT_GFS_RGRP)
Packit 6ef888
FP(di_goal_rgrp, .points_to = LGFS2_MT_GFS_RGRP)
Packit 6ef888
F(di_goal_dblk)
Packit 6ef888
F(di_goal_mblk)
Packit 6ef888
F(di_flags, .flags = LGFS2_MFF_MASK, .symtab=lgfs2_di_flags, .nsyms=ARRAY_SIZE(lgfs2_di_flags))
Packit 6ef888
F(di_payload_format)
Packit 6ef888
F(di_type)
Packit 6ef888
F(di_height)
Packit 6ef888
F(di_incarn)
Packit 6ef888
F(di_pad)
Packit 6ef888
F(di_depth)
Packit 6ef888
F(di_entries)
Packit 6ef888
INR(di_next_unused, .points_to = (1 << LGFS2_MT_GFS_DINODE))
Packit 6ef888
FP(di_eattr, .points_to = (1 << LGFS2_MT_EA_ATTR)|(1 << LGFS2_MT_GFS_INDIRECT))
Packit 6ef888
F(di_reserved)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
struct gfs2_indirect { struct gfs2_meta_header in_header; };
Packit 6ef888
#define STRUCT gfs2_indirect
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_indirect_fields[] = {
Packit 6ef888
MH(in_header)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs_indirect
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs_indirect_fields[] = {
Packit 6ef888
MH(in_header)
Packit 6ef888
RF(in_reserved)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs2_leaf
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_leaf_fields[] = {
Packit 6ef888
MH(lf_header)
Packit 6ef888
F(lf_depth)
Packit 6ef888
F(lf_entries)
Packit 6ef888
F(lf_dirent_format)
Packit 6ef888
F(lf_next)
Packit 6ef888
#ifdef GFS2_HAS_LEAF_HINTS
Packit 6ef888
FP(lf_inode, .points_to = (1 << LGFS2_MT_GFS2_DINODE))
Packit 6ef888
F(lf_dist)
Packit 6ef888
F(lf_nsec, .flags = LGFS2_MFF_NSECS)
Packit 6ef888
F(lf_sec, .flags = LGFS2_MFF_SECS)
Packit 6ef888
RF(lf_reserved2)
Packit 6ef888
#else
Packit 6ef888
RF(lf_reserved)
Packit 6ef888
#endif
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
struct gfs2_jrnl_data { struct gfs2_meta_header jd_header; };
Packit 6ef888
#define STRUCT gfs2_jrnl_data
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_jdata_fields[] = {
Packit 6ef888
MH(jd_header)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs2_log_header
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_log_header_fields[] = {
Packit 6ef888
MH(lh_header)
Packit 6ef888
F(lh_sequence)
Packit 6ef888
F(lh_flags)
Packit 6ef888
F(lh_tail)
Packit 6ef888
F(lh_blkno)
Packit 6ef888
F(lh_hash, .flags = LGFS2_MFF_CHECK)
Packit 6ef888
#ifdef GFS2_HAS_LH_V2
Packit 6ef888
F(lh_crc, .flags = LGFS2_MFF_CHECK)
Packit 6ef888
F(lh_nsec, .flags = LGFS2_MFF_NSECS)
Packit 6ef888
F(lh_sec, .flags = LGFS2_MFF_SECS)
Packit 6ef888
FP(lh_addr, .points_to = (1 << LGFS2_MT_GFS2_LOG_BLOCK))
Packit 6ef888
FP(lh_jinode, .points_to = (1 << LGFS2_MT_GFS2_DINODE))
Packit 6ef888
FP(lh_statfs_addr, .points_to = (1 << LGFS2_MT_GFS2_DINODE))
Packit 6ef888
FP(lh_quota_addr, .points_to = (1 << LGFS2_MT_GFS2_DINODE))
Packit 6ef888
F(lh_local_total, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
F(lh_local_free, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
F(lh_local_dinodes, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
#endif
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs_log_header
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs_log_header_fields[] = {
Packit 6ef888
MH(lh_header)
Packit 6ef888
F(lh_flags, .flags = LGFS2_MFF_MASK, .symtab = lgfs2_lh_flags, .nsyms = ARRAY_SIZE(lgfs2_lh_flags))
Packit 6ef888
RF(lh_pad)
Packit 6ef888
F(lh_first)
Packit 6ef888
F(lh_sequence)
Packit 6ef888
F(lh_tail)
Packit 6ef888
F(lh_last_dump)
Packit 6ef888
RF(lh_reserved)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs2_log_descriptor
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_log_desc_fields[] = {
Packit 6ef888
MH(ld_header)
Packit 6ef888
F(ld_type, .flags = LGFS2_MFF_ENUM, .symtab = lgfs2_ld_types, .nsyms = ARRAY_SIZE(lgfs2_ld_types))
Packit 6ef888
F(ld_length, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
F(ld_data1)
Packit 6ef888
F(ld_data2)
Packit 6ef888
RF(ld_reserved)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs_log_descriptor
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs_log_desc_fields[] = {
Packit 6ef888
MH(ld_header)
Packit 6ef888
F(ld_type, .flags = LGFS2_MFF_ENUM, .symtab = lgfs2_ld1_types, .nsyms = ARRAY_SIZE(lgfs2_ld1_types))
Packit 6ef888
F(ld_length, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
F(ld_data1)
Packit 6ef888
F(ld_data2)
Packit 6ef888
RF(ld_reserved)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
struct gfs2_log_block { struct gfs2_meta_header lb_header; };
Packit 6ef888
#define STRUCT gfs2_log_block
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_log_block_fields[] = {
Packit 6ef888
MH(lb_header)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
struct gfs2_ea_attr { struct gfs2_meta_header ea_header; };
Packit 6ef888
#define STRUCT gfs2_ea_attr
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_ea_attr_fields[] = {
Packit 6ef888
MH(ea_header)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
struct gfs2_ea_data { struct gfs2_meta_header ed_header; };
Packit 6ef888
#define STRUCT gfs2_ea_data
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_ea_data_fields[] = {
Packit 6ef888
MH(ed_header)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs2_quota_change
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_quota_change_fields[] = {
Packit 6ef888
F(qc_change, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
F(qc_flags)
Packit 6ef888
F(qc_id)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs2_dirent
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_dirent_fields[] = {
Packit 6ef888
IN(de_inum, .points_to = (1 << LGFS2_MT_GFS_DINODE)|(1 << LGFS2_MT_GFS2_DINODE))
Packit 6ef888
F(de_hash, .flags = LGFS2_MFF_CHECK)
Packit 6ef888
F(de_rec_len, .flags = LGFS2_MFF_BYTES)
Packit 6ef888
F(de_name_len, .flags = LGFS2_MFF_BYTES)
Packit 6ef888
F(de_type)
Packit 6ef888
#ifdef GFS2_HAS_DE_RAHEAD
Packit 6ef888
F(de_rahead)
Packit 6ef888
#ifdef GFS2_HAS_DE_COOKIE
Packit 6ef888
F(de_cookie)
Packit 6ef888
RF(pad3)
Packit 6ef888
#else
Packit 6ef888
RF(pad2)
Packit 6ef888
#endif /* GFS2_HAS_DE_COOKIE */
Packit 6ef888
#else
Packit 6ef888
RF(__pad)
Packit 6ef888
#endif /* GFS2_HAS_DE_RAHEAD */
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs2_ea_header
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_ea_header_fields[] = {
Packit 6ef888
F(ea_rec_len, .flags = LGFS2_MFF_BYTES)
Packit 6ef888
F(ea_data_len, .flags = LGFS2_MFF_BYTES)
Packit 6ef888
F(ea_name_len, .flags = LGFS2_MFF_BYTES)
Packit 6ef888
F(ea_type)
Packit 6ef888
F(ea_flags)
Packit 6ef888
F(ea_num_ptrs)
Packit 6ef888
RF(__pad)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs2_inum_range
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_inum_range_fields[] = {
Packit 6ef888
F(ir_start)
Packit 6ef888
F(ir_length)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs2_statfs_change
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs2_statfs_change_fields[] = {
Packit 6ef888
F(sc_total, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
F(sc_free, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
F(sc_dinodes, .flags = LGFS2_MFF_FSBLOCKS)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
#define STRUCT gfs_jindex
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs_jindex_fields[] = {
Packit 6ef888
FP(ji_addr, .points_to = (1 << LGFS2_MT_DATA))
Packit 6ef888
F(ji_nsegment)
Packit 6ef888
RF(ji_pad)
Packit 6ef888
RF(ji_reserved)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
#undef STRUCT
Packit 6ef888
struct gfs_block_tag {
Packit 6ef888
	uint64_t bt_blkno;      /* inplace block number */
Packit 6ef888
	uint32_t bt_flags;      /* ?? */
Packit 6ef888
	uint32_t bt_pad;
Packit 6ef888
};
Packit 6ef888
#define STRUCT gfs_block_tag
Packit 6ef888
Packit 6ef888
static const struct lgfs2_metafield gfs_block_tag_fields[] = {
Packit 6ef888
FP(bt_blkno, .points_to = ANY_GFS_BLOCK)
Packit 6ef888
RF(bt_flags)
Packit 6ef888
RF(bt_pad)
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
const struct lgfs2_metadata lgfs2_metadata[] = {
Packit 6ef888
	[LGFS2_MT_GFS2_SB] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS2,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_SB,
Packit 6ef888
		.mh_format = GFS2_FORMAT_SB,
Packit 6ef888
		.name = "gfs2_sb",
Packit 6ef888
		.fields = gfs2_sb_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_sb_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_sb),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_GFS_SB] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_SB,
Packit 6ef888
		.mh_format = GFS_FORMAT_SB,
Packit 6ef888
		.name = "gfs_sb",
Packit 6ef888
		.fields = gfs_sb_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs_sb_fields),
Packit 6ef888
		.size = sizeof(struct gfs_sb),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_RINDEX] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1 | LGFS2_MD_GFS2,
Packit 6ef888
		.name = "rindex",
Packit 6ef888
		.fields = gfs2_rindex_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_rindex_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_rindex),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_GFS2_RGRP] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS2,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_RG,
Packit 6ef888
		.mh_format = GFS2_FORMAT_RG,
Packit 6ef888
		.name = "gfs2_rgrp",
Packit 6ef888
		.fields = gfs2_rgrp_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_rgrp_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_rgrp),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_GFS_RGRP] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_RG,
Packit 6ef888
		.mh_format = GFS2_FORMAT_RG,
Packit 6ef888
		.name = "gfs_rgrp",
Packit 6ef888
		.fields = gfs_rgrp_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs_rgrp_fields),
Packit 6ef888
		.size = sizeof(struct gfs_rgrp),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_RGRP_BITMAP] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1 | LGFS2_MD_GFS2,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_RB,
Packit 6ef888
		.mh_format = GFS2_FORMAT_RB,
Packit 6ef888
		.name = "gfs2_rgrp_bitmap",
Packit 6ef888
		.fields = gfs2_rgrp_bitmap_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_rgrp_bitmap_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_meta_header),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_GFS2_DINODE] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS2,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_DI,
Packit 6ef888
		.mh_format = GFS2_FORMAT_DI,
Packit 6ef888
		.name = "gfs2_dinode",
Packit 6ef888
		.fields = gfs2_dinode_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_dinode_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_dinode),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_GFS_DINODE] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_DI,
Packit 6ef888
		.mh_format = GFS2_FORMAT_DI,
Packit 6ef888
		.name = "gfs_dinode",
Packit 6ef888
		.fields = gfs_dinode_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs_dinode_fields),
Packit 6ef888
		.size = sizeof(struct gfs_dinode),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_GFS2_INDIRECT] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS2,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_IN,
Packit 6ef888
		.mh_format = GFS2_FORMAT_IN,
Packit 6ef888
		.name = "gfs2_indirect",
Packit 6ef888
		.fields = gfs2_indirect_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_indirect_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_meta_header),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_GFS_INDIRECT] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_IN,
Packit 6ef888
		.mh_format = GFS2_FORMAT_IN,
Packit 6ef888
		.name = "gfs_indirect",
Packit 6ef888
		.fields = gfs_indirect_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs_indirect_fields),
Packit 6ef888
		.size = sizeof(struct gfs_indirect),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_DIR_LEAF] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1 | LGFS2_MD_GFS2,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_LF,
Packit 6ef888
		.mh_format = GFS2_FORMAT_LF,
Packit 6ef888
		.name = "gfs2_leaf",
Packit 6ef888
		.fields = gfs2_leaf_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_leaf_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_leaf),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_JRNL_DATA] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1 | LGFS2_MD_GFS2,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_JD,
Packit 6ef888
		.mh_format = GFS2_FORMAT_JD,
Packit 6ef888
		.name = "gfs2_jdata",
Packit 6ef888
		.fields = gfs2_jdata_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_jdata_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_meta_header),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_GFS2_LOG_HEADER] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS2,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_LH,
Packit 6ef888
		.mh_format = GFS2_FORMAT_LH,
Packit 6ef888
		.name = "gfs2_log_header",
Packit 6ef888
		.fields = gfs2_log_header_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_log_header_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_log_header),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_GFS_LOG_HEADER] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_LH,
Packit 6ef888
		.mh_format = GFS2_FORMAT_LH,
Packit 6ef888
		.name = "gfs_log_header",
Packit 6ef888
		.fields = gfs_log_header_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs_log_header_fields),
Packit 6ef888
		.size = sizeof(struct gfs_log_header),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_GFS2_LOG_DESC] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS2,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_LD,
Packit 6ef888
		.mh_format = GFS2_FORMAT_LD,
Packit 6ef888
		.name = "gfs2_log_desc",
Packit 6ef888
		.fields = gfs2_log_desc_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_log_desc_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_log_descriptor),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_GFS_LOG_DESC] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_LD,
Packit 6ef888
		.mh_format = GFS2_FORMAT_LD,
Packit 6ef888
		.name = "gfs_log_desc",
Packit 6ef888
		.fields = gfs_log_desc_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs_log_desc_fields),
Packit 6ef888
		.size = sizeof(struct gfs_log_descriptor),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_GFS2_LOG_BLOCK] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS2,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_LB,
Packit 6ef888
		.mh_format = GFS2_FORMAT_LB,
Packit 6ef888
		.name = "gfs2_log_block",
Packit 6ef888
		.fields = gfs2_log_block_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_log_block_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_meta_header),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_EA_ATTR] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1 | LGFS2_MD_GFS2,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_EA,
Packit 6ef888
		.mh_format = GFS2_FORMAT_EA,
Packit 6ef888
		.name = "gfs2_ea_attr",
Packit 6ef888
		.fields = gfs2_ea_attr_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_ea_attr_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_meta_header),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_EA_DATA] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1 | LGFS2_MD_GFS2,
Packit 6ef888
		.header = 1,
Packit 6ef888
		.mh_type = GFS2_METATYPE_ED,
Packit 6ef888
		.mh_format = GFS2_FORMAT_ED,
Packit 6ef888
		.name = "gfs2_ea_data",
Packit 6ef888
		.fields = gfs2_ea_data_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_ea_data_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_meta_header),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_GFS2_QUOTA_CHANGE] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS2,
Packit 6ef888
		.name = "gfs2_quota_change",
Packit 6ef888
		.fields = gfs2_quota_change_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_quota_change_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_quota_change),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_DIRENT] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1 | LGFS2_MD_GFS2,
Packit 6ef888
		.name = "gfs2_dirent",
Packit 6ef888
		.fields = gfs2_dirent_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_dirent_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_dirent),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_EA_HEADER] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1 | LGFS2_MD_GFS2,
Packit 6ef888
		.name = "gfs2_ea_header",
Packit 6ef888
		.fields = gfs2_ea_header_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_ea_header_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_ea_header),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_GFS2_INUM_RANGE] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS2,
Packit 6ef888
		.name = "gfs2_inum_range",
Packit 6ef888
		.fields = gfs2_inum_range_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_inum_range_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_inum_range),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_STATFS_CHANGE] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1 | LGFS2_MD_GFS2,
Packit 6ef888
		.name = "gfs2_statfs_change",
Packit 6ef888
		.fields = gfs2_statfs_change_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs2_statfs_change_fields),
Packit 6ef888
		.size = sizeof(struct gfs2_statfs_change),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_GFS_JINDEX] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1,
Packit 6ef888
		.name = "gfs_jindex",
Packit 6ef888
		.fields = gfs_jindex_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs_jindex_fields),
Packit 6ef888
		.size = sizeof(struct gfs_jindex),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_GFS_BLOCK_TAG] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1,
Packit 6ef888
		.name = "gfs_block_tag",
Packit 6ef888
		.fields = gfs_block_tag_fields,
Packit 6ef888
		.nfields = ARRAY_SIZE(gfs_block_tag_fields),
Packit 6ef888
		.size = sizeof(struct gfs_block_tag),
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_DATA] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1 | LGFS2_MD_GFS2,
Packit 6ef888
		.name = "data",
Packit 6ef888
	},
Packit 6ef888
	[LGFS2_MT_FREE] = {
Packit 6ef888
		.versions = LGFS2_MD_GFS1 | LGFS2_MD_GFS2,
Packit 6ef888
		.name = "free",
Packit 6ef888
	},
Packit 6ef888
};
Packit 6ef888
Packit 6ef888
const unsigned lgfs2_metadata_size = ARRAY_SIZE(lgfs2_metadata);
Packit 6ef888
Packit 6ef888
const struct lgfs2_metafield *lgfs2_find_mfield_name(const char *name, const struct lgfs2_metadata *mtype)
Packit 6ef888
{
Packit 6ef888
	int j;
Packit 6ef888
	const struct lgfs2_metafield *f;
Packit 6ef888
Packit 6ef888
	for (j = 0; j < mtype->nfields; j++) {
Packit 6ef888
		f = &mtype->fields[j];
Packit 6ef888
		if (strcmp(f->name, name) == 0)
Packit 6ef888
			return f;
Packit 6ef888
	}
Packit 6ef888
	return NULL;
Packit 6ef888
}
Packit 6ef888
Packit 6ef888
static int check_metadata_sizes(void)
Packit 6ef888
{
Packit 6ef888
	unsigned offset;
Packit 6ef888
	int i, j;
Packit 6ef888
	int ret = 0;
Packit 6ef888
Packit 6ef888
	for (i = 0; i < lgfs2_metadata_size; i++) {
Packit 6ef888
		const struct lgfs2_metadata *m = &lgfs2_metadata[i];
Packit 6ef888
		offset = 0;
Packit 6ef888
		for (j = 0; j < m->nfields; j++) {
Packit 6ef888
			const struct lgfs2_metafield *f = &m->fields[j];
Packit 6ef888
			if (f->offset != offset) {
Packit 6ef888
				fprintf(stderr, "%s: %s: offset is %u, expected %u\n", m->name, f->name, f->offset, offset);
Packit 6ef888
				ret = -1;
Packit 6ef888
			}
Packit 6ef888
			offset += f->length;
Packit 6ef888
		}
Packit 6ef888
		if (offset != m->size) {
Packit 6ef888
			fprintf(stderr, "%s: size mismatch between struct %u and fields %u\n", m->name, m->size, offset);
Packit 6ef888
			ret = -1;
Packit 6ef888
		}
Packit 6ef888
	}
Packit 6ef888
Packit 6ef888
	return ret;
Packit 6ef888
}
Packit 6ef888
Packit 6ef888
static int check_symtab(void)
Packit 6ef888
{
Packit 6ef888
	int i, j;
Packit 6ef888
	int ret = 0;
Packit 6ef888
Packit 6ef888
	for (i = 0; i < lgfs2_metadata_size; i++) {
Packit 6ef888
		const struct lgfs2_metadata *m = &lgfs2_metadata[i];
Packit 6ef888
		for (j = 0; j < m->nfields; j++) {
Packit 6ef888
			const struct lgfs2_metafield *f = &m->fields[j];
Packit 6ef888
			if (f->flags & (LGFS2_MFF_MASK|LGFS2_MFF_ENUM)) {
Packit 6ef888
				if (f->symtab == NULL) {
Packit 6ef888
					fprintf(stderr, "%s: Missing symtab for %s\n", m->name, f->name);
Packit 6ef888
					ret = -1;
Packit 6ef888
				}
Packit 6ef888
			}
Packit 6ef888
			if (f->symtab) {
Packit 6ef888
				if (!(f->flags & (LGFS2_MFF_MASK|LGFS2_MFF_ENUM))) {
Packit 6ef888
					fprintf(stderr, "%s: Symtab for non-enum and non-mask field %s\n", m->name, f->name);
Packit 6ef888
					ret = -1;
Packit 6ef888
				}
Packit 6ef888
			}
Packit 6ef888
		}
Packit 6ef888
	}
Packit 6ef888
Packit 6ef888
	return ret;
Packit 6ef888
}
Packit 6ef888
Packit 6ef888
static int check_ptrs(void)
Packit 6ef888
{
Packit 6ef888
	int i, j;
Packit 6ef888
	int ret = 0;
Packit 6ef888
Packit 6ef888
	for (i = 0; i < lgfs2_metadata_size; i++) {
Packit 6ef888
		const struct lgfs2_metadata *m = &lgfs2_metadata[i];
Packit 6ef888
		for (j = 0; j < m->nfields; j++) {
Packit 6ef888
			const struct lgfs2_metafield *f = &m->fields[j];
Packit 6ef888
			if ((f->flags & LGFS2_MFF_POINTER) && !f->points_to) {
Packit 6ef888
				fprintf(stderr, "%s: Pointer entry %s has no destination\n", m->name, f->name);
Packit 6ef888
				ret = -1;
Packit 6ef888
			}
Packit 6ef888
		}
Packit 6ef888
	}
Packit 6ef888
Packit 6ef888
	return ret;
Packit 6ef888
}
Packit 6ef888
Packit 6ef888
int lgfs2_selfcheck(void)
Packit 6ef888
{
Packit 6ef888
	int ret = 0;
Packit 6ef888
Packit 6ef888
	ret |= check_metadata_sizes();
Packit 6ef888
	ret |= check_symtab();
Packit 6ef888
	ret |= check_ptrs();
Packit 6ef888
Packit 6ef888
	return ret;
Packit 6ef888
}
Packit 6ef888
Packit 6ef888
const struct lgfs2_metadata *lgfs2_find_mtype(uint32_t mh_type, const unsigned versions)
Packit 6ef888
{
Packit 6ef888
	const struct lgfs2_metadata *m = lgfs2_metadata;
Packit 6ef888
	unsigned n = 0;
Packit 6ef888
Packit 6ef888
	do {
Packit 6ef888
		if ((m[n].versions & versions) && m[n].mh_type == mh_type)
Packit 6ef888
			return &m[n];
Packit 6ef888
		n++;
Packit 6ef888
	} while (n < lgfs2_metadata_size);
Packit 6ef888
Packit 6ef888
	return NULL;
Packit 6ef888
}
Packit 6ef888
Packit 6ef888
const struct lgfs2_metadata *lgfs2_find_mtype_name(const char *name, const unsigned versions)
Packit 6ef888
{
Packit 6ef888
	const struct lgfs2_metadata *m = lgfs2_metadata;
Packit 6ef888
	unsigned n = 0;
Packit 6ef888
Packit 6ef888
	do {
Packit 6ef888
		if ((m[n].versions & versions) && !strcmp(m[n].name, name))
Packit 6ef888
			return &m[n];
Packit 6ef888
		n++;
Packit 6ef888
	} while (n < lgfs2_metadata_size);
Packit 6ef888
Packit 6ef888
	return NULL;
Packit 6ef888
}
Packit 6ef888
Packit 6ef888
int lgfs2_field_str(char *str, const size_t size, const char *blk, const struct lgfs2_metafield *field, int hex)
Packit 6ef888
{
Packit 6ef888
	const char *fieldp = blk + field->offset;
Packit 6ef888
Packit 6ef888
	errno = EINVAL;
Packit 6ef888
	if (str == NULL)
Packit 6ef888
		return 1;
Packit 6ef888
Packit 6ef888
	if (field->flags & LGFS2_MFF_UUID) {
Packit 6ef888
#ifdef GFS2_HAS_UUID
Packit 6ef888
		char readable_uuid[36+1];
Packit 6ef888
		uuid_t uuid;
Packit 6ef888
Packit 6ef888
		memcpy(uuid, fieldp, sizeof(uuid_t));
Packit 6ef888
		uuid_unparse(uuid, readable_uuid);
Packit 6ef888
		snprintf(str, size, "%s", readable_uuid);
Packit 6ef888
#endif
Packit 6ef888
	} else if (field->flags & LGFS2_MFF_STRING) {
Packit 6ef888
		snprintf(str, size, "%s", fieldp);
Packit 6ef888
	} else {
Packit 6ef888
		switch(field->length) {
Packit 6ef888
		case sizeof(uint8_t):
Packit 6ef888
			snprintf(str, size, hex? "%"PRIx8 : "%"PRIu8, *(uint8_t *)fieldp);
Packit 6ef888
			break;
Packit 6ef888
		case sizeof(uint16_t):
Packit 6ef888
			snprintf(str, size, hex? "%"PRIx16 : "%"PRIu16, be16_to_cpu(*(uint16_t *)fieldp));
Packit 6ef888
			break;
Packit 6ef888
		case sizeof(uint32_t):
Packit 6ef888
			snprintf(str, size, hex? "%"PRIx32 : "%"PRIu32, be32_to_cpu(*(uint32_t *)fieldp));
Packit 6ef888
			break;
Packit 6ef888
		case sizeof(uint64_t):
Packit 6ef888
			snprintf(str, size, hex? "%"PRIx64 : "%"PRIu64, be64_to_cpu(*(uint64_t *)fieldp));
Packit 6ef888
			break;
Packit 6ef888
		default:
Packit 6ef888
			break;
Packit 6ef888
		}
Packit 6ef888
	}
Packit 6ef888
	str[size - 1] = '\0';
Packit 6ef888
	return 0;
Packit 6ef888
}
Packit 6ef888
Packit 6ef888
int lgfs2_field_assign(char *blk, const struct lgfs2_metafield *field, const void *val)
Packit 6ef888
{
Packit 6ef888
	char *fieldp = blk + field->offset;
Packit Service e66bb1
	uint64_t num = *(uint64_t *)val;
Packit 6ef888
Packit 6ef888
	if (field->flags & LGFS2_MFF_UUID) {
Packit 6ef888
		memcpy(fieldp, val, 16);
Packit 6ef888
		return 0;
Packit 6ef888
	}
Packit 6ef888
Packit 6ef888
	errno = EINVAL;
Packit 6ef888
	if (field->flags & LGFS2_MFF_STRING) {
Packit 6ef888
		size_t len = strnlen(val, field->length);
Packit 6ef888
Packit 6ef888
		if (len >= field->length)
Packit 6ef888
			return 1;
Packit 6ef888
		strncpy(fieldp, val, field->length - 1);
Packit 6ef888
		fieldp[field->length - 1] = '\0';
Packit 6ef888
		return 0;
Packit 6ef888
	}
Packit 6ef888
Packit 6ef888
	switch(field->length) {
Packit 6ef888
	case sizeof(uint8_t):
Packit Service e66bb1
		*fieldp = (uint8_t)num;
Packit 6ef888
		return 0;
Packit 6ef888
	case sizeof(uint16_t):
Packit Service e66bb1
		*(uint16_t *)fieldp = cpu_to_be16((uint16_t)num);
Packit 6ef888
		return 0;
Packit 6ef888
	case sizeof(uint32_t):
Packit Service e66bb1
		*(uint32_t *)fieldp = cpu_to_be32((uint32_t)num);
Packit 6ef888
		return 0;
Packit 6ef888
	case sizeof(uint64_t):
Packit Service e66bb1
		*(uint64_t *)fieldp = cpu_to_be64((uint64_t)num);
Packit 6ef888
		return 0;
Packit 6ef888
	default:
Packit 6ef888
		/* Will never happen */
Packit 6ef888
		break;
Packit 6ef888
	}
Packit 6ef888
Packit 6ef888
	return 1;
Packit 6ef888
}