1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
6 #ifndef __XFS_INODE_FORK_H__
7 #define __XFS_INODE_FORK_H__
9 struct xfs_inode_log_item;
13 * File incore extent information, present for each of data & attr forks.
16 int64_t if_bytes; /* bytes in if_u1 */
17 struct xfs_btree_block *if_broot; /* file's incore btree root */
18 unsigned int if_seq; /* fork mod counter */
19 int if_height; /* height of the extent tree */
21 void *if_root; /* extent tree root */
22 char *if_data; /* inline file data */
24 short if_broot_bytes; /* bytes allocated for root */
25 unsigned char if_flags; /* per-fork flags */
29 * Per-fork incore inode flags.
31 #define XFS_IFINLINE 0x01 /* Inline data is read in */
32 #define XFS_IFEXTENTS 0x02 /* All extent pointers are read in */
33 #define XFS_IFBROOT 0x04 /* i_broot points to the bmap b-tree root */
39 #define XFS_IFORK_Q(ip) ((ip)->i_d.di_forkoff != 0)
40 #define XFS_IFORK_BOFF(ip) ((int)((ip)->i_d.di_forkoff << 3))
42 #define XFS_IFORK_PTR(ip,w) \
43 ((w) == XFS_DATA_FORK ? \
45 ((w) == XFS_ATTR_FORK ? \
48 #define XFS_IFORK_DSIZE(ip) \
50 XFS_IFORK_BOFF(ip) : \
51 XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version))
52 #define XFS_IFORK_ASIZE(ip) \
54 XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version) - \
55 XFS_IFORK_BOFF(ip) : \
57 #define XFS_IFORK_SIZE(ip,w) \
58 ((w) == XFS_DATA_FORK ? \
59 XFS_IFORK_DSIZE(ip) : \
60 ((w) == XFS_ATTR_FORK ? \
61 XFS_IFORK_ASIZE(ip) : \
63 #define XFS_IFORK_FORMAT(ip,w) \
64 ((w) == XFS_DATA_FORK ? \
65 (ip)->i_d.di_format : \
66 ((w) == XFS_ATTR_FORK ? \
67 (ip)->i_d.di_aformat : \
69 #define XFS_IFORK_FMT_SET(ip,w,n) \
70 ((w) == XFS_DATA_FORK ? \
71 ((ip)->i_d.di_format = (n)) : \
72 ((w) == XFS_ATTR_FORK ? \
73 ((ip)->i_d.di_aformat = (n)) : \
74 ((ip)->i_cformat = (n))))
75 #define XFS_IFORK_NEXTENTS(ip,w) \
76 ((w) == XFS_DATA_FORK ? \
77 (ip)->i_d.di_nextents : \
78 ((w) == XFS_ATTR_FORK ? \
79 (ip)->i_d.di_anextents : \
81 #define XFS_IFORK_NEXT_SET(ip,w,n) \
82 ((w) == XFS_DATA_FORK ? \
83 ((ip)->i_d.di_nextents = (n)) : \
84 ((w) == XFS_ATTR_FORK ? \
85 ((ip)->i_d.di_anextents = (n)) : \
86 ((ip)->i_cnextents = (n))))
87 #define XFS_IFORK_MAXEXT(ip, w) \
88 (XFS_IFORK_SIZE(ip, w) / sizeof(xfs_bmbt_rec_t))
90 #define xfs_ifork_has_extents(ip, w) \
91 (XFS_IFORK_FORMAT((ip), (w)) == XFS_DINODE_FMT_EXTENTS || \
92 XFS_IFORK_FORMAT((ip), (w)) == XFS_DINODE_FMT_BTREE)
94 struct xfs_ifork *xfs_iext_state_to_fork(struct xfs_inode *ip, int state);
96 int xfs_iformat_fork(struct xfs_inode *, struct xfs_dinode *);
97 void xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *,
98 struct xfs_inode_log_item *, int);
99 void xfs_idestroy_fork(struct xfs_inode *, int);
100 void xfs_idata_realloc(struct xfs_inode *ip, int64_t byte_diff,
102 void xfs_iroot_realloc(struct xfs_inode *, int, int);
103 int xfs_iread_extents(struct xfs_trans *, struct xfs_inode *, int);
104 int xfs_iextents_copy(struct xfs_inode *, struct xfs_bmbt_rec *,
106 void xfs_init_local_fork(struct xfs_inode *ip, int whichfork,
107 const void *data, int64_t size);
109 xfs_extnum_t xfs_iext_count(struct xfs_ifork *ifp);
110 void xfs_iext_insert(struct xfs_inode *, struct xfs_iext_cursor *cur,
111 struct xfs_bmbt_irec *, int);
112 void xfs_iext_remove(struct xfs_inode *, struct xfs_iext_cursor *,
114 void xfs_iext_destroy(struct xfs_ifork *);
116 bool xfs_iext_lookup_extent(struct xfs_inode *ip,
117 struct xfs_ifork *ifp, xfs_fileoff_t bno,
118 struct xfs_iext_cursor *cur,
119 struct xfs_bmbt_irec *gotp);
120 bool xfs_iext_lookup_extent_before(struct xfs_inode *ip,
121 struct xfs_ifork *ifp, xfs_fileoff_t *end,
122 struct xfs_iext_cursor *cur,
123 struct xfs_bmbt_irec *gotp);
124 bool xfs_iext_get_extent(struct xfs_ifork *ifp,
125 struct xfs_iext_cursor *cur,
126 struct xfs_bmbt_irec *gotp);
127 void xfs_iext_update_extent(struct xfs_inode *ip, int state,
128 struct xfs_iext_cursor *cur,
129 struct xfs_bmbt_irec *gotp);
131 void xfs_iext_first(struct xfs_ifork *, struct xfs_iext_cursor *);
132 void xfs_iext_last(struct xfs_ifork *, struct xfs_iext_cursor *);
133 void xfs_iext_next(struct xfs_ifork *, struct xfs_iext_cursor *);
134 void xfs_iext_prev(struct xfs_ifork *, struct xfs_iext_cursor *);
136 static inline bool xfs_iext_next_extent(struct xfs_ifork *ifp,
137 struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
139 xfs_iext_next(ifp, cur);
140 return xfs_iext_get_extent(ifp, cur, gotp);
143 static inline bool xfs_iext_prev_extent(struct xfs_ifork *ifp,
144 struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
146 xfs_iext_prev(ifp, cur);
147 return xfs_iext_get_extent(ifp, cur, gotp);
151 * Return the extent after cur in gotp without updating the cursor.
153 static inline bool xfs_iext_peek_next_extent(struct xfs_ifork *ifp,
154 struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
156 struct xfs_iext_cursor ncur = *cur;
158 xfs_iext_next(ifp, &ncur);
159 return xfs_iext_get_extent(ifp, &ncur, gotp);
163 * Return the extent before cur in gotp without updating the cursor.
165 static inline bool xfs_iext_peek_prev_extent(struct xfs_ifork *ifp,
166 struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
168 struct xfs_iext_cursor ncur = *cur;
170 xfs_iext_prev(ifp, &ncur);
171 return xfs_iext_get_extent(ifp, &ncur, gotp);
174 #define for_each_xfs_iext(ifp, ext, got) \
175 for (xfs_iext_first((ifp), (ext)); \
176 xfs_iext_get_extent((ifp), (ext), (got)); \
177 xfs_iext_next((ifp), (ext)))
179 extern struct kmem_zone *xfs_ifork_zone;
181 extern void xfs_ifork_init_cow(struct xfs_inode *ip);
183 typedef xfs_failaddr_t (*xfs_ifork_verifier_t)(struct xfs_inode *);
185 struct xfs_ifork_ops {
186 xfs_ifork_verifier_t verify_symlink;
187 xfs_ifork_verifier_t verify_dir;
188 xfs_ifork_verifier_t verify_attr;
190 extern struct xfs_ifork_ops xfs_default_ifork_ops;
192 xfs_failaddr_t xfs_ifork_verify_data(struct xfs_inode *ip,
193 struct xfs_ifork_ops *ops);
194 xfs_failaddr_t xfs_ifork_verify_attr(struct xfs_inode *ip,
195 struct xfs_ifork_ops *ops);
197 #endif /* __XFS_INODE_FORK_H__ */