blob: dffba9ba0db634c29b1bc012b4f54923cda76c55 [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
Christoph Hellwig51ce16d2008-11-28 14:23:39 +110021#define XFS_DINODE_MAGIC 0x494e /* 'IN' */
22#define XFS_DINODE_GOOD_VERSION(v) (((v) == 1 || (v) == 2))
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024typedef struct xfs_timestamp {
Christoph Hellwig347d1c02007-08-28 13:57:51 +100025 __be32 t_sec; /* timestamp seconds */
26 __be32 t_nsec; /* timestamp nanoseconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -070027} xfs_timestamp_t;
28
29/*
Christoph Hellwig81591fe2008-11-28 14:23:39 +110030 * On-disk inode structure.
31 *
32 * This is just the header or "dinode core", the inode is expanded to fill a
33 * variable size the leftover area split into a data and an attribute fork.
34 * The format of the data and attribute fork depends on the format of the
35 * inode as indicated by di_format and di_aformat. To access the data and
36 * attribute use the XFS_DFORK_PTR, XFS_DFORK_DPTR, and XFS_DFORK_PTR macros
37 * below.
38 *
39 * There is a very similar struct icdinode in xfs_inode which matches the
40 * layout of the first 96 bytes of this structure, but is kept in native
41 * format instead of big endian.
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 */
Christoph Hellwig81591fe2008-11-28 14:23:39 +110043typedef struct xfs_dinode {
Christoph Hellwig347d1c02007-08-28 13:57:51 +100044 __be16 di_magic; /* inode magic # = XFS_DINODE_MAGIC */
45 __be16 di_mode; /* mode and type of file */
46 __u8 di_version; /* inode version */
47 __u8 di_format; /* format of di_c data */
48 __be16 di_onlink; /* old number of links to file */
49 __be32 di_uid; /* owner's user id */
50 __be32 di_gid; /* owner's group id */
51 __be32 di_nlink; /* number of links to file */
Arkadiusz Mi?kiewicz67430992010-09-26 06:10:18 +000052 __be16 di_projid_lo; /* lower part of owner's project id */
53 __be16 di_projid_hi; /* higher part owner's project id */
54 __u8 di_pad[6]; /* unused, zeroed space */
Christoph Hellwig347d1c02007-08-28 13:57:51 +100055 __be16 di_flushiter; /* incremented on flush */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 xfs_timestamp_t di_atime; /* time last accessed */
57 xfs_timestamp_t di_mtime; /* time last modified */
58 xfs_timestamp_t di_ctime; /* time created/inode modified */
Christoph Hellwig347d1c02007-08-28 13:57:51 +100059 __be64 di_size; /* number of bytes in file */
60 __be64 di_nblocks; /* # of direct & btree blocks used */
61 __be32 di_extsize; /* basic/minimum extent size for file */
62 __be32 di_nextents; /* number of extents in data fork */
63 __be16 di_anextents; /* number of extents in attribute fork*/
64 __u8 di_forkoff; /* attr fork offs, <<3 for 64b align */
65 __s8 di_aformat; /* format of attr fork's data */
66 __be32 di_dmevmask; /* DMIG event mask */
67 __be16 di_dmstate; /* DMIG state info */
68 __be16 di_flags; /* random flags, XFS_DIFLAG_... */
69 __be32 di_gen; /* generation number */
Christoph Hellwig81591fe2008-11-28 14:23:39 +110070
71 /* di_next_unlinked is the only non-core field in the old dinode */
72 __be32 di_next_unlinked;/* agi unlinked list ptr */
73} __attribute__((packed)) xfs_dinode_t;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75#define DI_MAX_FLUSH 0xffff
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077/*
78 * The 32 bit link count in the inode theoretically maxes out at UINT_MAX.
79 * Since the pathconf interface is signed, we use 2^31 - 1 instead.
80 * The old inode format had a 16 bit link count, so its maximum is USHRT_MAX.
81 */
82#define XFS_MAXLINK ((1U << 31) - 1U)
83#define XFS_MAXLINK_1 65535U
84
85/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 * Values for di_format
87 */
Christoph Hellwig81591fe2008-11-28 14:23:39 +110088typedef enum xfs_dinode_fmt {
89 XFS_DINODE_FMT_DEV, /* xfs_dev_t */
90 XFS_DINODE_FMT_LOCAL, /* bulk data */
91 XFS_DINODE_FMT_EXTENTS, /* struct xfs_bmbt_rec */
92 XFS_DINODE_FMT_BTREE, /* struct xfs_bmdr_block */
93 XFS_DINODE_FMT_UUID /* uuid_t */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094} xfs_dinode_fmt_t;
95
96/*
97 * Inode minimum and maximum sizes.
98 */
99#define XFS_DINODE_MIN_LOG 8
100#define XFS_DINODE_MAX_LOG 11
101#define XFS_DINODE_MIN_SIZE (1 << XFS_DINODE_MIN_LOG)
102#define XFS_DINODE_MAX_SIZE (1 << XFS_DINODE_MAX_LOG)
103
104/*
105 * Inode size for given fs.
106 */
Christoph Hellwig6447c362009-03-29 09:51:14 +0200107#define XFS_LITINO(mp) \
108 ((int)(((mp)->m_sb.sb_inodesize) - sizeof(struct xfs_dinode)))
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#define XFS_BROOT_SIZE_ADJ \
Christoph Hellwig7cc95a82008-10-30 17:14:34 +1100111 (XFS_BTREE_LBLOCK_LEN - sizeof(xfs_bmdr_block_t))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 * Inode data & attribute fork sizes, per inode.
115 */
Christoph Hellwig81591fe2008-11-28 14:23:39 +1100116#define XFS_DFORK_Q(dip) ((dip)->di_forkoff != 0)
117#define XFS_DFORK_BOFF(dip) ((int)((dip)->di_forkoff << 3))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Nathan Scotta844f452005-11-02 14:38:42 +1100119#define XFS_DFORK_DSIZE(dip,mp) \
Christoph Hellwig45ba5982007-12-07 14:07:20 +1100120 (XFS_DFORK_Q(dip) ? \
121 XFS_DFORK_BOFF(dip) : \
122 XFS_LITINO(mp))
Nathan Scotta844f452005-11-02 14:38:42 +1100123#define XFS_DFORK_ASIZE(dip,mp) \
Christoph Hellwig45ba5982007-12-07 14:07:20 +1100124 (XFS_DFORK_Q(dip) ? \
125 XFS_LITINO(mp) - XFS_DFORK_BOFF(dip) : \
126 0)
127#define XFS_DFORK_SIZE(dip,mp,w) \
128 ((w) == XFS_DATA_FORK ? \
129 XFS_DFORK_DSIZE(dip, mp) : \
130 XFS_DFORK_ASIZE(dip, mp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Christoph Hellwig81591fe2008-11-28 14:23:39 +1100132/*
133 * Return pointers to the data or attribute forks.
134 */
135#define XFS_DFORK_DPTR(dip) \
136 ((char *)(dip) + sizeof(struct xfs_dinode))
Christoph Hellwig45ba5982007-12-07 14:07:20 +1100137#define XFS_DFORK_APTR(dip) \
Christoph Hellwig81591fe2008-11-28 14:23:39 +1100138 (XFS_DFORK_DPTR(dip) + XFS_DFORK_BOFF(dip))
Christoph Hellwig45ba5982007-12-07 14:07:20 +1100139#define XFS_DFORK_PTR(dip,w) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 ((w) == XFS_DATA_FORK ? XFS_DFORK_DPTR(dip) : XFS_DFORK_APTR(dip))
Christoph Hellwig81591fe2008-11-28 14:23:39 +1100141
Christoph Hellwig45ba5982007-12-07 14:07:20 +1100142#define XFS_DFORK_FORMAT(dip,w) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 ((w) == XFS_DATA_FORK ? \
Christoph Hellwig81591fe2008-11-28 14:23:39 +1100144 (dip)->di_format : \
145 (dip)->di_aformat)
Christoph Hellwig45ba5982007-12-07 14:07:20 +1100146#define XFS_DFORK_NEXTENTS(dip,w) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 ((w) == XFS_DATA_FORK ? \
Christoph Hellwig81591fe2008-11-28 14:23:39 +1100148 be32_to_cpu((dip)->di_nextents) : \
149 be16_to_cpu((dip)->di_anextents))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Nathan Scotta844f452005-11-02 14:38:42 +1100151#define XFS_BUF_TO_DINODE(bp) ((xfs_dinode_t *)XFS_BUF_PTR(bp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153/*
Christoph Hellwig81591fe2008-11-28 14:23:39 +1100154 * For block and character special files the 32bit dev_t is stored at the
155 * beginning of the data fork.
156 */
157static inline xfs_dev_t xfs_dinode_get_rdev(struct xfs_dinode *dip)
158{
159 return be32_to_cpu(*(__be32 *)XFS_DFORK_DPTR(dip));
160}
161
162static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
163{
164 *(__be32 *)XFS_DFORK_DPTR(dip) = cpu_to_be32(rdev);
165}
166
167/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 * Values for di_flags
169 * There should be a one-to-one correspondence between these flags and the
170 * XFS_XFLAG_s.
171 */
172#define XFS_DIFLAG_REALTIME_BIT 0 /* file's blocks come from rt area */
173#define XFS_DIFLAG_PREALLOC_BIT 1 /* file space has been preallocated */
174#define XFS_DIFLAG_NEWRTBM_BIT 2 /* for rtbitmap inode, new format */
175#define XFS_DIFLAG_IMMUTABLE_BIT 3 /* inode is immutable */
176#define XFS_DIFLAG_APPEND_BIT 4 /* inode is append-only */
177#define XFS_DIFLAG_SYNC_BIT 5 /* inode is written synchronously */
178#define XFS_DIFLAG_NOATIME_BIT 6 /* do not update atime */
179#define XFS_DIFLAG_NODUMP_BIT 7 /* do not dump */
180#define XFS_DIFLAG_RTINHERIT_BIT 8 /* create with realtime bit set */
Nathan Scottdd9f4382006-01-11 15:28:28 +1100181#define XFS_DIFLAG_PROJINHERIT_BIT 9 /* create with parents projid */
182#define XFS_DIFLAG_NOSYMLINKS_BIT 10 /* disallow symlink creation */
183#define XFS_DIFLAG_EXTSIZE_BIT 11 /* inode extent size allocator hint */
184#define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
Barry Naujokd3446ea2006-06-09 14:54:19 +1000185#define XFS_DIFLAG_NODEFRAG_BIT 13 /* do not reorganize/defragment */
David Chinner2a82b8b2007-07-11 11:09:12 +1000186#define XFS_DIFLAG_FILESTREAM_BIT 14 /* use filestream allocator */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187#define XFS_DIFLAG_REALTIME (1 << XFS_DIFLAG_REALTIME_BIT)
188#define XFS_DIFLAG_PREALLOC (1 << XFS_DIFLAG_PREALLOC_BIT)
189#define XFS_DIFLAG_NEWRTBM (1 << XFS_DIFLAG_NEWRTBM_BIT)
190#define XFS_DIFLAG_IMMUTABLE (1 << XFS_DIFLAG_IMMUTABLE_BIT)
191#define XFS_DIFLAG_APPEND (1 << XFS_DIFLAG_APPEND_BIT)
192#define XFS_DIFLAG_SYNC (1 << XFS_DIFLAG_SYNC_BIT)
193#define XFS_DIFLAG_NOATIME (1 << XFS_DIFLAG_NOATIME_BIT)
194#define XFS_DIFLAG_NODUMP (1 << XFS_DIFLAG_NODUMP_BIT)
195#define XFS_DIFLAG_RTINHERIT (1 << XFS_DIFLAG_RTINHERIT_BIT)
196#define XFS_DIFLAG_PROJINHERIT (1 << XFS_DIFLAG_PROJINHERIT_BIT)
197#define XFS_DIFLAG_NOSYMLINKS (1 << XFS_DIFLAG_NOSYMLINKS_BIT)
Nathan Scottdd9f4382006-01-11 15:28:28 +1100198#define XFS_DIFLAG_EXTSIZE (1 << XFS_DIFLAG_EXTSIZE_BIT)
199#define XFS_DIFLAG_EXTSZINHERIT (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
Barry Naujokd3446ea2006-06-09 14:54:19 +1000200#define XFS_DIFLAG_NODEFRAG (1 << XFS_DIFLAG_NODEFRAG_BIT)
David Chinner2a82b8b2007-07-11 11:09:12 +1000201#define XFS_DIFLAG_FILESTREAM (1 << XFS_DIFLAG_FILESTREAM_BIT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Eric Sandeen71ddabb2007-11-23 16:29:42 +1100203#ifdef CONFIG_XFS_RT
204#define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
205#else
206#define XFS_IS_REALTIME_INODE(ip) (0)
207#endif
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209#define XFS_DIFLAG_ANY \
210 (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
211 XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
212 XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
Nathan Scottdd9f4382006-01-11 15:28:28 +1100213 XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
David Chinner2a82b8b2007-07-11 11:09:12 +1000214 XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216#endif /* __XFS_DINODE_H__ */