• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
4  * All Rights Reserved.
5  */
6 #ifndef	__XFS_INODE_FORK_H__
7 #define	__XFS_INODE_FORK_H__
8 
9 struct xfs_inode_log_item;
10 struct xfs_dinode;
11 
12 /*
13  * File incore extent information, present for each of data & attr forks.
14  */
15 struct xfs_ifork {
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 */
20 	union {
21 		void		*if_root;	/* extent tree root */
22 		char		*if_data;	/* inline file data */
23 	} if_u1;
24 	short			if_broot_bytes;	/* bytes allocated for root */
25 	unsigned char		if_flags;	/* per-fork flags */
26 };
27 
28 /*
29  * Per-fork incore inode flags.
30  */
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 */
34 
35 /*
36  * Fork handling.
37  */
38 
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))
41 
42 #define XFS_IFORK_PTR(ip,w)		\
43 	((w) == XFS_DATA_FORK ? \
44 		&(ip)->i_df : \
45 		((w) == XFS_ATTR_FORK ? \
46 			(ip)->i_afp : \
47 			(ip)->i_cowfp))
48 #define XFS_IFORK_DSIZE(ip) \
49 	(XFS_IFORK_Q(ip) ? XFS_IFORK_BOFF(ip) : XFS_LITINO((ip)->i_mount))
50 #define XFS_IFORK_ASIZE(ip) \
51 	(XFS_IFORK_Q(ip) ? XFS_LITINO((ip)->i_mount) - XFS_IFORK_BOFF(ip) : 0)
52 #define XFS_IFORK_SIZE(ip,w) \
53 	((w) == XFS_DATA_FORK ? \
54 		XFS_IFORK_DSIZE(ip) : \
55 		((w) == XFS_ATTR_FORK ? \
56 			XFS_IFORK_ASIZE(ip) : \
57 			0))
58 #define XFS_IFORK_FORMAT(ip,w) \
59 	((w) == XFS_DATA_FORK ? \
60 		(ip)->i_d.di_format : \
61 		((w) == XFS_ATTR_FORK ? \
62 			(ip)->i_d.di_aformat : \
63 			(ip)->i_cformat))
64 #define XFS_IFORK_FMT_SET(ip,w,n) \
65 	((w) == XFS_DATA_FORK ? \
66 		((ip)->i_d.di_format = (n)) : \
67 		((w) == XFS_ATTR_FORK ? \
68 			((ip)->i_d.di_aformat = (n)) : \
69 			((ip)->i_cformat = (n))))
70 #define XFS_IFORK_NEXTENTS(ip,w) \
71 	((w) == XFS_DATA_FORK ? \
72 		(ip)->i_d.di_nextents : \
73 		((w) == XFS_ATTR_FORK ? \
74 			(ip)->i_d.di_anextents : \
75 			(ip)->i_cnextents))
76 #define XFS_IFORK_NEXT_SET(ip,w,n) \
77 	((w) == XFS_DATA_FORK ? \
78 		((ip)->i_d.di_nextents = (n)) : \
79 		((w) == XFS_ATTR_FORK ? \
80 			((ip)->i_d.di_anextents = (n)) : \
81 			((ip)->i_cnextents = (n))))
82 #define XFS_IFORK_MAXEXT(ip, w) \
83 	(XFS_IFORK_SIZE(ip, w) / sizeof(xfs_bmbt_rec_t))
84 
85 struct xfs_ifork *xfs_iext_state_to_fork(struct xfs_inode *ip, int state);
86 
87 int		xfs_iformat_fork(struct xfs_inode *, struct xfs_dinode *);
88 void		xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *,
89 				struct xfs_inode_log_item *, int);
90 void		xfs_idestroy_fork(struct xfs_inode *, int);
91 void		xfs_idata_realloc(struct xfs_inode *ip, int64_t byte_diff,
92 				int whichfork);
93 void		xfs_iroot_realloc(struct xfs_inode *, int, int);
94 int		xfs_iread_extents(struct xfs_trans *, struct xfs_inode *, int);
95 int		xfs_iextents_copy(struct xfs_inode *, struct xfs_bmbt_rec *,
96 				  int);
97 void		xfs_init_local_fork(struct xfs_inode *ip, int whichfork,
98 				const void *data, int64_t size);
99 
100 xfs_extnum_t	xfs_iext_count(struct xfs_ifork *ifp);
101 void		xfs_iext_insert(struct xfs_inode *, struct xfs_iext_cursor *cur,
102 			struct xfs_bmbt_irec *, int);
103 void		xfs_iext_remove(struct xfs_inode *, struct xfs_iext_cursor *,
104 			int);
105 void		xfs_iext_destroy(struct xfs_ifork *);
106 
107 bool		xfs_iext_lookup_extent(struct xfs_inode *ip,
108 			struct xfs_ifork *ifp, xfs_fileoff_t bno,
109 			struct xfs_iext_cursor *cur,
110 			struct xfs_bmbt_irec *gotp);
111 bool		xfs_iext_lookup_extent_before(struct xfs_inode *ip,
112 			struct xfs_ifork *ifp, xfs_fileoff_t *end,
113 			struct xfs_iext_cursor *cur,
114 			struct xfs_bmbt_irec *gotp);
115 bool		xfs_iext_get_extent(struct xfs_ifork *ifp,
116 			struct xfs_iext_cursor *cur,
117 			struct xfs_bmbt_irec *gotp);
118 void		xfs_iext_update_extent(struct xfs_inode *ip, int state,
119 			struct xfs_iext_cursor *cur,
120 			struct xfs_bmbt_irec *gotp);
121 
122 void		xfs_iext_first(struct xfs_ifork *, struct xfs_iext_cursor *);
123 void		xfs_iext_last(struct xfs_ifork *, struct xfs_iext_cursor *);
124 void		xfs_iext_next(struct xfs_ifork *, struct xfs_iext_cursor *);
125 void		xfs_iext_prev(struct xfs_ifork *, struct xfs_iext_cursor *);
126 
xfs_iext_next_extent(struct xfs_ifork * ifp,struct xfs_iext_cursor * cur,struct xfs_bmbt_irec * gotp)127 static inline bool xfs_iext_next_extent(struct xfs_ifork *ifp,
128 		struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
129 {
130 	xfs_iext_next(ifp, cur);
131 	return xfs_iext_get_extent(ifp, cur, gotp);
132 }
133 
xfs_iext_prev_extent(struct xfs_ifork * ifp,struct xfs_iext_cursor * cur,struct xfs_bmbt_irec * gotp)134 static inline bool xfs_iext_prev_extent(struct xfs_ifork *ifp,
135 		struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
136 {
137 	xfs_iext_prev(ifp, cur);
138 	return xfs_iext_get_extent(ifp, cur, gotp);
139 }
140 
141 /*
142  * Return the extent after cur in gotp without updating the cursor.
143  */
xfs_iext_peek_next_extent(struct xfs_ifork * ifp,struct xfs_iext_cursor * cur,struct xfs_bmbt_irec * gotp)144 static inline bool xfs_iext_peek_next_extent(struct xfs_ifork *ifp,
145 		struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
146 {
147 	struct xfs_iext_cursor ncur = *cur;
148 
149 	xfs_iext_next(ifp, &ncur);
150 	return xfs_iext_get_extent(ifp, &ncur, gotp);
151 }
152 
153 /*
154  * Return the extent before cur in gotp without updating the cursor.
155  */
xfs_iext_peek_prev_extent(struct xfs_ifork * ifp,struct xfs_iext_cursor * cur,struct xfs_bmbt_irec * gotp)156 static inline bool xfs_iext_peek_prev_extent(struct xfs_ifork *ifp,
157 		struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
158 {
159 	struct xfs_iext_cursor ncur = *cur;
160 
161 	xfs_iext_prev(ifp, &ncur);
162 	return xfs_iext_get_extent(ifp, &ncur, gotp);
163 }
164 
165 #define for_each_xfs_iext(ifp, ext, got)		\
166 	for (xfs_iext_first((ifp), (ext));		\
167 	     xfs_iext_get_extent((ifp), (ext), (got));	\
168 	     xfs_iext_next((ifp), (ext)))
169 
170 extern struct kmem_zone	*xfs_ifork_zone;
171 
172 extern void xfs_ifork_init_cow(struct xfs_inode *ip);
173 
174 typedef xfs_failaddr_t (*xfs_ifork_verifier_t)(struct xfs_inode *);
175 
176 struct xfs_ifork_ops {
177 	xfs_ifork_verifier_t	verify_symlink;
178 	xfs_ifork_verifier_t	verify_dir;
179 	xfs_ifork_verifier_t	verify_attr;
180 };
181 extern struct xfs_ifork_ops	xfs_default_ifork_ops;
182 
183 xfs_failaddr_t xfs_ifork_verify_data(struct xfs_inode *ip,
184 		struct xfs_ifork_ops *ops);
185 xfs_failaddr_t xfs_ifork_verify_attr(struct xfs_inode *ip,
186 		struct xfs_ifork_ops *ops);
187 
188 #endif	/* __XFS_INODE_FORK_H__ */
189