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 | 21 | #define XFS_DINODE_MAGIC 0x494e /* 'IN' */ |
93848a99 | 22 | #define XFS_DINODE_GOOD_VERSION(v) ((v) >= 1 && (v) <= 3) |
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 | |
51c84223 | 36 | * attribute use the XFS_DFORK_DPTR, XFS_DFORK_APTR, and XFS_DFORK_PTR macros |
81591fe2 CH |
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 */ | |
6743099c AM |
52 | __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 */ | |
347d1c01 | 55 | __be16 di_flushiter; /* incremented on flush */ |
1da177e4 LT |
56 | 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 */ | |
347d1c01 CH |
59 | __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 */ | |
1da177e4 | 70 | |
81591fe2 CH |
71 | /* di_next_unlinked is the only non-core field in the old dinode */ |
72 | __be32 di_next_unlinked;/* agi unlinked list ptr */ | |
93848a99 CH |
73 | |
74 | /* start of the extended dinode, writable fields */ | |
75 | __le32 di_crc; /* CRC of the inode */ | |
76 | __be64 di_changecount; /* number of attribute changes */ | |
77 | __be64 di_lsn; /* flush sequence */ | |
78 | __be64 di_flags2; /* more random flags */ | |
79 | __u8 di_pad2[16]; /* more padding for future expansion */ | |
80 | ||
81 | /* fields only written to during inode creation */ | |
82 | xfs_timestamp_t di_crtime; /* time created */ | |
83 | __be64 di_ino; /* inode number */ | |
84 | uuid_t di_uuid; /* UUID of the filesystem */ | |
85 | ||
86 | /* structure must be padded to 64 bit alignment */ | |
87 | } xfs_dinode_t; | |
1da177e4 | 88 | |
81591fe2 | 89 | #define DI_MAX_FLUSH 0xffff |
1da177e4 | 90 | |
93848a99 CH |
91 | /* |
92 | * Size of the core inode on disk. Version 1 and 2 inodes have | |
93 | * the same size, but version 3 has grown a few additional fields. | |
94 | */ | |
95 | static inline uint xfs_dinode_size(int version) | |
96 | { | |
97 | if (version == 3) | |
98 | return sizeof(struct xfs_dinode); | |
99 | return offsetof(struct xfs_dinode, di_crc); | |
100 | } | |
101 | ||
1da177e4 LT |
102 | /* |
103 | * The 32 bit link count in the inode theoretically maxes out at UINT_MAX. | |
104 | * Since the pathconf interface is signed, we use 2^31 - 1 instead. | |
105 | * The old inode format had a 16 bit link count, so its maximum is USHRT_MAX. | |
106 | */ | |
107 | #define XFS_MAXLINK ((1U << 31) - 1U) | |
108 | #define XFS_MAXLINK_1 65535U | |
109 | ||
1da177e4 LT |
110 | /* |
111 | * Values for di_format | |
112 | */ | |
81591fe2 CH |
113 | typedef enum xfs_dinode_fmt { |
114 | XFS_DINODE_FMT_DEV, /* xfs_dev_t */ | |
115 | XFS_DINODE_FMT_LOCAL, /* bulk data */ | |
116 | XFS_DINODE_FMT_EXTENTS, /* struct xfs_bmbt_rec */ | |
117 | XFS_DINODE_FMT_BTREE, /* struct xfs_bmdr_block */ | |
118 | XFS_DINODE_FMT_UUID /* uuid_t */ | |
1da177e4 LT |
119 | } xfs_dinode_fmt_t; |
120 | ||
121 | /* | |
122 | * Inode minimum and maximum sizes. | |
123 | */ | |
124 | #define XFS_DINODE_MIN_LOG 8 | |
125 | #define XFS_DINODE_MAX_LOG 11 | |
126 | #define XFS_DINODE_MIN_SIZE (1 << XFS_DINODE_MIN_LOG) | |
127 | #define XFS_DINODE_MAX_SIZE (1 << XFS_DINODE_MAX_LOG) | |
128 | ||
129 | /* | |
130 | * Inode size for given fs. | |
131 | */ | |
56cea2d0 | 132 | #define XFS_LITINO(mp, version) \ |
93848a99 | 133 | ((int)(((mp)->m_sb.sb_inodesize) - xfs_dinode_size(version))) |
6447c362 | 134 | |
ee1a47ab CH |
135 | #define XFS_BROOT_SIZE_ADJ(ip) \ |
136 | (XFS_BMBT_BLOCK_LEN((ip)->i_mount) - sizeof(xfs_bmdr_block_t)) | |
1da177e4 | 137 | |
1da177e4 LT |
138 | /* |
139 | * Inode data & attribute fork sizes, per inode. | |
140 | */ | |
81591fe2 CH |
141 | #define XFS_DFORK_Q(dip) ((dip)->di_forkoff != 0) |
142 | #define XFS_DFORK_BOFF(dip) ((int)((dip)->di_forkoff << 3)) | |
1da177e4 | 143 | |
a844f451 | 144 | #define XFS_DFORK_DSIZE(dip,mp) \ |
45ba598e CH |
145 | (XFS_DFORK_Q(dip) ? \ |
146 | XFS_DFORK_BOFF(dip) : \ | |
56cea2d0 | 147 | XFS_LITINO(mp, (dip)->di_version)) |
a844f451 | 148 | #define XFS_DFORK_ASIZE(dip,mp) \ |
45ba598e | 149 | (XFS_DFORK_Q(dip) ? \ |
56cea2d0 | 150 | XFS_LITINO(mp, (dip)->di_version) - XFS_DFORK_BOFF(dip) : \ |
45ba598e CH |
151 | 0) |
152 | #define XFS_DFORK_SIZE(dip,mp,w) \ | |
1da177e4 | 153 | ((w) == XFS_DATA_FORK ? \ |
45ba598e CH |
154 | XFS_DFORK_DSIZE(dip, mp) : \ |
155 | XFS_DFORK_ASIZE(dip, mp)) | |
1da177e4 | 156 | |
81591fe2 CH |
157 | /* |
158 | * Return pointers to the data or attribute forks. | |
159 | */ | |
160 | #define XFS_DFORK_DPTR(dip) \ | |
93848a99 | 161 | ((char *)dip + xfs_dinode_size(dip->di_version)) |
45ba598e | 162 | #define XFS_DFORK_APTR(dip) \ |
81591fe2 | 163 | (XFS_DFORK_DPTR(dip) + XFS_DFORK_BOFF(dip)) |
45ba598e CH |
164 | #define XFS_DFORK_PTR(dip,w) \ |
165 | ((w) == XFS_DATA_FORK ? XFS_DFORK_DPTR(dip) : XFS_DFORK_APTR(dip)) | |
81591fe2 | 166 | |
45ba598e | 167 | #define XFS_DFORK_FORMAT(dip,w) \ |
1da177e4 | 168 | ((w) == XFS_DATA_FORK ? \ |
81591fe2 CH |
169 | (dip)->di_format : \ |
170 | (dip)->di_aformat) | |
45ba598e | 171 | #define XFS_DFORK_NEXTENTS(dip,w) \ |
1da177e4 | 172 | ((w) == XFS_DATA_FORK ? \ |
81591fe2 CH |
173 | be32_to_cpu((dip)->di_nextents) : \ |
174 | be16_to_cpu((dip)->di_anextents)) | |
1da177e4 | 175 | |
62926044 | 176 | #define XFS_BUF_TO_DINODE(bp) ((xfs_dinode_t *)((bp)->b_addr)) |
1da177e4 | 177 | |
81591fe2 CH |
178 | /* |
179 | * For block and character special files the 32bit dev_t is stored at the | |
180 | * beginning of the data fork. | |
181 | */ | |
182 | static inline xfs_dev_t xfs_dinode_get_rdev(struct xfs_dinode *dip) | |
183 | { | |
184 | return be32_to_cpu(*(__be32 *)XFS_DFORK_DPTR(dip)); | |
185 | } | |
186 | ||
187 | static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev) | |
188 | { | |
189 | *(__be32 *)XFS_DFORK_DPTR(dip) = cpu_to_be32(rdev); | |
190 | } | |
191 | ||
1da177e4 LT |
192 | /* |
193 | * Values for di_flags | |
194 | * There should be a one-to-one correspondence between these flags and the | |
195 | * XFS_XFLAG_s. | |
196 | */ | |
197 | #define XFS_DIFLAG_REALTIME_BIT 0 /* file's blocks come from rt area */ | |
198 | #define XFS_DIFLAG_PREALLOC_BIT 1 /* file space has been preallocated */ | |
199 | #define XFS_DIFLAG_NEWRTBM_BIT 2 /* for rtbitmap inode, new format */ | |
200 | #define XFS_DIFLAG_IMMUTABLE_BIT 3 /* inode is immutable */ | |
201 | #define XFS_DIFLAG_APPEND_BIT 4 /* inode is append-only */ | |
202 | #define XFS_DIFLAG_SYNC_BIT 5 /* inode is written synchronously */ | |
203 | #define XFS_DIFLAG_NOATIME_BIT 6 /* do not update atime */ | |
204 | #define XFS_DIFLAG_NODUMP_BIT 7 /* do not dump */ | |
205 | #define XFS_DIFLAG_RTINHERIT_BIT 8 /* create with realtime bit set */ | |
dd9f438e NS |
206 | #define XFS_DIFLAG_PROJINHERIT_BIT 9 /* create with parents projid */ |
207 | #define XFS_DIFLAG_NOSYMLINKS_BIT 10 /* disallow symlink creation */ | |
208 | #define XFS_DIFLAG_EXTSIZE_BIT 11 /* inode extent size allocator hint */ | |
209 | #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */ | |
d3446eac | 210 | #define XFS_DIFLAG_NODEFRAG_BIT 13 /* do not reorganize/defragment */ |
2a82b8be | 211 | #define XFS_DIFLAG_FILESTREAM_BIT 14 /* use filestream allocator */ |
1da177e4 LT |
212 | #define XFS_DIFLAG_REALTIME (1 << XFS_DIFLAG_REALTIME_BIT) |
213 | #define XFS_DIFLAG_PREALLOC (1 << XFS_DIFLAG_PREALLOC_BIT) | |
214 | #define XFS_DIFLAG_NEWRTBM (1 << XFS_DIFLAG_NEWRTBM_BIT) | |
215 | #define XFS_DIFLAG_IMMUTABLE (1 << XFS_DIFLAG_IMMUTABLE_BIT) | |
216 | #define XFS_DIFLAG_APPEND (1 << XFS_DIFLAG_APPEND_BIT) | |
217 | #define XFS_DIFLAG_SYNC (1 << XFS_DIFLAG_SYNC_BIT) | |
218 | #define XFS_DIFLAG_NOATIME (1 << XFS_DIFLAG_NOATIME_BIT) | |
219 | #define XFS_DIFLAG_NODUMP (1 << XFS_DIFLAG_NODUMP_BIT) | |
220 | #define XFS_DIFLAG_RTINHERIT (1 << XFS_DIFLAG_RTINHERIT_BIT) | |
221 | #define XFS_DIFLAG_PROJINHERIT (1 << XFS_DIFLAG_PROJINHERIT_BIT) | |
222 | #define XFS_DIFLAG_NOSYMLINKS (1 << XFS_DIFLAG_NOSYMLINKS_BIT) | |
dd9f438e NS |
223 | #define XFS_DIFLAG_EXTSIZE (1 << XFS_DIFLAG_EXTSIZE_BIT) |
224 | #define XFS_DIFLAG_EXTSZINHERIT (1 << XFS_DIFLAG_EXTSZINHERIT_BIT) | |
d3446eac | 225 | #define XFS_DIFLAG_NODEFRAG (1 << XFS_DIFLAG_NODEFRAG_BIT) |
2a82b8be | 226 | #define XFS_DIFLAG_FILESTREAM (1 << XFS_DIFLAG_FILESTREAM_BIT) |
1da177e4 | 227 | |
71ddabb9 ES |
228 | #ifdef CONFIG_XFS_RT |
229 | #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME) | |
230 | #else | |
231 | #define XFS_IS_REALTIME_INODE(ip) (0) | |
232 | #endif | |
233 | ||
1da177e4 LT |
234 | #define XFS_DIFLAG_ANY \ |
235 | (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \ | |
236 | XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \ | |
237 | XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \ | |
dd9f438e | 238 | XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \ |
2a82b8be | 239 | XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM) |
1da177e4 LT |
240 | |
241 | #endif /* __XFS_DINODE_H__ */ |