xfs_dir2_data.c 31 KB

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