xref: /openbmc/linux/fs/freevxfs/vxfs.h (revision 2f164822)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2000-2001 Christoph Hellwig.
4  * Copyright (c) 2016 Krzysztof Blaszkowski
5  */
6 #ifndef _VXFS_SUPER_H_
7 #define _VXFS_SUPER_H_
8 
9 /*
10  * Veritas filesystem driver - superblock structure.
11  *
12  * This file contains the definition of the disk and core
13  * superblocks of the Veritas Filesystem.
14  */
15 #include <linux/types.h>
16 
17 /*
18  * Superblock magic number (vxfs_super->vs_magic).
19  */
20 #define VXFS_SUPER_MAGIC	0xa501FCF5
21 
22 /*
23  * The root inode.
24  */
25 #define VXFS_ROOT_INO		2
26 
27 /*
28  * Num of entries in free extent array
29  */
30 #define VXFS_NEFREE		32
31 
32 enum vxfs_byte_order {
33 	VXFS_BO_LE,
34 	VXFS_BO_BE,
35 };
36 
37 typedef __u16 __bitwise __fs16;
38 typedef __u32 __bitwise __fs32;
39 typedef __u64 __bitwise __fs64;
40 
41 /*
42  * VxFS superblock (disk).
43  */
44 struct vxfs_sb {
45 	/*
46 	 * Readonly fields for the version 1 superblock.
47 	 *
48 	 * Lots of this fields are no more used by version 2
49 	 * and never filesystems.
50 	 */
51 	__fs32		vs_magic;		/* Magic number */
52 	__fs32		vs_version;		/* VxFS version */
53 	__fs32		vs_ctime;		/* create time - secs */
54 	__fs32		vs_cutime;		/* create time - usecs */
55 	__fs32		__unused1;		/* unused */
56 	__fs32		__unused2;		/* unused */
57 	__fs32		vs_old_logstart;	/* obsolete */
58 	__fs32		vs_old_logend;		/* obsolete */
59 	__fs32		vs_bsize;		/* block size */
60 	__fs32		vs_size;		/* number of blocks */
61 	__fs32		vs_dsize;		/* number of data blocks */
62 	__fs32		vs_old_ninode;		/* obsolete */
63 	__fs32		vs_old_nau;		/* obsolete */
64 	__fs32		__unused3;		/* unused */
65 	__fs32		vs_old_defiextsize;	/* obsolete */
66 	__fs32		vs_old_ilbsize;		/* obsolete */
67 	__fs32		vs_immedlen;		/* size of immediate data area */
68 	__fs32		vs_ndaddr;		/* number of direct extentes */
69 	__fs32		vs_firstau;		/* address of first AU */
70 	__fs32		vs_emap;		/* offset of extent map in AU */
71 	__fs32		vs_imap;		/* offset of inode map in AU */
72 	__fs32		vs_iextop;		/* offset of ExtOp. map in AU */
73 	__fs32		vs_istart;		/* offset of inode list in AU */
74 	__fs32		vs_bstart;		/* offset of fdblock in AU */
75 	__fs32		vs_femap;		/* aufirst + emap */
76 	__fs32		vs_fimap;		/* aufirst + imap */
77 	__fs32		vs_fiextop;		/* aufirst + iextop */
78 	__fs32		vs_fistart;		/* aufirst + istart */
79 	__fs32		vs_fbstart;		/* aufirst + bstart */
80 	__fs32		vs_nindir;		/* number of entries in indir */
81 	__fs32		vs_aulen;		/* length of AU in blocks */
82 	__fs32		vs_auimlen;		/* length of imap in blocks */
83 	__fs32		vs_auemlen;		/* length of emap in blocks */
84 	__fs32		vs_auilen;		/* length of ilist in blocks */
85 	__fs32		vs_aupad;		/* length of pad in blocks */
86 	__fs32		vs_aublocks;		/* data blocks in AU */
87 	__fs32		vs_maxtier;		/* log base 2 of aublocks */
88 	__fs32		vs_inopb;		/* number of inodes per blk */
89 	__fs32		vs_old_inopau;		/* obsolete */
90 	__fs32		vs_old_inopilb;		/* obsolete */
91 	__fs32		vs_old_ndiripau;	/* obsolete */
92 	__fs32		vs_iaddrlen;		/* size of indirect addr ext. */
93 	__fs32		vs_bshift;		/* log base 2 of bsize */
94 	__fs32		vs_inoshift;		/* log base 2 of inobp */
95 	__fs32		vs_bmask;		/* ~( bsize - 1 ) */
96 	__fs32		vs_boffmask;		/* bsize - 1 */
97 	__fs32		vs_old_inomask;		/* old_inopilb - 1 */
98 	__fs32		vs_checksum;		/* checksum of V1 data */
99 
100 	/*
101 	 * Version 1, writable
102 	 */
103 	__fs32		vs_free;		/* number of free blocks */
104 	__fs32		vs_ifree;		/* number of free inodes */
105 	__fs32		vs_efree[VXFS_NEFREE];	/* number of free extents by size */
106 	__fs32		vs_flags;		/* flags ?!? */
107 	__u8		vs_mod;			/* filesystem has been changed */
108 	__u8		vs_clean;		/* clean FS */
109 	__fs16		__unused4;		/* unused */
110 	__fs32		vs_firstlogid;		/* mount time log ID */
111 	__fs32		vs_wtime;		/* last time written - sec */
112 	__fs32		vs_wutime;		/* last time written - usec */
113 	__u8		vs_fname[6];		/* FS name */
114 	__u8		vs_fpack[6];		/* FS pack name */
115 	__fs32		vs_logversion;		/* log format version */
116 	__u32		__unused5;		/* unused */
117 
118 	/*
119 	 * Version 2, Read-only
120 	 */
121 	__fs32		vs_oltext[2];		/* OLT extent and replica */
122 	__fs32		vs_oltsize;		/* OLT extent size */
123 	__fs32		vs_iauimlen;		/* size of inode map */
124 	__fs32		vs_iausize;		/* size of IAU in blocks */
125 	__fs32		vs_dinosize;		/* size of inode in bytes */
126 	__fs32		vs_old_dniaddr;		/* indir levels per inode */
127 	__fs32		vs_checksum2;		/* checksum of V2 RO */
128 
129 	/*
130 	 * Actually much more...
131 	 */
132 };
133 
134 
135 /*
136  * In core superblock filesystem private data for VxFS.
137  */
138 struct vxfs_sb_info {
139 	struct vxfs_sb		*vsi_raw;	/* raw (on disk) superblock */
140 	struct buffer_head	*vsi_bp;	/* buffer for raw superblock*/
141 	struct inode		*vsi_fship;	/* fileset header inode */
142 	struct inode		*vsi_ilist;	/* inode list inode */
143 	struct inode		*vsi_stilist;	/* structural inode list inode */
144 	u_long			vsi_iext;	/* initial inode list */
145 	ino_t			vsi_fshino;	/* fileset header inode */
146 	daddr_t			vsi_oltext;	/* OLT extent */
147 	daddr_t			vsi_oltsize;	/* OLT size */
148 	enum vxfs_byte_order	byte_order;
149 };
150 
151 static inline u16 fs16_to_cpu(struct vxfs_sb_info *sbi, __fs16 a)
152 {
153 	if (sbi->byte_order == VXFS_BO_BE)
154 		return be16_to_cpu((__force __be16)a);
155 	else
156 		return le16_to_cpu((__force __le16)a);
157 }
158 
159 static inline u32 fs32_to_cpu(struct vxfs_sb_info *sbi, __fs32 a)
160 {
161 	if (sbi->byte_order == VXFS_BO_BE)
162 		return be32_to_cpu((__force __be32)a);
163 	else
164 		return le32_to_cpu((__force __le32)a);
165 }
166 
167 static inline u64 fs64_to_cpu(struct vxfs_sb_info *sbi, __fs64 a)
168 {
169 	if (sbi->byte_order == VXFS_BO_BE)
170 		return be64_to_cpu((__force __be64)a);
171 	else
172 		return le64_to_cpu((__force __le64)a);
173 }
174 
175 /*
176  * File modes.  File types above 0xf000 are vxfs internal only, they should
177  * not be passed back to higher levels of the system.  vxfs file types must
178  * never have one of the regular file type bits set.
179  */
180 enum vxfs_mode {
181 	VXFS_ISUID = 0x00000800,	/* setuid */
182 	VXFS_ISGID = 0x00000400,	/* setgid */
183 	VXFS_ISVTX = 0x00000200,	/* sticky bit */
184 	VXFS_IREAD = 0x00000100,	/* read */
185 	VXFS_IWRITE = 0x00000080,	/* write */
186 	VXFS_IEXEC = 0x00000040,	/* exec */
187 
188 	VXFS_IFIFO = 0x00001000,	/* Named pipe */
189 	VXFS_IFCHR = 0x00002000,	/* Character device */
190 	VXFS_IFDIR = 0x00004000,	/* Directory */
191 	VXFS_IFNAM = 0x00005000,	/* Xenix device ?? */
192 	VXFS_IFBLK = 0x00006000,	/* Block device */
193 	VXFS_IFREG = 0x00008000,	/* Regular file */
194 	VXFS_IFCMP = 0x00009000,	/* Compressed file ?!? */
195 	VXFS_IFLNK = 0x0000a000,	/* Symlink */
196 	VXFS_IFSOC = 0x0000c000,	/* Socket */
197 
198 	/* VxFS internal */
199 	VXFS_IFFSH = 0x10000000,	/* Fileset header */
200 	VXFS_IFILT = 0x20000000,	/* Inode list */
201 	VXFS_IFIAU = 0x30000000,	/* Inode allocation unit */
202 	VXFS_IFCUT = 0x40000000,	/* Current usage table */
203 	VXFS_IFATT = 0x50000000,	/* Attr. inode */
204 	VXFS_IFLCT = 0x60000000,	/* Link count table */
205 	VXFS_IFIAT = 0x70000000,	/* Indirect attribute file */
206 	VXFS_IFEMR = 0x80000000,	/* Extent map reorg file */
207 	VXFS_IFQUO = 0x90000000,	/* BSD quota file */
208 	VXFS_IFPTI = 0xa0000000,	/* "Pass through" inode */
209 	VXFS_IFLAB = 0x11000000,	/* Device label file */
210 	VXFS_IFOLT = 0x12000000,	/* OLT file */
211 	VXFS_IFLOG = 0x13000000,	/* Log file */
212 	VXFS_IFEMP = 0x14000000,	/* Extent map file */
213 	VXFS_IFEAU = 0x15000000,	/* Extent AU file */
214 	VXFS_IFAUS = 0x16000000,	/* Extent AU summary file */
215 	VXFS_IFDEV = 0x17000000,	/* Device config file */
216 
217 };
218 
219 #define	VXFS_TYPE_MASK		0xfffff000
220 
221 #define VXFS_IS_TYPE(ip,type)	(((ip)->vii_mode & VXFS_TYPE_MASK) == (type))
222 #define VXFS_ISFIFO(x)		VXFS_IS_TYPE((x),VXFS_IFIFO)
223 #define VXFS_ISCHR(x)		VXFS_IS_TYPE((x),VXFS_IFCHR)
224 #define VXFS_ISDIR(x)		VXFS_IS_TYPE((x),VXFS_IFDIR)
225 #define VXFS_ISNAM(x)		VXFS_IS_TYPE((x),VXFS_IFNAM)
226 #define VXFS_ISBLK(x)		VXFS_IS_TYPE((x),VXFS_IFBLK)
227 #define VXFS_ISLNK(x)		VXFS_IS_TYPE((x),VXFS_IFLNK)
228 #define VXFS_ISREG(x)		VXFS_IS_TYPE((x),VXFS_IFREG)
229 #define VXFS_ISCMP(x)		VXFS_IS_TYPE((x),VXFS_IFCMP)
230 #define VXFS_ISSOC(x)		VXFS_IS_TYPE((x),VXFS_IFSOC)
231 
232 #define VXFS_ISFSH(x)		VXFS_IS_TYPE((x),VXFS_IFFSH)
233 #define VXFS_ISILT(x)		VXFS_IS_TYPE((x),VXFS_IFILT)
234 
235 /*
236  * Inmode organisation types.
237  */
238 enum {
239 	VXFS_ORG_NONE	= 0,	/* Inode has *no* format ?!? */
240 	VXFS_ORG_EXT4	= 1,	/* Ext4 */
241 	VXFS_ORG_IMMED	= 2,	/* All data stored in inode */
242 	VXFS_ORG_TYPED	= 3,	/* Typed extents */
243 };
244 
245 #define VXFS_IS_ORG(ip,org)	((ip)->vii_orgtype == (org))
246 #define VXFS_ISNONE(ip)		VXFS_IS_ORG((ip), VXFS_ORG_NONE)
247 #define VXFS_ISEXT4(ip)		VXFS_IS_ORG((ip), VXFS_ORG_EXT4)
248 #define VXFS_ISIMMED(ip)	VXFS_IS_ORG((ip), VXFS_ORG_IMMED)
249 #define VXFS_ISTYPED(ip)	VXFS_IS_ORG((ip), VXFS_ORG_TYPED)
250 
251 /*
252  * Get filesystem private data from VFS superblock.
253  */
254 #define VXFS_SBI(sbp) \
255 	((struct vxfs_sb_info *)(sbp)->s_fs_info)
256 
257 #endif /* _VXFS_SUPER_H_ */
258