]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/xfs_inode.h
xfs: move inode fork definitions to a new header file
[thirdparty/xfsprogs-dev.git] / include / xfs_inode.h
1 /*
2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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
7 * published by the Free Software Foundation.
8 *
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.
13 *
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
17 */
18 #ifndef __XFS_INODE_H__
19 #define __XFS_INODE_H__
20
21 struct posix_acl;
22 struct xfs_dinode;
23 struct xfs_inode;
24
25 #include "xfs_inode_fork.h"
26
27 /*
28 * Inode location information. Stored in the inode and passed to
29 * xfs_imap_to_bp() to get a buffer and dinode for a given inode.
30 */
31 struct xfs_imap {
32 xfs_daddr_t im_blkno; /* starting BB of inode chunk */
33 ushort im_len; /* length in BBs of inode chunk */
34 ushort im_boffset; /* inode offset in block in bytes */
35 };
36
37 /*
38 * This is the xfs in-core inode structure.
39 * Most of the on-disk inode is embedded in the i_d field.
40 *
41 * The extent pointers/inline file space, however, are managed
42 * separately. The memory for this information is pointed to by
43 * the if_u1 unions depending on the type of the data.
44 * This is used to linearize the array of extents for fast in-core
45 * access. This is used until the file's number of extents
46 * surpasses XFS_MAX_INCORE_EXTENTS, at which point all extent pointers
47 * are accessed through the buffer cache.
48 *
49 * Other state kept in the in-core inode is used for identification,
50 * locking, transactional updating, etc of the inode.
51 *
52 * Generally, we do not want to hold the i_rlock while holding the
53 * i_ilock. Hierarchy is i_iolock followed by i_rlock.
54 *
55 * xfs_iptr_t contains all the inode fields up to and including the
56 * i_mnext and i_mprev fields, it is used as a marker in the inode
57 * chain off the mount structure by xfs_sync calls.
58 */
59 /*
60 * Flags for xfs_ichgtime().
61 */
62 #define XFS_ICHGTIME_MOD 0x1 /* data fork modification timestamp */
63 #define XFS_ICHGTIME_CHG 0x2 /* inode field change timestamp */
64 #define XFS_ICHGTIME_CREATE 0x4 /* inode create timestamp */
65
66
67 #ifdef __KERNEL__
68
69 struct xfs_buf;
70 struct xfs_bmap_free;
71 struct xfs_bmbt_irec;
72 struct xfs_inode_log_item;
73 struct xfs_mount;
74 struct xfs_trans;
75 struct xfs_dquot;
76
77 typedef struct xfs_inode {
78 /* Inode linking and identification information. */
79 struct xfs_mount *i_mount; /* fs mount struct ptr */
80 struct xfs_dquot *i_udquot; /* user dquot */
81 struct xfs_dquot *i_gdquot; /* group dquot */
82
83 /* Inode location stuff */
84 xfs_ino_t i_ino; /* inode number (agno/agino)*/
85 struct xfs_imap i_imap; /* location for xfs_imap() */
86
87 /* Extent information. */
88 xfs_ifork_t *i_afp; /* attribute fork pointer */
89 xfs_ifork_t i_df; /* data fork */
90
91 /* Transaction and locking information. */
92 struct xfs_inode_log_item *i_itemp; /* logging information */
93 mrlock_t i_lock; /* inode lock */
94 mrlock_t i_iolock; /* inode IO lock */
95 atomic_t i_pincount; /* inode pin count */
96 spinlock_t i_flags_lock; /* inode i_flags lock */
97 /* Miscellaneous state. */
98 unsigned long i_flags; /* see defined flags below */
99 unsigned int i_delayed_blks; /* count of delay alloc blks */
100
101 xfs_icdinode_t i_d; /* most of ondisk inode */
102
103 /* VFS inode */
104 struct inode i_vnode; /* embedded VFS inode */
105 } xfs_inode_t;
106
107 /* Convert from vfs inode to xfs inode */
108 static inline struct xfs_inode *XFS_I(struct inode *inode)
109 {
110 return container_of(inode, struct xfs_inode, i_vnode);
111 }
112
113 /* convert from xfs inode to vfs inode */
114 static inline struct inode *VFS_I(struct xfs_inode *ip)
115 {
116 return &ip->i_vnode;
117 }
118
119 /*
120 * For regular files we only update the on-disk filesize when actually
121 * writing data back to disk. Until then only the copy in the VFS inode
122 * is uptodate.
123 */
124 static inline xfs_fsize_t XFS_ISIZE(struct xfs_inode *ip)
125 {
126 if (S_ISREG(ip->i_d.di_mode))
127 return i_size_read(VFS_I(ip));
128 return ip->i_d.di_size;
129 }
130
131 /*
132 * If this I/O goes past the on-disk inode size update it unless it would
133 * be past the current in-core inode size.
134 */
135 static inline xfs_fsize_t
136 xfs_new_eof(struct xfs_inode *ip, xfs_fsize_t new_size)
137 {
138 xfs_fsize_t i_size = i_size_read(VFS_I(ip));
139
140 if (new_size > i_size)
141 new_size = i_size;
142 return new_size > ip->i_d.di_size ? new_size : 0;
143 }
144
145 /*
146 * i_flags helper functions
147 */
148 static inline void
149 __xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
150 {
151 ip->i_flags |= flags;
152 }
153
154 static inline void
155 xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
156 {
157 spin_lock(&ip->i_flags_lock);
158 __xfs_iflags_set(ip, flags);
159 spin_unlock(&ip->i_flags_lock);
160 }
161
162 static inline void
163 xfs_iflags_clear(xfs_inode_t *ip, unsigned short flags)
164 {
165 spin_lock(&ip->i_flags_lock);
166 ip->i_flags &= ~flags;
167 spin_unlock(&ip->i_flags_lock);
168 }
169
170 static inline int
171 __xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
172 {
173 return (ip->i_flags & flags);
174 }
175
176 static inline int
177 xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
178 {
179 int ret;
180 spin_lock(&ip->i_flags_lock);
181 ret = __xfs_iflags_test(ip, flags);
182 spin_unlock(&ip->i_flags_lock);
183 return ret;
184 }
185
186 static inline int
187 xfs_iflags_test_and_clear(xfs_inode_t *ip, unsigned short flags)
188 {
189 int ret;
190
191 spin_lock(&ip->i_flags_lock);
192 ret = ip->i_flags & flags;
193 if (ret)
194 ip->i_flags &= ~flags;
195 spin_unlock(&ip->i_flags_lock);
196 return ret;
197 }
198
199 static inline int
200 xfs_iflags_test_and_set(xfs_inode_t *ip, unsigned short flags)
201 {
202 int ret;
203
204 spin_lock(&ip->i_flags_lock);
205 ret = ip->i_flags & flags;
206 if (!ret)
207 ip->i_flags |= flags;
208 spin_unlock(&ip->i_flags_lock);
209 return ret;
210 }
211
212 /*
213 * Project quota id helpers (previously projid was 16bit only
214 * and using two 16bit values to hold new 32bit projid was chosen
215 * to retain compatibility with "old" filesystems).
216 */
217 static inline prid_t
218 xfs_get_projid(struct xfs_inode *ip)
219 {
220 return (prid_t)ip->i_d.di_projid_hi << 16 | ip->i_d.di_projid_lo;
221 }
222
223 static inline void
224 xfs_set_projid(struct xfs_inode *ip,
225 prid_t projid)
226 {
227 ip->i_d.di_projid_hi = (__uint16_t) (projid >> 16);
228 ip->i_d.di_projid_lo = (__uint16_t) (projid & 0xffff);
229 }
230
231 /*
232 * In-core inode flags.
233 */
234 #define XFS_IRECLAIM (1 << 0) /* started reclaiming this inode */
235 #define XFS_ISTALE (1 << 1) /* inode has been staled */
236 #define XFS_IRECLAIMABLE (1 << 2) /* inode can be reclaimed */
237 #define XFS_INEW (1 << 3) /* inode has just been allocated */
238 #define XFS_IFILESTREAM (1 << 4) /* inode is in a filestream dir. */
239 #define XFS_ITRUNCATED (1 << 5) /* truncated down so flush-on-close */
240 #define XFS_IDIRTY_RELEASE (1 << 6) /* dirty release already seen */
241 #define __XFS_IFLOCK_BIT 7 /* inode is being flushed right now */
242 #define XFS_IFLOCK (1 << __XFS_IFLOCK_BIT)
243 #define __XFS_IPINNED_BIT 8 /* wakeup key for zero pin count */
244 #define XFS_IPINNED (1 << __XFS_IPINNED_BIT)
245 #define XFS_IDONTCACHE (1 << 9) /* don't cache the inode long term */
246
247 /*
248 * Per-lifetime flags need to be reset when re-using a reclaimable inode during
249 * inode lookup. This prevents unintended behaviour on the new inode from
250 * ocurring.
251 */
252 #define XFS_IRECLAIM_RESET_FLAGS \
253 (XFS_IRECLAIMABLE | XFS_IRECLAIM | \
254 XFS_IDIRTY_RELEASE | XFS_ITRUNCATED | \
255 XFS_IFILESTREAM);
256
257 /*
258 * Synchronize processes attempting to flush the in-core inode back to disk.
259 */
260
261 extern void __xfs_iflock(struct xfs_inode *ip);
262
263 static inline int xfs_iflock_nowait(struct xfs_inode *ip)
264 {
265 return !xfs_iflags_test_and_set(ip, XFS_IFLOCK);
266 }
267
268 static inline void xfs_iflock(struct xfs_inode *ip)
269 {
270 if (!xfs_iflock_nowait(ip))
271 __xfs_iflock(ip);
272 }
273
274 static inline void xfs_ifunlock(struct xfs_inode *ip)
275 {
276 xfs_iflags_clear(ip, XFS_IFLOCK);
277 smp_mb();
278 wake_up_bit(&ip->i_flags, __XFS_IFLOCK_BIT);
279 }
280
281 static inline int xfs_isiflocked(struct xfs_inode *ip)
282 {
283 return xfs_iflags_test(ip, XFS_IFLOCK);
284 }
285
286 /*
287 * Flags for inode locking.
288 * Bit ranges: 1<<1 - 1<<16-1 -- iolock/ilock modes (bitfield)
289 * 1<<16 - 1<<32-1 -- lockdep annotation (integers)
290 */
291 #define XFS_IOLOCK_EXCL (1<<0)
292 #define XFS_IOLOCK_SHARED (1<<1)
293 #define XFS_ILOCK_EXCL (1<<2)
294 #define XFS_ILOCK_SHARED (1<<3)
295
296 #define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \
297 | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED)
298
299 #define XFS_LOCK_FLAGS \
300 { XFS_IOLOCK_EXCL, "IOLOCK_EXCL" }, \
301 { XFS_IOLOCK_SHARED, "IOLOCK_SHARED" }, \
302 { XFS_ILOCK_EXCL, "ILOCK_EXCL" }, \
303 { XFS_ILOCK_SHARED, "ILOCK_SHARED" }
304
305
306 /*
307 * Flags for lockdep annotations.
308 *
309 * XFS_LOCK_PARENT - for directory operations that require locking a
310 * parent directory inode and a child entry inode. The parent gets locked
311 * with this flag so it gets a lockdep subclass of 1 and the child entry
312 * lock will have a lockdep subclass of 0.
313 *
314 * XFS_LOCK_RTBITMAP/XFS_LOCK_RTSUM - the realtime device bitmap and summary
315 * inodes do not participate in the normal lock order, and thus have their
316 * own subclasses.
317 *
318 * XFS_LOCK_INUMORDER - for locking several inodes at the some time
319 * with xfs_lock_inodes(). This flag is used as the starting subclass
320 * and each subsequent lock acquired will increment the subclass by one.
321 * So the first lock acquired will have a lockdep subclass of 4, the
322 * second lock will have a lockdep subclass of 5, and so on. It is
323 * the responsibility of the class builder to shift this to the correct
324 * portion of the lock_mode lockdep mask.
325 */
326 #define XFS_LOCK_PARENT 1
327 #define XFS_LOCK_RTBITMAP 2
328 #define XFS_LOCK_RTSUM 3
329 #define XFS_LOCK_INUMORDER 4
330
331 #define XFS_IOLOCK_SHIFT 16
332 #define XFS_IOLOCK_PARENT (XFS_LOCK_PARENT << XFS_IOLOCK_SHIFT)
333
334 #define XFS_ILOCK_SHIFT 24
335 #define XFS_ILOCK_PARENT (XFS_LOCK_PARENT << XFS_ILOCK_SHIFT)
336 #define XFS_ILOCK_RTBITMAP (XFS_LOCK_RTBITMAP << XFS_ILOCK_SHIFT)
337 #define XFS_ILOCK_RTSUM (XFS_LOCK_RTSUM << XFS_ILOCK_SHIFT)
338
339 #define XFS_IOLOCK_DEP_MASK 0x00ff0000
340 #define XFS_ILOCK_DEP_MASK 0xff000000
341 #define XFS_LOCK_DEP_MASK (XFS_IOLOCK_DEP_MASK | XFS_ILOCK_DEP_MASK)
342
343 #define XFS_IOLOCK_DEP(flags) (((flags) & XFS_IOLOCK_DEP_MASK) >> XFS_IOLOCK_SHIFT)
344 #define XFS_ILOCK_DEP(flags) (((flags) & XFS_ILOCK_DEP_MASK) >> XFS_ILOCK_SHIFT)
345
346 /*
347 * For multiple groups support: if S_ISGID bit is set in the parent
348 * directory, group of new file is set to that of the parent, and
349 * new subdirectory gets S_ISGID bit from parent.
350 */
351 #define XFS_INHERIT_GID(pip) \
352 (((pip)->i_mount->m_flags & XFS_MOUNT_GRPID) || \
353 ((pip)->i_d.di_mode & S_ISGID))
354
355
356 /*
357 * xfs_inode.c prototypes.
358 */
359 void xfs_ilock(xfs_inode_t *, uint);
360 int xfs_ilock_nowait(xfs_inode_t *, uint);
361 void xfs_iunlock(xfs_inode_t *, uint);
362 void xfs_ilock_demote(xfs_inode_t *, uint);
363 int xfs_isilocked(xfs_inode_t *, uint);
364 uint xfs_ilock_map_shared(xfs_inode_t *);
365 void xfs_iunlock_map_shared(xfs_inode_t *, uint);
366 int xfs_ialloc(struct xfs_trans *, xfs_inode_t *, umode_t,
367 xfs_nlink_t, xfs_dev_t, prid_t, int,
368 struct xfs_buf **, xfs_inode_t **);
369
370 uint xfs_ip2xflags(struct xfs_inode *);
371 uint xfs_dic2xflags(struct xfs_dinode *);
372 int xfs_ifree(struct xfs_trans *, xfs_inode_t *,
373 struct xfs_bmap_free *);
374 int xfs_itruncate_extents(struct xfs_trans **, struct xfs_inode *,
375 int, xfs_fsize_t);
376 int xfs_iunlink(struct xfs_trans *, xfs_inode_t *);
377
378 void xfs_iext_realloc(xfs_inode_t *, int, int);
379 void xfs_iunpin_wait(xfs_inode_t *);
380 int xfs_iflush(struct xfs_inode *, struct xfs_buf **);
381 void xfs_lock_inodes(xfs_inode_t **, int, uint);
382 void xfs_lock_two_inodes(xfs_inode_t *, xfs_inode_t *, uint);
383
384 xfs_extlen_t xfs_get_extsz_hint(struct xfs_inode *ip);
385
386 #define IHOLD(ip) \
387 do { \
388 ASSERT(atomic_read(&VFS_I(ip)->i_count) > 0) ; \
389 ihold(VFS_I(ip)); \
390 trace_xfs_ihold(ip, _THIS_IP_); \
391 } while (0)
392
393 #define IRELE(ip) \
394 do { \
395 trace_xfs_irele(ip, _THIS_IP_); \
396 iput(VFS_I(ip)); \
397 } while (0)
398
399 #endif /* __KERNEL__ */
400
401 /*
402 * Flags for xfs_iget()
403 */
404 #define XFS_IGET_CREATE 0x1
405 #define XFS_IGET_UNTRUSTED 0x2
406 #define XFS_IGET_DONTCACHE 0x4
407
408 int xfs_imap_to_bp(struct xfs_mount *, struct xfs_trans *,
409 struct xfs_imap *, struct xfs_dinode **,
410 struct xfs_buf **, uint, uint);
411 int xfs_iread(struct xfs_mount *, struct xfs_trans *,
412 struct xfs_inode *, uint);
413 void xfs_dinode_calc_crc(struct xfs_mount *, struct xfs_dinode *);
414 void xfs_dinode_to_disk(struct xfs_dinode *,
415 struct xfs_icdinode *);
416 bool xfs_can_free_eofblocks(struct xfs_inode *, bool);
417
418 #define xfs_ipincount(ip) ((unsigned int) atomic_read(&ip->i_pincount))
419
420 #if defined(DEBUG)
421 void xfs_inobp_check(struct xfs_mount *, struct xfs_buf *);
422 #else
423 #define xfs_inobp_check(mp, bp)
424 #endif /* DEBUG */
425
426 extern struct kmem_zone *xfs_inode_zone;
427 extern const struct xfs_buf_ops xfs_inode_buf_ops;
428
429 #endif /* __XFS_INODE_H__ */