2 * Copyright (c) 2000, 2002 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
32 #ifndef __XFS_DINODE_H__
33 #define __XFS_DINODE_H__
38 #define XFS_DINODE_VERSION_1 1
39 #define XFS_DINODE_VERSION_2 2
40 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DINODE_GOOD_VERSION)
41 int xfs_dinode_good_version(int v);
42 #define XFS_DINODE_GOOD_VERSION(v) xfs_dinode_good_version(v)
44 #define XFS_DINODE_GOOD_VERSION(v) (((v) == XFS_DINODE_VERSION_1) || \
45 ((v) == XFS_DINODE_VERSION_2))
47 #define XFS_DINODE_MAGIC 0x494e /* 'IN' */
50 * Disk inode structure.
51 * This is just the header; the inode is expanded to fill a variable size
52 * with the last field expanding. It is split into the core and "other"
53 * because we only need the core part in the in-core inode.
55 typedef struct xfs_timestamp {
56 __int32_t t_sec; /* timestamp seconds */
57 __int32_t t_nsec; /* timestamp nanoseconds */
61 * Note: Coordinate changes to this structure with the XFS_DI_* #defines
62 * below and the offsets table in xfs_ialloc_log_di().
64 typedef struct xfs_dinode_core
66 __uint16_t di_magic; /* inode magic # = XFS_DINODE_MAGIC */
67 __uint16_t di_mode; /* mode and type of file */
68 __int8_t di_version; /* inode version */
69 __int8_t di_format; /* format of di_c data */
70 __uint16_t di_onlink; /* old number of links to file */
71 __uint32_t di_uid; /* owner's user id */
72 __uint32_t di_gid; /* owner's group id */
73 __uint32_t di_nlink; /* number of links to file */
74 __uint16_t di_projid; /* owner's project id */
75 __uint16_t di_xid; /* vserver context id */
76 __uint8_t di_pad[6]; /* unused, zeroed space */
77 __uint16_t di_flushiter; /* incremented on flush */
78 xfs_timestamp_t di_atime; /* time last accessed */
79 xfs_timestamp_t di_mtime; /* time last modified */
80 xfs_timestamp_t di_ctime; /* time created/inode modified */
81 xfs_fsize_t di_size; /* number of bytes in file */
82 xfs_drfsbno_t di_nblocks; /* # of direct & btree blocks used */
83 xfs_extlen_t di_extsize; /* basic/minimum extent size for file */
84 xfs_extnum_t di_nextents; /* number of extents in data fork */
85 xfs_aextnum_t di_anextents; /* number of extents in attribute fork*/
86 __uint8_t di_forkoff; /* attr fork offs, <<3 for 64b align */
87 __int8_t di_aformat; /* format of attr fork's data */
88 __uint32_t di_dmevmask; /* DMIG event mask */
89 __uint16_t di_dmstate; /* DMIG state info */
90 __uint16_t di_flags; /* random flags, XFS_DIFLAG_... */
91 __uint32_t di_gen; /* generation number */
94 #define DI_MAX_FLUSH 0xffff
96 typedef struct xfs_dinode
98 xfs_dinode_core_t di_core;
100 * In adding anything between the core and the union, be
101 * sure to update the macros like XFS_LITINO below and
102 * XFS_BMAP_RBLOCK_DSIZE in xfs_bmap_btree.h.
104 xfs_agino_t di_next_unlinked;/* agi unlinked list ptr */
106 xfs_bmdr_block_t di_bmbt; /* btree root block */
107 xfs_bmbt_rec_32_t di_bmx[1]; /* extent list */
108 xfs_dir_shortform_t di_dirsf; /* shortform directory */
109 xfs_dir2_sf_t di_dir2sf; /* shortform directory v2 */
110 char di_c[1]; /* local contents */
111 xfs_dev_t di_dev; /* device for S_IFCHR/S_IFBLK */
112 uuid_t di_muuid; /* mount point value */
113 char di_symlink[1]; /* local symbolic link */
116 xfs_bmdr_block_t di_abmbt; /* btree root block */
117 xfs_bmbt_rec_32_t di_abmx[1]; /* extent list */
118 xfs_attr_shortform_t di_attrsf; /* shortform attribute list */
123 * The 32 bit link count in the inode theoretically maxes out at UINT_MAX.
124 * Since the pathconf interface is signed, we use 2^31 - 1 instead.
125 * The old inode format had a 16 bit link count, so its maximum is USHRT_MAX.
127 #define XFS_MAXLINK ((1U << 31) - 1U)
128 #define XFS_MAXLINK_1 65535U
131 * Bit names for logging disk inodes only
133 #define XFS_DI_MAGIC 0x0000001
134 #define XFS_DI_MODE 0x0000002
135 #define XFS_DI_VERSION 0x0000004
136 #define XFS_DI_FORMAT 0x0000008
137 #define XFS_DI_ONLINK 0x0000010
138 #define XFS_DI_UID 0x0000020
139 #define XFS_DI_GID 0x0000040
140 #define XFS_DI_NLINK 0x0000080
141 #define XFS_DI_PROJID 0x0000100
142 #define XFS_DI_PAD 0x0000200
143 #define XFS_DI_ATIME 0x0000400
144 #define XFS_DI_MTIME 0x0000800
145 #define XFS_DI_CTIME 0x0001000
146 #define XFS_DI_SIZE 0x0002000
147 #define XFS_DI_NBLOCKS 0x0004000
148 #define XFS_DI_EXTSIZE 0x0008000
149 #define XFS_DI_NEXTENTS 0x0010000
150 #define XFS_DI_NAEXTENTS 0x0020000
151 #define XFS_DI_FORKOFF 0x0040000
152 #define XFS_DI_AFORMAT 0x0080000
153 #define XFS_DI_DMEVMASK 0x0100000
154 #define XFS_DI_DMSTATE 0x0200000
155 #define XFS_DI_FLAGS 0x0400000
156 #define XFS_DI_GEN 0x0800000
157 #define XFS_DI_NEXT_UNLINKED 0x1000000
158 #define XFS_DI_U 0x2000000
159 #define XFS_DI_A 0x4000000
160 #define XFS_DI_NUM_BITS 27
161 #define XFS_DI_ALL_BITS ((1 << XFS_DI_NUM_BITS) - 1)
162 #define XFS_DI_CORE_BITS (XFS_DI_ALL_BITS & ~(XFS_DI_U|XFS_DI_A))
165 * Values for di_format
167 typedef enum xfs_dinode_fmt
169 XFS_DINODE_FMT_DEV, /* CHR, BLK: di_dev */
170 XFS_DINODE_FMT_LOCAL, /* DIR, REG: di_c */
171 /* LNK: di_symlink */
172 XFS_DINODE_FMT_EXTENTS, /* DIR, REG, LNK: di_bmx */
173 XFS_DINODE_FMT_BTREE, /* DIR, REG, LNK: di_bmbt */
174 XFS_DINODE_FMT_UUID /* MNT: di_uuid */
178 * Inode minimum and maximum sizes.
180 #define XFS_DINODE_MIN_LOG 8
181 #define XFS_DINODE_MAX_LOG 11
182 #define XFS_DINODE_MIN_SIZE (1 << XFS_DINODE_MIN_LOG)
183 #define XFS_DINODE_MAX_SIZE (1 << XFS_DINODE_MAX_LOG)
186 * Inode size for given fs.
188 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_LITINO)
189 int xfs_litino(struct xfs_mount *mp);
190 #define XFS_LITINO(mp) xfs_litino(mp)
192 #define XFS_LITINO(mp) ((mp)->m_litino)
194 #define XFS_BROOT_SIZE_ADJ \
195 (sizeof(xfs_bmbt_block_t) - sizeof(xfs_bmdr_block_t))
198 * Fork identifiers. Here so utilities can use them without including
201 #define XFS_DATA_FORK 0
202 #define XFS_ATTR_FORK 1
205 * Inode data & attribute fork sizes, per inode.
207 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_CFORK_Q)
208 int xfs_cfork_q_disk(xfs_dinode_core_t *dcp);
209 int xfs_cfork_q(xfs_dinode_core_t *dcp);
210 #define XFS_CFORK_Q_DISK(dcp) xfs_cfork_q_disk(dcp)
211 #define XFS_CFORK_Q(dcp) xfs_cfork_q(dcp)
213 #define XFS_CFORK_Q_DISK(dcp) ((dcp)->di_forkoff != 0)
214 #define XFS_CFORK_Q(dcp) ((dcp)->di_forkoff != 0)
217 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_CFORK_BOFF)
218 int xfs_cfork_boff_disk(xfs_dinode_core_t *dcp);
219 int xfs_cfork_boff(xfs_dinode_core_t *dcp);
220 #define XFS_CFORK_BOFF_DISK(dcp) xfs_cfork_boff_disk(dcp)
221 #define XFS_CFORK_BOFF(dcp) xfs_cfork_boff(dcp)
223 #define XFS_CFORK_BOFF_DISK(dcp) ((int)(INT_GET((dcp)->di_forkoff, ARCH_CONVERT) << 3))
224 #define XFS_CFORK_BOFF(dcp) ((int)((dcp)->di_forkoff << 3))
227 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_CFORK_DSIZE)
228 int xfs_cfork_dsize_disk(xfs_dinode_core_t *dcp, struct xfs_mount *mp);
229 int xfs_cfork_dsize(xfs_dinode_core_t *dcp, struct xfs_mount *mp);
230 #define XFS_CFORK_DSIZE_DISK(dcp,mp) xfs_cfork_dsize_disk(dcp,mp)
231 #define XFS_CFORK_DSIZE(dcp,mp) xfs_cfork_dsize(dcp,mp)
233 #define XFS_CFORK_DSIZE_DISK(dcp,mp) \
234 (XFS_CFORK_Q_DISK(dcp) ? XFS_CFORK_BOFF_DISK(dcp) : XFS_LITINO(mp))
235 #define XFS_CFORK_DSIZE(dcp,mp) \
236 (XFS_CFORK_Q(dcp) ? XFS_CFORK_BOFF(dcp) : XFS_LITINO(mp))
239 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_CFORK_ASIZE)
240 int xfs_cfork_asize_disk(xfs_dinode_core_t *dcp, struct xfs_mount *mp);
241 int xfs_cfork_asize(xfs_dinode_core_t *dcp, struct xfs_mount *mp);
242 #define XFS_CFORK_ASIZE_DISK(dcp,mp) xfs_cfork_asize_disk(dcp,mp)
243 #define XFS_CFORK_ASIZE(dcp,mp) xfs_cfork_asize(dcp,mp)
245 #define XFS_CFORK_ASIZE_DISK(dcp,mp) \
246 (XFS_CFORK_Q_DISK(dcp) ? XFS_LITINO(mp) - XFS_CFORK_BOFF_DISK(dcp) : 0)
247 #define XFS_CFORK_ASIZE(dcp,mp) \
248 (XFS_CFORK_Q(dcp) ? XFS_LITINO(mp) - XFS_CFORK_BOFF(dcp) : 0)
251 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_CFORK_SIZE)
252 int xfs_cfork_size_disk(xfs_dinode_core_t *dcp, struct xfs_mount *mp, int w);
253 int xfs_cfork_size(xfs_dinode_core_t *dcp, struct xfs_mount *mp, int w);
254 #define XFS_CFORK_SIZE_DISK(dcp,mp,w) xfs_cfork_size_disk(dcp,mp,w)
255 #define XFS_CFORK_SIZE(dcp,mp,w) xfs_cfork_size(dcp,mp,w)
257 #define XFS_CFORK_SIZE_DISK(dcp,mp,w) \
258 ((w) == XFS_DATA_FORK ? \
259 XFS_CFORK_DSIZE_DISK(dcp, mp) : \
260 XFS_CFORK_ASIZE_DISK(dcp, mp))
261 #define XFS_CFORK_SIZE(dcp,mp,w) \
262 ((w) == XFS_DATA_FORK ? \
263 XFS_CFORK_DSIZE(dcp, mp) : XFS_CFORK_ASIZE(dcp, mp))
267 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DFORK_DSIZE)
268 int xfs_dfork_dsize(xfs_dinode_t *dip, struct xfs_mount *mp);
269 #define XFS_DFORK_DSIZE(dip,mp) xfs_dfork_dsize(dip,mp)
271 #define XFS_DFORK_DSIZE(dip,mp) XFS_CFORK_DSIZE_DISK(&(dip)->di_core, mp)
274 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DFORK_ASIZE)
275 int xfs_dfork_asize(xfs_dinode_t *dip, struct xfs_mount *mp);
276 #define XFS_DFORK_ASIZE(dip,mp) xfs_dfork_asize(dip,mp)
278 #define XFS_DFORK_ASIZE(dip,mp) XFS_CFORK_ASIZE_DISK(&(dip)->di_core, mp)
281 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DFORK_SIZE)
282 int xfs_dfork_size(xfs_dinode_t *dip, struct xfs_mount *mp, int w);
283 #define XFS_DFORK_SIZE(dip,mp,w) xfs_dfork_size(dip,mp,w)
285 #define XFS_DFORK_SIZE(dip,mp,w) XFS_CFORK_SIZE_DISK(&(dip)->di_core, mp, w)
290 * Macros for accessing per-fork disk inode information.
292 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DFORK_Q)
293 int xfs_dfork_q(xfs_dinode_t *dip);
294 #define XFS_DFORK_Q(dip) xfs_dfork_q(dip)
296 #define XFS_DFORK_Q(dip) XFS_CFORK_Q_DISK(&(dip)->di_core)
299 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DFORK_BOFF)
300 int xfs_dfork_boff(xfs_dinode_t *dip);
301 #define XFS_DFORK_BOFF(dip) xfs_dfork_boff(dip)
303 #define XFS_DFORK_BOFF(dip) XFS_CFORK_BOFF_DISK(&(dip)->di_core)
306 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DFORK_DPTR)
307 char *xfs_dfork_dptr(xfs_dinode_t *dip);
308 #define XFS_DFORK_DPTR(dip) xfs_dfork_dptr(dip)
310 #define XFS_DFORK_DPTR(dip) ((dip)->di_u.di_c)
313 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DFORK_APTR)
314 char *xfs_dfork_aptr(xfs_dinode_t *dip);
315 #define XFS_DFORK_APTR(dip) xfs_dfork_aptr(dip)
317 #define XFS_DFORK_APTR(dip) ((dip)->di_u.di_c + XFS_DFORK_BOFF(dip))
320 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DFORK_PTR)
321 char *xfs_dfork_ptr(xfs_dinode_t *dip, int w);
322 #define XFS_DFORK_PTR(dip,w) xfs_dfork_ptr(dip,w)
324 #define XFS_DFORK_PTR(dip,w) \
325 ((w) == XFS_DATA_FORK ? XFS_DFORK_DPTR(dip) : XFS_DFORK_APTR(dip))
328 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_CFORK_FORMAT)
329 int xfs_cfork_format(xfs_dinode_core_t *dcp, int w);
330 #define XFS_CFORK_FORMAT(dcp,w) xfs_cfork_format(dcp,w)
332 #define XFS_CFORK_FORMAT(dcp,w) \
333 ((w) == XFS_DATA_FORK ? (dcp)->di_format : (dcp)->di_aformat)
336 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_CFORK_FMT_SET)
337 void xfs_cfork_fmt_set(xfs_dinode_core_t *dcp, int w, int n);
338 #define XFS_CFORK_FMT_SET(dcp,w,n) xfs_cfork_fmt_set(dcp,w,n)
340 #define XFS_CFORK_FMT_SET(dcp,w,n) \
341 ((w) == XFS_DATA_FORK ? \
342 ((dcp)->di_format = (n)) : \
343 ((dcp)->di_aformat = (n)))
346 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_CFORK_NEXTENTS)
347 int xfs_cfork_nextents_disk(xfs_dinode_core_t *dcp, int w);
348 int xfs_cfork_nextents(xfs_dinode_core_t *dcp, int w);
349 #define XFS_CFORK_NEXTENTS_DISK(dcp,w) xfs_cfork_nextents_disk(dcp,w)
350 #define XFS_CFORK_NEXTENTS(dcp,w) xfs_cfork_nextents(dcp,w)
352 #define XFS_CFORK_NEXTENTS_DISK(dcp,w) \
353 ((w) == XFS_DATA_FORK ? \
354 INT_GET((dcp)->di_nextents, ARCH_CONVERT) : \
355 INT_GET((dcp)->di_anextents, ARCH_CONVERT))
356 #define XFS_CFORK_NEXTENTS(dcp,w) \
357 ((w) == XFS_DATA_FORK ? (dcp)->di_nextents : (dcp)->di_anextents)
360 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_CFORK_NEXT_SET)
361 void xfs_cfork_next_set(xfs_dinode_core_t *dcp, int w, int n);
362 #define XFS_CFORK_NEXT_SET(dcp,w,n) xfs_cfork_next_set(dcp,w,n)
364 #define XFS_CFORK_NEXT_SET(dcp,w,n) \
365 ((w) == XFS_DATA_FORK ? \
366 ((dcp)->di_nextents = (n)) : \
367 ((dcp)->di_anextents = (n)))
371 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DFORK_NEXTENTS)
372 int xfs_dfork_nextents(xfs_dinode_t *dip, int w);
373 #define XFS_DFORK_NEXTENTS(dip,w) xfs_dfork_nextents(dip,w)
375 #define XFS_DFORK_NEXTENTS(dip,w) XFS_CFORK_NEXTENTS_DISK(&(dip)->di_core, w)
378 #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_DINODE)
379 xfs_dinode_t *xfs_buf_to_dinode(struct xfs_buf *bp);
380 #define XFS_BUF_TO_DINODE(bp) xfs_buf_to_dinode(bp)
382 #define XFS_BUF_TO_DINODE(bp) ((xfs_dinode_t *)(XFS_BUF_PTR(bp)))
386 * Values for di_flags
387 * There should be a one-to-one correspondence between these flags and the
390 #define XFS_DIFLAG_REALTIME_BIT 0 /* file's blocks come from rt area */
391 #define XFS_DIFLAG_PREALLOC_BIT 1 /* file space has been preallocated */
392 #define XFS_DIFLAG_NEWRTBM_BIT 2 /* for rtbitmap inode, new format */
393 #define XFS_DIFLAG_IMMUTABLE_BIT 3 /* inode is immutable */
394 #define XFS_DIFLAG_APPEND_BIT 4 /* inode is append-only */
395 #define XFS_DIFLAG_SYNC_BIT 5 /* inode is written synchronously */
396 #define XFS_DIFLAG_NOATIME_BIT 6 /* do not update atime */
397 #define XFS_DIFLAG_NODUMP_BIT 7 /* do not dump */
398 #define XFS_DIFLAG_RTINHERIT_BIT 8 /* create with realtime bit set */
399 #define XFS_DIFLAG_PROJINHERIT_BIT 9 /* create with parents projid */
400 #define XFS_DIFLAG_NOSYMLINKS_BIT 10 /* disallow symlink creation */
401 #define XFS_DIFLAG_BARRIER_BIT 12 /* chroot() barrier */
402 #define XFS_DIFLAG_IUNLINK_BIT 13 /* immutable unlink */
404 #define XFS_DIFLAG_REALTIME (1 << XFS_DIFLAG_REALTIME_BIT)
405 #define XFS_DIFLAG_PREALLOC (1 << XFS_DIFLAG_PREALLOC_BIT)
406 #define XFS_DIFLAG_NEWRTBM (1 << XFS_DIFLAG_NEWRTBM_BIT)
407 #define XFS_DIFLAG_IMMUTABLE (1 << XFS_DIFLAG_IMMUTABLE_BIT)
408 #define XFS_DIFLAG_APPEND (1 << XFS_DIFLAG_APPEND_BIT)
409 #define XFS_DIFLAG_SYNC (1 << XFS_DIFLAG_SYNC_BIT)
410 #define XFS_DIFLAG_NOATIME (1 << XFS_DIFLAG_NOATIME_BIT)
411 #define XFS_DIFLAG_NODUMP (1 << XFS_DIFLAG_NODUMP_BIT)
412 #define XFS_DIFLAG_RTINHERIT (1 << XFS_DIFLAG_RTINHERIT_BIT)
413 #define XFS_DIFLAG_PROJINHERIT (1 << XFS_DIFLAG_PROJINHERIT_BIT)
414 #define XFS_DIFLAG_NOSYMLINKS (1 << XFS_DIFLAG_NOSYMLINKS_BIT)
415 #define XFS_DIFLAG_BARRIER (1 << XFS_DIFLAG_BARRIER_BIT)
416 #define XFS_DIFLAG_IUNLINK (1 << XFS_DIFLAG_IUNLINK_BIT)
419 #define XFS_DIFLAG_ANY \
420 (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
421 XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
422 XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
423 XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | \
424 XFS_DIFLAG_BARRIER | XFS_DIFLAG_IUNLINK)
426 #endif /* __XFS_DINODE_H__ */