Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it would be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write the Free Software Foundation, |
| 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | #ifndef __XFS_INODE_FORK_H__ |
| 19 | #define __XFS_INODE_FORK_H__ |
| 20 | |
| 21 | struct xfs_inode_log_item; |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 22 | struct xfs_dinode; |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 23 | |
| 24 | /* |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 25 | * File incore extent information, present for each of data & attr forks. |
| 26 | */ |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 27 | typedef struct xfs_ifork { |
| 28 | int if_bytes; /* bytes in if_u1 */ |
| 29 | int if_real_bytes; /* bytes allocated in if_u1 */ |
| 30 | struct xfs_btree_block *if_broot; /* file's incore btree root */ |
| 31 | short if_broot_bytes; /* bytes allocated for root */ |
| 32 | unsigned char if_flags; /* per-fork flags */ |
Christoph Hellwig | 6bdcf26 | 2017-11-03 10:34:46 -0700 | [diff] [blame^] | 33 | int if_height; /* height of the extent tree */ |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 34 | union { |
Christoph Hellwig | 6bdcf26 | 2017-11-03 10:34:46 -0700 | [diff] [blame^] | 35 | void *if_root; /* extent tree root */ |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 36 | char *if_data; /* inline file data */ |
| 37 | } if_u1; |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 38 | } xfs_ifork_t; |
| 39 | |
| 40 | /* |
| 41 | * Per-fork incore inode flags. |
| 42 | */ |
| 43 | #define XFS_IFINLINE 0x01 /* Inline data is read in */ |
| 44 | #define XFS_IFEXTENTS 0x02 /* All extent pointers are read in */ |
| 45 | #define XFS_IFBROOT 0x04 /* i_broot points to the bmap b-tree root */ |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 46 | |
| 47 | /* |
| 48 | * Fork handling. |
| 49 | */ |
| 50 | |
| 51 | #define XFS_IFORK_Q(ip) ((ip)->i_d.di_forkoff != 0) |
| 52 | #define XFS_IFORK_BOFF(ip) ((int)((ip)->i_d.di_forkoff << 3)) |
| 53 | |
| 54 | #define XFS_IFORK_PTR(ip,w) \ |
| 55 | ((w) == XFS_DATA_FORK ? \ |
| 56 | &(ip)->i_df : \ |
Darrick J. Wong | 3993bae | 2016-10-03 09:11:32 -0700 | [diff] [blame] | 57 | ((w) == XFS_ATTR_FORK ? \ |
| 58 | (ip)->i_afp : \ |
| 59 | (ip)->i_cowfp)) |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 60 | #define XFS_IFORK_DSIZE(ip) \ |
| 61 | (XFS_IFORK_Q(ip) ? \ |
| 62 | XFS_IFORK_BOFF(ip) : \ |
| 63 | XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version)) |
| 64 | #define XFS_IFORK_ASIZE(ip) \ |
| 65 | (XFS_IFORK_Q(ip) ? \ |
| 66 | XFS_LITINO((ip)->i_mount, (ip)->i_d.di_version) - \ |
| 67 | XFS_IFORK_BOFF(ip) : \ |
| 68 | 0) |
| 69 | #define XFS_IFORK_SIZE(ip,w) \ |
| 70 | ((w) == XFS_DATA_FORK ? \ |
| 71 | XFS_IFORK_DSIZE(ip) : \ |
Darrick J. Wong | 3993bae | 2016-10-03 09:11:32 -0700 | [diff] [blame] | 72 | ((w) == XFS_ATTR_FORK ? \ |
| 73 | XFS_IFORK_ASIZE(ip) : \ |
| 74 | 0)) |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 75 | #define XFS_IFORK_FORMAT(ip,w) \ |
| 76 | ((w) == XFS_DATA_FORK ? \ |
| 77 | (ip)->i_d.di_format : \ |
Darrick J. Wong | 3993bae | 2016-10-03 09:11:32 -0700 | [diff] [blame] | 78 | ((w) == XFS_ATTR_FORK ? \ |
| 79 | (ip)->i_d.di_aformat : \ |
| 80 | (ip)->i_cformat)) |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 81 | #define XFS_IFORK_FMT_SET(ip,w,n) \ |
| 82 | ((w) == XFS_DATA_FORK ? \ |
| 83 | ((ip)->i_d.di_format = (n)) : \ |
Darrick J. Wong | 3993bae | 2016-10-03 09:11:32 -0700 | [diff] [blame] | 84 | ((w) == XFS_ATTR_FORK ? \ |
| 85 | ((ip)->i_d.di_aformat = (n)) : \ |
| 86 | ((ip)->i_cformat = (n)))) |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 87 | #define XFS_IFORK_NEXTENTS(ip,w) \ |
| 88 | ((w) == XFS_DATA_FORK ? \ |
| 89 | (ip)->i_d.di_nextents : \ |
Darrick J. Wong | 3993bae | 2016-10-03 09:11:32 -0700 | [diff] [blame] | 90 | ((w) == XFS_ATTR_FORK ? \ |
| 91 | (ip)->i_d.di_anextents : \ |
| 92 | (ip)->i_cnextents)) |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 93 | #define XFS_IFORK_NEXT_SET(ip,w,n) \ |
| 94 | ((w) == XFS_DATA_FORK ? \ |
| 95 | ((ip)->i_d.di_nextents = (n)) : \ |
Darrick J. Wong | 3993bae | 2016-10-03 09:11:32 -0700 | [diff] [blame] | 96 | ((w) == XFS_ATTR_FORK ? \ |
| 97 | ((ip)->i_d.di_anextents = (n)) : \ |
| 98 | ((ip)->i_cnextents = (n)))) |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 99 | #define XFS_IFORK_MAXEXT(ip, w) \ |
| 100 | (XFS_IFORK_SIZE(ip, w) / sizeof(xfs_bmbt_rec_t)) |
| 101 | |
Darrick J. Wong | 3993bae | 2016-10-03 09:11:32 -0700 | [diff] [blame] | 102 | struct xfs_ifork *xfs_iext_state_to_fork(struct xfs_inode *ip, int state); |
| 103 | |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 104 | int xfs_iformat_fork(struct xfs_inode *, struct xfs_dinode *); |
Darrick J. Wong | 7842028 | 2017-04-03 12:22:20 -0700 | [diff] [blame] | 105 | void xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *, |
Eric Sandeen | fd9fdba | 2014-04-14 19:04:46 +1000 | [diff] [blame] | 106 | struct xfs_inode_log_item *, int); |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 107 | void xfs_idestroy_fork(struct xfs_inode *, int); |
| 108 | void xfs_idata_realloc(struct xfs_inode *, int, int); |
| 109 | void xfs_iroot_realloc(struct xfs_inode *, int, int); |
| 110 | int xfs_iread_extents(struct xfs_trans *, struct xfs_inode *, int); |
| 111 | int xfs_iextents_copy(struct xfs_inode *, struct xfs_bmbt_rec *, |
| 112 | int); |
Christoph Hellwig | 143f4ae | 2016-04-06 07:41:43 +1000 | [diff] [blame] | 113 | void xfs_init_local_fork(struct xfs_inode *, int, const void *, int); |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 114 | |
Christoph Hellwig | 6bdcf26 | 2017-11-03 10:34:46 -0700 | [diff] [blame^] | 115 | xfs_extnum_t xfs_iext_count(struct xfs_ifork *ifp); |
Christoph Hellwig | b2b1712 | 2017-11-03 10:34:43 -0700 | [diff] [blame] | 116 | void xfs_iext_insert(struct xfs_inode *, struct xfs_iext_cursor *cur, |
| 117 | xfs_extnum_t, struct xfs_bmbt_irec *, int); |
Christoph Hellwig | b2b1712 | 2017-11-03 10:34:43 -0700 | [diff] [blame] | 118 | void xfs_iext_remove(struct xfs_inode *, struct xfs_iext_cursor *, |
| 119 | int, int); |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 120 | void xfs_iext_destroy(struct xfs_ifork *); |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 121 | |
Christoph Hellwig | 93533c7 | 2016-11-24 11:39:32 +1100 | [diff] [blame] | 122 | bool xfs_iext_lookup_extent(struct xfs_inode *ip, |
| 123 | struct xfs_ifork *ifp, xfs_fileoff_t bno, |
Christoph Hellwig | b2b1712 | 2017-11-03 10:34:43 -0700 | [diff] [blame] | 124 | struct xfs_iext_cursor *cur, |
| 125 | struct xfs_bmbt_irec *gotp); |
Christoph Hellwig | dc56015 | 2017-10-23 16:32:39 -0700 | [diff] [blame] | 126 | bool xfs_iext_lookup_extent_before(struct xfs_inode *ip, |
| 127 | struct xfs_ifork *ifp, xfs_fileoff_t *end, |
Christoph Hellwig | b2b1712 | 2017-11-03 10:34:43 -0700 | [diff] [blame] | 128 | struct xfs_iext_cursor *cur, |
| 129 | struct xfs_bmbt_irec *gotp); |
| 130 | bool xfs_iext_get_extent(struct xfs_ifork *ifp, |
| 131 | struct xfs_iext_cursor *cur, |
Christoph Hellwig | 93533c7 | 2016-11-24 11:39:32 +1100 | [diff] [blame] | 132 | struct xfs_bmbt_irec *gotp); |
Christoph Hellwig | ca5d8e5 | 2017-10-19 11:04:44 -0700 | [diff] [blame] | 133 | void xfs_iext_update_extent(struct xfs_inode *ip, int state, |
Christoph Hellwig | b2b1712 | 2017-11-03 10:34:43 -0700 | [diff] [blame] | 134 | struct xfs_iext_cursor *cur, |
| 135 | struct xfs_bmbt_irec *gotp); |
| 136 | |
Christoph Hellwig | 6bdcf26 | 2017-11-03 10:34:46 -0700 | [diff] [blame^] | 137 | void xfs_iext_first(struct xfs_ifork *, struct xfs_iext_cursor *); |
| 138 | void xfs_iext_last(struct xfs_ifork *, struct xfs_iext_cursor *); |
| 139 | void xfs_iext_next(struct xfs_ifork *, struct xfs_iext_cursor *); |
| 140 | void xfs_iext_prev(struct xfs_ifork *, struct xfs_iext_cursor *); |
Christoph Hellwig | b2b1712 | 2017-11-03 10:34:43 -0700 | [diff] [blame] | 141 | |
| 142 | static inline bool xfs_iext_next_extent(struct xfs_ifork *ifp, |
| 143 | struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp) |
| 144 | { |
| 145 | xfs_iext_next(ifp, cur); |
| 146 | return xfs_iext_get_extent(ifp, cur, gotp); |
| 147 | } |
| 148 | |
| 149 | static inline bool xfs_iext_prev_extent(struct xfs_ifork *ifp, |
| 150 | struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp) |
| 151 | { |
| 152 | xfs_iext_prev(ifp, cur); |
| 153 | return xfs_iext_get_extent(ifp, cur, gotp); |
| 154 | } |
| 155 | |
| 156 | /* |
| 157 | * Return the extent after cur in gotp without updating the cursor. |
| 158 | */ |
| 159 | static inline bool xfs_iext_peek_next_extent(struct xfs_ifork *ifp, |
| 160 | struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp) |
| 161 | { |
| 162 | struct xfs_iext_cursor ncur = *cur; |
| 163 | |
| 164 | xfs_iext_next(ifp, &ncur); |
| 165 | return xfs_iext_get_extent(ifp, &ncur, gotp); |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * Return the extent before cur in gotp without updating the cursor. |
| 170 | */ |
| 171 | static inline bool xfs_iext_peek_prev_extent(struct xfs_ifork *ifp, |
| 172 | struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *gotp) |
| 173 | { |
| 174 | struct xfs_iext_cursor ncur = *cur; |
| 175 | |
| 176 | xfs_iext_prev(ifp, &ncur); |
| 177 | return xfs_iext_get_extent(ifp, &ncur, gotp); |
| 178 | } |
| 179 | |
| 180 | #define for_each_xfs_iext(ifp, ext, got) \ |
| 181 | for (xfs_iext_first((ifp), (ext)); \ |
| 182 | xfs_iext_get_extent((ifp), (ext), (got)); \ |
| 183 | xfs_iext_next((ifp), (ext))) |
Christoph Hellwig | 93533c7 | 2016-11-24 11:39:32 +1100 | [diff] [blame] | 184 | |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 185 | extern struct kmem_zone *xfs_ifork_zone; |
| 186 | |
Darrick J. Wong | 3993bae | 2016-10-03 09:11:32 -0700 | [diff] [blame] | 187 | extern void xfs_ifork_init_cow(struct xfs_inode *ip); |
| 188 | |
Dave Chinner | 5c4d97d | 2013-08-12 20:49:33 +1000 | [diff] [blame] | 189 | #endif /* __XFS_INODE_FORK_H__ */ |