]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - fs/xfs/xfs_dinode.h
9e1fd2323255ace8c7bb0f5a2df208c5561b0919
[mirror_ubuntu-bionic-kernel.git] / fs / xfs / xfs_dinode.h
1 /*
2 * Copyright (c) 2000, 2002 Silicon Graphics, Inc. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22 *
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
25 *
26 * http://www.sgi.com
27 *
28 * For further information regarding this notice, see:
29 *
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31 */
32 #ifndef __XFS_DINODE_H__
33 #define __XFS_DINODE_H__
34
35 struct xfs_buf;
36 struct xfs_mount;
37
38 #define XFS_DINODE_VERSION_1 1
39 #define XFS_DINODE_VERSION_2 2
40 #define XFS_DINODE_GOOD_VERSION(v) \
41 (((v) == XFS_DINODE_VERSION_1 || (v) == XFS_DINODE_VERSION_2))
42 #define XFS_DINODE_MAGIC 0x494e /* 'IN' */
43
44 /*
45 * Disk inode structure.
46 * This is just the header; the inode is expanded to fill a variable size
47 * with the last field expanding. It is split into the core and "other"
48 * because we only need the core part in the in-core inode.
49 */
50 typedef struct xfs_timestamp {
51 __int32_t t_sec; /* timestamp seconds */
52 __int32_t t_nsec; /* timestamp nanoseconds */
53 } xfs_timestamp_t;
54
55 /*
56 * Note: Coordinate changes to this structure with the XFS_DI_* #defines
57 * below and the offsets table in xfs_ialloc_log_di().
58 */
59 typedef struct xfs_dinode_core
60 {
61 __uint16_t di_magic; /* inode magic # = XFS_DINODE_MAGIC */
62 __uint16_t di_mode; /* mode and type of file */
63 __int8_t di_version; /* inode version */
64 __int8_t di_format; /* format of di_c data */
65 __uint16_t di_onlink; /* old number of links to file */
66 __uint32_t di_uid; /* owner's user id */
67 __uint32_t di_gid; /* owner's group id */
68 __uint32_t di_nlink; /* number of links to file */
69 __uint16_t di_projid; /* owner's project id */
70 __uint8_t di_pad[8]; /* unused, zeroed space */
71 __uint16_t di_flushiter; /* incremented on flush */
72 xfs_timestamp_t di_atime; /* time last accessed */
73 xfs_timestamp_t di_mtime; /* time last modified */
74 xfs_timestamp_t di_ctime; /* time created/inode modified */
75 xfs_fsize_t di_size; /* number of bytes in file */
76 xfs_drfsbno_t di_nblocks; /* # of direct & btree blocks used */
77 xfs_extlen_t di_extsize; /* basic/minimum extent size for file */
78 xfs_extnum_t di_nextents; /* number of extents in data fork */
79 xfs_aextnum_t di_anextents; /* number of extents in attribute fork*/
80 __uint8_t di_forkoff; /* attr fork offs, <<3 for 64b align */
81 __int8_t di_aformat; /* format of attr fork's data */
82 __uint32_t di_dmevmask; /* DMIG event mask */
83 __uint16_t di_dmstate; /* DMIG state info */
84 __uint16_t di_flags; /* random flags, XFS_DIFLAG_... */
85 __uint32_t di_gen; /* generation number */
86 } xfs_dinode_core_t;
87
88 #define DI_MAX_FLUSH 0xffff
89
90 typedef struct xfs_dinode
91 {
92 xfs_dinode_core_t di_core;
93 /*
94 * In adding anything between the core and the union, be
95 * sure to update the macros like XFS_LITINO below and
96 * XFS_BMAP_RBLOCK_DSIZE in xfs_bmap_btree.h.
97 */
98 xfs_agino_t di_next_unlinked;/* agi unlinked list ptr */
99 union {
100 xfs_bmdr_block_t di_bmbt; /* btree root block */
101 xfs_bmbt_rec_32_t di_bmx[1]; /* extent list */
102 xfs_dir_shortform_t di_dirsf; /* shortform directory */
103 xfs_dir2_sf_t di_dir2sf; /* shortform directory v2 */
104 char di_c[1]; /* local contents */
105 xfs_dev_t di_dev; /* device for S_IFCHR/S_IFBLK */
106 uuid_t di_muuid; /* mount point value */
107 char di_symlink[1]; /* local symbolic link */
108 } di_u;
109 union {
110 xfs_bmdr_block_t di_abmbt; /* btree root block */
111 xfs_bmbt_rec_32_t di_abmx[1]; /* extent list */
112 xfs_attr_shortform_t di_attrsf; /* shortform attribute list */
113 } di_a;
114 } xfs_dinode_t;
115
116 /*
117 * The 32 bit link count in the inode theoretically maxes out at UINT_MAX.
118 * Since the pathconf interface is signed, we use 2^31 - 1 instead.
119 * The old inode format had a 16 bit link count, so its maximum is USHRT_MAX.
120 */
121 #define XFS_MAXLINK ((1U << 31) - 1U)
122 #define XFS_MAXLINK_1 65535U
123
124 /*
125 * Bit names for logging disk inodes only
126 */
127 #define XFS_DI_MAGIC 0x0000001
128 #define XFS_DI_MODE 0x0000002
129 #define XFS_DI_VERSION 0x0000004
130 #define XFS_DI_FORMAT 0x0000008
131 #define XFS_DI_ONLINK 0x0000010
132 #define XFS_DI_UID 0x0000020
133 #define XFS_DI_GID 0x0000040
134 #define XFS_DI_NLINK 0x0000080
135 #define XFS_DI_PROJID 0x0000100
136 #define XFS_DI_PAD 0x0000200
137 #define XFS_DI_ATIME 0x0000400
138 #define XFS_DI_MTIME 0x0000800
139 #define XFS_DI_CTIME 0x0001000
140 #define XFS_DI_SIZE 0x0002000
141 #define XFS_DI_NBLOCKS 0x0004000
142 #define XFS_DI_EXTSIZE 0x0008000
143 #define XFS_DI_NEXTENTS 0x0010000
144 #define XFS_DI_NAEXTENTS 0x0020000
145 #define XFS_DI_FORKOFF 0x0040000
146 #define XFS_DI_AFORMAT 0x0080000
147 #define XFS_DI_DMEVMASK 0x0100000
148 #define XFS_DI_DMSTATE 0x0200000
149 #define XFS_DI_FLAGS 0x0400000
150 #define XFS_DI_GEN 0x0800000
151 #define XFS_DI_NEXT_UNLINKED 0x1000000
152 #define XFS_DI_U 0x2000000
153 #define XFS_DI_A 0x4000000
154 #define XFS_DI_NUM_BITS 27
155 #define XFS_DI_ALL_BITS ((1 << XFS_DI_NUM_BITS) - 1)
156 #define XFS_DI_CORE_BITS (XFS_DI_ALL_BITS & ~(XFS_DI_U|XFS_DI_A))
157
158 /*
159 * Values for di_format
160 */
161 typedef enum xfs_dinode_fmt
162 {
163 XFS_DINODE_FMT_DEV, /* CHR, BLK: di_dev */
164 XFS_DINODE_FMT_LOCAL, /* DIR, REG: di_c */
165 /* LNK: di_symlink */
166 XFS_DINODE_FMT_EXTENTS, /* DIR, REG, LNK: di_bmx */
167 XFS_DINODE_FMT_BTREE, /* DIR, REG, LNK: di_bmbt */
168 XFS_DINODE_FMT_UUID /* MNT: di_uuid */
169 } xfs_dinode_fmt_t;
170
171 /*
172 * Inode minimum and maximum sizes.
173 */
174 #define XFS_DINODE_MIN_LOG 8
175 #define XFS_DINODE_MAX_LOG 11
176 #define XFS_DINODE_MIN_SIZE (1 << XFS_DINODE_MIN_LOG)
177 #define XFS_DINODE_MAX_SIZE (1 << XFS_DINODE_MAX_LOG)
178
179 /*
180 * Inode size for given fs.
181 */
182 #define XFS_LITINO(mp) ((mp)->m_litino)
183 #define XFS_BROOT_SIZE_ADJ \
184 (sizeof(xfs_bmbt_block_t) - sizeof(xfs_bmdr_block_t))
185
186 /*
187 * Inode data & attribute fork sizes, per inode.
188 */
189 #define XFS_CFORK_Q(dcp) ((dcp)->di_forkoff != 0)
190 #define XFS_CFORK_Q_DISK(dcp) ((dcp)->di_forkoff != 0)
191
192 #define XFS_CFORK_BOFF(dcp) ((int)((dcp)->di_forkoff << 3))
193 #define XFS_CFORK_BOFF_DISK(dcp) \
194 ((int)(INT_GET((dcp)->di_forkoff, ARCH_CONVERT) << 3))
195
196 #define XFS_CFORK_DSIZE_DISK(dcp,mp) \
197 (XFS_CFORK_Q_DISK(dcp) ? XFS_CFORK_BOFF_DISK(dcp) : XFS_LITINO(mp))
198 #define XFS_CFORK_DSIZE(dcp,mp) \
199 (XFS_CFORK_Q(dcp) ? XFS_CFORK_BOFF(dcp) : XFS_LITINO(mp))
200
201 #define XFS_CFORK_ASIZE_DISK(dcp,mp) \
202 (XFS_CFORK_Q_DISK(dcp) ? XFS_LITINO(mp) - XFS_CFORK_BOFF_DISK(dcp) : 0)
203 #define XFS_CFORK_ASIZE(dcp,mp) \
204 (XFS_CFORK_Q(dcp) ? XFS_LITINO(mp) - XFS_CFORK_BOFF(dcp) : 0)
205
206 #define XFS_CFORK_SIZE_DISK(dcp,mp,w) \
207 ((w) == XFS_DATA_FORK ? \
208 XFS_CFORK_DSIZE_DISK(dcp, mp) : \
209 XFS_CFORK_ASIZE_DISK(dcp, mp))
210 #define XFS_CFORK_SIZE(dcp,mp,w) \
211 ((w) == XFS_DATA_FORK ? \
212 XFS_CFORK_DSIZE(dcp, mp) : XFS_CFORK_ASIZE(dcp, mp))
213
214 #define XFS_DFORK_DSIZE(dip,mp) \
215 XFS_CFORK_DSIZE_DISK(&(dip)->di_core, mp)
216 #define XFS_DFORK_ASIZE(dip,mp) \
217 XFS_CFORK_ASIZE_DISK(&(dip)->di_core, mp)
218 #define XFS_DFORK_SIZE(dip,mp,w) \
219 XFS_CFORK_SIZE_DISK(&(dip)->di_core, mp, w)
220
221 #define XFS_DFORK_Q(dip) XFS_CFORK_Q_DISK(&(dip)->di_core)
222 #define XFS_DFORK_BOFF(dip) XFS_CFORK_BOFF_DISK(&(dip)->di_core)
223 #define XFS_DFORK_DPTR(dip) ((dip)->di_u.di_c)
224 #define XFS_DFORK_APTR(dip) \
225 ((dip)->di_u.di_c + XFS_DFORK_BOFF(dip))
226 #define XFS_DFORK_PTR(dip,w) \
227 ((w) == XFS_DATA_FORK ? XFS_DFORK_DPTR(dip) : XFS_DFORK_APTR(dip))
228 #define XFS_CFORK_FORMAT(dcp,w) \
229 ((w) == XFS_DATA_FORK ? (dcp)->di_format : (dcp)->di_aformat)
230 #define XFS_CFORK_FMT_SET(dcp,w,n) \
231 ((w) == XFS_DATA_FORK ? \
232 ((dcp)->di_format = (n)) : ((dcp)->di_aformat = (n)))
233
234 #define XFS_CFORK_NEXTENTS_DISK(dcp,w) \
235 ((w) == XFS_DATA_FORK ? \
236 INT_GET((dcp)->di_nextents, ARCH_CONVERT) : \
237 INT_GET((dcp)->di_anextents, ARCH_CONVERT))
238 #define XFS_CFORK_NEXTENTS(dcp,w) \
239 ((w) == XFS_DATA_FORK ? (dcp)->di_nextents : (dcp)->di_anextents)
240
241 #define XFS_CFORK_NEXT_SET(dcp,w,n) \
242 ((w) == XFS_DATA_FORK ? \
243 ((dcp)->di_nextents = (n)) : ((dcp)->di_anextents = (n)))
244
245 #define XFS_DFORK_NEXTENTS(dip,w) XFS_CFORK_NEXTENTS_DISK(&(dip)->di_core, w)
246
247 #define XFS_BUF_TO_DINODE(bp) ((xfs_dinode_t *)XFS_BUF_PTR(bp))
248
249 /*
250 * Values for di_flags
251 * There should be a one-to-one correspondence between these flags and the
252 * XFS_XFLAG_s.
253 */
254 #define XFS_DIFLAG_REALTIME_BIT 0 /* file's blocks come from rt area */
255 #define XFS_DIFLAG_PREALLOC_BIT 1 /* file space has been preallocated */
256 #define XFS_DIFLAG_NEWRTBM_BIT 2 /* for rtbitmap inode, new format */
257 #define XFS_DIFLAG_IMMUTABLE_BIT 3 /* inode is immutable */
258 #define XFS_DIFLAG_APPEND_BIT 4 /* inode is append-only */
259 #define XFS_DIFLAG_SYNC_BIT 5 /* inode is written synchronously */
260 #define XFS_DIFLAG_NOATIME_BIT 6 /* do not update atime */
261 #define XFS_DIFLAG_NODUMP_BIT 7 /* do not dump */
262 #define XFS_DIFLAG_RTINHERIT_BIT 8 /* create with realtime bit set */
263 #define XFS_DIFLAG_PROJINHERIT_BIT 9 /* create with parents projid */
264 #define XFS_DIFLAG_NOSYMLINKS_BIT 10 /* disallow symlink creation */
265 #define XFS_DIFLAG_REALTIME (1 << XFS_DIFLAG_REALTIME_BIT)
266 #define XFS_DIFLAG_PREALLOC (1 << XFS_DIFLAG_PREALLOC_BIT)
267 #define XFS_DIFLAG_NEWRTBM (1 << XFS_DIFLAG_NEWRTBM_BIT)
268 #define XFS_DIFLAG_IMMUTABLE (1 << XFS_DIFLAG_IMMUTABLE_BIT)
269 #define XFS_DIFLAG_APPEND (1 << XFS_DIFLAG_APPEND_BIT)
270 #define XFS_DIFLAG_SYNC (1 << XFS_DIFLAG_SYNC_BIT)
271 #define XFS_DIFLAG_NOATIME (1 << XFS_DIFLAG_NOATIME_BIT)
272 #define XFS_DIFLAG_NODUMP (1 << XFS_DIFLAG_NODUMP_BIT)
273 #define XFS_DIFLAG_RTINHERIT (1 << XFS_DIFLAG_RTINHERIT_BIT)
274 #define XFS_DIFLAG_PROJINHERIT (1 << XFS_DIFLAG_PROJINHERIT_BIT)
275 #define XFS_DIFLAG_NOSYMLINKS (1 << XFS_DIFLAG_NOSYMLINKS_BIT)
276
277 #define XFS_DIFLAG_ANY \
278 (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
279 XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
280 XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
281 XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS)
282
283 #endif /* __XFS_DINODE_H__ */