blob: d7cf392cc8526ae2b1b79d3b022570f04ae30119 [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 {
Christoph Hellwig347d1c02007-08-28 13:57:51 +100037 __be32 t_sec; /* timestamp seconds */
38 __be32 t_nsec; /* timestamp nanoseconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -070039} xfs_timestamp_t;
40
41/*
42 * Note: Coordinate changes to this structure with the XFS_DI_* #defines
Christoph Hellwig347d1c02007-08-28 13:57:51 +100043 * below, the offsets table in xfs_ialloc_log_di() and struct xfs_icdinode
44 * in xfs_inode.h.
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 */
Christoph Hellwig347d1c02007-08-28 13:57:51 +100046typedef struct xfs_dinode_core {
47 __be16 di_magic; /* inode magic # = XFS_DINODE_MAGIC */
48 __be16 di_mode; /* mode and type of file */
49 __u8 di_version; /* inode version */
50 __u8 di_format; /* format of di_c data */
51 __be16 di_onlink; /* old number of links to file */
52 __be32 di_uid; /* owner's user id */
53 __be32 di_gid; /* owner's group id */
54 __be32 di_nlink; /* number of links to file */
55 __be16 di_projid; /* owner's project id */
56 __u8 di_pad[8]; /* unused, zeroed space */
57 __be16 di_flushiter; /* incremented on flush */
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 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 */
Christoph Hellwig347d1c02007-08-28 13:57:51 +100061 __be64 di_size; /* number of bytes in file */
62 __be64 di_nblocks; /* # of direct & btree blocks used */
63 __be32 di_extsize; /* basic/minimum extent size for file */
64 __be32 di_nextents; /* number of extents in data fork */
65 __be16 di_anextents; /* number of extents in attribute fork*/
66 __u8 di_forkoff; /* attr fork offs, <<3 for 64b align */
67 __s8 di_aformat; /* format of attr fork's data */
68 __be32 di_dmevmask; /* DMIG event mask */
69 __be16 di_dmstate; /* DMIG state info */
70 __be16 di_flags; /* random flags, XFS_DIFLAG_... */
71 __be32 di_gen; /* generation number */
Linus Torvalds1da177e2005-04-16 15:20:36 -070072} 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
Christoph Hellwig60197e82008-10-30 17:11:19 +110081 * sure to update the macros like XFS_LITINO below.
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 */
Christoph Hellwig347d1c02007-08-28 13:57:51 +100083 __be32 di_next_unlinked;/* agi unlinked list ptr */
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 union {
85 xfs_bmdr_block_t di_bmbt; /* btree root block */
86 xfs_bmbt_rec_32_t di_bmx[1]; /* extent list */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 xfs_dir2_sf_t di_dir2sf; /* shortform directory v2 */
88 char di_c[1]; /* local contents */
Christoph Hellwig347d1c02007-08-28 13:57:51 +100089 __be32 di_dev; /* device for S_IFCHR/S_IFBLK */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 uuid_t di_muuid; /* mount point value */
91 char di_symlink[1]; /* local symbolic link */
92 } di_u;
93 union {
94 xfs_bmdr_block_t di_abmbt; /* btree root block */
95 xfs_bmbt_rec_32_t di_abmx[1]; /* extent list */
96 xfs_attr_shortform_t di_attrsf; /* shortform attribute list */
97 } di_a;
98} xfs_dinode_t;
99
100/*
101 * The 32 bit link count in the inode theoretically maxes out at UINT_MAX.
102 * Since the pathconf interface is signed, we use 2^31 - 1 instead.
103 * The old inode format had a 16 bit link count, so its maximum is USHRT_MAX.
104 */
105#define XFS_MAXLINK ((1U << 31) - 1U)
106#define XFS_MAXLINK_1 65535U
107
108/*
109 * Bit names for logging disk inodes only
110 */
111#define XFS_DI_MAGIC 0x0000001
112#define XFS_DI_MODE 0x0000002
113#define XFS_DI_VERSION 0x0000004
114#define XFS_DI_FORMAT 0x0000008
115#define XFS_DI_ONLINK 0x0000010
116#define XFS_DI_UID 0x0000020
117#define XFS_DI_GID 0x0000040
118#define XFS_DI_NLINK 0x0000080
119#define XFS_DI_PROJID 0x0000100
120#define XFS_DI_PAD 0x0000200
121#define XFS_DI_ATIME 0x0000400
122#define XFS_DI_MTIME 0x0000800
123#define XFS_DI_CTIME 0x0001000
124#define XFS_DI_SIZE 0x0002000
125#define XFS_DI_NBLOCKS 0x0004000
126#define XFS_DI_EXTSIZE 0x0008000
127#define XFS_DI_NEXTENTS 0x0010000
128#define XFS_DI_NAEXTENTS 0x0020000
129#define XFS_DI_FORKOFF 0x0040000
130#define XFS_DI_AFORMAT 0x0080000
131#define XFS_DI_DMEVMASK 0x0100000
132#define XFS_DI_DMSTATE 0x0200000
133#define XFS_DI_FLAGS 0x0400000
134#define XFS_DI_GEN 0x0800000
135#define XFS_DI_NEXT_UNLINKED 0x1000000
136#define XFS_DI_U 0x2000000
137#define XFS_DI_A 0x4000000
138#define XFS_DI_NUM_BITS 27
139#define XFS_DI_ALL_BITS ((1 << XFS_DI_NUM_BITS) - 1)
140#define XFS_DI_CORE_BITS (XFS_DI_ALL_BITS & ~(XFS_DI_U|XFS_DI_A))
141
142/*
143 * Values for di_format
144 */
145typedef enum xfs_dinode_fmt
146{
147 XFS_DINODE_FMT_DEV, /* CHR, BLK: di_dev */
148 XFS_DINODE_FMT_LOCAL, /* DIR, REG: di_c */
149 /* LNK: di_symlink */
150 XFS_DINODE_FMT_EXTENTS, /* DIR, REG, LNK: di_bmx */
151 XFS_DINODE_FMT_BTREE, /* DIR, REG, LNK: di_bmbt */
152 XFS_DINODE_FMT_UUID /* MNT: di_uuid */
153} xfs_dinode_fmt_t;
154
155/*
156 * Inode minimum and maximum sizes.
157 */
158#define XFS_DINODE_MIN_LOG 8
159#define XFS_DINODE_MAX_LOG 11
160#define XFS_DINODE_MIN_SIZE (1 << XFS_DINODE_MIN_LOG)
161#define XFS_DINODE_MAX_SIZE (1 << XFS_DINODE_MAX_LOG)
162
163/*
164 * Inode size for given fs.
165 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166#define XFS_LITINO(mp) ((mp)->m_litino)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167#define XFS_BROOT_SIZE_ADJ \
Christoph Hellwig7cc95a82008-10-30 17:14:34 +1100168 (XFS_BTREE_LBLOCK_LEN - sizeof(xfs_bmdr_block_t))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 * Inode data & attribute fork sizes, per inode.
172 */
Christoph Hellwig45ba5982007-12-07 14:07:20 +1100173#define XFS_DFORK_Q(dip) ((dip)->di_core.di_forkoff != 0)
174#define XFS_DFORK_BOFF(dip) ((int)((dip)->di_core.di_forkoff << 3))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Nathan Scotta844f452005-11-02 14:38:42 +1100176#define XFS_DFORK_DSIZE(dip,mp) \
Christoph Hellwig45ba5982007-12-07 14:07:20 +1100177 (XFS_DFORK_Q(dip) ? \
178 XFS_DFORK_BOFF(dip) : \
179 XFS_LITINO(mp))
Nathan Scotta844f452005-11-02 14:38:42 +1100180#define XFS_DFORK_ASIZE(dip,mp) \
Christoph Hellwig45ba5982007-12-07 14:07:20 +1100181 (XFS_DFORK_Q(dip) ? \
182 XFS_LITINO(mp) - XFS_DFORK_BOFF(dip) : \
183 0)
184#define XFS_DFORK_SIZE(dip,mp,w) \
185 ((w) == XFS_DATA_FORK ? \
186 XFS_DFORK_DSIZE(dip, mp) : \
187 XFS_DFORK_ASIZE(dip, mp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Christoph Hellwig45ba5982007-12-07 14:07:20 +1100189#define XFS_DFORK_DPTR(dip) ((dip)->di_u.di_c)
190#define XFS_DFORK_APTR(dip) \
Nathan Scotta844f452005-11-02 14:38:42 +1100191 ((dip)->di_u.di_c + XFS_DFORK_BOFF(dip))
Christoph Hellwig45ba5982007-12-07 14:07:20 +1100192#define XFS_DFORK_PTR(dip,w) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 ((w) == XFS_DATA_FORK ? XFS_DFORK_DPTR(dip) : XFS_DFORK_APTR(dip))
Christoph Hellwig45ba5982007-12-07 14:07:20 +1100194#define XFS_DFORK_FORMAT(dip,w) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 ((w) == XFS_DATA_FORK ? \
Christoph Hellwig45ba5982007-12-07 14:07:20 +1100196 (dip)->di_core.di_format : \
197 (dip)->di_core.di_aformat)
198#define XFS_DFORK_NEXTENTS(dip,w) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 ((w) == XFS_DATA_FORK ? \
Christoph Hellwig45ba5982007-12-07 14:07:20 +1100200 be32_to_cpu((dip)->di_core.di_nextents) : \
201 be16_to_cpu((dip)->di_core.di_anextents))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Nathan Scotta844f452005-11-02 14:38:42 +1100203#define XFS_BUF_TO_DINODE(bp) ((xfs_dinode_t *)XFS_BUF_PTR(bp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205/*
206 * Values for di_flags
207 * There should be a one-to-one correspondence between these flags and the
208 * XFS_XFLAG_s.
209 */
210#define XFS_DIFLAG_REALTIME_BIT 0 /* file's blocks come from rt area */
211#define XFS_DIFLAG_PREALLOC_BIT 1 /* file space has been preallocated */
212#define XFS_DIFLAG_NEWRTBM_BIT 2 /* for rtbitmap inode, new format */
213#define XFS_DIFLAG_IMMUTABLE_BIT 3 /* inode is immutable */
214#define XFS_DIFLAG_APPEND_BIT 4 /* inode is append-only */
215#define XFS_DIFLAG_SYNC_BIT 5 /* inode is written synchronously */
216#define XFS_DIFLAG_NOATIME_BIT 6 /* do not update atime */
217#define XFS_DIFLAG_NODUMP_BIT 7 /* do not dump */
218#define XFS_DIFLAG_RTINHERIT_BIT 8 /* create with realtime bit set */
Nathan Scottdd9f4382006-01-11 15:28:28 +1100219#define XFS_DIFLAG_PROJINHERIT_BIT 9 /* create with parents projid */
220#define XFS_DIFLAG_NOSYMLINKS_BIT 10 /* disallow symlink creation */
221#define XFS_DIFLAG_EXTSIZE_BIT 11 /* inode extent size allocator hint */
222#define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
Barry Naujokd3446ea2006-06-09 14:54:19 +1000223#define XFS_DIFLAG_NODEFRAG_BIT 13 /* do not reorganize/defragment */
David Chinner2a82b8b2007-07-11 11:09:12 +1000224#define XFS_DIFLAG_FILESTREAM_BIT 14 /* use filestream allocator */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225#define XFS_DIFLAG_REALTIME (1 << XFS_DIFLAG_REALTIME_BIT)
226#define XFS_DIFLAG_PREALLOC (1 << XFS_DIFLAG_PREALLOC_BIT)
227#define XFS_DIFLAG_NEWRTBM (1 << XFS_DIFLAG_NEWRTBM_BIT)
228#define XFS_DIFLAG_IMMUTABLE (1 << XFS_DIFLAG_IMMUTABLE_BIT)
229#define XFS_DIFLAG_APPEND (1 << XFS_DIFLAG_APPEND_BIT)
230#define XFS_DIFLAG_SYNC (1 << XFS_DIFLAG_SYNC_BIT)
231#define XFS_DIFLAG_NOATIME (1 << XFS_DIFLAG_NOATIME_BIT)
232#define XFS_DIFLAG_NODUMP (1 << XFS_DIFLAG_NODUMP_BIT)
233#define XFS_DIFLAG_RTINHERIT (1 << XFS_DIFLAG_RTINHERIT_BIT)
234#define XFS_DIFLAG_PROJINHERIT (1 << XFS_DIFLAG_PROJINHERIT_BIT)
235#define XFS_DIFLAG_NOSYMLINKS (1 << XFS_DIFLAG_NOSYMLINKS_BIT)
Nathan Scottdd9f4382006-01-11 15:28:28 +1100236#define XFS_DIFLAG_EXTSIZE (1 << XFS_DIFLAG_EXTSIZE_BIT)
237#define XFS_DIFLAG_EXTSZINHERIT (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
Barry Naujokd3446ea2006-06-09 14:54:19 +1000238#define XFS_DIFLAG_NODEFRAG (1 << XFS_DIFLAG_NODEFRAG_BIT)
David Chinner2a82b8b2007-07-11 11:09:12 +1000239#define XFS_DIFLAG_FILESTREAM (1 << XFS_DIFLAG_FILESTREAM_BIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Eric Sandeen71ddabb2007-11-23 16:29:42 +1100241#ifdef CONFIG_XFS_RT
242#define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
243#else
244#define XFS_IS_REALTIME_INODE(ip) (0)
245#endif
246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247#define XFS_DIFLAG_ANY \
248 (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
249 XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
250 XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
Nathan Scottdd9f4382006-01-11 15:28:28 +1100251 XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
David Chinner2a82b8b2007-07-11 11:09:12 +1000252 XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254#endif /* __XFS_DINODE_H__ */