Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
7b718769 NS |
2 | * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
1da177e4 | 4 | * |
7b718769 NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
1da177e4 LT |
7 | * published by the Free Software Foundation. |
8 | * | |
7b718769 NS |
9 | * 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. | |
1da177e4 | 13 | * |
7b718769 NS |
14 | * 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 | |
1da177e4 LT |
17 | */ |
18 | #ifndef __XFS_DINODE_H__ | |
19 | #define __XFS_DINODE_H__ | |
20 | ||
51ce16d5 CH |
21 | #define XFS_DINODE_MAGIC 0x494e /* 'IN' */ |
22 | #define XFS_DINODE_GOOD_VERSION(v) (((v) == 1 || (v) == 2)) | |
1da177e4 | 23 | |
1da177e4 | 24 | typedef struct xfs_timestamp { |
347d1c01 CH |
25 | __be32 t_sec; /* timestamp seconds */ |
26 | __be32 t_nsec; /* timestamp nanoseconds */ | |
1da177e4 LT |
27 | } xfs_timestamp_t; |
28 | ||
29 | /* | |
81591fe2 CH |
30 | * 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. | |
1da177e4 | 42 | */ |
81591fe2 | 43 | typedef struct xfs_dinode { |
347d1c01 CH |
44 | __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 */ | |
52 | __be16 di_projid; /* owner's project id */ | |
53 | __u8 di_pad[8]; /* unused, zeroed space */ | |
54 | __be16 di_flushiter; /* incremented on flush */ | |
1da177e4 LT |
55 | xfs_timestamp_t di_atime; /* time last accessed */ |
56 | xfs_timestamp_t di_mtime; /* time last modified */ | |
57 | xfs_timestamp_t di_ctime; /* time created/inode modified */ | |
347d1c01 CH |
58 | __be64 di_size; /* number of bytes in file */ |
59 | __be64 di_nblocks; /* # of direct & btree blocks used */ | |
60 | __be32 di_extsize; /* basic/minimum extent size for file */ | |
61 | __be32 di_nextents; /* number of extents in data fork */ | |
62 | __be16 di_anextents; /* number of extents in attribute fork*/ | |
63 | __u8 di_forkoff; /* attr fork offs, <<3 for 64b align */ | |
64 | __s8 di_aformat; /* format of attr fork's data */ | |
65 | __be32 di_dmevmask; /* DMIG event mask */ | |
66 | __be16 di_dmstate; /* DMIG state info */ | |
67 | __be16 di_flags; /* random flags, XFS_DIFLAG_... */ | |
68 | __be32 di_gen; /* generation number */ | |
1da177e4 | 69 | |
81591fe2 CH |
70 | /* di_next_unlinked is the only non-core field in the old dinode */ |
71 | __be32 di_next_unlinked;/* agi unlinked list ptr */ | |
72 | } __attribute__((packed)) xfs_dinode_t; | |
1da177e4 | 73 | |
81591fe2 | 74 | #define DI_MAX_FLUSH 0xffff |
1da177e4 LT |
75 | |
76 | /* | |
77 | * The 32 bit link count in the inode theoretically maxes out at UINT_MAX. | |
78 | * Since the pathconf interface is signed, we use 2^31 - 1 instead. | |
79 | * The old inode format had a 16 bit link count, so its maximum is USHRT_MAX. | |
80 | */ | |
81 | #define XFS_MAXLINK ((1U << 31) - 1U) | |
82 | #define XFS_MAXLINK_1 65535U | |
83 | ||
1da177e4 LT |
84 | /* |
85 | * Values for di_format | |
86 | */ | |
81591fe2 CH |
87 | typedef enum xfs_dinode_fmt { |
88 | XFS_DINODE_FMT_DEV, /* xfs_dev_t */ | |
89 | XFS_DINODE_FMT_LOCAL, /* bulk data */ | |
90 | XFS_DINODE_FMT_EXTENTS, /* struct xfs_bmbt_rec */ | |
91 | XFS_DINODE_FMT_BTREE, /* struct xfs_bmdr_block */ | |
92 | XFS_DINODE_FMT_UUID /* uuid_t */ | |
1da177e4 LT |
93 | } xfs_dinode_fmt_t; |
94 | ||
95 | /* | |
96 | * Inode minimum and maximum sizes. | |
97 | */ | |
98 | #define XFS_DINODE_MIN_LOG 8 | |
99 | #define XFS_DINODE_MAX_LOG 11 | |
100 | #define XFS_DINODE_MIN_SIZE (1 << XFS_DINODE_MIN_LOG) | |
101 | #define XFS_DINODE_MAX_SIZE (1 << XFS_DINODE_MAX_LOG) | |
102 | ||
103 | /* | |
104 | * Inode size for given fs. | |
105 | */ | |
6447c362 CH |
106 | #define XFS_LITINO(mp) \ |
107 | ((int)(((mp)->m_sb.sb_inodesize) - sizeof(struct xfs_dinode))) | |
108 | ||
1da177e4 | 109 | #define XFS_BROOT_SIZE_ADJ \ |
7cc95a82 | 110 | (XFS_BTREE_LBLOCK_LEN - sizeof(xfs_bmdr_block_t)) |
1da177e4 | 111 | |
1da177e4 LT |
112 | /* |
113 | * Inode data & attribute fork sizes, per inode. | |
114 | */ | |
81591fe2 CH |
115 | #define XFS_DFORK_Q(dip) ((dip)->di_forkoff != 0) |
116 | #define XFS_DFORK_BOFF(dip) ((int)((dip)->di_forkoff << 3)) | |
1da177e4 | 117 | |
a844f451 | 118 | #define XFS_DFORK_DSIZE(dip,mp) \ |
45ba598e CH |
119 | (XFS_DFORK_Q(dip) ? \ |
120 | XFS_DFORK_BOFF(dip) : \ | |
121 | XFS_LITINO(mp)) | |
a844f451 | 122 | #define XFS_DFORK_ASIZE(dip,mp) \ |
45ba598e CH |
123 | (XFS_DFORK_Q(dip) ? \ |
124 | XFS_LITINO(mp) - XFS_DFORK_BOFF(dip) : \ | |
125 | 0) | |
126 | #define XFS_DFORK_SIZE(dip,mp,w) \ | |
1da177e4 | 127 | ((w) == XFS_DATA_FORK ? \ |
45ba598e CH |
128 | XFS_DFORK_DSIZE(dip, mp) : \ |
129 | XFS_DFORK_ASIZE(dip, mp)) | |
1da177e4 | 130 | |
81591fe2 CH |
131 | /* |
132 | * Return pointers to the data or attribute forks. | |
133 | */ | |
134 | #define XFS_DFORK_DPTR(dip) \ | |
135 | ((char *)(dip) + sizeof(struct xfs_dinode)) | |
45ba598e | 136 | #define XFS_DFORK_APTR(dip) \ |
81591fe2 | 137 | (XFS_DFORK_DPTR(dip) + XFS_DFORK_BOFF(dip)) |
45ba598e CH |
138 | #define XFS_DFORK_PTR(dip,w) \ |
139 | ((w) == XFS_DATA_FORK ? XFS_DFORK_DPTR(dip) : XFS_DFORK_APTR(dip)) | |
81591fe2 | 140 | |
45ba598e | 141 | #define XFS_DFORK_FORMAT(dip,w) \ |
1da177e4 | 142 | ((w) == XFS_DATA_FORK ? \ |
81591fe2 CH |
143 | (dip)->di_format : \ |
144 | (dip)->di_aformat) | |
45ba598e | 145 | #define XFS_DFORK_NEXTENTS(dip,w) \ |
1da177e4 | 146 | ((w) == XFS_DATA_FORK ? \ |
81591fe2 CH |
147 | be32_to_cpu((dip)->di_nextents) : \ |
148 | be16_to_cpu((dip)->di_anextents)) | |
1da177e4 | 149 | |
a844f451 | 150 | #define XFS_BUF_TO_DINODE(bp) ((xfs_dinode_t *)XFS_BUF_PTR(bp)) |
1da177e4 | 151 | |
81591fe2 CH |
152 | /* |
153 | * For block and character special files the 32bit dev_t is stored at the | |
154 | * beginning of the data fork. | |
155 | */ | |
156 | static inline xfs_dev_t xfs_dinode_get_rdev(struct xfs_dinode *dip) | |
157 | { | |
158 | return be32_to_cpu(*(__be32 *)XFS_DFORK_DPTR(dip)); | |
159 | } | |
160 | ||
161 | static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev) | |
162 | { | |
163 | *(__be32 *)XFS_DFORK_DPTR(dip) = cpu_to_be32(rdev); | |
164 | } | |
165 | ||
1da177e4 LT |
166 | /* |
167 | * Values for di_flags | |
168 | * There should be a one-to-one correspondence between these flags and the | |
169 | * XFS_XFLAG_s. | |
170 | */ | |
171 | #define XFS_DIFLAG_REALTIME_BIT 0 /* file's blocks come from rt area */ | |
172 | #define XFS_DIFLAG_PREALLOC_BIT 1 /* file space has been preallocated */ | |
173 | #define XFS_DIFLAG_NEWRTBM_BIT 2 /* for rtbitmap inode, new format */ | |
174 | #define XFS_DIFLAG_IMMUTABLE_BIT 3 /* inode is immutable */ | |
175 | #define XFS_DIFLAG_APPEND_BIT 4 /* inode is append-only */ | |
176 | #define XFS_DIFLAG_SYNC_BIT 5 /* inode is written synchronously */ | |
177 | #define XFS_DIFLAG_NOATIME_BIT 6 /* do not update atime */ | |
178 | #define XFS_DIFLAG_NODUMP_BIT 7 /* do not dump */ | |
179 | #define XFS_DIFLAG_RTINHERIT_BIT 8 /* create with realtime bit set */ | |
dd9f438e NS |
180 | #define XFS_DIFLAG_PROJINHERIT_BIT 9 /* create with parents projid */ |
181 | #define XFS_DIFLAG_NOSYMLINKS_BIT 10 /* disallow symlink creation */ | |
182 | #define XFS_DIFLAG_EXTSIZE_BIT 11 /* inode extent size allocator hint */ | |
183 | #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */ | |
d3446eac | 184 | #define XFS_DIFLAG_NODEFRAG_BIT 13 /* do not reorganize/defragment */ |
2a82b8be | 185 | #define XFS_DIFLAG_FILESTREAM_BIT 14 /* use filestream allocator */ |
1da177e4 LT |
186 | #define XFS_DIFLAG_REALTIME (1 << XFS_DIFLAG_REALTIME_BIT) |
187 | #define XFS_DIFLAG_PREALLOC (1 << XFS_DIFLAG_PREALLOC_BIT) | |
188 | #define XFS_DIFLAG_NEWRTBM (1 << XFS_DIFLAG_NEWRTBM_BIT) | |
189 | #define XFS_DIFLAG_IMMUTABLE (1 << XFS_DIFLAG_IMMUTABLE_BIT) | |
190 | #define XFS_DIFLAG_APPEND (1 << XFS_DIFLAG_APPEND_BIT) | |
191 | #define XFS_DIFLAG_SYNC (1 << XFS_DIFLAG_SYNC_BIT) | |
192 | #define XFS_DIFLAG_NOATIME (1 << XFS_DIFLAG_NOATIME_BIT) | |
193 | #define XFS_DIFLAG_NODUMP (1 << XFS_DIFLAG_NODUMP_BIT) | |
194 | #define XFS_DIFLAG_RTINHERIT (1 << XFS_DIFLAG_RTINHERIT_BIT) | |
195 | #define XFS_DIFLAG_PROJINHERIT (1 << XFS_DIFLAG_PROJINHERIT_BIT) | |
196 | #define XFS_DIFLAG_NOSYMLINKS (1 << XFS_DIFLAG_NOSYMLINKS_BIT) | |
dd9f438e NS |
197 | #define XFS_DIFLAG_EXTSIZE (1 << XFS_DIFLAG_EXTSIZE_BIT) |
198 | #define XFS_DIFLAG_EXTSZINHERIT (1 << XFS_DIFLAG_EXTSZINHERIT_BIT) | |
d3446eac | 199 | #define XFS_DIFLAG_NODEFRAG (1 << XFS_DIFLAG_NODEFRAG_BIT) |
2a82b8be | 200 | #define XFS_DIFLAG_FILESTREAM (1 << XFS_DIFLAG_FILESTREAM_BIT) |
1da177e4 | 201 | |
71ddabb9 ES |
202 | #ifdef CONFIG_XFS_RT |
203 | #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME) | |
204 | #else | |
205 | #define XFS_IS_REALTIME_INODE(ip) (0) | |
206 | #endif | |
207 | ||
1da177e4 LT |
208 | #define XFS_DIFLAG_ANY \ |
209 | (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \ | |
210 | XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \ | |
211 | XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \ | |
dd9f438e | 212 | XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \ |
2a82b8be | 213 | XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM) |
1da177e4 LT |
214 | |
215 | #endif /* __XFS_DINODE_H__ */ |