0001
0002
0003
0004
0005
0006 #ifndef __XFS_BMAP_H__
0007 #define __XFS_BMAP_H__
0008
0009 struct getbmap;
0010 struct xfs_bmbt_irec;
0011 struct xfs_ifork;
0012 struct xfs_inode;
0013 struct xfs_mount;
0014 struct xfs_trans;
0015
0016
0017
0018
0019 struct xfs_bmalloca {
0020 struct xfs_trans *tp;
0021 struct xfs_inode *ip;
0022 struct xfs_bmbt_irec prev;
0023 struct xfs_bmbt_irec got;
0024
0025 xfs_fileoff_t offset;
0026 xfs_extlen_t length;
0027 xfs_fsblock_t blkno;
0028
0029 struct xfs_btree_cur *cur;
0030 struct xfs_iext_cursor icur;
0031 int nallocs;
0032 int logflags;
0033
0034 xfs_extlen_t total;
0035 xfs_extlen_t minlen;
0036 xfs_extlen_t minleft;
0037 bool eof;
0038 bool wasdel;
0039 bool aeof;
0040 bool conv;
0041 int datatype;
0042 uint32_t flags;
0043 };
0044
0045 #define XFS_BMAP_MAX_NMAP 4
0046
0047
0048
0049
0050 #define XFS_BMAPI_ENTIRE (1u << 0)
0051 #define XFS_BMAPI_METADATA (1u << 1)
0052 #define XFS_BMAPI_ATTRFORK (1u << 2)
0053 #define XFS_BMAPI_PREALLOC (1u << 3)
0054 #define XFS_BMAPI_CONTIG (1u << 4)
0055
0056
0057
0058
0059
0060 #define XFS_BMAPI_CONVERT (1u << 5)
0061
0062
0063
0064
0065
0066
0067
0068 #define XFS_BMAPI_ZERO (1u << 6)
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078 #define XFS_BMAPI_REMAP (1u << 7)
0079
0080
0081 #define XFS_BMAPI_COWFORK (1u << 8)
0082
0083
0084 #define XFS_BMAPI_NODISCARD (1u << 9)
0085
0086
0087 #define XFS_BMAPI_NORMAP (1u << 10)
0088
0089 #define XFS_BMAPI_FLAGS \
0090 { XFS_BMAPI_ENTIRE, "ENTIRE" }, \
0091 { XFS_BMAPI_METADATA, "METADATA" }, \
0092 { XFS_BMAPI_ATTRFORK, "ATTRFORK" }, \
0093 { XFS_BMAPI_PREALLOC, "PREALLOC" }, \
0094 { XFS_BMAPI_CONTIG, "CONTIG" }, \
0095 { XFS_BMAPI_CONVERT, "CONVERT" }, \
0096 { XFS_BMAPI_ZERO, "ZERO" }, \
0097 { XFS_BMAPI_REMAP, "REMAP" }, \
0098 { XFS_BMAPI_COWFORK, "COWFORK" }, \
0099 { XFS_BMAPI_NODISCARD, "NODISCARD" }, \
0100 { XFS_BMAPI_NORMAP, "NORMAP" }
0101
0102
0103 static inline int xfs_bmapi_aflag(int w)
0104 {
0105 return (w == XFS_ATTR_FORK ? XFS_BMAPI_ATTRFORK :
0106 (w == XFS_COW_FORK ? XFS_BMAPI_COWFORK : 0));
0107 }
0108
0109 static inline int xfs_bmapi_whichfork(uint32_t bmapi_flags)
0110 {
0111 if (bmapi_flags & XFS_BMAPI_COWFORK)
0112 return XFS_COW_FORK;
0113 else if (bmapi_flags & XFS_BMAPI_ATTRFORK)
0114 return XFS_ATTR_FORK;
0115 return XFS_DATA_FORK;
0116 }
0117
0118
0119
0120
0121 #define DELAYSTARTBLOCK ((xfs_fsblock_t)-1LL)
0122 #define HOLESTARTBLOCK ((xfs_fsblock_t)-2LL)
0123
0124
0125
0126
0127 #define BMAP_LEFT_CONTIG (1u << 0)
0128 #define BMAP_RIGHT_CONTIG (1u << 1)
0129 #define BMAP_LEFT_FILLING (1u << 2)
0130 #define BMAP_RIGHT_FILLING (1u << 3)
0131 #define BMAP_LEFT_DELAY (1u << 4)
0132 #define BMAP_RIGHT_DELAY (1u << 5)
0133 #define BMAP_LEFT_VALID (1u << 6)
0134 #define BMAP_RIGHT_VALID (1u << 7)
0135 #define BMAP_ATTRFORK (1u << 8)
0136 #define BMAP_COWFORK (1u << 9)
0137
0138 #define XFS_BMAP_EXT_FLAGS \
0139 { BMAP_LEFT_CONTIG, "LC" }, \
0140 { BMAP_RIGHT_CONTIG, "RC" }, \
0141 { BMAP_LEFT_FILLING, "LF" }, \
0142 { BMAP_RIGHT_FILLING, "RF" }, \
0143 { BMAP_ATTRFORK, "ATTR" }, \
0144 { BMAP_COWFORK, "COW" }
0145
0146
0147 static inline bool xfs_bmap_is_real_extent(struct xfs_bmbt_irec *irec)
0148 {
0149 return irec->br_startblock != HOLESTARTBLOCK &&
0150 irec->br_startblock != DELAYSTARTBLOCK &&
0151 !isnullstartblock(irec->br_startblock);
0152 }
0153
0154
0155
0156
0157
0158 static inline bool xfs_bmap_is_written_extent(struct xfs_bmbt_irec *irec)
0159 {
0160 return xfs_bmap_is_real_extent(irec) &&
0161 irec->br_state != XFS_EXT_UNWRITTEN;
0162 }
0163
0164
0165
0166
0167
0168 #define xfs_valid_startblock(ip, startblock) \
0169 ((startblock) != 0 || XFS_IS_REALTIME_INODE(ip))
0170
0171 void xfs_trim_extent(struct xfs_bmbt_irec *irec, xfs_fileoff_t bno,
0172 xfs_filblks_t len);
0173 unsigned int xfs_bmap_compute_attr_offset(struct xfs_mount *mp);
0174 int xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd);
0175 void xfs_bmap_local_to_extents_empty(struct xfs_trans *tp,
0176 struct xfs_inode *ip, int whichfork);
0177 void xfs_bmap_compute_maxlevels(struct xfs_mount *mp, int whichfork);
0178 int xfs_bmap_first_unused(struct xfs_trans *tp, struct xfs_inode *ip,
0179 xfs_extlen_t len, xfs_fileoff_t *unused, int whichfork);
0180 int xfs_bmap_last_before(struct xfs_trans *tp, struct xfs_inode *ip,
0181 xfs_fileoff_t *last_block, int whichfork);
0182 int xfs_bmap_last_offset(struct xfs_inode *ip, xfs_fileoff_t *unused,
0183 int whichfork);
0184 int xfs_bmapi_read(struct xfs_inode *ip, xfs_fileoff_t bno,
0185 xfs_filblks_t len, struct xfs_bmbt_irec *mval,
0186 int *nmap, uint32_t flags);
0187 int xfs_bmapi_write(struct xfs_trans *tp, struct xfs_inode *ip,
0188 xfs_fileoff_t bno, xfs_filblks_t len, uint32_t flags,
0189 xfs_extlen_t total, struct xfs_bmbt_irec *mval, int *nmap);
0190 int __xfs_bunmapi(struct xfs_trans *tp, struct xfs_inode *ip,
0191 xfs_fileoff_t bno, xfs_filblks_t *rlen, uint32_t flags,
0192 xfs_extnum_t nexts);
0193 int xfs_bunmapi(struct xfs_trans *tp, struct xfs_inode *ip,
0194 xfs_fileoff_t bno, xfs_filblks_t len, uint32_t flags,
0195 xfs_extnum_t nexts, int *done);
0196 int xfs_bmap_del_extent_delay(struct xfs_inode *ip, int whichfork,
0197 struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *got,
0198 struct xfs_bmbt_irec *del);
0199 void xfs_bmap_del_extent_cow(struct xfs_inode *ip,
0200 struct xfs_iext_cursor *cur, struct xfs_bmbt_irec *got,
0201 struct xfs_bmbt_irec *del);
0202 uint xfs_default_attroffset(struct xfs_inode *ip);
0203 int xfs_bmap_collapse_extents(struct xfs_trans *tp, struct xfs_inode *ip,
0204 xfs_fileoff_t *next_fsb, xfs_fileoff_t offset_shift_fsb,
0205 bool *done);
0206 int xfs_bmap_can_insert_extents(struct xfs_inode *ip, xfs_fileoff_t off,
0207 xfs_fileoff_t shift);
0208 int xfs_bmap_insert_extents(struct xfs_trans *tp, struct xfs_inode *ip,
0209 xfs_fileoff_t *next_fsb, xfs_fileoff_t offset_shift_fsb,
0210 bool *done, xfs_fileoff_t stop_fsb);
0211 int xfs_bmap_split_extent(struct xfs_trans *tp, struct xfs_inode *ip,
0212 xfs_fileoff_t split_offset);
0213 int xfs_bmapi_reserve_delalloc(struct xfs_inode *ip, int whichfork,
0214 xfs_fileoff_t off, xfs_filblks_t len, xfs_filblks_t prealloc,
0215 struct xfs_bmbt_irec *got, struct xfs_iext_cursor *cur,
0216 int eof);
0217 int xfs_bmapi_convert_delalloc(struct xfs_inode *ip, int whichfork,
0218 xfs_off_t offset, struct iomap *iomap, unsigned int *seq);
0219 int xfs_bmap_add_extent_unwritten_real(struct xfs_trans *tp,
0220 struct xfs_inode *ip, int whichfork,
0221 struct xfs_iext_cursor *icur, struct xfs_btree_cur **curp,
0222 struct xfs_bmbt_irec *new, int *logflagsp);
0223
0224 enum xfs_bmap_intent_type {
0225 XFS_BMAP_MAP = 1,
0226 XFS_BMAP_UNMAP,
0227 };
0228
0229 struct xfs_bmap_intent {
0230 struct list_head bi_list;
0231 enum xfs_bmap_intent_type bi_type;
0232 int bi_whichfork;
0233 struct xfs_inode *bi_owner;
0234 struct xfs_bmbt_irec bi_bmap;
0235 };
0236
0237 int xfs_bmap_finish_one(struct xfs_trans *tp, struct xfs_inode *ip,
0238 enum xfs_bmap_intent_type type, int whichfork,
0239 xfs_fileoff_t startoff, xfs_fsblock_t startblock,
0240 xfs_filblks_t *blockcount, xfs_exntst_t state);
0241 void xfs_bmap_map_extent(struct xfs_trans *tp, struct xfs_inode *ip,
0242 struct xfs_bmbt_irec *imap);
0243 void xfs_bmap_unmap_extent(struct xfs_trans *tp, struct xfs_inode *ip,
0244 struct xfs_bmbt_irec *imap);
0245
0246 static inline uint32_t xfs_bmap_fork_to_state(int whichfork)
0247 {
0248 switch (whichfork) {
0249 case XFS_ATTR_FORK:
0250 return BMAP_ATTRFORK;
0251 case XFS_COW_FORK:
0252 return BMAP_COWFORK;
0253 default:
0254 return 0;
0255 }
0256 }
0257
0258 xfs_failaddr_t xfs_bmap_validate_extent(struct xfs_inode *ip, int whichfork,
0259 struct xfs_bmbt_irec *irec);
0260
0261 int xfs_bmapi_remap(struct xfs_trans *tp, struct xfs_inode *ip,
0262 xfs_fileoff_t bno, xfs_filblks_t len, xfs_fsblock_t startblock,
0263 uint32_t flags);
0264
0265 extern struct kmem_cache *xfs_bmap_intent_cache;
0266
0267 int __init xfs_bmap_intent_init_cache(void);
0268 void xfs_bmap_intent_destroy_cache(void);
0269
0270 #endif