162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2000-2001 Christoph Hellwig.
462306a36Sopenharmony_ci * Copyright (c) 2016 Krzysztof Blaszkowski
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci#ifndef _VXFS_SUPER_H_
762306a36Sopenharmony_ci#define _VXFS_SUPER_H_
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci/*
1062306a36Sopenharmony_ci * Veritas filesystem driver - superblock structure.
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci * This file contains the definition of the disk and core
1362306a36Sopenharmony_ci * superblocks of the Veritas Filesystem.
1462306a36Sopenharmony_ci */
1562306a36Sopenharmony_ci#include <linux/types.h>
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci/*
1862306a36Sopenharmony_ci * Superblock magic number (vxfs_super->vs_magic).
1962306a36Sopenharmony_ci */
2062306a36Sopenharmony_ci#define VXFS_SUPER_MAGIC	0xa501FCF5
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci/*
2362306a36Sopenharmony_ci * The root inode.
2462306a36Sopenharmony_ci */
2562306a36Sopenharmony_ci#define VXFS_ROOT_INO		2
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci/*
2862306a36Sopenharmony_ci * Num of entries in free extent array
2962306a36Sopenharmony_ci */
3062306a36Sopenharmony_ci#define VXFS_NEFREE		32
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_cienum vxfs_byte_order {
3362306a36Sopenharmony_ci	VXFS_BO_LE,
3462306a36Sopenharmony_ci	VXFS_BO_BE,
3562306a36Sopenharmony_ci};
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_citypedef __u16 __bitwise __fs16;
3862306a36Sopenharmony_citypedef __u32 __bitwise __fs32;
3962306a36Sopenharmony_citypedef __u64 __bitwise __fs64;
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci/*
4262306a36Sopenharmony_ci * VxFS superblock (disk).
4362306a36Sopenharmony_ci */
4462306a36Sopenharmony_cistruct vxfs_sb {
4562306a36Sopenharmony_ci	/*
4662306a36Sopenharmony_ci	 * Readonly fields for the version 1 superblock.
4762306a36Sopenharmony_ci	 *
4862306a36Sopenharmony_ci	 * Lots of this fields are no more used by version 2
4962306a36Sopenharmony_ci	 * and never filesystems.
5062306a36Sopenharmony_ci	 */
5162306a36Sopenharmony_ci	__fs32		vs_magic;		/* Magic number */
5262306a36Sopenharmony_ci	__fs32		vs_version;		/* VxFS version */
5362306a36Sopenharmony_ci	__fs32		vs_ctime;		/* create time - secs */
5462306a36Sopenharmony_ci	__fs32		vs_cutime;		/* create time - usecs */
5562306a36Sopenharmony_ci	__fs32		__unused1;		/* unused */
5662306a36Sopenharmony_ci	__fs32		__unused2;		/* unused */
5762306a36Sopenharmony_ci	__fs32		vs_old_logstart;	/* obsolete */
5862306a36Sopenharmony_ci	__fs32		vs_old_logend;		/* obsolete */
5962306a36Sopenharmony_ci	__fs32		vs_bsize;		/* block size */
6062306a36Sopenharmony_ci	__fs32		vs_size;		/* number of blocks */
6162306a36Sopenharmony_ci	__fs32		vs_dsize;		/* number of data blocks */
6262306a36Sopenharmony_ci	__fs32		vs_old_ninode;		/* obsolete */
6362306a36Sopenharmony_ci	__fs32		vs_old_nau;		/* obsolete */
6462306a36Sopenharmony_ci	__fs32		__unused3;		/* unused */
6562306a36Sopenharmony_ci	__fs32		vs_old_defiextsize;	/* obsolete */
6662306a36Sopenharmony_ci	__fs32		vs_old_ilbsize;		/* obsolete */
6762306a36Sopenharmony_ci	__fs32		vs_immedlen;		/* size of immediate data area */
6862306a36Sopenharmony_ci	__fs32		vs_ndaddr;		/* number of direct extentes */
6962306a36Sopenharmony_ci	__fs32		vs_firstau;		/* address of first AU */
7062306a36Sopenharmony_ci	__fs32		vs_emap;		/* offset of extent map in AU */
7162306a36Sopenharmony_ci	__fs32		vs_imap;		/* offset of inode map in AU */
7262306a36Sopenharmony_ci	__fs32		vs_iextop;		/* offset of ExtOp. map in AU */
7362306a36Sopenharmony_ci	__fs32		vs_istart;		/* offset of inode list in AU */
7462306a36Sopenharmony_ci	__fs32		vs_bstart;		/* offset of fdblock in AU */
7562306a36Sopenharmony_ci	__fs32		vs_femap;		/* aufirst + emap */
7662306a36Sopenharmony_ci	__fs32		vs_fimap;		/* aufirst + imap */
7762306a36Sopenharmony_ci	__fs32		vs_fiextop;		/* aufirst + iextop */
7862306a36Sopenharmony_ci	__fs32		vs_fistart;		/* aufirst + istart */
7962306a36Sopenharmony_ci	__fs32		vs_fbstart;		/* aufirst + bstart */
8062306a36Sopenharmony_ci	__fs32		vs_nindir;		/* number of entries in indir */
8162306a36Sopenharmony_ci	__fs32		vs_aulen;		/* length of AU in blocks */
8262306a36Sopenharmony_ci	__fs32		vs_auimlen;		/* length of imap in blocks */
8362306a36Sopenharmony_ci	__fs32		vs_auemlen;		/* length of emap in blocks */
8462306a36Sopenharmony_ci	__fs32		vs_auilen;		/* length of ilist in blocks */
8562306a36Sopenharmony_ci	__fs32		vs_aupad;		/* length of pad in blocks */
8662306a36Sopenharmony_ci	__fs32		vs_aublocks;		/* data blocks in AU */
8762306a36Sopenharmony_ci	__fs32		vs_maxtier;		/* log base 2 of aublocks */
8862306a36Sopenharmony_ci	__fs32		vs_inopb;		/* number of inodes per blk */
8962306a36Sopenharmony_ci	__fs32		vs_old_inopau;		/* obsolete */
9062306a36Sopenharmony_ci	__fs32		vs_old_inopilb;		/* obsolete */
9162306a36Sopenharmony_ci	__fs32		vs_old_ndiripau;	/* obsolete */
9262306a36Sopenharmony_ci	__fs32		vs_iaddrlen;		/* size of indirect addr ext. */
9362306a36Sopenharmony_ci	__fs32		vs_bshift;		/* log base 2 of bsize */
9462306a36Sopenharmony_ci	__fs32		vs_inoshift;		/* log base 2 of inobp */
9562306a36Sopenharmony_ci	__fs32		vs_bmask;		/* ~( bsize - 1 ) */
9662306a36Sopenharmony_ci	__fs32		vs_boffmask;		/* bsize - 1 */
9762306a36Sopenharmony_ci	__fs32		vs_old_inomask;		/* old_inopilb - 1 */
9862306a36Sopenharmony_ci	__fs32		vs_checksum;		/* checksum of V1 data */
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci	/*
10162306a36Sopenharmony_ci	 * Version 1, writable
10262306a36Sopenharmony_ci	 */
10362306a36Sopenharmony_ci	__fs32		vs_free;		/* number of free blocks */
10462306a36Sopenharmony_ci	__fs32		vs_ifree;		/* number of free inodes */
10562306a36Sopenharmony_ci	__fs32		vs_efree[VXFS_NEFREE];	/* number of free extents by size */
10662306a36Sopenharmony_ci	__fs32		vs_flags;		/* flags ?!? */
10762306a36Sopenharmony_ci	__u8		vs_mod;			/* filesystem has been changed */
10862306a36Sopenharmony_ci	__u8		vs_clean;		/* clean FS */
10962306a36Sopenharmony_ci	__fs16		__unused4;		/* unused */
11062306a36Sopenharmony_ci	__fs32		vs_firstlogid;		/* mount time log ID */
11162306a36Sopenharmony_ci	__fs32		vs_wtime;		/* last time written - sec */
11262306a36Sopenharmony_ci	__fs32		vs_wutime;		/* last time written - usec */
11362306a36Sopenharmony_ci	__u8		vs_fname[6];		/* FS name */
11462306a36Sopenharmony_ci	__u8		vs_fpack[6];		/* FS pack name */
11562306a36Sopenharmony_ci	__fs32		vs_logversion;		/* log format version */
11662306a36Sopenharmony_ci	__u32		__unused5;		/* unused */
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci	/*
11962306a36Sopenharmony_ci	 * Version 2, Read-only
12062306a36Sopenharmony_ci	 */
12162306a36Sopenharmony_ci	__fs32		vs_oltext[2];		/* OLT extent and replica */
12262306a36Sopenharmony_ci	__fs32		vs_oltsize;		/* OLT extent size */
12362306a36Sopenharmony_ci	__fs32		vs_iauimlen;		/* size of inode map */
12462306a36Sopenharmony_ci	__fs32		vs_iausize;		/* size of IAU in blocks */
12562306a36Sopenharmony_ci	__fs32		vs_dinosize;		/* size of inode in bytes */
12662306a36Sopenharmony_ci	__fs32		vs_old_dniaddr;		/* indir levels per inode */
12762306a36Sopenharmony_ci	__fs32		vs_checksum2;		/* checksum of V2 RO */
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci	/*
13062306a36Sopenharmony_ci	 * Actually much more...
13162306a36Sopenharmony_ci	 */
13262306a36Sopenharmony_ci};
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci/*
13662306a36Sopenharmony_ci * In core superblock filesystem private data for VxFS.
13762306a36Sopenharmony_ci */
13862306a36Sopenharmony_cistruct vxfs_sb_info {
13962306a36Sopenharmony_ci	struct vxfs_sb		*vsi_raw;	/* raw (on disk) superblock */
14062306a36Sopenharmony_ci	struct buffer_head	*vsi_bp;	/* buffer for raw superblock*/
14162306a36Sopenharmony_ci	struct inode		*vsi_fship;	/* fileset header inode */
14262306a36Sopenharmony_ci	struct inode		*vsi_ilist;	/* inode list inode */
14362306a36Sopenharmony_ci	struct inode		*vsi_stilist;	/* structural inode list inode */
14462306a36Sopenharmony_ci	u_long			vsi_iext;	/* initial inode list */
14562306a36Sopenharmony_ci	ino_t			vsi_fshino;	/* fileset header inode */
14662306a36Sopenharmony_ci	daddr_t			vsi_oltext;	/* OLT extent */
14762306a36Sopenharmony_ci	daddr_t			vsi_oltsize;	/* OLT size */
14862306a36Sopenharmony_ci	enum vxfs_byte_order	byte_order;
14962306a36Sopenharmony_ci};
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_cistatic inline u16 fs16_to_cpu(struct vxfs_sb_info *sbi, __fs16 a)
15262306a36Sopenharmony_ci{
15362306a36Sopenharmony_ci	if (sbi->byte_order == VXFS_BO_BE)
15462306a36Sopenharmony_ci		return be16_to_cpu((__force __be16)a);
15562306a36Sopenharmony_ci	else
15662306a36Sopenharmony_ci		return le16_to_cpu((__force __le16)a);
15762306a36Sopenharmony_ci}
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_cistatic inline u32 fs32_to_cpu(struct vxfs_sb_info *sbi, __fs32 a)
16062306a36Sopenharmony_ci{
16162306a36Sopenharmony_ci	if (sbi->byte_order == VXFS_BO_BE)
16262306a36Sopenharmony_ci		return be32_to_cpu((__force __be32)a);
16362306a36Sopenharmony_ci	else
16462306a36Sopenharmony_ci		return le32_to_cpu((__force __le32)a);
16562306a36Sopenharmony_ci}
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_cistatic inline u64 fs64_to_cpu(struct vxfs_sb_info *sbi, __fs64 a)
16862306a36Sopenharmony_ci{
16962306a36Sopenharmony_ci	if (sbi->byte_order == VXFS_BO_BE)
17062306a36Sopenharmony_ci		return be64_to_cpu((__force __be64)a);
17162306a36Sopenharmony_ci	else
17262306a36Sopenharmony_ci		return le64_to_cpu((__force __le64)a);
17362306a36Sopenharmony_ci}
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci/*
17662306a36Sopenharmony_ci * File modes.  File types above 0xf000 are vxfs internal only, they should
17762306a36Sopenharmony_ci * not be passed back to higher levels of the system.  vxfs file types must
17862306a36Sopenharmony_ci * never have one of the regular file type bits set.
17962306a36Sopenharmony_ci */
18062306a36Sopenharmony_cienum vxfs_mode {
18162306a36Sopenharmony_ci	VXFS_ISUID = 0x00000800,	/* setuid */
18262306a36Sopenharmony_ci	VXFS_ISGID = 0x00000400,	/* setgid */
18362306a36Sopenharmony_ci	VXFS_ISVTX = 0x00000200,	/* sticky bit */
18462306a36Sopenharmony_ci	VXFS_IREAD = 0x00000100,	/* read */
18562306a36Sopenharmony_ci	VXFS_IWRITE = 0x00000080,	/* write */
18662306a36Sopenharmony_ci	VXFS_IEXEC = 0x00000040,	/* exec */
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci	VXFS_IFIFO = 0x00001000,	/* Named pipe */
18962306a36Sopenharmony_ci	VXFS_IFCHR = 0x00002000,	/* Character device */
19062306a36Sopenharmony_ci	VXFS_IFDIR = 0x00004000,	/* Directory */
19162306a36Sopenharmony_ci	VXFS_IFNAM = 0x00005000,	/* Xenix device ?? */
19262306a36Sopenharmony_ci	VXFS_IFBLK = 0x00006000,	/* Block device */
19362306a36Sopenharmony_ci	VXFS_IFREG = 0x00008000,	/* Regular file */
19462306a36Sopenharmony_ci	VXFS_IFCMP = 0x00009000,	/* Compressed file ?!? */
19562306a36Sopenharmony_ci	VXFS_IFLNK = 0x0000a000,	/* Symlink */
19662306a36Sopenharmony_ci	VXFS_IFSOC = 0x0000c000,	/* Socket */
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ci	/* VxFS internal */
19962306a36Sopenharmony_ci	VXFS_IFFSH = 0x10000000,	/* Fileset header */
20062306a36Sopenharmony_ci	VXFS_IFILT = 0x20000000,	/* Inode list */
20162306a36Sopenharmony_ci	VXFS_IFIAU = 0x30000000,	/* Inode allocation unit */
20262306a36Sopenharmony_ci	VXFS_IFCUT = 0x40000000,	/* Current usage table */
20362306a36Sopenharmony_ci	VXFS_IFATT = 0x50000000,	/* Attr. inode */
20462306a36Sopenharmony_ci	VXFS_IFLCT = 0x60000000,	/* Link count table */
20562306a36Sopenharmony_ci	VXFS_IFIAT = 0x70000000,	/* Indirect attribute file */
20662306a36Sopenharmony_ci	VXFS_IFEMR = 0x80000000,	/* Extent map reorg file */
20762306a36Sopenharmony_ci	VXFS_IFQUO = 0x90000000,	/* BSD quota file */
20862306a36Sopenharmony_ci	VXFS_IFPTI = 0xa0000000,	/* "Pass through" inode */
20962306a36Sopenharmony_ci	VXFS_IFLAB = 0x11000000,	/* Device label file */
21062306a36Sopenharmony_ci	VXFS_IFOLT = 0x12000000,	/* OLT file */
21162306a36Sopenharmony_ci	VXFS_IFLOG = 0x13000000,	/* Log file */
21262306a36Sopenharmony_ci	VXFS_IFEMP = 0x14000000,	/* Extent map file */
21362306a36Sopenharmony_ci	VXFS_IFEAU = 0x15000000,	/* Extent AU file */
21462306a36Sopenharmony_ci	VXFS_IFAUS = 0x16000000,	/* Extent AU summary file */
21562306a36Sopenharmony_ci	VXFS_IFDEV = 0x17000000,	/* Device config file */
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_ci};
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci#define	VXFS_TYPE_MASK		0xfffff000
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_ci#define VXFS_IS_TYPE(ip,type)	(((ip)->vii_mode & VXFS_TYPE_MASK) == (type))
22262306a36Sopenharmony_ci#define VXFS_ISFIFO(x)		VXFS_IS_TYPE((x),VXFS_IFIFO)
22362306a36Sopenharmony_ci#define VXFS_ISCHR(x)		VXFS_IS_TYPE((x),VXFS_IFCHR)
22462306a36Sopenharmony_ci#define VXFS_ISDIR(x)		VXFS_IS_TYPE((x),VXFS_IFDIR)
22562306a36Sopenharmony_ci#define VXFS_ISNAM(x)		VXFS_IS_TYPE((x),VXFS_IFNAM)
22662306a36Sopenharmony_ci#define VXFS_ISBLK(x)		VXFS_IS_TYPE((x),VXFS_IFBLK)
22762306a36Sopenharmony_ci#define VXFS_ISLNK(x)		VXFS_IS_TYPE((x),VXFS_IFLNK)
22862306a36Sopenharmony_ci#define VXFS_ISREG(x)		VXFS_IS_TYPE((x),VXFS_IFREG)
22962306a36Sopenharmony_ci#define VXFS_ISCMP(x)		VXFS_IS_TYPE((x),VXFS_IFCMP)
23062306a36Sopenharmony_ci#define VXFS_ISSOC(x)		VXFS_IS_TYPE((x),VXFS_IFSOC)
23162306a36Sopenharmony_ci
23262306a36Sopenharmony_ci#define VXFS_ISFSH(x)		VXFS_IS_TYPE((x),VXFS_IFFSH)
23362306a36Sopenharmony_ci#define VXFS_ISILT(x)		VXFS_IS_TYPE((x),VXFS_IFILT)
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_ci/*
23662306a36Sopenharmony_ci * Inmode organisation types.
23762306a36Sopenharmony_ci */
23862306a36Sopenharmony_cienum {
23962306a36Sopenharmony_ci	VXFS_ORG_NONE	= 0,	/* Inode has *no* format ?!? */
24062306a36Sopenharmony_ci	VXFS_ORG_EXT4	= 1,	/* Ext4 */
24162306a36Sopenharmony_ci	VXFS_ORG_IMMED	= 2,	/* All data stored in inode */
24262306a36Sopenharmony_ci	VXFS_ORG_TYPED	= 3,	/* Typed extents */
24362306a36Sopenharmony_ci};
24462306a36Sopenharmony_ci
24562306a36Sopenharmony_ci#define VXFS_IS_ORG(ip,org)	((ip)->vii_orgtype == (org))
24662306a36Sopenharmony_ci#define VXFS_ISNONE(ip)		VXFS_IS_ORG((ip), VXFS_ORG_NONE)
24762306a36Sopenharmony_ci#define VXFS_ISEXT4(ip)		VXFS_IS_ORG((ip), VXFS_ORG_EXT4)
24862306a36Sopenharmony_ci#define VXFS_ISIMMED(ip)	VXFS_IS_ORG((ip), VXFS_ORG_IMMED)
24962306a36Sopenharmony_ci#define VXFS_ISTYPED(ip)	VXFS_IS_ORG((ip), VXFS_ORG_TYPED)
25062306a36Sopenharmony_ci
25162306a36Sopenharmony_ci/*
25262306a36Sopenharmony_ci * Get filesystem private data from VFS superblock.
25362306a36Sopenharmony_ci */
25462306a36Sopenharmony_ci#define VXFS_SBI(sbp) \
25562306a36Sopenharmony_ci	((struct vxfs_sb_info *)(sbp)->s_fs_info)
25662306a36Sopenharmony_ci
25762306a36Sopenharmony_ci#endif /* _VXFS_SUPER_H_ */
258