Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 3 | * Copyright (c) 2013 Red Hat, Inc. |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 4 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * published by the Free Software Foundation. |
| 9 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 10 | * This program is distributed in the hope that it would be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include "xfs.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 20 | #include "xfs_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include "xfs_types.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include "xfs_log.h" |
| 23 | #include "xfs_trans.h" |
| 24 | #include "xfs_sb.h" |
David Chinner | da353b0 | 2007-08-28 14:00:13 +1000 | [diff] [blame] | 25 | #include "xfs_ag.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include "xfs_mount.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 27 | #include "xfs_da_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include "xfs_bmap_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include "xfs_dinode.h" |
| 30 | #include "xfs_inode.h" |
Christoph Hellwig | 5792664 | 2011-07-13 13:43:48 +0200 | [diff] [blame] | 31 | #include "xfs_dir2_format.h" |
| 32 | #include "xfs_dir2_priv.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include "xfs_error.h" |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 34 | #include "xfs_buf_item.h" |
| 35 | #include "xfs_cksum.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 37 | STATIC xfs_dir2_data_free_t * |
| 38 | xfs_dir2_data_freefind(xfs_dir2_data_hdr_t *hdr, xfs_dir2_data_unused_t *dup); |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | /* |
| 41 | * Check the consistency of the data block. |
| 42 | * The input can also be a block-format directory. |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 43 | * Return 0 is the buffer is good, otherwise an error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | */ |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 45 | int |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 46 | __xfs_dir3_data_check( |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 47 | struct xfs_inode *dp, /* incore inode pointer */ |
| 48 | struct xfs_buf *bp) /* data block's buffer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
| 50 | xfs_dir2_dataptr_t addr; /* addr for leaf lookup */ |
| 51 | xfs_dir2_data_free_t *bf; /* bestfree table */ |
| 52 | xfs_dir2_block_tail_t *btp=NULL; /* block tail */ |
| 53 | int count; /* count of entries found */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 54 | xfs_dir2_data_hdr_t *hdr; /* data block header */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | xfs_dir2_data_entry_t *dep; /* data entry */ |
| 56 | xfs_dir2_data_free_t *dfp; /* bestfree entry */ |
| 57 | xfs_dir2_data_unused_t *dup; /* unused entry */ |
| 58 | char *endp; /* end of useful data */ |
| 59 | int freeseen; /* mask of bestfrees seen */ |
| 60 | xfs_dahash_t hash; /* hash of current name */ |
| 61 | int i; /* leaf index */ |
| 62 | int lastfree; /* last entry was unused */ |
| 63 | xfs_dir2_leaf_entry_t *lep=NULL; /* block leaf entries */ |
| 64 | xfs_mount_t *mp; /* filesystem mount point */ |
| 65 | char *p; /* current data position */ |
| 66 | int stale; /* count of stale leaves */ |
Barry Naujok | 5163f95 | 2008-05-21 16:41:01 +1000 | [diff] [blame] | 67 | struct xfs_name name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 69 | mp = bp->b_target->bt_mount; |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 70 | hdr = bp->b_addr; |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 71 | bf = xfs_dir3_data_bestfree_p(hdr); |
| 72 | p = (char *)xfs_dir3_data_entry_p(hdr); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 73 | |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 74 | switch (hdr->magic) { |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 75 | case cpu_to_be32(XFS_DIR3_BLOCK_MAGIC): |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 76 | case cpu_to_be32(XFS_DIR2_BLOCK_MAGIC): |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 77 | btp = xfs_dir2_block_tail_p(mp, hdr); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 78 | lep = xfs_dir2_block_leaf_p(btp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | endp = (char *)lep; |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 80 | break; |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 81 | case cpu_to_be32(XFS_DIR3_DATA_MAGIC): |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 82 | case cpu_to_be32(XFS_DIR2_DATA_MAGIC): |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 83 | endp = (char *)hdr + mp->m_dirblksize; |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 84 | break; |
| 85 | default: |
| 86 | XFS_ERROR_REPORT("Bad Magic", XFS_ERRLEVEL_LOW, mp); |
| 87 | return EFSCORRUPTED; |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 88 | } |
| 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | count = lastfree = freeseen = 0; |
| 91 | /* |
| 92 | * Account for zero bestfree entries. |
| 93 | */ |
| 94 | if (!bf[0].length) { |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 95 | XFS_WANT_CORRUPTED_RETURN(!bf[0].offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | freeseen |= 1 << 0; |
| 97 | } |
| 98 | if (!bf[1].length) { |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 99 | XFS_WANT_CORRUPTED_RETURN(!bf[1].offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | freeseen |= 1 << 1; |
| 101 | } |
| 102 | if (!bf[2].length) { |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 103 | XFS_WANT_CORRUPTED_RETURN(!bf[2].offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | freeseen |= 1 << 2; |
| 105 | } |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 106 | |
| 107 | XFS_WANT_CORRUPTED_RETURN(be16_to_cpu(bf[0].length) >= |
| 108 | be16_to_cpu(bf[1].length)); |
| 109 | XFS_WANT_CORRUPTED_RETURN(be16_to_cpu(bf[1].length) >= |
| 110 | be16_to_cpu(bf[2].length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | /* |
| 112 | * Loop over the data/unused entries. |
| 113 | */ |
| 114 | while (p < endp) { |
| 115 | dup = (xfs_dir2_data_unused_t *)p; |
| 116 | /* |
| 117 | * If it's unused, look for the space in the bestfree table. |
| 118 | * If we find it, account for that, else make sure it |
| 119 | * doesn't need to be there. |
| 120 | */ |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 121 | if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) { |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 122 | XFS_WANT_CORRUPTED_RETURN(lastfree == 0); |
| 123 | XFS_WANT_CORRUPTED_RETURN( |
| 124 | be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)) == |
| 125 | (char *)dup - (char *)hdr); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 126 | dfp = xfs_dir2_data_freefind(hdr, dup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | if (dfp) { |
| 128 | i = (int)(dfp - bf); |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 129 | XFS_WANT_CORRUPTED_RETURN( |
| 130 | (freeseen & (1 << i)) == 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | freeseen |= 1 << i; |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 132 | } else { |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 133 | XFS_WANT_CORRUPTED_RETURN( |
| 134 | be16_to_cpu(dup->length) <= |
| 135 | be16_to_cpu(bf[2].length)); |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 136 | } |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 137 | p += be16_to_cpu(dup->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | lastfree = 1; |
| 139 | continue; |
| 140 | } |
| 141 | /* |
| 142 | * It's a real entry. Validate the fields. |
| 143 | * If this is a block directory then make sure it's |
| 144 | * in the leaf section of the block. |
| 145 | * The linear search is crude but this is DEBUG code. |
| 146 | */ |
| 147 | dep = (xfs_dir2_data_entry_t *)p; |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 148 | XFS_WANT_CORRUPTED_RETURN(dep->namelen != 0); |
| 149 | XFS_WANT_CORRUPTED_RETURN( |
| 150 | !xfs_dir_ino_validate(mp, be64_to_cpu(dep->inumber))); |
| 151 | XFS_WANT_CORRUPTED_RETURN( |
| 152 | be16_to_cpu(*xfs_dir2_data_entry_tag_p(dep)) == |
| 153 | (char *)dep - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | count++; |
| 155 | lastfree = 0; |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 156 | if (hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 157 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)) { |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 158 | addr = xfs_dir2_db_off_to_dataptr(mp, mp->m_dirdatablk, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | (xfs_dir2_data_aoff_t) |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 160 | ((char *)dep - (char *)hdr)); |
Barry Naujok | 5163f95 | 2008-05-21 16:41:01 +1000 | [diff] [blame] | 161 | name.name = dep->name; |
| 162 | name.len = dep->namelen; |
| 163 | hash = mp->m_dirnameops->hashname(&name); |
Nathan Scott | e922fff | 2006-03-17 17:27:56 +1100 | [diff] [blame] | 164 | for (i = 0; i < be32_to_cpu(btp->count); i++) { |
Nathan Scott | 3c1f9c1 | 2006-03-17 17:28:18 +1100 | [diff] [blame] | 165 | if (be32_to_cpu(lep[i].address) == addr && |
| 166 | be32_to_cpu(lep[i].hashval) == hash) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | break; |
| 168 | } |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 169 | XFS_WANT_CORRUPTED_RETURN(i < be32_to_cpu(btp->count)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 171 | p += xfs_dir2_data_entsize(dep->namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | /* |
| 174 | * Need to have seen all the entries and all the bestfree slots. |
| 175 | */ |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 176 | XFS_WANT_CORRUPTED_RETURN(freeseen == 7); |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 177 | if (hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 178 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)) { |
Nathan Scott | e922fff | 2006-03-17 17:27:56 +1100 | [diff] [blame] | 179 | for (i = stale = 0; i < be32_to_cpu(btp->count); i++) { |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 180 | if (lep[i].address == |
| 181 | cpu_to_be32(XFS_DIR2_NULL_DATAPTR)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | stale++; |
| 183 | if (i > 0) |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 184 | XFS_WANT_CORRUPTED_RETURN( |
| 185 | be32_to_cpu(lep[i].hashval) >= |
| 186 | be32_to_cpu(lep[i - 1].hashval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 188 | XFS_WANT_CORRUPTED_RETURN(count == |
| 189 | be32_to_cpu(btp->count) - be32_to_cpu(btp->stale)); |
| 190 | XFS_WANT_CORRUPTED_RETURN(stale == be32_to_cpu(btp->stale)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
Dave Chinner | 82025d7 | 2012-11-12 22:54:12 +1100 | [diff] [blame] | 192 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 195 | static bool |
| 196 | xfs_dir3_data_verify( |
Dave Chinner | e481357 | 2012-11-12 22:54:14 +1100 | [diff] [blame] | 197 | struct xfs_buf *bp) |
| 198 | { |
| 199 | struct xfs_mount *mp = bp->b_target->bt_mount; |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 200 | struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; |
Dave Chinner | e481357 | 2012-11-12 22:54:14 +1100 | [diff] [blame] | 201 | |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 202 | if (xfs_sb_version_hascrc(&mp->m_sb)) { |
| 203 | if (hdr3->magic != cpu_to_be32(XFS_DIR3_DATA_MAGIC)) |
| 204 | return false; |
| 205 | if (!uuid_equal(&hdr3->uuid, &mp->m_sb.sb_uuid)) |
| 206 | return false; |
| 207 | if (be64_to_cpu(hdr3->blkno) != bp->b_bn) |
| 208 | return false; |
| 209 | } else { |
| 210 | if (hdr3->magic != cpu_to_be32(XFS_DIR2_DATA_MAGIC)) |
| 211 | return false; |
Dave Chinner | e481357 | 2012-11-12 22:54:14 +1100 | [diff] [blame] | 212 | } |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 213 | if (__xfs_dir3_data_check(NULL, bp)) |
| 214 | return false; |
| 215 | return true; |
Dave Chinner | 612cfbf | 2012-11-14 17:52:32 +1100 | [diff] [blame] | 216 | } |
Dave Chinner | e481357 | 2012-11-12 22:54:14 +1100 | [diff] [blame] | 217 | |
Dave Chinner | 1813dd6 | 2012-11-14 17:54:40 +1100 | [diff] [blame] | 218 | /* |
| 219 | * Readahead of the first block of the directory when it is opened is completely |
| 220 | * oblivious to the format of the directory. Hence we can either get a block |
| 221 | * format buffer or a data format buffer on readahead. |
| 222 | */ |
| 223 | static void |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 224 | xfs_dir3_data_reada_verify( |
Dave Chinner | 1813dd6 | 2012-11-14 17:54:40 +1100 | [diff] [blame] | 225 | struct xfs_buf *bp) |
Dave Chinner | 612cfbf | 2012-11-14 17:52:32 +1100 | [diff] [blame] | 226 | { |
Dave Chinner | 1813dd6 | 2012-11-14 17:54:40 +1100 | [diff] [blame] | 227 | struct xfs_mount *mp = bp->b_target->bt_mount; |
| 228 | struct xfs_dir2_data_hdr *hdr = bp->b_addr; |
| 229 | |
| 230 | switch (hdr->magic) { |
| 231 | case cpu_to_be32(XFS_DIR2_BLOCK_MAGIC): |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 232 | case cpu_to_be32(XFS_DIR3_BLOCK_MAGIC): |
| 233 | bp->b_ops = &xfs_dir3_block_buf_ops; |
Dave Chinner | 1813dd6 | 2012-11-14 17:54:40 +1100 | [diff] [blame] | 234 | bp->b_ops->verify_read(bp); |
| 235 | return; |
| 236 | case cpu_to_be32(XFS_DIR2_DATA_MAGIC): |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 237 | case cpu_to_be32(XFS_DIR3_DATA_MAGIC): |
| 238 | xfs_dir3_data_verify(bp); |
Dave Chinner | 1813dd6 | 2012-11-14 17:54:40 +1100 | [diff] [blame] | 239 | return; |
| 240 | default: |
| 241 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, hdr); |
| 242 | xfs_buf_ioerror(bp, EFSCORRUPTED); |
| 243 | break; |
| 244 | } |
Dave Chinner | 612cfbf | 2012-11-14 17:52:32 +1100 | [diff] [blame] | 245 | } |
| 246 | |
Dave Chinner | b0f539d | 2012-11-14 17:53:49 +1100 | [diff] [blame] | 247 | static void |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 248 | xfs_dir3_data_read_verify( |
Dave Chinner | 612cfbf | 2012-11-14 17:52:32 +1100 | [diff] [blame] | 249 | struct xfs_buf *bp) |
| 250 | { |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 251 | struct xfs_mount *mp = bp->b_target->bt_mount; |
| 252 | |
| 253 | if ((xfs_sb_version_hascrc(&mp->m_sb) && |
| 254 | !xfs_verify_cksum(bp->b_addr, BBTOB(bp->b_length), |
| 255 | XFS_DIR3_DATA_CRC_OFF)) || |
| 256 | !xfs_dir3_data_verify(bp)) { |
| 257 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, bp->b_addr); |
| 258 | xfs_buf_ioerror(bp, EFSCORRUPTED); |
| 259 | } |
Dave Chinner | e481357 | 2012-11-12 22:54:14 +1100 | [diff] [blame] | 260 | } |
| 261 | |
Dave Chinner | 1813dd6 | 2012-11-14 17:54:40 +1100 | [diff] [blame] | 262 | static void |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 263 | xfs_dir3_data_write_verify( |
Dave Chinner | 1813dd6 | 2012-11-14 17:54:40 +1100 | [diff] [blame] | 264 | struct xfs_buf *bp) |
| 265 | { |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 266 | struct xfs_mount *mp = bp->b_target->bt_mount; |
| 267 | struct xfs_buf_log_item *bip = bp->b_fspriv; |
| 268 | struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; |
| 269 | |
| 270 | if (!xfs_dir3_data_verify(bp)) { |
| 271 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, bp->b_addr); |
| 272 | xfs_buf_ioerror(bp, EFSCORRUPTED); |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | if (!xfs_sb_version_hascrc(&mp->m_sb)) |
| 277 | return; |
| 278 | |
| 279 | if (bip) |
| 280 | hdr3->lsn = cpu_to_be64(bip->bli_item.li_lsn); |
| 281 | |
| 282 | xfs_update_cksum(bp->b_addr, BBTOB(bp->b_length), XFS_DIR3_DATA_CRC_OFF); |
Dave Chinner | 1813dd6 | 2012-11-14 17:54:40 +1100 | [diff] [blame] | 283 | } |
| 284 | |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 285 | const struct xfs_buf_ops xfs_dir3_data_buf_ops = { |
| 286 | .verify_read = xfs_dir3_data_read_verify, |
| 287 | .verify_write = xfs_dir3_data_write_verify, |
Dave Chinner | 1813dd6 | 2012-11-14 17:54:40 +1100 | [diff] [blame] | 288 | }; |
| 289 | |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 290 | static const struct xfs_buf_ops xfs_dir3_data_reada_buf_ops = { |
| 291 | .verify_read = xfs_dir3_data_reada_verify, |
| 292 | .verify_write = xfs_dir3_data_write_verify, |
Dave Chinner | 1813dd6 | 2012-11-14 17:54:40 +1100 | [diff] [blame] | 293 | }; |
| 294 | |
Dave Chinner | 612cfbf | 2012-11-14 17:52:32 +1100 | [diff] [blame] | 295 | |
Dave Chinner | e481357 | 2012-11-12 22:54:14 +1100 | [diff] [blame] | 296 | int |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 297 | xfs_dir3_data_read( |
Dave Chinner | e481357 | 2012-11-12 22:54:14 +1100 | [diff] [blame] | 298 | struct xfs_trans *tp, |
| 299 | struct xfs_inode *dp, |
| 300 | xfs_dablk_t bno, |
| 301 | xfs_daddr_t mapped_bno, |
| 302 | struct xfs_buf **bpp) |
| 303 | { |
Dave Chinner | d75afeb | 2013-04-03 16:11:29 +1100 | [diff] [blame] | 304 | int err; |
| 305 | |
| 306 | err = xfs_da_read_buf(tp, dp, bno, mapped_bno, bpp, |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 307 | XFS_DATA_FORK, &xfs_dir3_data_buf_ops); |
Dave Chinner | d75afeb | 2013-04-03 16:11:29 +1100 | [diff] [blame] | 308 | if (!err && tp) |
Dave Chinner | 61fe135 | 2013-04-03 16:11:30 +1100 | [diff] [blame] | 309 | xfs_trans_buf_set_type(tp, *bpp, XFS_BLFT_DIR_DATA_BUF); |
Dave Chinner | d75afeb | 2013-04-03 16:11:29 +1100 | [diff] [blame] | 310 | return err; |
Dave Chinner | e481357 | 2012-11-12 22:54:14 +1100 | [diff] [blame] | 311 | } |
| 312 | |
Dave Chinner | da6958c | 2012-11-12 22:54:18 +1100 | [diff] [blame] | 313 | int |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 314 | xfs_dir3_data_readahead( |
Dave Chinner | da6958c | 2012-11-12 22:54:18 +1100 | [diff] [blame] | 315 | struct xfs_trans *tp, |
| 316 | struct xfs_inode *dp, |
| 317 | xfs_dablk_t bno, |
| 318 | xfs_daddr_t mapped_bno) |
| 319 | { |
| 320 | return xfs_da_reada_buf(tp, dp, bno, mapped_bno, |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 321 | XFS_DATA_FORK, &xfs_dir3_data_reada_buf_ops); |
Dave Chinner | da6958c | 2012-11-12 22:54:18 +1100 | [diff] [blame] | 322 | } |
| 323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | /* |
| 325 | * Given a data block and an unused entry from that block, |
| 326 | * return the bestfree entry if any that corresponds to it. |
| 327 | */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 328 | STATIC xfs_dir2_data_free_t * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | xfs_dir2_data_freefind( |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 330 | xfs_dir2_data_hdr_t *hdr, /* data block */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | xfs_dir2_data_unused_t *dup) /* data unused entry */ |
| 332 | { |
| 333 | xfs_dir2_data_free_t *dfp; /* bestfree entry */ |
| 334 | xfs_dir2_data_aoff_t off; /* offset value needed */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 335 | struct xfs_dir2_data_free *bf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | #if defined(DEBUG) && defined(__KERNEL__) |
| 337 | int matched; /* matched the value */ |
| 338 | int seenzero; /* saw a 0 bestfree entry */ |
| 339 | #endif |
| 340 | |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 341 | off = (xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr); |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 342 | bf = xfs_dir3_data_bestfree_p(hdr); |
| 343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | #if defined(DEBUG) && defined(__KERNEL__) |
| 345 | /* |
| 346 | * Validate some consistency in the bestfree table. |
| 347 | * Check order, non-overlapping entries, and if we find the |
| 348 | * one we're looking for it has to be exact. |
| 349 | */ |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 350 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 351 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 352 | hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 353 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
| 354 | for (dfp = &bf[0], seenzero = matched = 0; |
| 355 | dfp < &bf[XFS_DIR2_DATA_FD_COUNT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | dfp++) { |
| 357 | if (!dfp->offset) { |
| 358 | ASSERT(!dfp->length); |
| 359 | seenzero = 1; |
| 360 | continue; |
| 361 | } |
| 362 | ASSERT(seenzero == 0); |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 363 | if (be16_to_cpu(dfp->offset) == off) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | matched = 1; |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 365 | ASSERT(dfp->length == dup->length); |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 366 | } else if (off < be16_to_cpu(dfp->offset)) |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 367 | ASSERT(off + be16_to_cpu(dup->length) <= be16_to_cpu(dfp->offset)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | else |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 369 | ASSERT(be16_to_cpu(dfp->offset) + be16_to_cpu(dfp->length) <= off); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 370 | ASSERT(matched || be16_to_cpu(dfp->length) >= be16_to_cpu(dup->length)); |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 371 | if (dfp > &bf[0]) |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 372 | ASSERT(be16_to_cpu(dfp[-1].length) >= be16_to_cpu(dfp[0].length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | #endif |
| 375 | /* |
| 376 | * If this is smaller than the smallest bestfree entry, |
| 377 | * it can't be there since they're sorted. |
| 378 | */ |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 379 | if (be16_to_cpu(dup->length) < |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 380 | be16_to_cpu(bf[XFS_DIR2_DATA_FD_COUNT - 1].length)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | return NULL; |
| 382 | /* |
| 383 | * Look at the three bestfree entries for our guy. |
| 384 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 385 | for (dfp = &bf[0]; dfp < &bf[XFS_DIR2_DATA_FD_COUNT]; dfp++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | if (!dfp->offset) |
| 387 | return NULL; |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 388 | if (be16_to_cpu(dfp->offset) == off) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | return dfp; |
| 390 | } |
| 391 | /* |
| 392 | * Didn't find it. This only happens if there are duplicate lengths. |
| 393 | */ |
| 394 | return NULL; |
| 395 | } |
| 396 | |
| 397 | /* |
| 398 | * Insert an unused-space entry into the bestfree table. |
| 399 | */ |
| 400 | xfs_dir2_data_free_t * /* entry inserted */ |
| 401 | xfs_dir2_data_freeinsert( |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 402 | xfs_dir2_data_hdr_t *hdr, /* data block pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | xfs_dir2_data_unused_t *dup, /* unused space */ |
| 404 | int *loghead) /* log the data header (out) */ |
| 405 | { |
| 406 | xfs_dir2_data_free_t *dfp; /* bestfree table pointer */ |
| 407 | xfs_dir2_data_free_t new; /* new bestfree entry */ |
| 408 | |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 409 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 410 | hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 411 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
| 412 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
| 413 | |
| 414 | dfp = xfs_dir3_data_bestfree_p(hdr); |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 415 | new.length = dup->length; |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 416 | new.offset = cpu_to_be16((char *)dup - (char *)hdr); |
| 417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | /* |
| 419 | * Insert at position 0, 1, or 2; or not at all. |
| 420 | */ |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 421 | if (be16_to_cpu(new.length) > be16_to_cpu(dfp[0].length)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | dfp[2] = dfp[1]; |
| 423 | dfp[1] = dfp[0]; |
| 424 | dfp[0] = new; |
| 425 | *loghead = 1; |
| 426 | return &dfp[0]; |
| 427 | } |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 428 | if (be16_to_cpu(new.length) > be16_to_cpu(dfp[1].length)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | dfp[2] = dfp[1]; |
| 430 | dfp[1] = new; |
| 431 | *loghead = 1; |
| 432 | return &dfp[1]; |
| 433 | } |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 434 | if (be16_to_cpu(new.length) > be16_to_cpu(dfp[2].length)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | dfp[2] = new; |
| 436 | *loghead = 1; |
| 437 | return &dfp[2]; |
| 438 | } |
| 439 | return NULL; |
| 440 | } |
| 441 | |
| 442 | /* |
| 443 | * Remove a bestfree entry from the table. |
| 444 | */ |
Christoph Hellwig | ba0f32d | 2005-06-21 15:36:52 +1000 | [diff] [blame] | 445 | STATIC void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | xfs_dir2_data_freeremove( |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 447 | xfs_dir2_data_hdr_t *hdr, /* data block header */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | xfs_dir2_data_free_t *dfp, /* bestfree entry pointer */ |
| 449 | int *loghead) /* out: log data header */ |
| 450 | { |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 451 | struct xfs_dir2_data_free *bf; |
| 452 | |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 453 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 454 | hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 455 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
| 456 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
| 457 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | /* |
| 459 | * It's the first entry, slide the next 2 up. |
| 460 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 461 | bf = xfs_dir3_data_bestfree_p(hdr); |
| 462 | if (dfp == &bf[0]) { |
| 463 | bf[0] = bf[1]; |
| 464 | bf[1] = bf[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | } |
| 466 | /* |
| 467 | * It's the second entry, slide the 3rd entry up. |
| 468 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 469 | else if (dfp == &bf[1]) |
| 470 | bf[1] = bf[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | /* |
| 472 | * Must be the last entry. |
| 473 | */ |
| 474 | else |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 475 | ASSERT(dfp == &bf[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | /* |
| 477 | * Clear the 3rd entry, must be zero now. |
| 478 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 479 | bf[2].length = 0; |
| 480 | bf[2].offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | *loghead = 1; |
| 482 | } |
| 483 | |
| 484 | /* |
| 485 | * Given a data block, reconstruct its bestfree map. |
| 486 | */ |
| 487 | void |
| 488 | xfs_dir2_data_freescan( |
| 489 | xfs_mount_t *mp, /* filesystem mount point */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 490 | xfs_dir2_data_hdr_t *hdr, /* data block header */ |
Eric Sandeen | ef497f8 | 2007-05-08 13:48:49 +1000 | [diff] [blame] | 491 | int *loghead) /* out: log data header */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
| 493 | xfs_dir2_block_tail_t *btp; /* block tail */ |
| 494 | xfs_dir2_data_entry_t *dep; /* active data entry */ |
| 495 | xfs_dir2_data_unused_t *dup; /* unused data entry */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 496 | struct xfs_dir2_data_free *bf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | char *endp; /* end of block's data */ |
| 498 | char *p; /* current entry pointer */ |
| 499 | |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 500 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 501 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 502 | hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 503 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
| 504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | /* |
| 506 | * Start by clearing the table. |
| 507 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 508 | bf = xfs_dir3_data_bestfree_p(hdr); |
| 509 | memset(bf, 0, sizeof(*bf) * XFS_DIR2_DATA_FD_COUNT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | *loghead = 1; |
| 511 | /* |
| 512 | * Set up pointers. |
| 513 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 514 | p = (char *)xfs_dir3_data_entry_p(hdr); |
| 515 | if (hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 516 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 517 | btp = xfs_dir2_block_tail_p(mp, hdr); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 518 | endp = (char *)xfs_dir2_block_leaf_p(btp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | } else |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 520 | endp = (char *)hdr + mp->m_dirblksize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | /* |
| 522 | * Loop over the block's entries. |
| 523 | */ |
| 524 | while (p < endp) { |
| 525 | dup = (xfs_dir2_data_unused_t *)p; |
| 526 | /* |
| 527 | * If it's a free entry, insert it. |
| 528 | */ |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 529 | if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 530 | ASSERT((char *)dup - (char *)hdr == |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 531 | be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup))); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 532 | xfs_dir2_data_freeinsert(hdr, dup, loghead); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 533 | p += be16_to_cpu(dup->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | } |
| 535 | /* |
| 536 | * For active entries, check their tags and skip them. |
| 537 | */ |
| 538 | else { |
| 539 | dep = (xfs_dir2_data_entry_t *)p; |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 540 | ASSERT((char *)dep - (char *)hdr == |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 541 | be16_to_cpu(*xfs_dir2_data_entry_tag_p(dep))); |
| 542 | p += xfs_dir2_data_entsize(dep->namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | } |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | /* |
| 548 | * Initialize a data block at the given block number in the directory. |
| 549 | * Give back the buffer for the created block. |
| 550 | */ |
| 551 | int /* error */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 552 | xfs_dir3_data_init( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | xfs_da_args_t *args, /* directory operation args */ |
| 554 | xfs_dir2_db_t blkno, /* logical dir block number */ |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 555 | struct xfs_buf **bpp) /* output block buffer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | { |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 557 | struct xfs_buf *bp; /* block buffer */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 558 | xfs_dir2_data_hdr_t *hdr; /* data block header */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | xfs_inode_t *dp; /* incore directory inode */ |
| 560 | xfs_dir2_data_unused_t *dup; /* unused entry pointer */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 561 | struct xfs_dir2_data_free *bf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | int error; /* error return value */ |
| 563 | int i; /* bestfree index */ |
| 564 | xfs_mount_t *mp; /* filesystem mount point */ |
| 565 | xfs_trans_t *tp; /* transaction pointer */ |
| 566 | int t; /* temp */ |
| 567 | |
| 568 | dp = args->dp; |
| 569 | mp = dp->i_mount; |
| 570 | tp = args->trans; |
| 571 | /* |
| 572 | * Get the buffer set up for the block. |
| 573 | */ |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 574 | error = xfs_da_get_buf(tp, dp, xfs_dir2_db_to_da(mp, blkno), -1, &bp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | XFS_DATA_FORK); |
Dave Chinner | b0f539d | 2012-11-14 17:53:49 +1100 | [diff] [blame] | 576 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | return error; |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 578 | bp->b_ops = &xfs_dir3_data_buf_ops; |
Dave Chinner | 61fe135 | 2013-04-03 16:11:30 +1100 | [diff] [blame] | 579 | xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DIR_DATA_BUF); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | /* |
| 582 | * Initialize the header. |
| 583 | */ |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 584 | hdr = bp->b_addr; |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 585 | if (xfs_sb_version_hascrc(&mp->m_sb)) { |
| 586 | struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; |
| 587 | |
| 588 | memset(hdr3, 0, sizeof(*hdr3)); |
| 589 | hdr3->magic = cpu_to_be32(XFS_DIR3_DATA_MAGIC); |
| 590 | hdr3->blkno = cpu_to_be64(bp->b_bn); |
| 591 | hdr3->owner = cpu_to_be64(dp->i_ino); |
| 592 | uuid_copy(&hdr3->uuid, &mp->m_sb.sb_uuid); |
| 593 | |
| 594 | } else |
| 595 | hdr->magic = cpu_to_be32(XFS_DIR2_DATA_MAGIC); |
| 596 | |
| 597 | bf = xfs_dir3_data_bestfree_p(hdr); |
| 598 | bf[0].offset = cpu_to_be16(xfs_dir3_data_entry_offset(hdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | for (i = 1; i < XFS_DIR2_DATA_FD_COUNT; i++) { |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 600 | bf[i].length = 0; |
| 601 | bf[i].offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | } |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 603 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | /* |
| 605 | * Set up an unused entry for the block's body. |
| 606 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 607 | dup = xfs_dir3_data_unused_p(hdr); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 608 | dup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 610 | t = mp->m_dirblksize - (uint)xfs_dir3_data_entry_offset(hdr); |
| 611 | bf[0].length = cpu_to_be16(t); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 612 | dup->length = cpu_to_be16(t); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 613 | *xfs_dir2_data_unused_tag_p(dup) = cpu_to_be16((char *)dup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | /* |
| 615 | * Log it and return it. |
| 616 | */ |
| 617 | xfs_dir2_data_log_header(tp, bp); |
| 618 | xfs_dir2_data_log_unused(tp, bp, dup); |
| 619 | *bpp = bp; |
| 620 | return 0; |
| 621 | } |
| 622 | |
| 623 | /* |
| 624 | * Log an active data entry from the block. |
| 625 | */ |
| 626 | void |
| 627 | xfs_dir2_data_log_entry( |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 628 | struct xfs_trans *tp, |
| 629 | struct xfs_buf *bp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | xfs_dir2_data_entry_t *dep) /* data entry pointer */ |
| 631 | { |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 632 | xfs_dir2_data_hdr_t *hdr = bp->b_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 634 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 635 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 636 | hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 637 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 638 | |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 639 | xfs_trans_log_buf(tp, bp, (uint)((char *)dep - (char *)hdr), |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 640 | (uint)((char *)(xfs_dir2_data_entry_tag_p(dep) + 1) - |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 641 | (char *)hdr - 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | /* |
| 645 | * Log a data block header. |
| 646 | */ |
| 647 | void |
| 648 | xfs_dir2_data_log_header( |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 649 | struct xfs_trans *tp, |
| 650 | struct xfs_buf *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | { |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 652 | xfs_dir2_data_hdr_t *hdr = bp->b_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 654 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 655 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 656 | hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 657 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 658 | |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 659 | xfs_trans_log_buf(tp, bp, 0, xfs_dir3_data_entry_offset(hdr) - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | /* |
| 663 | * Log a data unused entry. |
| 664 | */ |
| 665 | void |
| 666 | xfs_dir2_data_log_unused( |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 667 | struct xfs_trans *tp, |
| 668 | struct xfs_buf *bp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | xfs_dir2_data_unused_t *dup) /* data unused pointer */ |
| 670 | { |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 671 | xfs_dir2_data_hdr_t *hdr = bp->b_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 673 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 674 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 675 | hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 676 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | /* |
| 679 | * Log the first part of the unused entry. |
| 680 | */ |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 681 | xfs_trans_log_buf(tp, bp, (uint)((char *)dup - (char *)hdr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | (uint)((char *)&dup->length + sizeof(dup->length) - |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 683 | 1 - (char *)hdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | /* |
| 685 | * Log the end (tag) of the unused entry. |
| 686 | */ |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 687 | xfs_trans_log_buf(tp, bp, |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 688 | (uint)((char *)xfs_dir2_data_unused_tag_p(dup) - (char *)hdr), |
| 689 | (uint)((char *)xfs_dir2_data_unused_tag_p(dup) - (char *)hdr + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | sizeof(xfs_dir2_data_off_t) - 1)); |
| 691 | } |
| 692 | |
| 693 | /* |
| 694 | * Make a byte range in the data block unused. |
| 695 | * Its current contents are unimportant. |
| 696 | */ |
| 697 | void |
| 698 | xfs_dir2_data_make_free( |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 699 | struct xfs_trans *tp, |
| 700 | struct xfs_buf *bp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | xfs_dir2_data_aoff_t offset, /* starting byte offset */ |
| 702 | xfs_dir2_data_aoff_t len, /* length in bytes */ |
| 703 | int *needlogp, /* out: log header */ |
| 704 | int *needscanp) /* out: regen bestfree */ |
| 705 | { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 706 | xfs_dir2_data_hdr_t *hdr; /* data block pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | xfs_dir2_data_free_t *dfp; /* bestfree pointer */ |
| 708 | char *endptr; /* end of data area */ |
| 709 | xfs_mount_t *mp; /* filesystem mount point */ |
| 710 | int needscan; /* need to regen bestfree */ |
| 711 | xfs_dir2_data_unused_t *newdup; /* new unused entry */ |
| 712 | xfs_dir2_data_unused_t *postdup; /* unused entry after us */ |
| 713 | xfs_dir2_data_unused_t *prevdup; /* unused entry before us */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 714 | struct xfs_dir2_data_free *bf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
| 716 | mp = tp->t_mountp; |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 717 | hdr = bp->b_addr; |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 718 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | /* |
| 720 | * Figure out where the end of the data area is. |
| 721 | */ |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 722 | if (hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
| 723 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC)) |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 724 | endptr = (char *)hdr + mp->m_dirblksize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | else { |
| 726 | xfs_dir2_block_tail_t *btp; /* block tail */ |
| 727 | |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 728 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 729 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 730 | btp = xfs_dir2_block_tail_p(mp, hdr); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 731 | endptr = (char *)xfs_dir2_block_leaf_p(btp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | } |
| 733 | /* |
| 734 | * If this isn't the start of the block, then back up to |
| 735 | * the previous entry and see if it's free. |
| 736 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 737 | if (offset > xfs_dir3_data_entry_offset(hdr)) { |
Nathan Scott | 3d693c6 | 2006-03-17 17:28:27 +1100 | [diff] [blame] | 738 | __be16 *tagp; /* tag just before us */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 740 | tagp = (__be16 *)((char *)hdr + offset) - 1; |
| 741 | prevdup = (xfs_dir2_data_unused_t *)((char *)hdr + be16_to_cpu(*tagp)); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 742 | if (be16_to_cpu(prevdup->freetag) != XFS_DIR2_DATA_FREE_TAG) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | prevdup = NULL; |
| 744 | } else |
| 745 | prevdup = NULL; |
| 746 | /* |
| 747 | * If this isn't the end of the block, see if the entry after |
| 748 | * us is free. |
| 749 | */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 750 | if ((char *)hdr + offset + len < endptr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | postdup = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 752 | (xfs_dir2_data_unused_t *)((char *)hdr + offset + len); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 753 | if (be16_to_cpu(postdup->freetag) != XFS_DIR2_DATA_FREE_TAG) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | postdup = NULL; |
| 755 | } else |
| 756 | postdup = NULL; |
| 757 | ASSERT(*needscanp == 0); |
| 758 | needscan = 0; |
| 759 | /* |
| 760 | * Previous and following entries are both free, |
| 761 | * merge everything into a single free entry. |
| 762 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 763 | bf = xfs_dir3_data_bestfree_p(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | if (prevdup && postdup) { |
| 765 | xfs_dir2_data_free_t *dfp2; /* another bestfree pointer */ |
| 766 | |
| 767 | /* |
| 768 | * See if prevdup and/or postdup are in bestfree table. |
| 769 | */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 770 | dfp = xfs_dir2_data_freefind(hdr, prevdup); |
| 771 | dfp2 = xfs_dir2_data_freefind(hdr, postdup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | /* |
| 773 | * We need a rescan unless there are exactly 2 free entries |
| 774 | * namely our two. Then we know what's happening, otherwise |
| 775 | * since the third bestfree is there, there might be more |
| 776 | * entries. |
| 777 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 778 | needscan = (bf[2].length != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | /* |
| 780 | * Fix up the new big freespace. |
| 781 | */ |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 782 | be16_add_cpu(&prevdup->length, len + be16_to_cpu(postdup->length)); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 783 | *xfs_dir2_data_unused_tag_p(prevdup) = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 784 | cpu_to_be16((char *)prevdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | xfs_dir2_data_log_unused(tp, bp, prevdup); |
| 786 | if (!needscan) { |
| 787 | /* |
| 788 | * Has to be the case that entries 0 and 1 are |
| 789 | * dfp and dfp2 (don't know which is which), and |
| 790 | * entry 2 is empty. |
| 791 | * Remove entry 1 first then entry 0. |
| 792 | */ |
| 793 | ASSERT(dfp && dfp2); |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 794 | if (dfp == &bf[1]) { |
| 795 | dfp = &bf[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | ASSERT(dfp2 == dfp); |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 797 | dfp2 = &bf[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | } |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 799 | xfs_dir2_data_freeremove(hdr, dfp2, needlogp); |
| 800 | xfs_dir2_data_freeremove(hdr, dfp, needlogp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | /* |
| 802 | * Now insert the new entry. |
| 803 | */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 804 | dfp = xfs_dir2_data_freeinsert(hdr, prevdup, needlogp); |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 805 | ASSERT(dfp == &bf[0]); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 806 | ASSERT(dfp->length == prevdup->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | ASSERT(!dfp[1].length); |
| 808 | ASSERT(!dfp[2].length); |
| 809 | } |
| 810 | } |
| 811 | /* |
| 812 | * The entry before us is free, merge with it. |
| 813 | */ |
| 814 | else if (prevdup) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 815 | dfp = xfs_dir2_data_freefind(hdr, prevdup); |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 816 | be16_add_cpu(&prevdup->length, len); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 817 | *xfs_dir2_data_unused_tag_p(prevdup) = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 818 | cpu_to_be16((char *)prevdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | xfs_dir2_data_log_unused(tp, bp, prevdup); |
| 820 | /* |
| 821 | * If the previous entry was in the table, the new entry |
| 822 | * is longer, so it will be in the table too. Remove |
| 823 | * the old one and add the new one. |
| 824 | */ |
| 825 | if (dfp) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 826 | xfs_dir2_data_freeremove(hdr, dfp, needlogp); |
| 827 | xfs_dir2_data_freeinsert(hdr, prevdup, needlogp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | } |
| 829 | /* |
| 830 | * Otherwise we need a scan if the new entry is big enough. |
| 831 | */ |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 832 | else { |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 833 | needscan = be16_to_cpu(prevdup->length) > |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 834 | be16_to_cpu(bf[2].length); |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 835 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | } |
| 837 | /* |
| 838 | * The following entry is free, merge with it. |
| 839 | */ |
| 840 | else if (postdup) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 841 | dfp = xfs_dir2_data_freefind(hdr, postdup); |
| 842 | newdup = (xfs_dir2_data_unused_t *)((char *)hdr + offset); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 843 | newdup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG); |
| 844 | newdup->length = cpu_to_be16(len + be16_to_cpu(postdup->length)); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 845 | *xfs_dir2_data_unused_tag_p(newdup) = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 846 | cpu_to_be16((char *)newdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | xfs_dir2_data_log_unused(tp, bp, newdup); |
| 848 | /* |
| 849 | * If the following entry was in the table, the new entry |
| 850 | * is longer, so it will be in the table too. Remove |
| 851 | * the old one and add the new one. |
| 852 | */ |
| 853 | if (dfp) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 854 | xfs_dir2_data_freeremove(hdr, dfp, needlogp); |
| 855 | xfs_dir2_data_freeinsert(hdr, newdup, needlogp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | } |
| 857 | /* |
| 858 | * Otherwise we need a scan if the new entry is big enough. |
| 859 | */ |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 860 | else { |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 861 | needscan = be16_to_cpu(newdup->length) > |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 862 | be16_to_cpu(bf[2].length); |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 863 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | } |
| 865 | /* |
| 866 | * Neither neighbor is free. Make a new entry. |
| 867 | */ |
| 868 | else { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 869 | newdup = (xfs_dir2_data_unused_t *)((char *)hdr + offset); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 870 | newdup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG); |
| 871 | newdup->length = cpu_to_be16(len); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 872 | *xfs_dir2_data_unused_tag_p(newdup) = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 873 | cpu_to_be16((char *)newdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | xfs_dir2_data_log_unused(tp, bp, newdup); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 875 | xfs_dir2_data_freeinsert(hdr, newdup, needlogp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | } |
| 877 | *needscanp = needscan; |
| 878 | } |
| 879 | |
| 880 | /* |
| 881 | * Take a byte range out of an existing unused space and make it un-free. |
| 882 | */ |
| 883 | void |
| 884 | xfs_dir2_data_use_free( |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 885 | struct xfs_trans *tp, |
| 886 | struct xfs_buf *bp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | xfs_dir2_data_unused_t *dup, /* unused entry */ |
| 888 | xfs_dir2_data_aoff_t offset, /* starting offset to use */ |
| 889 | xfs_dir2_data_aoff_t len, /* length to use */ |
| 890 | int *needlogp, /* out: need to log header */ |
| 891 | int *needscanp) /* out: need regen bestfree */ |
| 892 | { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 893 | xfs_dir2_data_hdr_t *hdr; /* data block header */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | xfs_dir2_data_free_t *dfp; /* bestfree pointer */ |
| 895 | int matchback; /* matches end of freespace */ |
| 896 | int matchfront; /* matches start of freespace */ |
| 897 | int needscan; /* need to regen bestfree */ |
| 898 | xfs_dir2_data_unused_t *newdup; /* new unused entry */ |
| 899 | xfs_dir2_data_unused_t *newdup2; /* another new unused entry */ |
| 900 | int oldlen; /* old unused entry's length */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 901 | struct xfs_dir2_data_free *bf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 903 | hdr = bp->b_addr; |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 904 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame] | 905 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 906 | hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 907 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 908 | ASSERT(be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 909 | ASSERT(offset >= (char *)dup - (char *)hdr); |
| 910 | ASSERT(offset + len <= (char *)dup + be16_to_cpu(dup->length) - (char *)hdr); |
| 911 | ASSERT((char *)dup - (char *)hdr == be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | /* |
| 913 | * Look up the entry in the bestfree table. |
| 914 | */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 915 | dfp = xfs_dir2_data_freefind(hdr, dup); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 916 | oldlen = be16_to_cpu(dup->length); |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 917 | bf = xfs_dir3_data_bestfree_p(hdr); |
| 918 | ASSERT(dfp || oldlen <= be16_to_cpu(bf[2].length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | /* |
| 920 | * Check for alignment with front and back of the entry. |
| 921 | */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 922 | matchfront = (char *)dup - (char *)hdr == offset; |
| 923 | matchback = (char *)dup + oldlen - (char *)hdr == offset + len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | ASSERT(*needscanp == 0); |
| 925 | needscan = 0; |
| 926 | /* |
| 927 | * If we matched it exactly we just need to get rid of it from |
| 928 | * the bestfree table. |
| 929 | */ |
| 930 | if (matchfront && matchback) { |
| 931 | if (dfp) { |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 932 | needscan = (bf[2].offset != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | if (!needscan) |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 934 | xfs_dir2_data_freeremove(hdr, dfp, needlogp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | } |
| 936 | } |
| 937 | /* |
| 938 | * We match the first part of the entry. |
| 939 | * Make a new entry with the remaining freespace. |
| 940 | */ |
| 941 | else if (matchfront) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 942 | newdup = (xfs_dir2_data_unused_t *)((char *)hdr + offset + len); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 943 | newdup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG); |
| 944 | newdup->length = cpu_to_be16(oldlen - len); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 945 | *xfs_dir2_data_unused_tag_p(newdup) = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 946 | cpu_to_be16((char *)newdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | xfs_dir2_data_log_unused(tp, bp, newdup); |
| 948 | /* |
| 949 | * If it was in the table, remove it and add the new one. |
| 950 | */ |
| 951 | if (dfp) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 952 | xfs_dir2_data_freeremove(hdr, dfp, needlogp); |
| 953 | dfp = xfs_dir2_data_freeinsert(hdr, newdup, needlogp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | ASSERT(dfp != NULL); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 955 | ASSERT(dfp->length == newdup->length); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 956 | ASSERT(be16_to_cpu(dfp->offset) == (char *)newdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | /* |
| 958 | * If we got inserted at the last slot, |
| 959 | * that means we don't know if there was a better |
| 960 | * choice for the last slot, or not. Rescan. |
| 961 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 962 | needscan = dfp == &bf[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | } |
| 964 | } |
| 965 | /* |
| 966 | * We match the last part of the entry. |
| 967 | * Trim the allocated space off the tail of the entry. |
| 968 | */ |
| 969 | else if (matchback) { |
| 970 | newdup = dup; |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 971 | newdup->length = cpu_to_be16(((char *)hdr + offset) - (char *)newdup); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 972 | *xfs_dir2_data_unused_tag_p(newdup) = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 973 | cpu_to_be16((char *)newdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | xfs_dir2_data_log_unused(tp, bp, newdup); |
| 975 | /* |
| 976 | * If it was in the table, remove it and add the new one. |
| 977 | */ |
| 978 | if (dfp) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 979 | xfs_dir2_data_freeremove(hdr, dfp, needlogp); |
| 980 | dfp = xfs_dir2_data_freeinsert(hdr, newdup, needlogp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | ASSERT(dfp != NULL); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 982 | ASSERT(dfp->length == newdup->length); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 983 | ASSERT(be16_to_cpu(dfp->offset) == (char *)newdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | /* |
| 985 | * If we got inserted at the last slot, |
| 986 | * that means we don't know if there was a better |
| 987 | * choice for the last slot, or not. Rescan. |
| 988 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 989 | needscan = dfp == &bf[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | /* |
| 993 | * Poking out the middle of an entry. |
| 994 | * Make two new entries. |
| 995 | */ |
| 996 | else { |
| 997 | newdup = dup; |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 998 | newdup->length = cpu_to_be16(((char *)hdr + offset) - (char *)newdup); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 999 | *xfs_dir2_data_unused_tag_p(newdup) = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 1000 | cpu_to_be16((char *)newdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | xfs_dir2_data_log_unused(tp, bp, newdup); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 1002 | newdup2 = (xfs_dir2_data_unused_t *)((char *)hdr + offset + len); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 1003 | newdup2->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG); |
| 1004 | newdup2->length = cpu_to_be16(oldlen - len - be16_to_cpu(newdup->length)); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 1005 | *xfs_dir2_data_unused_tag_p(newdup2) = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 1006 | cpu_to_be16((char *)newdup2 - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | xfs_dir2_data_log_unused(tp, bp, newdup2); |
| 1008 | /* |
| 1009 | * If the old entry was in the table, we need to scan |
| 1010 | * if the 3rd entry was valid, since these entries |
| 1011 | * are smaller than the old one. |
| 1012 | * If we don't need to scan that means there were 1 or 2 |
| 1013 | * entries in the table, and removing the old and adding |
| 1014 | * the 2 new will work. |
| 1015 | */ |
| 1016 | if (dfp) { |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 1017 | needscan = (bf[2].length != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | if (!needscan) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 1019 | xfs_dir2_data_freeremove(hdr, dfp, needlogp); |
| 1020 | xfs_dir2_data_freeinsert(hdr, newdup, needlogp); |
| 1021 | xfs_dir2_data_freeinsert(hdr, newdup2, |
| 1022 | needlogp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | } |
| 1026 | *needscanp = needscan; |
| 1027 | } |