xfs_dir2_data.c 31 KB

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