xfs_dir2_data.c 31 KB

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