1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef __XFS_INODE_H__
19#define __XFS_INODE_H__
20
21struct posix_acl;
22struct xfs_dinode;
23struct xfs_inode;
24
25
26
27
28#define XFS_DATA_FORK 0
29#define XFS_ATTR_FORK 1
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50typedef struct xfs_ext_irec {
51 xfs_bmbt_rec_host_t *er_extbuf;
52 xfs_extnum_t er_extoff;
53 xfs_extnum_t er_extcount;
54} xfs_ext_irec_t;
55
56
57
58
59#define XFS_IEXT_BUFSZ 4096
60#define XFS_LINEAR_EXTS (XFS_IEXT_BUFSZ / (uint)sizeof(xfs_bmbt_rec_t))
61#define XFS_INLINE_EXTS 2
62#define XFS_INLINE_DATA 32
63typedef struct xfs_ifork {
64 int if_bytes;
65 int if_real_bytes;
66 struct xfs_btree_block *if_broot;
67 short if_broot_bytes;
68 unsigned char if_flags;
69 union {
70 xfs_bmbt_rec_host_t *if_extents;
71 xfs_ext_irec_t *if_ext_irec;
72 char *if_data;
73 } if_u1;
74 union {
75 xfs_bmbt_rec_host_t if_inline_ext[XFS_INLINE_EXTS];
76
77 char if_inline_data[XFS_INLINE_DATA];
78
79 xfs_dev_t if_rdev;
80 uuid_t if_uuid;
81 } if_u2;
82} xfs_ifork_t;
83
84
85
86
87
88struct xfs_imap {
89 xfs_daddr_t im_blkno;
90 ushort im_len;
91 ushort im_boffset;
92};
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117typedef struct xfs_ictimestamp {
118 __int32_t t_sec;
119 __int32_t t_nsec;
120} xfs_ictimestamp_t;
121
122
123
124
125
126typedef struct xfs_icdinode {
127 __uint16_t di_magic;
128 __uint16_t di_mode;
129 __int8_t di_version;
130 __int8_t di_format;
131 __uint16_t di_onlink;
132 __uint32_t di_uid;
133 __uint32_t di_gid;
134 __uint32_t di_nlink;
135 __uint16_t di_projid_lo;
136 __uint16_t di_projid_hi;
137 __uint8_t di_pad[6];
138 __uint16_t di_flushiter;
139 xfs_ictimestamp_t di_atime;
140 xfs_ictimestamp_t di_mtime;
141 xfs_ictimestamp_t di_ctime;
142 xfs_fsize_t di_size;
143 xfs_drfsbno_t di_nblocks;
144 xfs_extlen_t di_extsize;
145 xfs_extnum_t di_nextents;
146 xfs_aextnum_t di_anextents;
147 __uint8_t di_forkoff;
148 __int8_t di_aformat;
149 __uint32_t di_dmevmask;
150 __uint16_t di_dmstate;
151 __uint16_t di_flags;
152 __uint32_t di_gen;
153} xfs_icdinode_t;
154
155
156
157
158#define XFS_ICHGTIME_MOD 0x1
159#define XFS_ICHGTIME_CHG 0x2
160
161
162
163
164#define XFS_IFINLINE 0x01
165#define XFS_IFEXTENTS 0x02
166#define XFS_IFBROOT 0x04
167#define XFS_IFEXTIREC 0x08
168
169
170
171
172
173#define XFS_IFORK_Q(ip) ((ip)->i_d.di_forkoff != 0)
174#define XFS_IFORK_BOFF(ip) ((int)((ip)->i_d.di_forkoff << 3))
175
176#define XFS_IFORK_PTR(ip,w) \
177 ((w) == XFS_DATA_FORK ? \
178 &(ip)->i_df : \
179 (ip)->i_afp)
180#define XFS_IFORK_DSIZE(ip) \
181 (XFS_IFORK_Q(ip) ? \
182 XFS_IFORK_BOFF(ip) : \
183 XFS_LITINO((ip)->i_mount))
184#define XFS_IFORK_ASIZE(ip) \
185 (XFS_IFORK_Q(ip) ? \
186 XFS_LITINO((ip)->i_mount) - XFS_IFORK_BOFF(ip) : \
187 0)
188#define XFS_IFORK_SIZE(ip,w) \
189 ((w) == XFS_DATA_FORK ? \
190 XFS_IFORK_DSIZE(ip) : \
191 XFS_IFORK_ASIZE(ip))
192#define XFS_IFORK_FORMAT(ip,w) \
193 ((w) == XFS_DATA_FORK ? \
194 (ip)->i_d.di_format : \
195 (ip)->i_d.di_aformat)
196#define XFS_IFORK_FMT_SET(ip,w,n) \
197 ((w) == XFS_DATA_FORK ? \
198 ((ip)->i_d.di_format = (n)) : \
199 ((ip)->i_d.di_aformat = (n)))
200#define XFS_IFORK_NEXTENTS(ip,w) \
201 ((w) == XFS_DATA_FORK ? \
202 (ip)->i_d.di_nextents : \
203 (ip)->i_d.di_anextents)
204#define XFS_IFORK_NEXT_SET(ip,w,n) \
205 ((w) == XFS_DATA_FORK ? \
206 ((ip)->i_d.di_nextents = (n)) : \
207 ((ip)->i_d.di_anextents = (n)))
208#define XFS_IFORK_MAXEXT(ip, w) \
209 (XFS_IFORK_SIZE(ip, w) / sizeof(xfs_bmbt_rec_t))
210
211
212#ifdef __KERNEL__
213
214struct xfs_buf;
215struct xfs_bmap_free;
216struct xfs_bmbt_irec;
217struct xfs_inode_log_item;
218struct xfs_mount;
219struct xfs_trans;
220struct xfs_dquot;
221
222typedef struct xfs_inode {
223
224 struct xfs_mount *i_mount;
225 struct xfs_dquot *i_udquot;
226 struct xfs_dquot *i_gdquot;
227
228
229 xfs_ino_t i_ino;
230 struct xfs_imap i_imap;
231
232
233 xfs_ifork_t *i_afp;
234 xfs_ifork_t i_df;
235
236
237 struct xfs_inode_log_item *i_itemp;
238 mrlock_t i_lock;
239 mrlock_t i_iolock;
240 atomic_t i_pincount;
241 spinlock_t i_flags_lock;
242
243 unsigned long i_flags;
244 unsigned int i_delayed_blks;
245
246 xfs_icdinode_t i_d;
247
248
249 struct inode i_vnode;
250} xfs_inode_t;
251
252
253static inline struct xfs_inode *XFS_I(struct inode *inode)
254{
255 return container_of(inode, struct xfs_inode, i_vnode);
256}
257
258
259static inline struct inode *VFS_I(struct xfs_inode *ip)
260{
261 return &ip->i_vnode;
262}
263
264
265
266
267
268
269static inline xfs_fsize_t XFS_ISIZE(struct xfs_inode *ip)
270{
271 if (S_ISREG(ip->i_d.di_mode))
272 return i_size_read(VFS_I(ip));
273 return ip->i_d.di_size;
274}
275
276
277
278
279
280static inline xfs_fsize_t
281xfs_new_eof(struct xfs_inode *ip, xfs_fsize_t new_size)
282{
283 xfs_fsize_t i_size = i_size_read(VFS_I(ip));
284
285 if (new_size > i_size)
286 new_size = i_size;
287 return new_size > ip->i_d.di_size ? new_size : 0;
288}
289
290
291
292
293static inline void
294__xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
295{
296 ip->i_flags |= flags;
297}
298
299static inline void
300xfs_iflags_set(xfs_inode_t *ip, unsigned short flags)
301{
302 spin_lock(&ip->i_flags_lock);
303 __xfs_iflags_set(ip, flags);
304 spin_unlock(&ip->i_flags_lock);
305}
306
307static inline void
308xfs_iflags_clear(xfs_inode_t *ip, unsigned short flags)
309{
310 spin_lock(&ip->i_flags_lock);
311 ip->i_flags &= ~flags;
312 spin_unlock(&ip->i_flags_lock);
313}
314
315static inline int
316__xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
317{
318 return (ip->i_flags & flags);
319}
320
321static inline int
322xfs_iflags_test(xfs_inode_t *ip, unsigned short flags)
323{
324 int ret;
325 spin_lock(&ip->i_flags_lock);
326 ret = __xfs_iflags_test(ip, flags);
327 spin_unlock(&ip->i_flags_lock);
328 return ret;
329}
330
331static inline int
332xfs_iflags_test_and_clear(xfs_inode_t *ip, unsigned short flags)
333{
334 int ret;
335
336 spin_lock(&ip->i_flags_lock);
337 ret = ip->i_flags & flags;
338 if (ret)
339 ip->i_flags &= ~flags;
340 spin_unlock(&ip->i_flags_lock);
341 return ret;
342}
343
344static inline int
345xfs_iflags_test_and_set(xfs_inode_t *ip, unsigned short flags)
346{
347 int ret;
348
349 spin_lock(&ip->i_flags_lock);
350 ret = ip->i_flags & flags;
351 if (!ret)
352 ip->i_flags |= flags;
353 spin_unlock(&ip->i_flags_lock);
354 return ret;
355}
356
357
358
359
360
361
362static inline prid_t
363xfs_get_projid(struct xfs_inode *ip)
364{
365 return (prid_t)ip->i_d.di_projid_hi << 16 | ip->i_d.di_projid_lo;
366}
367
368static inline void
369xfs_set_projid(struct xfs_inode *ip,
370 prid_t projid)
371{
372 ip->i_d.di_projid_hi = (__uint16_t) (projid >> 16);
373 ip->i_d.di_projid_lo = (__uint16_t) (projid & 0xffff);
374}
375
376
377
378
379#define XFS_IRECLAIM (1 << 0)
380#define XFS_ISTALE (1 << 1)
381#define XFS_IRECLAIMABLE (1 << 2)
382#define XFS_INEW (1 << 3)
383#define XFS_IFILESTREAM (1 << 4)
384#define XFS_ITRUNCATED (1 << 5)
385#define XFS_IDIRTY_RELEASE (1 << 6)
386#define __XFS_IFLOCK_BIT 7
387#define XFS_IFLOCK (1 << __XFS_IFLOCK_BIT)
388#define __XFS_IPINNED_BIT 8
389#define XFS_IPINNED (1 << __XFS_IPINNED_BIT)
390#define XFS_IDONTCACHE (1 << 9)
391
392
393
394
395
396
397#define XFS_IRECLAIM_RESET_FLAGS \
398 (XFS_IRECLAIMABLE | XFS_IRECLAIM | \
399 XFS_IDIRTY_RELEASE | XFS_ITRUNCATED | \
400 XFS_IFILESTREAM);
401
402
403
404
405
406extern void __xfs_iflock(struct xfs_inode *ip);
407
408static inline int xfs_iflock_nowait(struct xfs_inode *ip)
409{
410 return !xfs_iflags_test_and_set(ip, XFS_IFLOCK);
411}
412
413static inline void xfs_iflock(struct xfs_inode *ip)
414{
415 if (!xfs_iflock_nowait(ip))
416 __xfs_iflock(ip);
417}
418
419static inline void xfs_ifunlock(struct xfs_inode *ip)
420{
421 xfs_iflags_clear(ip, XFS_IFLOCK);
422 wake_up_bit(&ip->i_flags, __XFS_IFLOCK_BIT);
423}
424
425static inline int xfs_isiflocked(struct xfs_inode *ip)
426{
427 return xfs_iflags_test(ip, XFS_IFLOCK);
428}
429
430
431
432
433
434
435#define XFS_IOLOCK_EXCL (1<<0)
436#define XFS_IOLOCK_SHARED (1<<1)
437#define XFS_ILOCK_EXCL (1<<2)
438#define XFS_ILOCK_SHARED (1<<3)
439
440#define XFS_LOCK_MASK (XFS_IOLOCK_EXCL | XFS_IOLOCK_SHARED \
441 | XFS_ILOCK_EXCL | XFS_ILOCK_SHARED)
442
443#define XFS_LOCK_FLAGS \
444 { XFS_IOLOCK_EXCL, "IOLOCK_EXCL" }, \
445 { XFS_IOLOCK_SHARED, "IOLOCK_SHARED" }, \
446 { XFS_ILOCK_EXCL, "ILOCK_EXCL" }, \
447 { XFS_ILOCK_SHARED, "ILOCK_SHARED" }
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470#define XFS_LOCK_PARENT 1
471#define XFS_LOCK_RTBITMAP 2
472#define XFS_LOCK_RTSUM 3
473#define XFS_LOCK_INUMORDER 4
474
475#define XFS_IOLOCK_SHIFT 16
476#define XFS_IOLOCK_PARENT (XFS_LOCK_PARENT << XFS_IOLOCK_SHIFT)
477
478#define XFS_ILOCK_SHIFT 24
479#define XFS_ILOCK_PARENT (XFS_LOCK_PARENT << XFS_ILOCK_SHIFT)
480#define XFS_ILOCK_RTBITMAP (XFS_LOCK_RTBITMAP << XFS_ILOCK_SHIFT)
481#define XFS_ILOCK_RTSUM (XFS_LOCK_RTSUM << XFS_ILOCK_SHIFT)
482
483#define XFS_IOLOCK_DEP_MASK 0x00ff0000
484#define XFS_ILOCK_DEP_MASK 0xff000000
485#define XFS_LOCK_DEP_MASK (XFS_IOLOCK_DEP_MASK | XFS_ILOCK_DEP_MASK)
486
487#define XFS_IOLOCK_DEP(flags) (((flags) & XFS_IOLOCK_DEP_MASK) >> XFS_IOLOCK_SHIFT)
488#define XFS_ILOCK_DEP(flags) (((flags) & XFS_ILOCK_DEP_MASK) >> XFS_ILOCK_SHIFT)
489
490
491
492
493
494
495#define XFS_INHERIT_GID(pip) \
496 (((pip)->i_mount->m_flags & XFS_MOUNT_GRPID) || \
497 ((pip)->i_d.di_mode & S_ISGID))
498
499
500
501
502int xfs_iget(struct xfs_mount *, struct xfs_trans *, xfs_ino_t,
503 uint, uint, xfs_inode_t **);
504void xfs_ilock(xfs_inode_t *, uint);
505int xfs_ilock_nowait(xfs_inode_t *, uint);
506void xfs_iunlock(xfs_inode_t *, uint);
507void xfs_ilock_demote(xfs_inode_t *, uint);
508int xfs_isilocked(xfs_inode_t *, uint);
509uint xfs_ilock_map_shared(xfs_inode_t *);
510void xfs_iunlock_map_shared(xfs_inode_t *, uint);
511void xfs_inode_free(struct xfs_inode *ip);
512
513
514
515
516int xfs_ialloc(struct xfs_trans *, xfs_inode_t *, umode_t,
517 xfs_nlink_t, xfs_dev_t, prid_t, int,
518 struct xfs_buf **, xfs_inode_t **);
519
520uint xfs_ip2xflags(struct xfs_inode *);
521uint xfs_dic2xflags(struct xfs_dinode *);
522int xfs_ifree(struct xfs_trans *, xfs_inode_t *,
523 struct xfs_bmap_free *);
524int xfs_itruncate_extents(struct xfs_trans **, struct xfs_inode *,
525 int, xfs_fsize_t);
526int xfs_iunlink(struct xfs_trans *, xfs_inode_t *);
527
528void xfs_iext_realloc(xfs_inode_t *, int, int);
529void xfs_iunpin_wait(xfs_inode_t *);
530int xfs_iflush(struct xfs_inode *, struct xfs_buf **);
531void xfs_lock_inodes(xfs_inode_t **, int, uint);
532void xfs_lock_two_inodes(xfs_inode_t *, xfs_inode_t *, uint);
533
534xfs_extlen_t xfs_get_extsz_hint(struct xfs_inode *ip);
535
536#define IHOLD(ip) \
537do { \
538 ASSERT(atomic_read(&VFS_I(ip)->i_count) > 0) ; \
539 ihold(VFS_I(ip)); \
540 trace_xfs_ihold(ip, _THIS_IP_); \
541} while (0)
542
543#define IRELE(ip) \
544do { \
545 trace_xfs_irele(ip, _THIS_IP_); \
546 iput(VFS_I(ip)); \
547} while (0)
548
549#endif
550
551
552
553
554#define XFS_IGET_CREATE 0x1
555#define XFS_IGET_UNTRUSTED 0x2
556#define XFS_IGET_DONTCACHE 0x4
557
558int xfs_imap_to_bp(struct xfs_mount *, struct xfs_trans *,
559 struct xfs_imap *, struct xfs_dinode **,
560 struct xfs_buf **, uint, uint);
561int xfs_iread(struct xfs_mount *, struct xfs_trans *,
562 struct xfs_inode *, uint);
563void xfs_dinode_to_disk(struct xfs_dinode *,
564 struct xfs_icdinode *);
565void xfs_idestroy_fork(struct xfs_inode *, int);
566void xfs_idata_realloc(struct xfs_inode *, int, int);
567void xfs_iroot_realloc(struct xfs_inode *, int, int);
568int xfs_iread_extents(struct xfs_trans *, struct xfs_inode *, int);
569int xfs_iextents_copy(struct xfs_inode *, xfs_bmbt_rec_t *, int);
570
571xfs_bmbt_rec_host_t *xfs_iext_get_ext(xfs_ifork_t *, xfs_extnum_t);
572void xfs_iext_insert(xfs_inode_t *, xfs_extnum_t, xfs_extnum_t,
573 xfs_bmbt_irec_t *, int);
574void xfs_iext_add(xfs_ifork_t *, xfs_extnum_t, int);
575void xfs_iext_add_indirect_multi(xfs_ifork_t *, int, xfs_extnum_t, int);
576void xfs_iext_remove(xfs_inode_t *, xfs_extnum_t, int, int);
577void xfs_iext_remove_inline(xfs_ifork_t *, xfs_extnum_t, int);
578void xfs_iext_remove_direct(xfs_ifork_t *, xfs_extnum_t, int);
579void xfs_iext_remove_indirect(xfs_ifork_t *, xfs_extnum_t, int);
580void xfs_iext_realloc_direct(xfs_ifork_t *, int);
581void xfs_iext_direct_to_inline(xfs_ifork_t *, xfs_extnum_t);
582void xfs_iext_inline_to_direct(xfs_ifork_t *, int);
583void xfs_iext_destroy(xfs_ifork_t *);
584xfs_bmbt_rec_host_t *xfs_iext_bno_to_ext(xfs_ifork_t *, xfs_fileoff_t, int *);
585xfs_ext_irec_t *xfs_iext_bno_to_irec(xfs_ifork_t *, xfs_fileoff_t, int *);
586xfs_ext_irec_t *xfs_iext_idx_to_irec(xfs_ifork_t *, xfs_extnum_t *, int *, int);
587void xfs_iext_irec_init(xfs_ifork_t *);
588xfs_ext_irec_t *xfs_iext_irec_new(xfs_ifork_t *, int);
589void xfs_iext_irec_remove(xfs_ifork_t *, int);
590void xfs_iext_irec_compact(xfs_ifork_t *);
591void xfs_iext_irec_compact_pages(xfs_ifork_t *);
592void xfs_iext_irec_compact_full(xfs_ifork_t *);
593void xfs_iext_irec_update_extoffs(xfs_ifork_t *, int, int);
594
595#define xfs_ipincount(ip) ((unsigned int) atomic_read(&ip->i_pincount))
596
597#if defined(DEBUG)
598void xfs_inobp_check(struct xfs_mount *, struct xfs_buf *);
599#else
600#define xfs_inobp_check(mp, bp)
601#endif
602
603extern struct kmem_zone *xfs_ifork_zone;
604extern struct kmem_zone *xfs_inode_zone;
605extern struct kmem_zone *xfs_ili_zone;
606
607#endif
608