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 | { |
| 304 | return xfs_da_read_buf(tp, dp, bno, mapped_bno, bpp, |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame^] | 305 | XFS_DATA_FORK, &xfs_dir3_data_buf_ops); |
Dave Chinner | e481357 | 2012-11-12 22:54:14 +1100 | [diff] [blame] | 306 | } |
| 307 | |
Dave Chinner | da6958c | 2012-11-12 22:54:18 +1100 | [diff] [blame] | 308 | int |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame^] | 309 | xfs_dir3_data_readahead( |
Dave Chinner | da6958c | 2012-11-12 22:54:18 +1100 | [diff] [blame] | 310 | struct xfs_trans *tp, |
| 311 | struct xfs_inode *dp, |
| 312 | xfs_dablk_t bno, |
| 313 | xfs_daddr_t mapped_bno) |
| 314 | { |
| 315 | return xfs_da_reada_buf(tp, dp, bno, mapped_bno, |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame^] | 316 | XFS_DATA_FORK, &xfs_dir3_data_reada_buf_ops); |
Dave Chinner | da6958c | 2012-11-12 22:54:18 +1100 | [diff] [blame] | 317 | } |
| 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | /* |
| 320 | * Given a data block and an unused entry from that block, |
| 321 | * return the bestfree entry if any that corresponds to it. |
| 322 | */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 323 | STATIC xfs_dir2_data_free_t * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | xfs_dir2_data_freefind( |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 325 | xfs_dir2_data_hdr_t *hdr, /* data block */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | xfs_dir2_data_unused_t *dup) /* data unused entry */ |
| 327 | { |
| 328 | xfs_dir2_data_free_t *dfp; /* bestfree entry */ |
| 329 | xfs_dir2_data_aoff_t off; /* offset value needed */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 330 | struct xfs_dir2_data_free *bf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | #if defined(DEBUG) && defined(__KERNEL__) |
| 332 | int matched; /* matched the value */ |
| 333 | int seenzero; /* saw a 0 bestfree entry */ |
| 334 | #endif |
| 335 | |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 336 | off = (xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr); |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 337 | bf = xfs_dir3_data_bestfree_p(hdr); |
| 338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | #if defined(DEBUG) && defined(__KERNEL__) |
| 340 | /* |
| 341 | * Validate some consistency in the bestfree table. |
| 342 | * Check order, non-overlapping entries, and if we find the |
| 343 | * one we're looking for it has to be exact. |
| 344 | */ |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 345 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame^] | 346 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 347 | hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 348 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
| 349 | for (dfp = &bf[0], seenzero = matched = 0; |
| 350 | dfp < &bf[XFS_DIR2_DATA_FD_COUNT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | dfp++) { |
| 352 | if (!dfp->offset) { |
| 353 | ASSERT(!dfp->length); |
| 354 | seenzero = 1; |
| 355 | continue; |
| 356 | } |
| 357 | ASSERT(seenzero == 0); |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 358 | if (be16_to_cpu(dfp->offset) == off) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | matched = 1; |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 360 | ASSERT(dfp->length == dup->length); |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 361 | } else if (off < be16_to_cpu(dfp->offset)) |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 362 | ASSERT(off + be16_to_cpu(dup->length) <= be16_to_cpu(dfp->offset)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | else |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 364 | ASSERT(be16_to_cpu(dfp->offset) + be16_to_cpu(dfp->length) <= off); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 365 | ASSERT(matched || be16_to_cpu(dfp->length) >= be16_to_cpu(dup->length)); |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 366 | if (dfp > &bf[0]) |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 367 | 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] | 368 | } |
| 369 | #endif |
| 370 | /* |
| 371 | * If this is smaller than the smallest bestfree entry, |
| 372 | * it can't be there since they're sorted. |
| 373 | */ |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 374 | if (be16_to_cpu(dup->length) < |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 375 | be16_to_cpu(bf[XFS_DIR2_DATA_FD_COUNT - 1].length)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | return NULL; |
| 377 | /* |
| 378 | * Look at the three bestfree entries for our guy. |
| 379 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 380 | for (dfp = &bf[0]; dfp < &bf[XFS_DIR2_DATA_FD_COUNT]; dfp++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | if (!dfp->offset) |
| 382 | return NULL; |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 383 | if (be16_to_cpu(dfp->offset) == off) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | return dfp; |
| 385 | } |
| 386 | /* |
| 387 | * Didn't find it. This only happens if there are duplicate lengths. |
| 388 | */ |
| 389 | return NULL; |
| 390 | } |
| 391 | |
| 392 | /* |
| 393 | * Insert an unused-space entry into the bestfree table. |
| 394 | */ |
| 395 | xfs_dir2_data_free_t * /* entry inserted */ |
| 396 | xfs_dir2_data_freeinsert( |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 397 | xfs_dir2_data_hdr_t *hdr, /* data block pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | xfs_dir2_data_unused_t *dup, /* unused space */ |
| 399 | int *loghead) /* log the data header (out) */ |
| 400 | { |
| 401 | xfs_dir2_data_free_t *dfp; /* bestfree table pointer */ |
| 402 | xfs_dir2_data_free_t new; /* new bestfree entry */ |
| 403 | |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 404 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 405 | hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 406 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
| 407 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
| 408 | |
| 409 | dfp = xfs_dir3_data_bestfree_p(hdr); |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 410 | new.length = dup->length; |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 411 | new.offset = cpu_to_be16((char *)dup - (char *)hdr); |
| 412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | /* |
| 414 | * Insert at position 0, 1, or 2; or not at all. |
| 415 | */ |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 416 | if (be16_to_cpu(new.length) > be16_to_cpu(dfp[0].length)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | dfp[2] = dfp[1]; |
| 418 | dfp[1] = dfp[0]; |
| 419 | dfp[0] = new; |
| 420 | *loghead = 1; |
| 421 | return &dfp[0]; |
| 422 | } |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 423 | if (be16_to_cpu(new.length) > be16_to_cpu(dfp[1].length)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | dfp[2] = dfp[1]; |
| 425 | dfp[1] = new; |
| 426 | *loghead = 1; |
| 427 | return &dfp[1]; |
| 428 | } |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 429 | if (be16_to_cpu(new.length) > be16_to_cpu(dfp[2].length)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | dfp[2] = new; |
| 431 | *loghead = 1; |
| 432 | return &dfp[2]; |
| 433 | } |
| 434 | return NULL; |
| 435 | } |
| 436 | |
| 437 | /* |
| 438 | * Remove a bestfree entry from the table. |
| 439 | */ |
Christoph Hellwig | ba0f32d | 2005-06-21 15:36:52 +1000 | [diff] [blame] | 440 | STATIC void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | xfs_dir2_data_freeremove( |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 442 | xfs_dir2_data_hdr_t *hdr, /* data block header */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | xfs_dir2_data_free_t *dfp, /* bestfree entry pointer */ |
| 444 | int *loghead) /* out: log data header */ |
| 445 | { |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 446 | struct xfs_dir2_data_free *bf; |
| 447 | |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 448 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 449 | hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 450 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
| 451 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
| 452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | /* |
| 454 | * It's the first entry, slide the next 2 up. |
| 455 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 456 | bf = xfs_dir3_data_bestfree_p(hdr); |
| 457 | if (dfp == &bf[0]) { |
| 458 | bf[0] = bf[1]; |
| 459 | bf[1] = bf[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | } |
| 461 | /* |
| 462 | * It's the second entry, slide the 3rd entry up. |
| 463 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 464 | else if (dfp == &bf[1]) |
| 465 | bf[1] = bf[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | /* |
| 467 | * Must be the last entry. |
| 468 | */ |
| 469 | else |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 470 | ASSERT(dfp == &bf[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | /* |
| 472 | * Clear the 3rd entry, must be zero now. |
| 473 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 474 | bf[2].length = 0; |
| 475 | bf[2].offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | *loghead = 1; |
| 477 | } |
| 478 | |
| 479 | /* |
| 480 | * Given a data block, reconstruct its bestfree map. |
| 481 | */ |
| 482 | void |
| 483 | xfs_dir2_data_freescan( |
| 484 | xfs_mount_t *mp, /* filesystem mount point */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 485 | xfs_dir2_data_hdr_t *hdr, /* data block header */ |
Eric Sandeen | ef497f8 | 2007-05-08 13:48:49 +1000 | [diff] [blame] | 486 | int *loghead) /* out: log data header */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | { |
| 488 | xfs_dir2_block_tail_t *btp; /* block tail */ |
| 489 | xfs_dir2_data_entry_t *dep; /* active data entry */ |
| 490 | xfs_dir2_data_unused_t *dup; /* unused data entry */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 491 | struct xfs_dir2_data_free *bf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | char *endp; /* end of block's data */ |
| 493 | char *p; /* current entry pointer */ |
| 494 | |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 495 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame^] | 496 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 497 | hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 498 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
| 499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | /* |
| 501 | * Start by clearing the table. |
| 502 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 503 | bf = xfs_dir3_data_bestfree_p(hdr); |
| 504 | memset(bf, 0, sizeof(*bf) * XFS_DIR2_DATA_FD_COUNT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | *loghead = 1; |
| 506 | /* |
| 507 | * Set up pointers. |
| 508 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 509 | p = (char *)xfs_dir3_data_entry_p(hdr); |
| 510 | if (hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 511 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 512 | btp = xfs_dir2_block_tail_p(mp, hdr); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 513 | endp = (char *)xfs_dir2_block_leaf_p(btp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | } else |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 515 | endp = (char *)hdr + mp->m_dirblksize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | /* |
| 517 | * Loop over the block's entries. |
| 518 | */ |
| 519 | while (p < endp) { |
| 520 | dup = (xfs_dir2_data_unused_t *)p; |
| 521 | /* |
| 522 | * If it's a free entry, insert it. |
| 523 | */ |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 524 | if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 525 | ASSERT((char *)dup - (char *)hdr == |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 526 | be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup))); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 527 | xfs_dir2_data_freeinsert(hdr, dup, loghead); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 528 | p += be16_to_cpu(dup->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | } |
| 530 | /* |
| 531 | * For active entries, check their tags and skip them. |
| 532 | */ |
| 533 | else { |
| 534 | dep = (xfs_dir2_data_entry_t *)p; |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 535 | ASSERT((char *)dep - (char *)hdr == |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 536 | be16_to_cpu(*xfs_dir2_data_entry_tag_p(dep))); |
| 537 | p += xfs_dir2_data_entsize(dep->namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | /* |
| 543 | * Initialize a data block at the given block number in the directory. |
| 544 | * Give back the buffer for the created block. |
| 545 | */ |
| 546 | int /* error */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 547 | xfs_dir3_data_init( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | xfs_da_args_t *args, /* directory operation args */ |
| 549 | xfs_dir2_db_t blkno, /* logical dir block number */ |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 550 | struct xfs_buf **bpp) /* output block buffer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | { |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 552 | struct xfs_buf *bp; /* block buffer */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 553 | xfs_dir2_data_hdr_t *hdr; /* data block header */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | xfs_inode_t *dp; /* incore directory inode */ |
| 555 | xfs_dir2_data_unused_t *dup; /* unused entry pointer */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 556 | struct xfs_dir2_data_free *bf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | int error; /* error return value */ |
| 558 | int i; /* bestfree index */ |
| 559 | xfs_mount_t *mp; /* filesystem mount point */ |
| 560 | xfs_trans_t *tp; /* transaction pointer */ |
| 561 | int t; /* temp */ |
| 562 | |
| 563 | dp = args->dp; |
| 564 | mp = dp->i_mount; |
| 565 | tp = args->trans; |
| 566 | /* |
| 567 | * Get the buffer set up for the block. |
| 568 | */ |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 569 | 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] | 570 | XFS_DATA_FORK); |
Dave Chinner | b0f539d | 2012-11-14 17:53:49 +1100 | [diff] [blame] | 571 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | return error; |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame^] | 573 | bp->b_ops = &xfs_dir3_data_buf_ops; |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | /* |
| 576 | * Initialize the header. |
| 577 | */ |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 578 | hdr = bp->b_addr; |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 579 | if (xfs_sb_version_hascrc(&mp->m_sb)) { |
| 580 | struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; |
| 581 | |
| 582 | memset(hdr3, 0, sizeof(*hdr3)); |
| 583 | hdr3->magic = cpu_to_be32(XFS_DIR3_DATA_MAGIC); |
| 584 | hdr3->blkno = cpu_to_be64(bp->b_bn); |
| 585 | hdr3->owner = cpu_to_be64(dp->i_ino); |
| 586 | uuid_copy(&hdr3->uuid, &mp->m_sb.sb_uuid); |
| 587 | |
| 588 | } else |
| 589 | hdr->magic = cpu_to_be32(XFS_DIR2_DATA_MAGIC); |
| 590 | |
| 591 | bf = xfs_dir3_data_bestfree_p(hdr); |
| 592 | bf[0].offset = cpu_to_be16(xfs_dir3_data_entry_offset(hdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | for (i = 1; i < XFS_DIR2_DATA_FD_COUNT; i++) { |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 594 | bf[i].length = 0; |
| 595 | bf[i].offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | } |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 597 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | /* |
| 599 | * Set up an unused entry for the block's body. |
| 600 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 601 | dup = xfs_dir3_data_unused_p(hdr); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 602 | dup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 604 | t = mp->m_dirblksize - (uint)xfs_dir3_data_entry_offset(hdr); |
| 605 | bf[0].length = cpu_to_be16(t); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 606 | dup->length = cpu_to_be16(t); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 607 | *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] | 608 | /* |
| 609 | * Log it and return it. |
| 610 | */ |
| 611 | xfs_dir2_data_log_header(tp, bp); |
| 612 | xfs_dir2_data_log_unused(tp, bp, dup); |
| 613 | *bpp = bp; |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | /* |
| 618 | * Log an active data entry from the block. |
| 619 | */ |
| 620 | void |
| 621 | xfs_dir2_data_log_entry( |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 622 | struct xfs_trans *tp, |
| 623 | struct xfs_buf *bp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | xfs_dir2_data_entry_t *dep) /* data entry pointer */ |
| 625 | { |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 626 | xfs_dir2_data_hdr_t *hdr = bp->b_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 628 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame^] | 629 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 630 | hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 631 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 632 | |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 633 | xfs_trans_log_buf(tp, bp, (uint)((char *)dep - (char *)hdr), |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 634 | (uint)((char *)(xfs_dir2_data_entry_tag_p(dep) + 1) - |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 635 | (char *)hdr - 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | /* |
| 639 | * Log a data block header. |
| 640 | */ |
| 641 | void |
| 642 | xfs_dir2_data_log_header( |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 643 | struct xfs_trans *tp, |
| 644 | struct xfs_buf *bp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | { |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 646 | xfs_dir2_data_hdr_t *hdr = bp->b_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 648 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame^] | 649 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 650 | hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 651 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 652 | |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 653 | 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] | 654 | } |
| 655 | |
| 656 | /* |
| 657 | * Log a data unused entry. |
| 658 | */ |
| 659 | void |
| 660 | xfs_dir2_data_log_unused( |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 661 | struct xfs_trans *tp, |
| 662 | struct xfs_buf *bp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | xfs_dir2_data_unused_t *dup) /* data unused pointer */ |
| 664 | { |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 665 | xfs_dir2_data_hdr_t *hdr = bp->b_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 667 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame^] | 668 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 669 | hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 670 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | /* |
| 673 | * Log the first part of the unused entry. |
| 674 | */ |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 675 | xfs_trans_log_buf(tp, bp, (uint)((char *)dup - (char *)hdr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | (uint)((char *)&dup->length + sizeof(dup->length) - |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 677 | 1 - (char *)hdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | /* |
| 679 | * Log the end (tag) of the unused entry. |
| 680 | */ |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 681 | xfs_trans_log_buf(tp, bp, |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 682 | (uint)((char *)xfs_dir2_data_unused_tag_p(dup) - (char *)hdr), |
| 683 | (uint)((char *)xfs_dir2_data_unused_tag_p(dup) - (char *)hdr + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | sizeof(xfs_dir2_data_off_t) - 1)); |
| 685 | } |
| 686 | |
| 687 | /* |
| 688 | * Make a byte range in the data block unused. |
| 689 | * Its current contents are unimportant. |
| 690 | */ |
| 691 | void |
| 692 | xfs_dir2_data_make_free( |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 693 | struct xfs_trans *tp, |
| 694 | struct xfs_buf *bp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | xfs_dir2_data_aoff_t offset, /* starting byte offset */ |
| 696 | xfs_dir2_data_aoff_t len, /* length in bytes */ |
| 697 | int *needlogp, /* out: log header */ |
| 698 | int *needscanp) /* out: regen bestfree */ |
| 699 | { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 700 | xfs_dir2_data_hdr_t *hdr; /* data block pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | xfs_dir2_data_free_t *dfp; /* bestfree pointer */ |
| 702 | char *endptr; /* end of data area */ |
| 703 | xfs_mount_t *mp; /* filesystem mount point */ |
| 704 | int needscan; /* need to regen bestfree */ |
| 705 | xfs_dir2_data_unused_t *newdup; /* new unused entry */ |
| 706 | xfs_dir2_data_unused_t *postdup; /* unused entry after us */ |
| 707 | xfs_dir2_data_unused_t *prevdup; /* unused entry before us */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 708 | struct xfs_dir2_data_free *bf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
| 710 | mp = tp->t_mountp; |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 711 | hdr = bp->b_addr; |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 712 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | /* |
| 714 | * Figure out where the end of the data area is. |
| 715 | */ |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame^] | 716 | if (hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
| 717 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC)) |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 718 | endptr = (char *)hdr + mp->m_dirblksize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | else { |
| 720 | xfs_dir2_block_tail_t *btp; /* block tail */ |
| 721 | |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 722 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 723 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 724 | btp = xfs_dir2_block_tail_p(mp, hdr); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 725 | endptr = (char *)xfs_dir2_block_leaf_p(btp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | } |
| 727 | /* |
| 728 | * If this isn't the start of the block, then back up to |
| 729 | * the previous entry and see if it's free. |
| 730 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 731 | if (offset > xfs_dir3_data_entry_offset(hdr)) { |
Nathan Scott | 3d693c6 | 2006-03-17 17:28:27 +1100 | [diff] [blame] | 732 | __be16 *tagp; /* tag just before us */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 734 | tagp = (__be16 *)((char *)hdr + offset) - 1; |
| 735 | prevdup = (xfs_dir2_data_unused_t *)((char *)hdr + be16_to_cpu(*tagp)); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 736 | if (be16_to_cpu(prevdup->freetag) != XFS_DIR2_DATA_FREE_TAG) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | prevdup = NULL; |
| 738 | } else |
| 739 | prevdup = NULL; |
| 740 | /* |
| 741 | * If this isn't the end of the block, see if the entry after |
| 742 | * us is free. |
| 743 | */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 744 | if ((char *)hdr + offset + len < endptr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | postdup = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 746 | (xfs_dir2_data_unused_t *)((char *)hdr + offset + len); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 747 | if (be16_to_cpu(postdup->freetag) != XFS_DIR2_DATA_FREE_TAG) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | postdup = NULL; |
| 749 | } else |
| 750 | postdup = NULL; |
| 751 | ASSERT(*needscanp == 0); |
| 752 | needscan = 0; |
| 753 | /* |
| 754 | * Previous and following entries are both free, |
| 755 | * merge everything into a single free entry. |
| 756 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 757 | bf = xfs_dir3_data_bestfree_p(hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | if (prevdup && postdup) { |
| 759 | xfs_dir2_data_free_t *dfp2; /* another bestfree pointer */ |
| 760 | |
| 761 | /* |
| 762 | * See if prevdup and/or postdup are in bestfree table. |
| 763 | */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 764 | dfp = xfs_dir2_data_freefind(hdr, prevdup); |
| 765 | dfp2 = xfs_dir2_data_freefind(hdr, postdup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | /* |
| 767 | * We need a rescan unless there are exactly 2 free entries |
| 768 | * namely our two. Then we know what's happening, otherwise |
| 769 | * since the third bestfree is there, there might be more |
| 770 | * entries. |
| 771 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 772 | needscan = (bf[2].length != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | /* |
| 774 | * Fix up the new big freespace. |
| 775 | */ |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 776 | be16_add_cpu(&prevdup->length, len + be16_to_cpu(postdup->length)); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 777 | *xfs_dir2_data_unused_tag_p(prevdup) = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 778 | cpu_to_be16((char *)prevdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | xfs_dir2_data_log_unused(tp, bp, prevdup); |
| 780 | if (!needscan) { |
| 781 | /* |
| 782 | * Has to be the case that entries 0 and 1 are |
| 783 | * dfp and dfp2 (don't know which is which), and |
| 784 | * entry 2 is empty. |
| 785 | * Remove entry 1 first then entry 0. |
| 786 | */ |
| 787 | ASSERT(dfp && dfp2); |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 788 | if (dfp == &bf[1]) { |
| 789 | dfp = &bf[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | ASSERT(dfp2 == dfp); |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 791 | dfp2 = &bf[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | } |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 793 | xfs_dir2_data_freeremove(hdr, dfp2, needlogp); |
| 794 | xfs_dir2_data_freeremove(hdr, dfp, needlogp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | /* |
| 796 | * Now insert the new entry. |
| 797 | */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 798 | dfp = xfs_dir2_data_freeinsert(hdr, prevdup, needlogp); |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 799 | ASSERT(dfp == &bf[0]); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 800 | ASSERT(dfp->length == prevdup->length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | ASSERT(!dfp[1].length); |
| 802 | ASSERT(!dfp[2].length); |
| 803 | } |
| 804 | } |
| 805 | /* |
| 806 | * The entry before us is free, merge with it. |
| 807 | */ |
| 808 | else if (prevdup) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 809 | dfp = xfs_dir2_data_freefind(hdr, prevdup); |
Marcin Slusarz | 413d57c | 2008-02-13 15:03:29 -0800 | [diff] [blame] | 810 | be16_add_cpu(&prevdup->length, len); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 811 | *xfs_dir2_data_unused_tag_p(prevdup) = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 812 | cpu_to_be16((char *)prevdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | xfs_dir2_data_log_unused(tp, bp, prevdup); |
| 814 | /* |
| 815 | * If the previous entry was in the table, the new entry |
| 816 | * is longer, so it will be in the table too. Remove |
| 817 | * the old one and add the new one. |
| 818 | */ |
| 819 | if (dfp) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 820 | xfs_dir2_data_freeremove(hdr, dfp, needlogp); |
| 821 | xfs_dir2_data_freeinsert(hdr, prevdup, needlogp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | } |
| 823 | /* |
| 824 | * Otherwise we need a scan if the new entry is big enough. |
| 825 | */ |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 826 | else { |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 827 | needscan = be16_to_cpu(prevdup->length) > |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 828 | be16_to_cpu(bf[2].length); |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 829 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | } |
| 831 | /* |
| 832 | * The following entry is free, merge with it. |
| 833 | */ |
| 834 | else if (postdup) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 835 | dfp = xfs_dir2_data_freefind(hdr, postdup); |
| 836 | newdup = (xfs_dir2_data_unused_t *)((char *)hdr + offset); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 837 | newdup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG); |
| 838 | newdup->length = cpu_to_be16(len + be16_to_cpu(postdup->length)); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 839 | *xfs_dir2_data_unused_tag_p(newdup) = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 840 | cpu_to_be16((char *)newdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | xfs_dir2_data_log_unused(tp, bp, newdup); |
| 842 | /* |
| 843 | * If the following entry was in the table, the new entry |
| 844 | * is longer, so it will be in the table too. Remove |
| 845 | * the old one and add the new one. |
| 846 | */ |
| 847 | if (dfp) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 848 | xfs_dir2_data_freeremove(hdr, dfp, needlogp); |
| 849 | xfs_dir2_data_freeinsert(hdr, newdup, needlogp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | } |
| 851 | /* |
| 852 | * Otherwise we need a scan if the new entry is big enough. |
| 853 | */ |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 854 | else { |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 855 | needscan = be16_to_cpu(newdup->length) > |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 856 | be16_to_cpu(bf[2].length); |
Nathan Scott | 70e73f5 | 2006-03-17 17:26:52 +1100 | [diff] [blame] | 857 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | } |
| 859 | /* |
| 860 | * Neither neighbor is free. Make a new entry. |
| 861 | */ |
| 862 | else { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 863 | newdup = (xfs_dir2_data_unused_t *)((char *)hdr + offset); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 864 | newdup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG); |
| 865 | newdup->length = cpu_to_be16(len); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 866 | *xfs_dir2_data_unused_tag_p(newdup) = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 867 | cpu_to_be16((char *)newdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | xfs_dir2_data_log_unused(tp, bp, newdup); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 869 | xfs_dir2_data_freeinsert(hdr, newdup, needlogp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | } |
| 871 | *needscanp = needscan; |
| 872 | } |
| 873 | |
| 874 | /* |
| 875 | * Take a byte range out of an existing unused space and make it un-free. |
| 876 | */ |
| 877 | void |
| 878 | xfs_dir2_data_use_free( |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 879 | struct xfs_trans *tp, |
| 880 | struct xfs_buf *bp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | xfs_dir2_data_unused_t *dup, /* unused entry */ |
| 882 | xfs_dir2_data_aoff_t offset, /* starting offset to use */ |
| 883 | xfs_dir2_data_aoff_t len, /* length to use */ |
| 884 | int *needlogp, /* out: need to log header */ |
| 885 | int *needscanp) /* out: need regen bestfree */ |
| 886 | { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 887 | xfs_dir2_data_hdr_t *hdr; /* data block header */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | xfs_dir2_data_free_t *dfp; /* bestfree pointer */ |
| 889 | int matchback; /* matches end of freespace */ |
| 890 | int matchfront; /* matches start of freespace */ |
| 891 | int needscan; /* need to regen bestfree */ |
| 892 | xfs_dir2_data_unused_t *newdup; /* new unused entry */ |
| 893 | xfs_dir2_data_unused_t *newdup2; /* another new unused entry */ |
| 894 | int oldlen; /* old unused entry's length */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 895 | struct xfs_dir2_data_free *bf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | |
Dave Chinner | 1d9025e | 2012-06-22 18:50:14 +1000 | [diff] [blame] | 897 | hdr = bp->b_addr; |
Christoph Hellwig | 69ef921 | 2011-07-08 14:36:05 +0200 | [diff] [blame] | 898 | ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) || |
Dave Chinner | 33363fe | 2013-04-03 16:11:22 +1100 | [diff] [blame^] | 899 | hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC) || |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 900 | hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) || |
| 901 | hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 902 | ASSERT(be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 903 | ASSERT(offset >= (char *)dup - (char *)hdr); |
| 904 | ASSERT(offset + len <= (char *)dup + be16_to_cpu(dup->length) - (char *)hdr); |
| 905 | 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] | 906 | /* |
| 907 | * Look up the entry in the bestfree table. |
| 908 | */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 909 | dfp = xfs_dir2_data_freefind(hdr, dup); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 910 | oldlen = be16_to_cpu(dup->length); |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 911 | bf = xfs_dir3_data_bestfree_p(hdr); |
| 912 | ASSERT(dfp || oldlen <= be16_to_cpu(bf[2].length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | /* |
| 914 | * Check for alignment with front and back of the entry. |
| 915 | */ |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 916 | matchfront = (char *)dup - (char *)hdr == offset; |
| 917 | matchback = (char *)dup + oldlen - (char *)hdr == offset + len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | ASSERT(*needscanp == 0); |
| 919 | needscan = 0; |
| 920 | /* |
| 921 | * If we matched it exactly we just need to get rid of it from |
| 922 | * the bestfree table. |
| 923 | */ |
| 924 | if (matchfront && matchback) { |
| 925 | if (dfp) { |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 926 | needscan = (bf[2].offset != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | if (!needscan) |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 928 | xfs_dir2_data_freeremove(hdr, dfp, needlogp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | } |
| 930 | } |
| 931 | /* |
| 932 | * We match the first part of the entry. |
| 933 | * Make a new entry with the remaining freespace. |
| 934 | */ |
| 935 | else if (matchfront) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 936 | newdup = (xfs_dir2_data_unused_t *)((char *)hdr + offset + len); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 937 | newdup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG); |
| 938 | newdup->length = cpu_to_be16(oldlen - len); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 939 | *xfs_dir2_data_unused_tag_p(newdup) = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 940 | cpu_to_be16((char *)newdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | xfs_dir2_data_log_unused(tp, bp, newdup); |
| 942 | /* |
| 943 | * If it was in the table, remove it and add the new one. |
| 944 | */ |
| 945 | if (dfp) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 946 | xfs_dir2_data_freeremove(hdr, dfp, needlogp); |
| 947 | dfp = xfs_dir2_data_freeinsert(hdr, newdup, needlogp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | ASSERT(dfp != NULL); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 949 | ASSERT(dfp->length == newdup->length); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 950 | ASSERT(be16_to_cpu(dfp->offset) == (char *)newdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | /* |
| 952 | * If we got inserted at the last slot, |
| 953 | * that means we don't know if there was a better |
| 954 | * choice for the last slot, or not. Rescan. |
| 955 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 956 | needscan = dfp == &bf[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | } |
| 958 | } |
| 959 | /* |
| 960 | * We match the last part of the entry. |
| 961 | * Trim the allocated space off the tail of the entry. |
| 962 | */ |
| 963 | else if (matchback) { |
| 964 | newdup = dup; |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 965 | newdup->length = cpu_to_be16(((char *)hdr + offset) - (char *)newdup); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 966 | *xfs_dir2_data_unused_tag_p(newdup) = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 967 | cpu_to_be16((char *)newdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | xfs_dir2_data_log_unused(tp, bp, newdup); |
| 969 | /* |
| 970 | * If it was in the table, remove it and add the new one. |
| 971 | */ |
| 972 | if (dfp) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 973 | xfs_dir2_data_freeremove(hdr, dfp, needlogp); |
| 974 | dfp = xfs_dir2_data_freeinsert(hdr, newdup, needlogp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | ASSERT(dfp != NULL); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 976 | ASSERT(dfp->length == newdup->length); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 977 | ASSERT(be16_to_cpu(dfp->offset) == (char *)newdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | /* |
| 979 | * If we got inserted at the last slot, |
| 980 | * that means we don't know if there was a better |
| 981 | * choice for the last slot, or not. Rescan. |
| 982 | */ |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 983 | needscan = dfp == &bf[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | } |
| 985 | } |
| 986 | /* |
| 987 | * Poking out the middle of an entry. |
| 988 | * Make two new entries. |
| 989 | */ |
| 990 | else { |
| 991 | newdup = dup; |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 992 | newdup->length = cpu_to_be16(((char *)hdr + offset) - (char *)newdup); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 993 | *xfs_dir2_data_unused_tag_p(newdup) = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 994 | cpu_to_be16((char *)newdup - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | xfs_dir2_data_log_unused(tp, bp, newdup); |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 996 | newdup2 = (xfs_dir2_data_unused_t *)((char *)hdr + offset + len); |
Nathan Scott | ad354eb | 2006-03-17 17:27:37 +1100 | [diff] [blame] | 997 | newdup2->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG); |
| 998 | newdup2->length = cpu_to_be16(oldlen - len - be16_to_cpu(newdup->length)); |
Christoph Hellwig | bbaaf53 | 2007-06-28 16:43:50 +1000 | [diff] [blame] | 999 | *xfs_dir2_data_unused_tag_p(newdup2) = |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 1000 | cpu_to_be16((char *)newdup2 - (char *)hdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | xfs_dir2_data_log_unused(tp, bp, newdup2); |
| 1002 | /* |
| 1003 | * If the old entry was in the table, we need to scan |
| 1004 | * if the 3rd entry was valid, since these entries |
| 1005 | * are smaller than the old one. |
| 1006 | * If we don't need to scan that means there were 1 or 2 |
| 1007 | * entries in the table, and removing the old and adding |
| 1008 | * the 2 new will work. |
| 1009 | */ |
| 1010 | if (dfp) { |
Dave Chinner | f5f3d9b | 2013-04-03 16:11:20 +1100 | [diff] [blame] | 1011 | needscan = (bf[2].length != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | if (!needscan) { |
Christoph Hellwig | c2066e2 | 2011-07-08 14:35:38 +0200 | [diff] [blame] | 1013 | xfs_dir2_data_freeremove(hdr, dfp, needlogp); |
| 1014 | xfs_dir2_data_freeinsert(hdr, newdup, needlogp); |
| 1015 | xfs_dir2_data_freeinsert(hdr, newdup2, |
| 1016 | needlogp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | } |
| 1018 | } |
| 1019 | } |
| 1020 | *needscanp = needscan; |
| 1021 | } |