xfs_inode_fork.h 6.1 KB
Newer Older
D
Dave Chinner 已提交
1
// SPDX-License-Identifier: GPL-2.0
2 3 4 5 6 7 8 9
/*
 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
 * All Rights Reserved.
 */
#ifndef	__XFS_INODE_FORK_H__
#define	__XFS_INODE_FORK_H__

struct xfs_inode_log_item;
10
struct xfs_dinode;
11 12 13 14

/*
 * File incore extent information, present for each of data & attr forks.
 */
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 23
		char		*if_data;	/* inline file data */
	} if_u1;
24 25
	short			if_broot_bytes;	/* bytes allocated for root */
	unsigned char		if_flags;	/* per-fork flags */
26
};
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

/*
 * Per-fork incore inode flags.
 */
#define	XFS_IFINLINE	0x01	/* Inline data is read in */
#define	XFS_IFEXTENTS	0x02	/* All extent pointers are read in */
#define	XFS_IFBROOT	0x04	/* i_broot points to the bmap b-tree root */

/*
 * Fork handling.
 */

#define XFS_IFORK_Q(ip)			((ip)->i_d.di_forkoff != 0)
#define XFS_IFORK_BOFF(ip)		((int)((ip)->i_d.di_forkoff << 3))

#define XFS_IFORK_PTR(ip,w)		\
	((w) == XFS_DATA_FORK ? \
		&(ip)->i_df : \
D
Darrick J. Wong 已提交
45 46 47
		((w) == XFS_ATTR_FORK ? \
			(ip)->i_afp : \
			(ip)->i_cowfp))
48 49 50 51 52 53 54 55 56 57 58 59
#define XFS_IFORK_DSIZE(ip) \
	(XFS_IFORK_Q(ip) ? \
		XFS_IFORK_BOFF(ip) : \
		XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version))
#define XFS_IFORK_ASIZE(ip) \
	(XFS_IFORK_Q(ip) ? \
		XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version) - \
			XFS_IFORK_BOFF(ip) : \
		0)
#define XFS_IFORK_SIZE(ip,w) \
	((w) == XFS_DATA_FORK ? \
		XFS_IFORK_DSIZE(ip) : \
D
Darrick J. Wong 已提交
60 61 62
		((w) == XFS_ATTR_FORK ? \
			XFS_IFORK_ASIZE(ip) : \
			0))
63 64 65
#define XFS_IFORK_FORMAT(ip,w) \
	((w) == XFS_DATA_FORK ? \
		(ip)->i_d.di_format : \
D
Darrick J. Wong 已提交
66 67 68
		((w) == XFS_ATTR_FORK ? \
			(ip)->i_d.di_aformat : \
			(ip)->i_cformat))
69 70 71
#define XFS_IFORK_FMT_SET(ip,w,n) \
	((w) == XFS_DATA_FORK ? \
		((ip)->i_d.di_format = (n)) : \
D
Darrick J. Wong 已提交
72 73 74
		((w) == XFS_ATTR_FORK ? \
			((ip)->i_d.di_aformat = (n)) : \
			((ip)->i_cformat = (n))))
75 76 77
#define XFS_IFORK_NEXTENTS(ip,w) \
	((w) == XFS_DATA_FORK ? \
		(ip)->i_d.di_nextents : \
D
Darrick J. Wong 已提交
78 79 80
		((w) == XFS_ATTR_FORK ? \
			(ip)->i_d.di_anextents : \
			(ip)->i_cnextents))
81 82 83
#define XFS_IFORK_NEXT_SET(ip,w,n) \
	((w) == XFS_DATA_FORK ? \
		((ip)->i_d.di_nextents = (n)) : \
D
Darrick J. Wong 已提交
84 85 86
		((w) == XFS_ATTR_FORK ? \
			((ip)->i_d.di_anextents = (n)) : \
			((ip)->i_cnextents = (n))))
87 88 89
#define XFS_IFORK_MAXEXT(ip, w) \
	(XFS_IFORK_SIZE(ip, w) / sizeof(xfs_bmbt_rec_t))

90 91 92 93
#define xfs_ifork_has_extents(ip, w) \
	(XFS_IFORK_FORMAT((ip), (w)) == XFS_DINODE_FMT_EXTENTS || \
	 XFS_IFORK_FORMAT((ip), (w)) == XFS_DINODE_FMT_BTREE)

D
Darrick J. Wong 已提交
94 95
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 101
void		xfs_idata_realloc(struct xfs_inode *ip, int64_t byte_diff,
				int whichfork);
102 103 104 105
void		xfs_iroot_realloc(struct xfs_inode *, int, int);
int		xfs_iread_extents(struct xfs_trans *, struct xfs_inode *, int);
int		xfs_iextents_copy(struct xfs_inode *, struct xfs_bmbt_rec *,
				  int);
106 107
void		xfs_init_local_fork(struct xfs_inode *ip, int whichfork,
				const void *data, int64_t size);
108

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 *,
113
			int);
114 115
void		xfs_iext_destroy(struct xfs_ifork *);

116 117
bool		xfs_iext_lookup_extent(struct xfs_inode *ip,
			struct xfs_ifork *ifp, xfs_fileoff_t bno,
118 119
			struct xfs_iext_cursor *cur,
			struct xfs_bmbt_irec *gotp);
120 121
bool		xfs_iext_lookup_extent_before(struct xfs_inode *ip,
			struct xfs_ifork *ifp, xfs_fileoff_t *end,
122 123 124 125
			struct xfs_iext_cursor *cur,
			struct xfs_bmbt_irec *gotp);
bool		xfs_iext_get_extent(struct xfs_ifork *ifp,
			struct xfs_iext_cursor *cur,
126
			struct xfs_bmbt_irec *gotp);
127
void		xfs_iext_update_extent(struct xfs_inode *ip, int state,
128 129 130
			struct xfs_iext_cursor *cur,
			struct xfs_bmbt_irec *gotp);

131 132 133 134
void		xfs_iext_first(struct xfs_ifork *, struct xfs_iext_cursor *);
void		xfs_iext_last(struct xfs_ifork *, struct xfs_iext_cursor *);
void		xfs_iext_next(struct xfs_ifork *, struct xfs_iext_cursor *);
void		xfs_iext_prev(struct xfs_ifork *, struct xfs_iext_cursor *);
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177

static inline bool xfs_iext_next_extent(struct xfs_ifork *ifp,
		struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
{
	xfs_iext_next(ifp, cur);
	return xfs_iext_get_extent(ifp, cur, gotp);
}

static inline bool xfs_iext_prev_extent(struct xfs_ifork *ifp,
		struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
{
	xfs_iext_prev(ifp, cur);
	return xfs_iext_get_extent(ifp, cur, gotp);
}

/*
 * Return the extent after cur in gotp without updating the cursor.
 */
static inline bool xfs_iext_peek_next_extent(struct xfs_ifork *ifp,
		struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
{
	struct xfs_iext_cursor ncur = *cur;

	xfs_iext_next(ifp, &ncur);
	return xfs_iext_get_extent(ifp, &ncur, gotp);
}

/*
 * Return the extent before cur in gotp without updating the cursor.
 */
static inline bool xfs_iext_peek_prev_extent(struct xfs_ifork *ifp,
		struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp)
{
	struct xfs_iext_cursor ncur = *cur;

	xfs_iext_prev(ifp, &ncur);
	return xfs_iext_get_extent(ifp, &ncur, gotp);
}

#define for_each_xfs_iext(ifp, ext, got)		\
	for (xfs_iext_first((ifp), (ext));		\
	     xfs_iext_get_extent((ifp), (ext), (got));	\
	     xfs_iext_next((ifp), (ext)))
178

179 180
extern struct kmem_zone	*xfs_ifork_zone;

D
Darrick J. Wong 已提交
181 182
extern void xfs_ifork_init_cow(struct xfs_inode *ip);

183 184 185 186 187 188 189 190 191 192 193 194 195 196
typedef xfs_failaddr_t (*xfs_ifork_verifier_t)(struct xfs_inode *);

struct xfs_ifork_ops {
	xfs_ifork_verifier_t	verify_symlink;
	xfs_ifork_verifier_t	verify_dir;
	xfs_ifork_verifier_t	verify_attr;
};
extern struct xfs_ifork_ops	xfs_default_ifork_ops;

xfs_failaddr_t xfs_ifork_verify_data(struct xfs_inode *ip,
		struct xfs_ifork_ops *ops);
xfs_failaddr_t xfs_ifork_verify_attr(struct xfs_inode *ip,
		struct xfs_ifork_ops *ops);

197
#endif	/* __XFS_INODE_FORK_H__ */