blob: b33826961c458f794bdbe0f711014fb73bbac432 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18#ifndef __XFS_DINODE_H__
19#define __XFS_DINODE_H__
20
21struct xfs_buf;
22struct xfs_mount;
23
24#define XFS_DINODE_VERSION_1 1
25#define XFS_DINODE_VERSION_2 2
Nathan Scotta844f452005-11-02 14:38:42 +110026#define XFS_DINODE_GOOD_VERSION(v) \
27 (((v) == XFS_DINODE_VERSION_1 || (v) == XFS_DINODE_VERSION_2))
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#define XFS_DINODE_MAGIC 0x494e /* 'IN' */
29
30/*
31 * Disk inode structure.
32 * This is just the header; the inode is expanded to fill a variable size
33 * with the last field expanding. It is split into the core and "other"
34 * because we only need the core part in the in-core inode.
35 */
36typedef struct xfs_timestamp {
37 __int32_t t_sec; /* timestamp seconds */
38 __int32_t t_nsec; /* timestamp nanoseconds */
39} xfs_timestamp_t;
40
41/*
42 * Note: Coordinate changes to this structure with the XFS_DI_* #defines
43 * below and the offsets table in xfs_ialloc_log_di().
44 */
45typedef struct xfs_dinode_core
46{
47 __uint16_t di_magic; /* inode magic # = XFS_DINODE_MAGIC */
48 __uint16_t di_mode; /* mode and type of file */
49 __int8_t di_version; /* inode version */
50 __int8_t di_format; /* format of di_c data */
51 __uint16_t di_onlink; /* old number of links to file */
52 __uint32_t di_uid; /* owner's user id */
53 __uint32_t di_gid; /* owner's group id */
54 __uint32_t di_nlink; /* number of links to file */
55 __uint16_t di_projid; /* owner's project id */
56 __uint8_t di_pad[8]; /* unused, zeroed space */
57 __uint16_t di_flushiter; /* incremented on flush */
58 xfs_timestamp_t di_atime; /* time last accessed */
59 xfs_timestamp_t di_mtime; /* time last modified */
60 xfs_timestamp_t di_ctime; /* time created/inode modified */
61 xfs_fsize_t di_size; /* number of bytes in file */
62 xfs_drfsbno_t di_nblocks; /* # of direct & btree blocks used */
63 xfs_extlen_t di_extsize; /* basic/minimum extent size for file */
64 xfs_extnum_t di_nextents; /* number of extents in data fork */
65 xfs_aextnum_t di_anextents; /* number of extents in attribute fork*/
66 __uint8_t di_forkoff; /* attr fork offs, <<3 for 64b align */
67 __int8_t di_aformat; /* format of attr fork's data */
68 __uint32_t di_dmevmask; /* DMIG event mask */
69 __uint16_t di_dmstate; /* DMIG state info */
70 __uint16_t di_flags; /* random flags, XFS_DIFLAG_... */
71 __uint32_t di_gen; /* generation number */
72} xfs_dinode_core_t;
73
74#define DI_MAX_FLUSH 0xffff
75
76typedef struct xfs_dinode
77{
78 xfs_dinode_core_t di_core;
79 /*
80 * In adding anything between the core and the union, be
81 * sure to update the macros like XFS_LITINO below and
82 * XFS_BMAP_RBLOCK_DSIZE in xfs_bmap_btree.h.
83 */
84 xfs_agino_t di_next_unlinked;/* agi unlinked list ptr */
85 union {
86 xfs_bmdr_block_t di_bmbt; /* btree root block */
87 xfs_bmbt_rec_32_t di_bmx[1]; /* extent list */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 xfs_dir2_sf_t di_dir2sf; /* shortform directory v2 */
89 char di_c[1]; /* local contents */
90 xfs_dev_t di_dev; /* device for S_IFCHR/S_IFBLK */
91 uuid_t di_muuid; /* mount point value */
92 char di_symlink[1]; /* local symbolic link */
93 } di_u;
94 union {
95 xfs_bmdr_block_t di_abmbt; /* btree root block */
96 xfs_bmbt_rec_32_t di_abmx[1]; /* extent list */
97 xfs_attr_shortform_t di_attrsf; /* shortform attribute list */
98 } di_a;
99} xfs_dinode_t;
100
101/*
102 * The 32 bit link count in the inode theoretically maxes out at UINT_MAX.
103 * Since the pathconf interface is signed, we use 2^31 - 1 instead.
104 * The old inode format had a 16 bit link count, so its maximum is USHRT_MAX.
105 */
106#define XFS_MAXLINK ((1U << 31) - 1U)
107#define XFS_MAXLINK_1 65535U
108
109/*
110 * Bit names for logging disk inodes only
111 */
112#define XFS_DI_MAGIC 0x0000001
113#define XFS_DI_MODE 0x0000002
114#define XFS_DI_VERSION 0x0000004
115#define XFS_DI_FORMAT 0x0000008
116#define XFS_DI_ONLINK 0x0000010
117#define XFS_DI_UID 0x0000020
118#define XFS_DI_GID 0x0000040
119#define XFS_DI_NLINK 0x0000080
120#define XFS_DI_PROJID 0x0000100
121#define XFS_DI_PAD 0x0000200
122#define XFS_DI_ATIME 0x0000400
123#define XFS_DI_MTIME 0x0000800
124#define XFS_DI_CTIME 0x0001000
125#define XFS_DI_SIZE 0x0002000
126#define XFS_DI_NBLOCKS 0x0004000
127#define XFS_DI_EXTSIZE 0x0008000
128#define XFS_DI_NEXTENTS 0x0010000
129#define XFS_DI_NAEXTENTS 0x0020000
130#define XFS_DI_FORKOFF 0x0040000
131#define XFS_DI_AFORMAT 0x0080000
132#define XFS_DI_DMEVMASK 0x0100000
133#define XFS_DI_DMSTATE 0x0200000
134#define XFS_DI_FLAGS 0x0400000
135#define XFS_DI_GEN 0x0800000
136#define XFS_DI_NEXT_UNLINKED 0x1000000
137#define XFS_DI_U 0x2000000
138#define XFS_DI_A 0x4000000
139#define XFS_DI_NUM_BITS 27
140#define XFS_DI_ALL_BITS ((1 << XFS_DI_NUM_BITS) - 1)
141#define XFS_DI_CORE_BITS (XFS_DI_ALL_BITS & ~(XFS_DI_U|XFS_DI_A))
142
143/*
144 * Values for di_format
145 */
146typedef enum xfs_dinode_fmt
147{
148 XFS_DINODE_FMT_DEV, /* CHR, BLK: di_dev */
149 XFS_DINODE_FMT_LOCAL, /* DIR, REG: di_c */
150 /* LNK: di_symlink */
151 XFS_DINODE_FMT_EXTENTS, /* DIR, REG, LNK: di_bmx */
152 XFS_DINODE_FMT_BTREE, /* DIR, REG, LNK: di_bmbt */
153 XFS_DINODE_FMT_UUID /* MNT: di_uuid */
154} xfs_dinode_fmt_t;
155
156/*
157 * Inode minimum and maximum sizes.
158 */
159#define XFS_DINODE_MIN_LOG 8
160#define XFS_DINODE_MAX_LOG 11
161#define XFS_DINODE_MIN_SIZE (1 << XFS_DINODE_MIN_LOG)
162#define XFS_DINODE_MAX_SIZE (1 << XFS_DINODE_MAX_LOG)
163
164/*
165 * Inode size for given fs.
166 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167#define XFS_LITINO(mp) ((mp)->m_litino)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168#define XFS_BROOT_SIZE_ADJ \
169 (sizeof(xfs_bmbt_block_t) - sizeof(xfs_bmdr_block_t))
170
171/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 * Inode data & attribute fork sizes, per inode.
173 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174#define XFS_CFORK_Q(dcp) ((dcp)->di_forkoff != 0)
Nathan Scotta844f452005-11-02 14:38:42 +1100175#define XFS_CFORK_Q_DISK(dcp) ((dcp)->di_forkoff != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177#define XFS_CFORK_BOFF(dcp) ((int)((dcp)->di_forkoff << 3))
Nathan Scotta844f452005-11-02 14:38:42 +1100178#define XFS_CFORK_BOFF_DISK(dcp) \
179 ((int)(INT_GET((dcp)->di_forkoff, ARCH_CONVERT) << 3))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181#define XFS_CFORK_DSIZE_DISK(dcp,mp) \
182 (XFS_CFORK_Q_DISK(dcp) ? XFS_CFORK_BOFF_DISK(dcp) : XFS_LITINO(mp))
183#define XFS_CFORK_DSIZE(dcp,mp) \
184 (XFS_CFORK_Q(dcp) ? XFS_CFORK_BOFF(dcp) : XFS_LITINO(mp))
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186#define XFS_CFORK_ASIZE_DISK(dcp,mp) \
187 (XFS_CFORK_Q_DISK(dcp) ? XFS_LITINO(mp) - XFS_CFORK_BOFF_DISK(dcp) : 0)
188#define XFS_CFORK_ASIZE(dcp,mp) \
189 (XFS_CFORK_Q(dcp) ? XFS_LITINO(mp) - XFS_CFORK_BOFF(dcp) : 0)
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191#define XFS_CFORK_SIZE_DISK(dcp,mp,w) \
192 ((w) == XFS_DATA_FORK ? \
193 XFS_CFORK_DSIZE_DISK(dcp, mp) : \
194 XFS_CFORK_ASIZE_DISK(dcp, mp))
195#define XFS_CFORK_SIZE(dcp,mp,w) \
196 ((w) == XFS_DATA_FORK ? \
197 XFS_CFORK_DSIZE(dcp, mp) : XFS_CFORK_ASIZE(dcp, mp))
198
Nathan Scotta844f452005-11-02 14:38:42 +1100199#define XFS_DFORK_DSIZE(dip,mp) \
200 XFS_CFORK_DSIZE_DISK(&(dip)->di_core, mp)
Nathan Scott3ddb8fa2006-01-11 15:33:02 +1100201#define XFS_DFORK_DSIZE_HOST(dip,mp) \
202 XFS_CFORK_DSIZE(&(dip)->di_core, mp)
Nathan Scotta844f452005-11-02 14:38:42 +1100203#define XFS_DFORK_ASIZE(dip,mp) \
204 XFS_CFORK_ASIZE_DISK(&(dip)->di_core, mp)
Nathan Scott3ddb8fa2006-01-11 15:33:02 +1100205#define XFS_DFORK_ASIZE_HOST(dip,mp) \
206 XFS_CFORK_ASIZE(&(dip)->di_core, mp)
Nathan Scotta844f452005-11-02 14:38:42 +1100207#define XFS_DFORK_SIZE(dip,mp,w) \
208 XFS_CFORK_SIZE_DISK(&(dip)->di_core, mp, w)
Nathan Scott3ddb8fa2006-01-11 15:33:02 +1100209#define XFS_DFORK_SIZE_HOST(dip,mp,w) \
210 XFS_CFORK_SIZE(&(dip)->di_core, mp, w)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212#define XFS_DFORK_Q(dip) XFS_CFORK_Q_DISK(&(dip)->di_core)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213#define XFS_DFORK_BOFF(dip) XFS_CFORK_BOFF_DISK(&(dip)->di_core)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214#define XFS_DFORK_DPTR(dip) ((dip)->di_u.di_c)
Nathan Scotta844f452005-11-02 14:38:42 +1100215#define XFS_DFORK_APTR(dip) \
216 ((dip)->di_u.di_c + XFS_DFORK_BOFF(dip))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217#define XFS_DFORK_PTR(dip,w) \
218 ((w) == XFS_DATA_FORK ? XFS_DFORK_DPTR(dip) : XFS_DFORK_APTR(dip))
Nathan Scotta844f452005-11-02 14:38:42 +1100219#define XFS_CFORK_FORMAT(dcp,w) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 ((w) == XFS_DATA_FORK ? (dcp)->di_format : (dcp)->di_aformat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221#define XFS_CFORK_FMT_SET(dcp,w,n) \
222 ((w) == XFS_DATA_FORK ? \
Nathan Scotta844f452005-11-02 14:38:42 +1100223 ((dcp)->di_format = (n)) : ((dcp)->di_aformat = (n)))
Nathan Scott3ddb8fa2006-01-11 15:33:02 +1100224#define XFS_DFORK_FORMAT(dip,w) XFS_CFORK_FORMAT(&(dip)->di_core, w)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226#define XFS_CFORK_NEXTENTS_DISK(dcp,w) \
227 ((w) == XFS_DATA_FORK ? \
228 INT_GET((dcp)->di_nextents, ARCH_CONVERT) : \
229 INT_GET((dcp)->di_anextents, ARCH_CONVERT))
230#define XFS_CFORK_NEXTENTS(dcp,w) \
231 ((w) == XFS_DATA_FORK ? (dcp)->di_nextents : (dcp)->di_anextents)
Nathan Scott3ddb8fa2006-01-11 15:33:02 +1100232#define XFS_DFORK_NEXTENTS(dip,w) XFS_CFORK_NEXTENTS_DISK(&(dip)->di_core, w)
233#define XFS_DFORK_NEXTENTS_HOST(dip,w) XFS_CFORK_NEXTENTS(&(dip)->di_core, w)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235#define XFS_CFORK_NEXT_SET(dcp,w,n) \
236 ((w) == XFS_DATA_FORK ? \
Nathan Scotta844f452005-11-02 14:38:42 +1100237 ((dcp)->di_nextents = (n)) : ((dcp)->di_anextents = (n)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Nathan Scotta844f452005-11-02 14:38:42 +1100239#define XFS_BUF_TO_DINODE(bp) ((xfs_dinode_t *)XFS_BUF_PTR(bp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241/*
242 * Values for di_flags
243 * There should be a one-to-one correspondence between these flags and the
244 * XFS_XFLAG_s.
245 */
246#define XFS_DIFLAG_REALTIME_BIT 0 /* file's blocks come from rt area */
247#define XFS_DIFLAG_PREALLOC_BIT 1 /* file space has been preallocated */
248#define XFS_DIFLAG_NEWRTBM_BIT 2 /* for rtbitmap inode, new format */
249#define XFS_DIFLAG_IMMUTABLE_BIT 3 /* inode is immutable */
250#define XFS_DIFLAG_APPEND_BIT 4 /* inode is append-only */
251#define XFS_DIFLAG_SYNC_BIT 5 /* inode is written synchronously */
252#define XFS_DIFLAG_NOATIME_BIT 6 /* do not update atime */
253#define XFS_DIFLAG_NODUMP_BIT 7 /* do not dump */
254#define XFS_DIFLAG_RTINHERIT_BIT 8 /* create with realtime bit set */
Nathan Scottdd9f4382006-01-11 15:28:28 +1100255#define XFS_DIFLAG_PROJINHERIT_BIT 9 /* create with parents projid */
256#define XFS_DIFLAG_NOSYMLINKS_BIT 10 /* disallow symlink creation */
257#define XFS_DIFLAG_EXTSIZE_BIT 11 /* inode extent size allocator hint */
258#define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
Barry Naujokd3446ea2006-06-09 14:54:19 +1000259#define XFS_DIFLAG_NODEFRAG_BIT 13 /* do not reorganize/defragment */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260#define XFS_DIFLAG_REALTIME (1 << XFS_DIFLAG_REALTIME_BIT)
261#define XFS_DIFLAG_PREALLOC (1 << XFS_DIFLAG_PREALLOC_BIT)
262#define XFS_DIFLAG_NEWRTBM (1 << XFS_DIFLAG_NEWRTBM_BIT)
263#define XFS_DIFLAG_IMMUTABLE (1 << XFS_DIFLAG_IMMUTABLE_BIT)
264#define XFS_DIFLAG_APPEND (1 << XFS_DIFLAG_APPEND_BIT)
265#define XFS_DIFLAG_SYNC (1 << XFS_DIFLAG_SYNC_BIT)
266#define XFS_DIFLAG_NOATIME (1 << XFS_DIFLAG_NOATIME_BIT)
267#define XFS_DIFLAG_NODUMP (1 << XFS_DIFLAG_NODUMP_BIT)
268#define XFS_DIFLAG_RTINHERIT (1 << XFS_DIFLAG_RTINHERIT_BIT)
269#define XFS_DIFLAG_PROJINHERIT (1 << XFS_DIFLAG_PROJINHERIT_BIT)
270#define XFS_DIFLAG_NOSYMLINKS (1 << XFS_DIFLAG_NOSYMLINKS_BIT)
Nathan Scottdd9f4382006-01-11 15:28:28 +1100271#define XFS_DIFLAG_EXTSIZE (1 << XFS_DIFLAG_EXTSIZE_BIT)
272#define XFS_DIFLAG_EXTSZINHERIT (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
Barry Naujokd3446ea2006-06-09 14:54:19 +1000273#define XFS_DIFLAG_NODEFRAG (1 << XFS_DIFLAG_NODEFRAG_BIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
275#define XFS_DIFLAG_ANY \
276 (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
277 XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
278 XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
Nathan Scottdd9f4382006-01-11 15:28:28 +1100279 XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
Barry Naujokd3446ea2006-06-09 14:54:19 +1000280 XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
282#endif /* __XFS_DINODE_H__ */