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 */
26 int8_t if_format; /* format of this fork */
27 xfs_extnum_t if_nextents; /* # of extents in this fork */
31 * Per-fork incore inode flags.
33 #define XFS_IFINLINE 0x01 /* Inline data is read in */
34 #define XFS_IFEXTENTS 0x02 /* All extent pointers are read in */
35 #define XFS_IFBROOT 0x04 /* i_broot points to the bmap b-tree root */
41 #define XFS_IFORK_Q(ip) ((ip)->i_d.di_forkoff != 0)
42 #define XFS_IFORK_BOFF(ip) ((int)((ip)->i_d.di_forkoff << 3))
44 #define XFS_IFORK_PTR(ip,w) \
45 ((w) == XFS_DATA_FORK ? \
47 ((w) == XFS_ATTR_FORK ? \
50 #define XFS_IFORK_DSIZE(ip) \
51 (XFS_IFORK_Q(ip) ? XFS_IFORK_BOFF(ip) : XFS_LITINO((ip)->i_mount))
52 #define XFS_IFORK_ASIZE(ip) \
53 (XFS_IFORK_Q(ip) ? XFS_LITINO((ip)->i_mount) - XFS_IFORK_BOFF(ip) : 0)
54 #define XFS_IFORK_SIZE(ip,w) \
55 ((w) == XFS_DATA_FORK ? \
56 XFS_IFORK_DSIZE(ip) : \
57 ((w) == XFS_ATTR_FORK ? \
58 XFS_IFORK_ASIZE(ip) : \
60 #define XFS_IFORK_MAXEXT(ip, w) \
61 (XFS_IFORK_SIZE(ip, w) / sizeof(xfs_bmbt_rec_t))
63 static inline bool xfs_ifork_has_extents(struct xfs_ifork *ifp)
65 return ifp->if_format == XFS_DINODE_FMT_EXTENTS ||
66 ifp->if_format == XFS_DINODE_FMT_BTREE;
69 static inline xfs_extnum_t xfs_ifork_nextents(struct xfs_ifork *ifp)
73 return ifp->if_nextents;
76 static inline int8_t xfs_ifork_format(struct xfs_ifork *ifp)
79 return XFS_DINODE_FMT_EXTENTS;
80 return ifp->if_format;
83 struct xfs_ifork *xfs_iext_state_to_fork(struct xfs_inode *ip, int state);
85 int xfs_iformat_data_fork(struct xfs_inode *, struct xfs_dinode *);
86 int xfs_iformat_attr_fork(struct xfs_inode *, struct xfs_dinode *);
87 void xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *,
88 struct xfs_inode_log_item *, int);
89 void xfs_idestroy_fork(struct xfs_ifork *ifp);
90 void xfs_idata_realloc(struct xfs_inode *ip, int64_t byte_diff,
92 void xfs_iroot_realloc(struct xfs_inode *, int, int);
93 int xfs_iread_extents(struct xfs_trans *, struct xfs_inode *, int);
94 int xfs_iextents_copy(struct xfs_inode *, struct xfs_bmbt_rec *,
96 void xfs_init_local_fork(struct xfs_inode *ip, int whichfork,
97 const void *data, int64_t size);
99 xfs_extnum_t xfs_iext_count(struct xfs_ifork *ifp);
100 void xfs_iext_insert(struct xfs_inode *, struct xfs_iext_cursor *cur,
101 struct xfs_bmbt_irec *, int);
102 void xfs_iext_remove(struct xfs_inode *, struct xfs_iext_cursor *,
104 void xfs_iext_destroy(struct xfs_ifork *);
106 bool xfs_iext_lookup_extent(struct xfs_inode *ip,
107 struct xfs_ifork *ifp, xfs_fileoff_t bno,
108 struct xfs_iext_cursor *cur,
109 struct xfs_bmbt_irec *gotp);
110 bool xfs_iext_lookup_extent_before(struct xfs_inode *ip,
111 struct xfs_ifork *ifp, xfs_fileoff_t *end,
112 struct xfs_iext_cursor *cur,
113 struct xfs_bmbt_irec *gotp);
114 bool xfs_iext_get_extent(struct xfs_ifork *ifp,
115 struct xfs_iext_cursor *cur,
116 struct xfs_bmbt_irec *gotp);
117 void xfs_iext_update_extent(struct xfs_inode *ip, int state,
118 struct xfs_iext_cursor *cur,
119 struct xfs_bmbt_irec *gotp);
121 void xfs_iext_first(struct xfs_ifork *, struct xfs_iext_cursor *);
122 void xfs_iext_last(struct xfs_ifork *, struct xfs_iext_cursor *);
123 void xfs_iext_next(struct xfs_ifork *, struct xfs_iext_cursor *);
124 void xfs_iext_prev(struct xfs_ifork *, struct xfs_iext_cursor *);
126 static inline bool xfs_iext_next_extent(struct xfs_ifork *ifp,
127 struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
129 xfs_iext_next(ifp, cur);
130 return xfs_iext_get_extent(ifp, cur, gotp);
133 static inline bool xfs_iext_prev_extent(struct xfs_ifork *ifp,
134 struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
136 xfs_iext_prev(ifp, cur);
137 return xfs_iext_get_extent(ifp, cur, gotp);
141 * Return the extent after cur in gotp without updating the cursor.
143 static inline bool xfs_iext_peek_next_extent(struct xfs_ifork *ifp,
144 struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
146 struct xfs_iext_cursor ncur = *cur;
148 xfs_iext_next(ifp, &ncur);
149 return xfs_iext_get_extent(ifp, &ncur, gotp);
153 * Return the extent before cur in gotp without updating the cursor.
155 static inline bool xfs_iext_peek_prev_extent(struct xfs_ifork *ifp,
156 struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
158 struct xfs_iext_cursor ncur = *cur;
160 xfs_iext_prev(ifp, &ncur);
161 return xfs_iext_get_extent(ifp, &ncur, gotp);
164 #define for_each_xfs_iext(ifp, ext, got) \
165 for (xfs_iext_first((ifp), (ext)); \
166 xfs_iext_get_extent((ifp), (ext), (got)); \
167 xfs_iext_next((ifp), (ext)))
169 extern struct kmem_zone *xfs_ifork_zone;
171 extern void xfs_ifork_init_cow(struct xfs_inode *ip);
173 int xfs_ifork_verify_local_data(struct xfs_inode *ip);
174 int xfs_ifork_verify_local_attr(struct xfs_inode *ip);
176 #endif /* __XFS_INODE_FORK_H__ */