| .. | .. |
|---|
| 6 | 6 | */ |
|---|
| 7 | 7 | #include "xfs.h" |
|---|
| 8 | 8 | #include "xfs_fs.h" |
|---|
| 9 | +#include "xfs_shared.h" |
|---|
| 9 | 10 | #include "xfs_format.h" |
|---|
| 10 | 11 | #include "xfs_log_format.h" |
|---|
| 11 | 12 | #include "xfs_trans_resv.h" |
|---|
| 12 | 13 | #include "xfs_mount.h" |
|---|
| 13 | | -#include "xfs_da_format.h" |
|---|
| 14 | | -#include "xfs_da_btree.h" |
|---|
| 15 | 14 | #include "xfs_inode.h" |
|---|
| 16 | 15 | #include "xfs_dir2.h" |
|---|
| 17 | 16 | #include "xfs_dir2_priv.h" |
|---|
| 18 | 17 | #include "xfs_error.h" |
|---|
| 19 | 18 | #include "xfs_trans.h" |
|---|
| 20 | 19 | #include "xfs_buf_item.h" |
|---|
| 21 | | -#include "xfs_cksum.h" |
|---|
| 22 | 20 | #include "xfs_log.h" |
|---|
| 23 | 21 | |
|---|
| 24 | 22 | static xfs_failaddr_t xfs_dir2_data_freefind_verify( |
|---|
| 25 | 23 | struct xfs_dir2_data_hdr *hdr, struct xfs_dir2_data_free *bf, |
|---|
| 26 | 24 | struct xfs_dir2_data_unused *dup, |
|---|
| 27 | 25 | struct xfs_dir2_data_free **bf_ent); |
|---|
| 26 | + |
|---|
| 27 | +struct xfs_dir2_data_free * |
|---|
| 28 | +xfs_dir2_data_bestfree_p( |
|---|
| 29 | + struct xfs_mount *mp, |
|---|
| 30 | + struct xfs_dir2_data_hdr *hdr) |
|---|
| 31 | +{ |
|---|
| 32 | + if (xfs_sb_version_hascrc(&mp->m_sb)) |
|---|
| 33 | + return ((struct xfs_dir3_data_hdr *)hdr)->best_free; |
|---|
| 34 | + return hdr->bestfree; |
|---|
| 35 | +} |
|---|
| 36 | + |
|---|
| 37 | +/* |
|---|
| 38 | + * Pointer to an entry's tag word. |
|---|
| 39 | + */ |
|---|
| 40 | +__be16 * |
|---|
| 41 | +xfs_dir2_data_entry_tag_p( |
|---|
| 42 | + struct xfs_mount *mp, |
|---|
| 43 | + struct xfs_dir2_data_entry *dep) |
|---|
| 44 | +{ |
|---|
| 45 | + return (__be16 *)((char *)dep + |
|---|
| 46 | + xfs_dir2_data_entsize(mp, dep->namelen) - sizeof(__be16)); |
|---|
| 47 | +} |
|---|
| 48 | + |
|---|
| 49 | +uint8_t |
|---|
| 50 | +xfs_dir2_data_get_ftype( |
|---|
| 51 | + struct xfs_mount *mp, |
|---|
| 52 | + struct xfs_dir2_data_entry *dep) |
|---|
| 53 | +{ |
|---|
| 54 | + if (xfs_sb_version_hasftype(&mp->m_sb)) { |
|---|
| 55 | + uint8_t ftype = dep->name[dep->namelen]; |
|---|
| 56 | + |
|---|
| 57 | + if (likely(ftype < XFS_DIR3_FT_MAX)) |
|---|
| 58 | + return ftype; |
|---|
| 59 | + } |
|---|
| 60 | + |
|---|
| 61 | + return XFS_DIR3_FT_UNKNOWN; |
|---|
| 62 | +} |
|---|
| 63 | + |
|---|
| 64 | +void |
|---|
| 65 | +xfs_dir2_data_put_ftype( |
|---|
| 66 | + struct xfs_mount *mp, |
|---|
| 67 | + struct xfs_dir2_data_entry *dep, |
|---|
| 68 | + uint8_t ftype) |
|---|
| 69 | +{ |
|---|
| 70 | + ASSERT(ftype < XFS_DIR3_FT_MAX); |
|---|
| 71 | + ASSERT(dep->namelen != 0); |
|---|
| 72 | + |
|---|
| 73 | + if (xfs_sb_version_hasftype(&mp->m_sb)) |
|---|
| 74 | + dep->name[dep->namelen] = ftype; |
|---|
| 75 | +} |
|---|
| 76 | + |
|---|
| 77 | +/* |
|---|
| 78 | + * The number of leaf entries is limited by the size of the block and the amount |
|---|
| 79 | + * of space used by the data entries. We don't know how much space is used by |
|---|
| 80 | + * the data entries yet, so just ensure that the count falls somewhere inside |
|---|
| 81 | + * the block right now. |
|---|
| 82 | + */ |
|---|
| 83 | +static inline unsigned int |
|---|
| 84 | +xfs_dir2_data_max_leaf_entries( |
|---|
| 85 | + struct xfs_da_geometry *geo) |
|---|
| 86 | +{ |
|---|
| 87 | + return (geo->blksize - sizeof(struct xfs_dir2_block_tail) - |
|---|
| 88 | + geo->data_entry_offset) / |
|---|
| 89 | + sizeof(struct xfs_dir2_leaf_entry); |
|---|
| 90 | +} |
|---|
| 28 | 91 | |
|---|
| 29 | 92 | /* |
|---|
| 30 | 93 | * Check the consistency of the data block. |
|---|
| .. | .. |
|---|
| 41 | 104 | xfs_dir2_block_tail_t *btp=NULL; /* block tail */ |
|---|
| 42 | 105 | int count; /* count of entries found */ |
|---|
| 43 | 106 | xfs_dir2_data_hdr_t *hdr; /* data block header */ |
|---|
| 44 | | - xfs_dir2_data_entry_t *dep; /* data entry */ |
|---|
| 45 | 107 | xfs_dir2_data_free_t *dfp; /* bestfree entry */ |
|---|
| 46 | | - xfs_dir2_data_unused_t *dup; /* unused entry */ |
|---|
| 47 | | - char *endp; /* end of useful data */ |
|---|
| 48 | 108 | int freeseen; /* mask of bestfrees seen */ |
|---|
| 49 | 109 | xfs_dahash_t hash; /* hash of current name */ |
|---|
| 50 | 110 | int i; /* leaf index */ |
|---|
| 51 | 111 | int lastfree; /* last entry was unused */ |
|---|
| 52 | 112 | xfs_dir2_leaf_entry_t *lep=NULL; /* block leaf entries */ |
|---|
| 53 | | - xfs_mount_t *mp; /* filesystem mount point */ |
|---|
| 54 | | - char *p; /* current data position */ |
|---|
| 113 | + struct xfs_mount *mp = bp->b_mount; |
|---|
| 55 | 114 | int stale; /* count of stale leaves */ |
|---|
| 56 | 115 | struct xfs_name name; |
|---|
| 57 | | - const struct xfs_dir_ops *ops; |
|---|
| 58 | | - struct xfs_da_geometry *geo; |
|---|
| 59 | | - |
|---|
| 60 | | - mp = bp->b_target->bt_mount; |
|---|
| 61 | | - geo = mp->m_dir_geo; |
|---|
| 116 | + unsigned int offset; |
|---|
| 117 | + unsigned int end; |
|---|
| 118 | + struct xfs_da_geometry *geo = mp->m_dir_geo; |
|---|
| 62 | 119 | |
|---|
| 63 | 120 | /* |
|---|
| 64 | | - * We can be passed a null dp here from a verifier, so we need to go the |
|---|
| 65 | | - * hard way to get them. |
|---|
| 121 | + * If this isn't a directory, something is seriously wrong. Bail out. |
|---|
| 66 | 122 | */ |
|---|
| 67 | | - ops = xfs_dir_get_ops(mp, dp); |
|---|
| 68 | | - |
|---|
| 69 | | - /* |
|---|
| 70 | | - * If this isn't a directory, or we don't get handed the dir ops, |
|---|
| 71 | | - * something is seriously wrong. Bail out. |
|---|
| 72 | | - */ |
|---|
| 73 | | - if ((dp && !S_ISDIR(VFS_I(dp)->i_mode)) || |
|---|
| 74 | | - ops != xfs_dir_get_ops(mp, NULL)) |
|---|
| 123 | + if (dp && !S_ISDIR(VFS_I(dp)->i_mode)) |
|---|
| 75 | 124 | return __this_address; |
|---|
| 76 | 125 | |
|---|
| 77 | 126 | hdr = bp->b_addr; |
|---|
| 78 | | - p = (char *)ops->data_entry_p(hdr); |
|---|
| 127 | + offset = geo->data_entry_offset; |
|---|
| 79 | 128 | |
|---|
| 80 | 129 | switch (hdr->magic) { |
|---|
| 81 | 130 | case cpu_to_be32(XFS_DIR3_BLOCK_MAGIC): |
|---|
| .. | .. |
|---|
| 83 | 132 | btp = xfs_dir2_block_tail_p(geo, hdr); |
|---|
| 84 | 133 | lep = xfs_dir2_block_leaf_p(btp); |
|---|
| 85 | 134 | |
|---|
| 86 | | - /* |
|---|
| 87 | | - * The number of leaf entries is limited by the size of the |
|---|
| 88 | | - * block and the amount of space used by the data entries. |
|---|
| 89 | | - * We don't know how much space is used by the data entries yet, |
|---|
| 90 | | - * so just ensure that the count falls somewhere inside the |
|---|
| 91 | | - * block right now. |
|---|
| 92 | | - */ |
|---|
| 93 | 135 | if (be32_to_cpu(btp->count) >= |
|---|
| 94 | | - ((char *)btp - p) / sizeof(struct xfs_dir2_leaf_entry)) |
|---|
| 136 | + xfs_dir2_data_max_leaf_entries(geo)) |
|---|
| 95 | 137 | return __this_address; |
|---|
| 96 | 138 | break; |
|---|
| 97 | 139 | case cpu_to_be32(XFS_DIR3_DATA_MAGIC): |
|---|
| .. | .. |
|---|
| 100 | 142 | default: |
|---|
| 101 | 143 | return __this_address; |
|---|
| 102 | 144 | } |
|---|
| 103 | | - endp = xfs_dir3_data_endp(geo, hdr); |
|---|
| 104 | | - if (!endp) |
|---|
| 145 | + end = xfs_dir3_data_end_offset(geo, hdr); |
|---|
| 146 | + if (!end) |
|---|
| 105 | 147 | return __this_address; |
|---|
| 106 | 148 | |
|---|
| 107 | 149 | /* |
|---|
| 108 | 150 | * Account for zero bestfree entries. |
|---|
| 109 | 151 | */ |
|---|
| 110 | | - bf = ops->data_bestfree_p(hdr); |
|---|
| 152 | + bf = xfs_dir2_data_bestfree_p(mp, hdr); |
|---|
| 111 | 153 | count = lastfree = freeseen = 0; |
|---|
| 112 | 154 | if (!bf[0].length) { |
|---|
| 113 | 155 | if (bf[0].offset) |
|---|
| .. | .. |
|---|
| 132 | 174 | /* |
|---|
| 133 | 175 | * Loop over the data/unused entries. |
|---|
| 134 | 176 | */ |
|---|
| 135 | | - while (p < endp) { |
|---|
| 136 | | - dup = (xfs_dir2_data_unused_t *)p; |
|---|
| 177 | + while (offset < end) { |
|---|
| 178 | + struct xfs_dir2_data_unused *dup = bp->b_addr + offset; |
|---|
| 179 | + struct xfs_dir2_data_entry *dep = bp->b_addr + offset; |
|---|
| 180 | + |
|---|
| 137 | 181 | /* |
|---|
| 138 | 182 | * If it's unused, look for the space in the bestfree table. |
|---|
| 139 | 183 | * If we find it, account for that, else make sure it |
|---|
| .. | .. |
|---|
| 144 | 188 | |
|---|
| 145 | 189 | if (lastfree != 0) |
|---|
| 146 | 190 | return __this_address; |
|---|
| 147 | | - if (endp < p + be16_to_cpu(dup->length)) |
|---|
| 191 | + if (offset + be16_to_cpu(dup->length) > end) |
|---|
| 148 | 192 | return __this_address; |
|---|
| 149 | 193 | if (be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)) != |
|---|
| 150 | | - (char *)dup - (char *)hdr) |
|---|
| 194 | + offset) |
|---|
| 151 | 195 | return __this_address; |
|---|
| 152 | 196 | fa = xfs_dir2_data_freefind_verify(hdr, bf, dup, &dfp); |
|---|
| 153 | 197 | if (fa) |
|---|
| .. | .. |
|---|
| 162 | 206 | be16_to_cpu(bf[2].length)) |
|---|
| 163 | 207 | return __this_address; |
|---|
| 164 | 208 | } |
|---|
| 165 | | - p += be16_to_cpu(dup->length); |
|---|
| 209 | + offset += be16_to_cpu(dup->length); |
|---|
| 166 | 210 | lastfree = 1; |
|---|
| 167 | 211 | continue; |
|---|
| 168 | 212 | } |
|---|
| .. | .. |
|---|
| 172 | 216 | * in the leaf section of the block. |
|---|
| 173 | 217 | * The linear search is crude but this is DEBUG code. |
|---|
| 174 | 218 | */ |
|---|
| 175 | | - dep = (xfs_dir2_data_entry_t *)p; |
|---|
| 176 | 219 | if (dep->namelen == 0) |
|---|
| 177 | 220 | return __this_address; |
|---|
| 178 | 221 | if (xfs_dir_ino_validate(mp, be64_to_cpu(dep->inumber))) |
|---|
| 179 | 222 | return __this_address; |
|---|
| 180 | | - if (endp < p + ops->data_entsize(dep->namelen)) |
|---|
| 223 | + if (offset + xfs_dir2_data_entsize(mp, dep->namelen) > end) |
|---|
| 181 | 224 | return __this_address; |
|---|
| 182 | | - if (be16_to_cpu(*ops->data_entry_tag_p(dep)) != |
|---|
| 183 | | - (char *)dep - (char *)hdr) |
|---|
| 225 | + if (be16_to_cpu(*xfs_dir2_data_entry_tag_p(mp, dep)) != offset) |
|---|
| 184 | 226 | return __this_address; |
|---|
| 185 | | - if (ops->data_get_ftype(dep) >= XFS_DIR3_FT_MAX) |
|---|
| 227 | + if (xfs_dir2_data_get_ftype(mp, dep) >= XFS_DIR3_FT_MAX) |
|---|
| 186 | 228 | return __this_address; |
|---|
| 187 | 229 | count++; |
|---|
| 188 | 230 | lastfree = 0; |
|---|
| .. | .. |
|---|
| 193 | 235 | ((char *)dep - (char *)hdr)); |
|---|
| 194 | 236 | name.name = dep->name; |
|---|
| 195 | 237 | name.len = dep->namelen; |
|---|
| 196 | | - hash = mp->m_dirnameops->hashname(&name); |
|---|
| 238 | + hash = xfs_dir2_hashname(mp, &name); |
|---|
| 197 | 239 | for (i = 0; i < be32_to_cpu(btp->count); i++) { |
|---|
| 198 | 240 | if (be32_to_cpu(lep[i].address) == addr && |
|---|
| 199 | 241 | be32_to_cpu(lep[i].hashval) == hash) |
|---|
| .. | .. |
|---|
| 202 | 244 | if (i >= be32_to_cpu(btp->count)) |
|---|
| 203 | 245 | return __this_address; |
|---|
| 204 | 246 | } |
|---|
| 205 | | - p += ops->data_entsize(dep->namelen); |
|---|
| 247 | + offset += xfs_dir2_data_entsize(mp, dep->namelen); |
|---|
| 206 | 248 | } |
|---|
| 207 | 249 | /* |
|---|
| 208 | 250 | * Need to have seen all the entries and all the bestfree slots. |
|---|
| .. | .. |
|---|
| 249 | 291 | xfs_dir3_data_verify( |
|---|
| 250 | 292 | struct xfs_buf *bp) |
|---|
| 251 | 293 | { |
|---|
| 252 | | - struct xfs_mount *mp = bp->b_target->bt_mount; |
|---|
| 294 | + struct xfs_mount *mp = bp->b_mount; |
|---|
| 253 | 295 | struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; |
|---|
| 254 | 296 | |
|---|
| 297 | + if (!xfs_verify_magic(bp, hdr3->magic)) |
|---|
| 298 | + return __this_address; |
|---|
| 299 | + |
|---|
| 255 | 300 | if (xfs_sb_version_hascrc(&mp->m_sb)) { |
|---|
| 256 | | - if (hdr3->magic != cpu_to_be32(XFS_DIR3_DATA_MAGIC)) |
|---|
| 257 | | - return __this_address; |
|---|
| 258 | 301 | if (!uuid_equal(&hdr3->uuid, &mp->m_sb.sb_meta_uuid)) |
|---|
| 259 | 302 | return __this_address; |
|---|
| 260 | 303 | if (be64_to_cpu(hdr3->blkno) != bp->b_bn) |
|---|
| 261 | 304 | return __this_address; |
|---|
| 262 | 305 | if (!xfs_log_check_lsn(mp, be64_to_cpu(hdr3->lsn))) |
|---|
| 263 | | - return __this_address; |
|---|
| 264 | | - } else { |
|---|
| 265 | | - if (hdr3->magic != cpu_to_be32(XFS_DIR2_DATA_MAGIC)) |
|---|
| 266 | 306 | return __this_address; |
|---|
| 267 | 307 | } |
|---|
| 268 | 308 | return __xfs_dir3_data_check(NULL, bp); |
|---|
| .. | .. |
|---|
| 300 | 340 | xfs_dir3_data_read_verify( |
|---|
| 301 | 341 | struct xfs_buf *bp) |
|---|
| 302 | 342 | { |
|---|
| 303 | | - struct xfs_mount *mp = bp->b_target->bt_mount; |
|---|
| 343 | + struct xfs_mount *mp = bp->b_mount; |
|---|
| 304 | 344 | xfs_failaddr_t fa; |
|---|
| 305 | 345 | |
|---|
| 306 | 346 | if (xfs_sb_version_hascrc(&mp->m_sb) && |
|---|
| .. | .. |
|---|
| 317 | 357 | xfs_dir3_data_write_verify( |
|---|
| 318 | 358 | struct xfs_buf *bp) |
|---|
| 319 | 359 | { |
|---|
| 320 | | - struct xfs_mount *mp = bp->b_target->bt_mount; |
|---|
| 360 | + struct xfs_mount *mp = bp->b_mount; |
|---|
| 321 | 361 | struct xfs_buf_log_item *bip = bp->b_log_item; |
|---|
| 322 | 362 | struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; |
|---|
| 323 | 363 | xfs_failaddr_t fa; |
|---|
| .. | .. |
|---|
| 339 | 379 | |
|---|
| 340 | 380 | const struct xfs_buf_ops xfs_dir3_data_buf_ops = { |
|---|
| 341 | 381 | .name = "xfs_dir3_data", |
|---|
| 382 | + .magic = { cpu_to_be32(XFS_DIR2_DATA_MAGIC), |
|---|
| 383 | + cpu_to_be32(XFS_DIR3_DATA_MAGIC) }, |
|---|
| 342 | 384 | .verify_read = xfs_dir3_data_read_verify, |
|---|
| 343 | 385 | .verify_write = xfs_dir3_data_write_verify, |
|---|
| 344 | 386 | .verify_struct = xfs_dir3_data_verify, |
|---|
| .. | .. |
|---|
| 346 | 388 | |
|---|
| 347 | 389 | static const struct xfs_buf_ops xfs_dir3_data_reada_buf_ops = { |
|---|
| 348 | 390 | .name = "xfs_dir3_data_reada", |
|---|
| 391 | + .magic = { cpu_to_be32(XFS_DIR2_DATA_MAGIC), |
|---|
| 392 | + cpu_to_be32(XFS_DIR3_DATA_MAGIC) }, |
|---|
| 349 | 393 | .verify_read = xfs_dir3_data_reada_verify, |
|---|
| 350 | 394 | .verify_write = xfs_dir3_data_write_verify, |
|---|
| 351 | 395 | }; |
|---|
| 352 | 396 | |
|---|
| 397 | +static xfs_failaddr_t |
|---|
| 398 | +xfs_dir3_data_header_check( |
|---|
| 399 | + struct xfs_inode *dp, |
|---|
| 400 | + struct xfs_buf *bp) |
|---|
| 401 | +{ |
|---|
| 402 | + struct xfs_mount *mp = dp->i_mount; |
|---|
| 403 | + |
|---|
| 404 | + if (xfs_sb_version_hascrc(&mp->m_sb)) { |
|---|
| 405 | + struct xfs_dir3_data_hdr *hdr3 = bp->b_addr; |
|---|
| 406 | + |
|---|
| 407 | + if (be64_to_cpu(hdr3->hdr.owner) != dp->i_ino) |
|---|
| 408 | + return __this_address; |
|---|
| 409 | + } |
|---|
| 410 | + |
|---|
| 411 | + return NULL; |
|---|
| 412 | +} |
|---|
| 353 | 413 | |
|---|
| 354 | 414 | int |
|---|
| 355 | 415 | xfs_dir3_data_read( |
|---|
| 356 | 416 | struct xfs_trans *tp, |
|---|
| 357 | 417 | struct xfs_inode *dp, |
|---|
| 358 | 418 | xfs_dablk_t bno, |
|---|
| 359 | | - xfs_daddr_t mapped_bno, |
|---|
| 419 | + unsigned int flags, |
|---|
| 360 | 420 | struct xfs_buf **bpp) |
|---|
| 361 | 421 | { |
|---|
| 422 | + xfs_failaddr_t fa; |
|---|
| 362 | 423 | int err; |
|---|
| 363 | 424 | |
|---|
| 364 | | - err = xfs_da_read_buf(tp, dp, bno, mapped_bno, bpp, |
|---|
| 365 | | - XFS_DATA_FORK, &xfs_dir3_data_buf_ops); |
|---|
| 366 | | - if (!err && tp && *bpp) |
|---|
| 367 | | - xfs_trans_buf_set_type(tp, *bpp, XFS_BLFT_DIR_DATA_BUF); |
|---|
| 425 | + err = xfs_da_read_buf(tp, dp, bno, flags, bpp, XFS_DATA_FORK, |
|---|
| 426 | + &xfs_dir3_data_buf_ops); |
|---|
| 427 | + if (err || !*bpp) |
|---|
| 428 | + return err; |
|---|
| 429 | + |
|---|
| 430 | + /* Check things that we can't do in the verifier. */ |
|---|
| 431 | + fa = xfs_dir3_data_header_check(dp, *bpp); |
|---|
| 432 | + if (fa) { |
|---|
| 433 | + __xfs_buf_mark_corrupt(*bpp, fa); |
|---|
| 434 | + xfs_trans_brelse(tp, *bpp); |
|---|
| 435 | + *bpp = NULL; |
|---|
| 436 | + return -EFSCORRUPTED; |
|---|
| 437 | + } |
|---|
| 438 | + |
|---|
| 439 | + xfs_trans_buf_set_type(tp, *bpp, XFS_BLFT_DIR_DATA_BUF); |
|---|
| 368 | 440 | return err; |
|---|
| 369 | 441 | } |
|---|
| 370 | 442 | |
|---|
| .. | .. |
|---|
| 372 | 444 | xfs_dir3_data_readahead( |
|---|
| 373 | 445 | struct xfs_inode *dp, |
|---|
| 374 | 446 | xfs_dablk_t bno, |
|---|
| 375 | | - xfs_daddr_t mapped_bno) |
|---|
| 447 | + unsigned int flags) |
|---|
| 376 | 448 | { |
|---|
| 377 | | - return xfs_da_reada_buf(dp, bno, mapped_bno, |
|---|
| 378 | | - XFS_DATA_FORK, &xfs_dir3_data_reada_buf_ops); |
|---|
| 449 | + return xfs_da_reada_buf(dp, bno, flags, XFS_DATA_FORK, |
|---|
| 450 | + &xfs_dir3_data_reada_buf_ops); |
|---|
| 379 | 451 | } |
|---|
| 380 | 452 | |
|---|
| 381 | 453 | /* |
|---|
| .. | .. |
|---|
| 563 | 635 | * Given a data block, reconstruct its bestfree map. |
|---|
| 564 | 636 | */ |
|---|
| 565 | 637 | void |
|---|
| 566 | | -xfs_dir2_data_freescan_int( |
|---|
| 567 | | - struct xfs_da_geometry *geo, |
|---|
| 568 | | - const struct xfs_dir_ops *ops, |
|---|
| 569 | | - struct xfs_dir2_data_hdr *hdr, |
|---|
| 570 | | - int *loghead) |
|---|
| 638 | +xfs_dir2_data_freescan( |
|---|
| 639 | + struct xfs_mount *mp, |
|---|
| 640 | + struct xfs_dir2_data_hdr *hdr, |
|---|
| 641 | + int *loghead) |
|---|
| 571 | 642 | { |
|---|
| 572 | | - xfs_dir2_data_entry_t *dep; /* active data entry */ |
|---|
| 573 | | - xfs_dir2_data_unused_t *dup; /* unused data entry */ |
|---|
| 574 | | - struct xfs_dir2_data_free *bf; |
|---|
| 575 | | - char *endp; /* end of block's data */ |
|---|
| 576 | | - char *p; /* current entry pointer */ |
|---|
| 643 | + struct xfs_da_geometry *geo = mp->m_dir_geo; |
|---|
| 644 | + struct xfs_dir2_data_free *bf = xfs_dir2_data_bestfree_p(mp, hdr); |
|---|
| 645 | + void *addr = hdr; |
|---|
| 646 | + unsigned int offset = geo->data_entry_offset; |
|---|
| 647 | + unsigned int end; |
|---|
| 577 | 648 | |
|---|
| 578 | 649 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
|---|
| 579 | 650 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
|---|
| .. | .. |
|---|
| 583 | 654 | /* |
|---|
| 584 | 655 | * Start by clearing the table. |
|---|
| 585 | 656 | */ |
|---|
| 586 | | - bf = ops->data_bestfree_p(hdr); |
|---|
| 587 | 657 | memset(bf, 0, sizeof(*bf) * XFS_DIR2_DATA_FD_COUNT); |
|---|
| 588 | 658 | *loghead = 1; |
|---|
| 589 | | - /* |
|---|
| 590 | | - * Set up pointers. |
|---|
| 591 | | - */ |
|---|
| 592 | | - p = (char *)ops->data_entry_p(hdr); |
|---|
| 593 | | - endp = xfs_dir3_data_endp(geo, hdr); |
|---|
| 594 | | - /* |
|---|
| 595 | | - * Loop over the block's entries. |
|---|
| 596 | | - */ |
|---|
| 597 | | - while (p < endp) { |
|---|
| 598 | | - dup = (xfs_dir2_data_unused_t *)p; |
|---|
| 659 | + |
|---|
| 660 | + end = xfs_dir3_data_end_offset(geo, addr); |
|---|
| 661 | + while (offset < end) { |
|---|
| 662 | + struct xfs_dir2_data_unused *dup = addr + offset; |
|---|
| 663 | + struct xfs_dir2_data_entry *dep = addr + offset; |
|---|
| 664 | + |
|---|
| 599 | 665 | /* |
|---|
| 600 | 666 | * If it's a free entry, insert it. |
|---|
| 601 | 667 | */ |
|---|
| 602 | 668 | if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) { |
|---|
| 603 | | - ASSERT((char *)dup - (char *)hdr == |
|---|
| 669 | + ASSERT(offset == |
|---|
| 604 | 670 | be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup))); |
|---|
| 605 | 671 | xfs_dir2_data_freeinsert(hdr, bf, dup, loghead); |
|---|
| 606 | | - p += be16_to_cpu(dup->length); |
|---|
| 672 | + offset += be16_to_cpu(dup->length); |
|---|
| 673 | + continue; |
|---|
| 607 | 674 | } |
|---|
| 675 | + |
|---|
| 608 | 676 | /* |
|---|
| 609 | 677 | * For active entries, check their tags and skip them. |
|---|
| 610 | 678 | */ |
|---|
| 611 | | - else { |
|---|
| 612 | | - dep = (xfs_dir2_data_entry_t *)p; |
|---|
| 613 | | - ASSERT((char *)dep - (char *)hdr == |
|---|
| 614 | | - be16_to_cpu(*ops->data_entry_tag_p(dep))); |
|---|
| 615 | | - p += ops->data_entsize(dep->namelen); |
|---|
| 616 | | - } |
|---|
| 679 | + ASSERT(offset == |
|---|
| 680 | + be16_to_cpu(*xfs_dir2_data_entry_tag_p(mp, dep))); |
|---|
| 681 | + offset += xfs_dir2_data_entsize(mp, dep->namelen); |
|---|
| 617 | 682 | } |
|---|
| 618 | | -} |
|---|
| 619 | | - |
|---|
| 620 | | -void |
|---|
| 621 | | -xfs_dir2_data_freescan( |
|---|
| 622 | | - struct xfs_inode *dp, |
|---|
| 623 | | - struct xfs_dir2_data_hdr *hdr, |
|---|
| 624 | | - int *loghead) |
|---|
| 625 | | -{ |
|---|
| 626 | | - return xfs_dir2_data_freescan_int(dp->i_mount->m_dir_geo, dp->d_ops, |
|---|
| 627 | | - hdr, loghead); |
|---|
| 628 | 683 | } |
|---|
| 629 | 684 | |
|---|
| 630 | 685 | /* |
|---|
| .. | .. |
|---|
| 633 | 688 | */ |
|---|
| 634 | 689 | int /* error */ |
|---|
| 635 | 690 | xfs_dir3_data_init( |
|---|
| 636 | | - xfs_da_args_t *args, /* directory operation args */ |
|---|
| 637 | | - xfs_dir2_db_t blkno, /* logical dir block number */ |
|---|
| 638 | | - struct xfs_buf **bpp) /* output block buffer */ |
|---|
| 691 | + struct xfs_da_args *args, /* directory operation args */ |
|---|
| 692 | + xfs_dir2_db_t blkno, /* logical dir block number */ |
|---|
| 693 | + struct xfs_buf **bpp) /* output block buffer */ |
|---|
| 639 | 694 | { |
|---|
| 640 | | - struct xfs_buf *bp; /* block buffer */ |
|---|
| 641 | | - xfs_dir2_data_hdr_t *hdr; /* data block header */ |
|---|
| 642 | | - xfs_inode_t *dp; /* incore directory inode */ |
|---|
| 643 | | - xfs_dir2_data_unused_t *dup; /* unused entry pointer */ |
|---|
| 644 | | - struct xfs_dir2_data_free *bf; |
|---|
| 645 | | - int error; /* error return value */ |
|---|
| 646 | | - int i; /* bestfree index */ |
|---|
| 647 | | - xfs_mount_t *mp; /* filesystem mount point */ |
|---|
| 648 | | - xfs_trans_t *tp; /* transaction pointer */ |
|---|
| 649 | | - int t; /* temp */ |
|---|
| 695 | + struct xfs_trans *tp = args->trans; |
|---|
| 696 | + struct xfs_inode *dp = args->dp; |
|---|
| 697 | + struct xfs_mount *mp = dp->i_mount; |
|---|
| 698 | + struct xfs_da_geometry *geo = args->geo; |
|---|
| 699 | + struct xfs_buf *bp; |
|---|
| 700 | + struct xfs_dir2_data_hdr *hdr; |
|---|
| 701 | + struct xfs_dir2_data_unused *dup; |
|---|
| 702 | + struct xfs_dir2_data_free *bf; |
|---|
| 703 | + int error; |
|---|
| 704 | + int i; |
|---|
| 650 | 705 | |
|---|
| 651 | | - dp = args->dp; |
|---|
| 652 | | - mp = dp->i_mount; |
|---|
| 653 | | - tp = args->trans; |
|---|
| 654 | 706 | /* |
|---|
| 655 | 707 | * Get the buffer set up for the block. |
|---|
| 656 | 708 | */ |
|---|
| 657 | 709 | error = xfs_da_get_buf(tp, dp, xfs_dir2_db_to_da(args->geo, blkno), |
|---|
| 658 | | - -1, &bp, XFS_DATA_FORK); |
|---|
| 710 | + &bp, XFS_DATA_FORK); |
|---|
| 659 | 711 | if (error) |
|---|
| 660 | 712 | return error; |
|---|
| 661 | 713 | bp->b_ops = &xfs_dir3_data_buf_ops; |
|---|
| .. | .. |
|---|
| 677 | 729 | } else |
|---|
| 678 | 730 | hdr->magic = cpu_to_be32(XFS_DIR2_DATA_MAGIC); |
|---|
| 679 | 731 | |
|---|
| 680 | | - bf = dp->d_ops->data_bestfree_p(hdr); |
|---|
| 681 | | - bf[0].offset = cpu_to_be16(dp->d_ops->data_entry_offset); |
|---|
| 732 | + bf = xfs_dir2_data_bestfree_p(mp, hdr); |
|---|
| 733 | + bf[0].offset = cpu_to_be16(geo->data_entry_offset); |
|---|
| 734 | + bf[0].length = cpu_to_be16(geo->blksize - geo->data_entry_offset); |
|---|
| 682 | 735 | for (i = 1; i < XFS_DIR2_DATA_FD_COUNT; i++) { |
|---|
| 683 | 736 | bf[i].length = 0; |
|---|
| 684 | 737 | bf[i].offset = 0; |
|---|
| .. | .. |
|---|
| 687 | 740 | /* |
|---|
| 688 | 741 | * Set up an unused entry for the block's body. |
|---|
| 689 | 742 | */ |
|---|
| 690 | | - dup = dp->d_ops->data_unused_p(hdr); |
|---|
| 743 | + dup = bp->b_addr + geo->data_entry_offset; |
|---|
| 691 | 744 | dup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG); |
|---|
| 692 | | - |
|---|
| 693 | | - t = args->geo->blksize - (uint)dp->d_ops->data_entry_offset; |
|---|
| 694 | | - bf[0].length = cpu_to_be16(t); |
|---|
| 695 | | - dup->length = cpu_to_be16(t); |
|---|
| 745 | + dup->length = bf[0].length; |
|---|
| 696 | 746 | *xfs_dir2_data_unused_tag_p(dup) = cpu_to_be16((char *)dup - (char *)hdr); |
|---|
| 747 | + |
|---|
| 697 | 748 | /* |
|---|
| 698 | 749 | * Log it and return it. |
|---|
| 699 | 750 | */ |
|---|
| .. | .. |
|---|
| 712 | 763 | struct xfs_buf *bp, |
|---|
| 713 | 764 | xfs_dir2_data_entry_t *dep) /* data entry pointer */ |
|---|
| 714 | 765 | { |
|---|
| 766 | + struct xfs_mount *mp = bp->b_mount; |
|---|
| 715 | 767 | struct xfs_dir2_data_hdr *hdr = bp->b_addr; |
|---|
| 716 | 768 | |
|---|
| 717 | 769 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
|---|
| .. | .. |
|---|
| 720 | 772 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
|---|
| 721 | 773 | |
|---|
| 722 | 774 | xfs_trans_log_buf(args->trans, bp, (uint)((char *)dep - (char *)hdr), |
|---|
| 723 | | - (uint)((char *)(args->dp->d_ops->data_entry_tag_p(dep) + 1) - |
|---|
| 775 | + (uint)((char *)(xfs_dir2_data_entry_tag_p(mp, dep) + 1) - |
|---|
| 724 | 776 | (char *)hdr - 1)); |
|---|
| 725 | 777 | } |
|---|
| 726 | 778 | |
|---|
| .. | .. |
|---|
| 741 | 793 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
|---|
| 742 | 794 | #endif |
|---|
| 743 | 795 | |
|---|
| 744 | | - xfs_trans_log_buf(args->trans, bp, 0, |
|---|
| 745 | | - args->dp->d_ops->data_entry_offset - 1); |
|---|
| 796 | + xfs_trans_log_buf(args->trans, bp, 0, args->geo->data_entry_offset - 1); |
|---|
| 746 | 797 | } |
|---|
| 747 | 798 | |
|---|
| 748 | 799 | /* |
|---|
| .. | .. |
|---|
| 791 | 842 | { |
|---|
| 792 | 843 | xfs_dir2_data_hdr_t *hdr; /* data block pointer */ |
|---|
| 793 | 844 | xfs_dir2_data_free_t *dfp; /* bestfree pointer */ |
|---|
| 794 | | - char *endptr; /* end of data area */ |
|---|
| 795 | 845 | int needscan; /* need to regen bestfree */ |
|---|
| 796 | 846 | xfs_dir2_data_unused_t *newdup; /* new unused entry */ |
|---|
| 797 | 847 | xfs_dir2_data_unused_t *postdup; /* unused entry after us */ |
|---|
| 798 | 848 | xfs_dir2_data_unused_t *prevdup; /* unused entry before us */ |
|---|
| 849 | + unsigned int end; |
|---|
| 799 | 850 | struct xfs_dir2_data_free *bf; |
|---|
| 800 | 851 | |
|---|
| 801 | 852 | hdr = bp->b_addr; |
|---|
| .. | .. |
|---|
| 803 | 854 | /* |
|---|
| 804 | 855 | * Figure out where the end of the data area is. |
|---|
| 805 | 856 | */ |
|---|
| 806 | | - endptr = xfs_dir3_data_endp(args->geo, hdr); |
|---|
| 807 | | - ASSERT(endptr != NULL); |
|---|
| 857 | + end = xfs_dir3_data_end_offset(args->geo, hdr); |
|---|
| 858 | + ASSERT(end != 0); |
|---|
| 808 | 859 | |
|---|
| 809 | 860 | /* |
|---|
| 810 | 861 | * If this isn't the start of the block, then back up to |
|---|
| 811 | 862 | * the previous entry and see if it's free. |
|---|
| 812 | 863 | */ |
|---|
| 813 | | - if (offset > args->dp->d_ops->data_entry_offset) { |
|---|
| 864 | + if (offset > args->geo->data_entry_offset) { |
|---|
| 814 | 865 | __be16 *tagp; /* tag just before us */ |
|---|
| 815 | 866 | |
|---|
| 816 | 867 | tagp = (__be16 *)((char *)hdr + offset) - 1; |
|---|
| .. | .. |
|---|
| 823 | 874 | * If this isn't the end of the block, see if the entry after |
|---|
| 824 | 875 | * us is free. |
|---|
| 825 | 876 | */ |
|---|
| 826 | | - if ((char *)hdr + offset + len < endptr) { |
|---|
| 877 | + if (offset + len < end) { |
|---|
| 827 | 878 | postdup = |
|---|
| 828 | 879 | (xfs_dir2_data_unused_t *)((char *)hdr + offset + len); |
|---|
| 829 | 880 | if (be16_to_cpu(postdup->freetag) != XFS_DIR2_DATA_FREE_TAG) |
|---|
| .. | .. |
|---|
| 836 | 887 | * Previous and following entries are both free, |
|---|
| 837 | 888 | * merge everything into a single free entry. |
|---|
| 838 | 889 | */ |
|---|
| 839 | | - bf = args->dp->d_ops->data_bestfree_p(hdr); |
|---|
| 890 | + bf = xfs_dir2_data_bestfree_p(args->dp->i_mount, hdr); |
|---|
| 840 | 891 | if (prevdup && postdup) { |
|---|
| 841 | 892 | xfs_dir2_data_free_t *dfp2; /* another bestfree pointer */ |
|---|
| 842 | 893 | |
|---|
| .. | .. |
|---|
| 1027 | 1078 | * Look up the entry in the bestfree table. |
|---|
| 1028 | 1079 | */ |
|---|
| 1029 | 1080 | oldlen = be16_to_cpu(dup->length); |
|---|
| 1030 | | - bf = args->dp->d_ops->data_bestfree_p(hdr); |
|---|
| 1081 | + bf = xfs_dir2_data_bestfree_p(args->dp->i_mount, hdr); |
|---|
| 1031 | 1082 | dfp = xfs_dir2_data_freefind(hdr, bf, dup); |
|---|
| 1032 | 1083 | ASSERT(dfp || oldlen <= be16_to_cpu(bf[2].length)); |
|---|
| 1033 | 1084 | /* |
|---|
| .. | .. |
|---|
| 1151 | 1202 | } |
|---|
| 1152 | 1203 | |
|---|
| 1153 | 1204 | /* Find the end of the entry data in a data/block format dir block. */ |
|---|
| 1154 | | -void * |
|---|
| 1155 | | -xfs_dir3_data_endp( |
|---|
| 1205 | +unsigned int |
|---|
| 1206 | +xfs_dir3_data_end_offset( |
|---|
| 1156 | 1207 | struct xfs_da_geometry *geo, |
|---|
| 1157 | 1208 | struct xfs_dir2_data_hdr *hdr) |
|---|
| 1158 | 1209 | { |
|---|
| 1210 | + void *p; |
|---|
| 1211 | + |
|---|
| 1159 | 1212 | switch (hdr->magic) { |
|---|
| 1160 | 1213 | case cpu_to_be32(XFS_DIR3_BLOCK_MAGIC): |
|---|
| 1161 | 1214 | case cpu_to_be32(XFS_DIR2_BLOCK_MAGIC): |
|---|
| 1162 | | - return xfs_dir2_block_leaf_p(xfs_dir2_block_tail_p(geo, hdr)); |
|---|
| 1215 | + p = xfs_dir2_block_leaf_p(xfs_dir2_block_tail_p(geo, hdr)); |
|---|
| 1216 | + return p - (void *)hdr; |
|---|
| 1163 | 1217 | case cpu_to_be32(XFS_DIR3_DATA_MAGIC): |
|---|
| 1164 | 1218 | case cpu_to_be32(XFS_DIR2_DATA_MAGIC): |
|---|
| 1165 | | - return (char *)hdr + geo->blksize; |
|---|
| 1219 | + return geo->blksize; |
|---|
| 1166 | 1220 | default: |
|---|
| 1167 | | - return NULL; |
|---|
| 1221 | + return 0; |
|---|
| 1168 | 1222 | } |
|---|
| 1169 | 1223 | } |
|---|