xfs_dir.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. /*
  2. * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include "xfs_fs.h"
  20. #include "xfs_types.h"
  21. #include "xfs_log.h"
  22. #include "xfs_inum.h"
  23. #include "xfs_trans.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_dir.h"
  26. #include "xfs_dir2.h"
  27. #include "xfs_dmapi.h"
  28. #include "xfs_mount.h"
  29. #include "xfs_da_btree.h"
  30. #include "xfs_bmap_btree.h"
  31. #include "xfs_alloc_btree.h"
  32. #include "xfs_ialloc_btree.h"
  33. #include "xfs_alloc.h"
  34. #include "xfs_btree.h"
  35. #include "xfs_dir_sf.h"
  36. #include "xfs_dir2_sf.h"
  37. #include "xfs_attr_sf.h"
  38. #include "xfs_dinode.h"
  39. #include "xfs_inode.h"
  40. #include "xfs_bmap.h"
  41. #include "xfs_dir_leaf.h"
  42. #include "xfs_error.h"
  43. /*
  44. * xfs_dir.c
  45. *
  46. * Provide the external interfaces to manage directories.
  47. */
  48. /*========================================================================
  49. * Function prototypes for the kernel.
  50. *========================================================================*/
  51. /*
  52. * Functions for the dirops interfaces.
  53. */
  54. static void xfs_dir_mount(struct xfs_mount *mp);
  55. static int xfs_dir_isempty(struct xfs_inode *dp);
  56. static int xfs_dir_init(struct xfs_trans *trans,
  57. struct xfs_inode *dir,
  58. struct xfs_inode *parent_dir);
  59. static int xfs_dir_createname(struct xfs_trans *trans,
  60. struct xfs_inode *dp,
  61. char *name_string,
  62. int name_len,
  63. xfs_ino_t inode_number,
  64. xfs_fsblock_t *firstblock,
  65. xfs_bmap_free_t *flist,
  66. xfs_extlen_t total);
  67. static int xfs_dir_lookup(struct xfs_trans *tp,
  68. struct xfs_inode *dp,
  69. char *name_string,
  70. int name_length,
  71. xfs_ino_t *inode_number);
  72. static int xfs_dir_removename(struct xfs_trans *trans,
  73. struct xfs_inode *dp,
  74. char *name_string,
  75. int name_length,
  76. xfs_ino_t ino,
  77. xfs_fsblock_t *firstblock,
  78. xfs_bmap_free_t *flist,
  79. xfs_extlen_t total);
  80. static int xfs_dir_getdents(struct xfs_trans *tp,
  81. struct xfs_inode *dp,
  82. struct uio *uiop,
  83. int *eofp);
  84. static int xfs_dir_replace(struct xfs_trans *tp,
  85. struct xfs_inode *dp,
  86. char *name_string,
  87. int name_length,
  88. xfs_ino_t inode_number,
  89. xfs_fsblock_t *firstblock,
  90. xfs_bmap_free_t *flist,
  91. xfs_extlen_t total);
  92. static int xfs_dir_canenter(struct xfs_trans *tp,
  93. struct xfs_inode *dp,
  94. char *name_string,
  95. int name_length);
  96. static int xfs_dir_shortform_validate_ondisk(xfs_mount_t *mp,
  97. xfs_dinode_t *dip);
  98. xfs_dirops_t xfsv1_dirops = {
  99. .xd_mount = xfs_dir_mount,
  100. .xd_isempty = xfs_dir_isempty,
  101. .xd_init = xfs_dir_init,
  102. .xd_createname = xfs_dir_createname,
  103. .xd_lookup = xfs_dir_lookup,
  104. .xd_removename = xfs_dir_removename,
  105. .xd_getdents = xfs_dir_getdents,
  106. .xd_replace = xfs_dir_replace,
  107. .xd_canenter = xfs_dir_canenter,
  108. .xd_shortform_validate_ondisk = xfs_dir_shortform_validate_ondisk,
  109. .xd_shortform_to_single = xfs_dir_shortform_to_leaf,
  110. };
  111. /*
  112. * Internal routines when dirsize == XFS_LBSIZE(mp).
  113. */
  114. STATIC int xfs_dir_leaf_lookup(xfs_da_args_t *args);
  115. STATIC int xfs_dir_leaf_removename(xfs_da_args_t *args, int *number_entries,
  116. int *total_namebytes);
  117. STATIC int xfs_dir_leaf_getdents(xfs_trans_t *trans, xfs_inode_t *dp,
  118. uio_t *uio, int *eofp,
  119. xfs_dirent_t *dbp,
  120. xfs_dir_put_t put);
  121. STATIC int xfs_dir_leaf_replace(xfs_da_args_t *args);
  122. /*
  123. * Internal routines when dirsize > XFS_LBSIZE(mp).
  124. */
  125. STATIC int xfs_dir_node_addname(xfs_da_args_t *args);
  126. STATIC int xfs_dir_node_lookup(xfs_da_args_t *args);
  127. STATIC int xfs_dir_node_removename(xfs_da_args_t *args);
  128. STATIC int xfs_dir_node_getdents(xfs_trans_t *trans, xfs_inode_t *dp,
  129. uio_t *uio, int *eofp,
  130. xfs_dirent_t *dbp,
  131. xfs_dir_put_t put);
  132. STATIC int xfs_dir_node_replace(xfs_da_args_t *args);
  133. #if defined(XFS_DIR_TRACE)
  134. ktrace_t *xfs_dir_trace_buf;
  135. #endif
  136. /*========================================================================
  137. * Overall external interface routines.
  138. *========================================================================*/
  139. xfs_dahash_t xfs_dir_hash_dot, xfs_dir_hash_dotdot;
  140. /*
  141. * One-time startup routine called from xfs_init().
  142. */
  143. void
  144. xfs_dir_startup(void)
  145. {
  146. xfs_dir_hash_dot = xfs_da_hashname(".", 1);
  147. xfs_dir_hash_dotdot = xfs_da_hashname("..", 2);
  148. }
  149. /*
  150. * Initialize directory-related fields in the mount structure.
  151. */
  152. static void
  153. xfs_dir_mount(xfs_mount_t *mp)
  154. {
  155. uint shortcount, leafcount, count;
  156. mp->m_dirversion = 1;
  157. if (!(mp->m_flags & XFS_MOUNT_ATTR2)) {
  158. shortcount = (mp->m_attroffset -
  159. (uint)sizeof(xfs_dir_sf_hdr_t)) /
  160. (uint)sizeof(xfs_dir_sf_entry_t);
  161. leafcount = (XFS_LBSIZE(mp) -
  162. (uint)sizeof(xfs_dir_leaf_hdr_t)) /
  163. ((uint)sizeof(xfs_dir_leaf_entry_t) +
  164. (uint)sizeof(xfs_dir_leaf_name_t));
  165. } else {
  166. shortcount = (XFS_BMDR_SPACE_CALC(MINABTPTRS) -
  167. (uint)sizeof(xfs_dir_sf_hdr_t)) /
  168. (uint)sizeof(xfs_dir_sf_entry_t);
  169. leafcount = (XFS_LBSIZE(mp) -
  170. (uint)sizeof(xfs_dir_leaf_hdr_t)) /
  171. ((uint)sizeof(xfs_dir_leaf_entry_t) +
  172. (uint)sizeof(xfs_dir_leaf_name_t));
  173. }
  174. count = shortcount > leafcount ? shortcount : leafcount;
  175. mp->m_dircook_elog = xfs_da_log2_roundup(count + 1);
  176. ASSERT(mp->m_dircook_elog <= mp->m_sb.sb_blocklog);
  177. mp->m_dir_node_ents = mp->m_attr_node_ents =
  178. (XFS_LBSIZE(mp) - (uint)sizeof(xfs_da_node_hdr_t)) /
  179. (uint)sizeof(xfs_da_node_entry_t);
  180. mp->m_dir_magicpct = (XFS_LBSIZE(mp) * 37) / 100;
  181. mp->m_dirblksize = mp->m_sb.sb_blocksize;
  182. mp->m_dirblkfsbs = 1;
  183. }
  184. /*
  185. * Return 1 if directory contains only "." and "..".
  186. */
  187. static int
  188. xfs_dir_isempty(xfs_inode_t *dp)
  189. {
  190. xfs_dir_sf_hdr_t *hdr;
  191. ASSERT((dp->i_d.di_mode & S_IFMT) == S_IFDIR);
  192. if (dp->i_d.di_size == 0)
  193. return(1);
  194. if (dp->i_d.di_size > XFS_IFORK_DSIZE(dp))
  195. return(0);
  196. hdr = (xfs_dir_sf_hdr_t *)dp->i_df.if_u1.if_data;
  197. return(hdr->count == 0);
  198. }
  199. /*
  200. * Initialize a directory with its "." and ".." entries.
  201. */
  202. static int
  203. xfs_dir_init(xfs_trans_t *trans, xfs_inode_t *dir, xfs_inode_t *parent_dir)
  204. {
  205. xfs_da_args_t args;
  206. int error;
  207. memset((char *)&args, 0, sizeof(args));
  208. args.dp = dir;
  209. args.trans = trans;
  210. ASSERT((dir->i_d.di_mode & S_IFMT) == S_IFDIR);
  211. if ((error = xfs_dir_ino_validate(trans->t_mountp, parent_dir->i_ino)))
  212. return error;
  213. return(xfs_dir_shortform_create(&args, parent_dir->i_ino));
  214. }
  215. /*
  216. * Generic handler routine to add a name to a directory.
  217. * Transitions directory from shortform to Btree as necessary.
  218. */
  219. static int /* error */
  220. xfs_dir_createname(xfs_trans_t *trans, xfs_inode_t *dp, char *name,
  221. int namelen, xfs_ino_t inum, xfs_fsblock_t *firstblock,
  222. xfs_bmap_free_t *flist, xfs_extlen_t total)
  223. {
  224. xfs_da_args_t args;
  225. int retval, newsize, done;
  226. ASSERT((dp->i_d.di_mode & S_IFMT) == S_IFDIR);
  227. if ((retval = xfs_dir_ino_validate(trans->t_mountp, inum)))
  228. return (retval);
  229. XFS_STATS_INC(xs_dir_create);
  230. /*
  231. * Fill in the arg structure for this request.
  232. */
  233. args.name = name;
  234. args.namelen = namelen;
  235. args.hashval = xfs_da_hashname(name, namelen);
  236. args.inumber = inum;
  237. args.dp = dp;
  238. args.firstblock = firstblock;
  239. args.flist = flist;
  240. args.total = total;
  241. args.whichfork = XFS_DATA_FORK;
  242. args.trans = trans;
  243. args.justcheck = 0;
  244. args.addname = args.oknoent = 1;
  245. /*
  246. * Decide on what work routines to call based on the inode size.
  247. */
  248. done = 0;
  249. if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) {
  250. newsize = XFS_DIR_SF_ENTSIZE_BYNAME(args.namelen);
  251. if ((dp->i_d.di_size + newsize) <= XFS_IFORK_DSIZE(dp)) {
  252. retval = xfs_dir_shortform_addname(&args);
  253. done = 1;
  254. } else {
  255. if (total == 0)
  256. return XFS_ERROR(ENOSPC);
  257. retval = xfs_dir_shortform_to_leaf(&args);
  258. done = retval != 0;
  259. }
  260. }
  261. if (!done && xfs_bmap_one_block(dp, XFS_DATA_FORK)) {
  262. retval = xfs_dir_leaf_addname(&args);
  263. done = retval != ENOSPC;
  264. if (!done) {
  265. if (total == 0)
  266. return XFS_ERROR(ENOSPC);
  267. retval = xfs_dir_leaf_to_node(&args);
  268. done = retval != 0;
  269. }
  270. }
  271. if (!done) {
  272. retval = xfs_dir_node_addname(&args);
  273. }
  274. return(retval);
  275. }
  276. /*
  277. * Generic handler routine to check if a name can be added to a directory,
  278. * without adding any blocks to the directory.
  279. */
  280. static int /* error */
  281. xfs_dir_canenter(xfs_trans_t *trans, xfs_inode_t *dp, char *name, int namelen)
  282. {
  283. xfs_da_args_t args;
  284. int retval, newsize;
  285. ASSERT((dp->i_d.di_mode & S_IFMT) == S_IFDIR);
  286. /*
  287. * Fill in the arg structure for this request.
  288. */
  289. args.name = name;
  290. args.namelen = namelen;
  291. args.hashval = xfs_da_hashname(name, namelen);
  292. args.inumber = 0;
  293. args.dp = dp;
  294. args.firstblock = NULL;
  295. args.flist = NULL;
  296. args.total = 0;
  297. args.whichfork = XFS_DATA_FORK;
  298. args.trans = trans;
  299. args.justcheck = args.addname = args.oknoent = 1;
  300. /*
  301. * Decide on what work routines to call based on the inode size.
  302. */
  303. if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) {
  304. newsize = XFS_DIR_SF_ENTSIZE_BYNAME(args.namelen);
  305. if ((dp->i_d.di_size + newsize) <= XFS_IFORK_DSIZE(dp))
  306. retval = 0;
  307. else
  308. retval = XFS_ERROR(ENOSPC);
  309. } else if (xfs_bmap_one_block(dp, XFS_DATA_FORK)) {
  310. retval = xfs_dir_leaf_addname(&args);
  311. } else {
  312. retval = xfs_dir_node_addname(&args);
  313. }
  314. return(retval);
  315. }
  316. /*
  317. * Generic handler routine to remove a name from a directory.
  318. * Transitions directory from Btree to shortform as necessary.
  319. */
  320. static int /* error */
  321. xfs_dir_removename(xfs_trans_t *trans, xfs_inode_t *dp, char *name,
  322. int namelen, xfs_ino_t ino, xfs_fsblock_t *firstblock,
  323. xfs_bmap_free_t *flist, xfs_extlen_t total)
  324. {
  325. xfs_da_args_t args;
  326. int count, totallen, newsize, retval;
  327. ASSERT((dp->i_d.di_mode & S_IFMT) == S_IFDIR);
  328. XFS_STATS_INC(xs_dir_remove);
  329. /*
  330. * Fill in the arg structure for this request.
  331. */
  332. args.name = name;
  333. args.namelen = namelen;
  334. args.hashval = xfs_da_hashname(name, namelen);
  335. args.inumber = ino;
  336. args.dp = dp;
  337. args.firstblock = firstblock;
  338. args.flist = flist;
  339. args.total = total;
  340. args.whichfork = XFS_DATA_FORK;
  341. args.trans = trans;
  342. args.justcheck = args.addname = args.oknoent = 0;
  343. /*
  344. * Decide on what work routines to call based on the inode size.
  345. */
  346. if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) {
  347. retval = xfs_dir_shortform_removename(&args);
  348. } else if (xfs_bmap_one_block(dp, XFS_DATA_FORK)) {
  349. retval = xfs_dir_leaf_removename(&args, &count, &totallen);
  350. if (retval == 0) {
  351. newsize = XFS_DIR_SF_ALLFIT(count, totallen);
  352. if (newsize <= XFS_IFORK_DSIZE(dp)) {
  353. retval = xfs_dir_leaf_to_shortform(&args);
  354. }
  355. }
  356. } else {
  357. retval = xfs_dir_node_removename(&args);
  358. }
  359. return(retval);
  360. }
  361. static int /* error */
  362. xfs_dir_lookup(xfs_trans_t *trans, xfs_inode_t *dp, char *name, int namelen,
  363. xfs_ino_t *inum)
  364. {
  365. xfs_da_args_t args;
  366. int retval;
  367. ASSERT((dp->i_d.di_mode & S_IFMT) == S_IFDIR);
  368. XFS_STATS_INC(xs_dir_lookup);
  369. /*
  370. * Fill in the arg structure for this request.
  371. */
  372. args.name = name;
  373. args.namelen = namelen;
  374. args.hashval = xfs_da_hashname(name, namelen);
  375. args.inumber = 0;
  376. args.dp = dp;
  377. args.firstblock = NULL;
  378. args.flist = NULL;
  379. args.total = 0;
  380. args.whichfork = XFS_DATA_FORK;
  381. args.trans = trans;
  382. args.justcheck = args.addname = 0;
  383. args.oknoent = 1;
  384. /*
  385. * Decide on what work routines to call based on the inode size.
  386. */
  387. if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) {
  388. retval = xfs_dir_shortform_lookup(&args);
  389. } else if (xfs_bmap_one_block(dp, XFS_DATA_FORK)) {
  390. retval = xfs_dir_leaf_lookup(&args);
  391. } else {
  392. retval = xfs_dir_node_lookup(&args);
  393. }
  394. if (retval == EEXIST)
  395. retval = 0;
  396. *inum = args.inumber;
  397. return(retval);
  398. }
  399. /*
  400. * Implement readdir.
  401. */
  402. static int /* error */
  403. xfs_dir_getdents(xfs_trans_t *trans, xfs_inode_t *dp, uio_t *uio, int *eofp)
  404. {
  405. xfs_dirent_t *dbp;
  406. int alignment, retval;
  407. xfs_dir_put_t put;
  408. XFS_STATS_INC(xs_dir_getdents);
  409. ASSERT((dp->i_d.di_mode & S_IFMT) == S_IFDIR);
  410. /*
  411. * If our caller has given us a single contiguous memory buffer,
  412. * just work directly within that buffer. If it's in user memory,
  413. * lock it down first.
  414. */
  415. alignment = sizeof(xfs_off_t) - 1;
  416. if ((uio->uio_iovcnt == 1) &&
  417. (((__psint_t)uio->uio_iov[0].iov_base & alignment) == 0) &&
  418. ((uio->uio_iov[0].iov_len & alignment) == 0)) {
  419. dbp = NULL;
  420. put = xfs_dir_put_dirent64_direct;
  421. } else {
  422. dbp = kmem_alloc(sizeof(*dbp) + MAXNAMELEN, KM_SLEEP);
  423. put = xfs_dir_put_dirent64_uio;
  424. }
  425. /*
  426. * Decide on what work routines to call based on the inode size.
  427. */
  428. *eofp = 0;
  429. if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) {
  430. retval = xfs_dir_shortform_getdents(dp, uio, eofp, dbp, put);
  431. } else if (xfs_bmap_one_block(dp, XFS_DATA_FORK)) {
  432. retval = xfs_dir_leaf_getdents(trans, dp, uio, eofp, dbp, put);
  433. } else {
  434. retval = xfs_dir_node_getdents(trans, dp, uio, eofp, dbp, put);
  435. }
  436. if (dbp != NULL)
  437. kmem_free(dbp, sizeof(*dbp) + MAXNAMELEN);
  438. return(retval);
  439. }
  440. static int /* error */
  441. xfs_dir_replace(xfs_trans_t *trans, xfs_inode_t *dp, char *name, int namelen,
  442. xfs_ino_t inum, xfs_fsblock_t *firstblock,
  443. xfs_bmap_free_t *flist, xfs_extlen_t total)
  444. {
  445. xfs_da_args_t args;
  446. int retval;
  447. ASSERT((dp->i_d.di_mode & S_IFMT) == S_IFDIR);
  448. if ((retval = xfs_dir_ino_validate(trans->t_mountp, inum)))
  449. return retval;
  450. /*
  451. * Fill in the arg structure for this request.
  452. */
  453. args.name = name;
  454. args.namelen = namelen;
  455. args.hashval = xfs_da_hashname(name, namelen);
  456. args.inumber = inum;
  457. args.dp = dp;
  458. args.firstblock = firstblock;
  459. args.flist = flist;
  460. args.total = total;
  461. args.whichfork = XFS_DATA_FORK;
  462. args.trans = trans;
  463. args.justcheck = args.addname = args.oknoent = 0;
  464. /*
  465. * Decide on what work routines to call based on the inode size.
  466. */
  467. if (dp->i_d.di_format == XFS_DINODE_FMT_LOCAL) {
  468. retval = xfs_dir_shortform_replace(&args);
  469. } else if (xfs_bmap_one_block(dp, XFS_DATA_FORK)) {
  470. retval = xfs_dir_leaf_replace(&args);
  471. } else {
  472. retval = xfs_dir_node_replace(&args);
  473. }
  474. return(retval);
  475. }
  476. static int
  477. xfs_dir_shortform_validate_ondisk(xfs_mount_t *mp, xfs_dinode_t *dp)
  478. {
  479. xfs_ino_t ino;
  480. int namelen_sum;
  481. int count;
  482. xfs_dir_shortform_t *sf;
  483. xfs_dir_sf_entry_t *sfe;
  484. int i;
  485. if ((INT_GET(dp->di_core.di_mode, ARCH_CONVERT) & S_IFMT) != S_IFDIR) {
  486. return 0;
  487. }
  488. if (INT_GET(dp->di_core.di_format, ARCH_CONVERT) != XFS_DINODE_FMT_LOCAL) {
  489. return 0;
  490. }
  491. if (INT_GET(dp->di_core.di_size, ARCH_CONVERT) < sizeof(sf->hdr)) {
  492. xfs_fs_cmn_err(CE_WARN, mp, "Invalid shortform size: dp 0x%p",
  493. dp);
  494. return 1;
  495. }
  496. sf = (xfs_dir_shortform_t *)(&dp->di_u.di_dirsf);
  497. ino = XFS_GET_DIR_INO8(sf->hdr.parent);
  498. if (xfs_dir_ino_validate(mp, ino))
  499. return 1;
  500. count = sf->hdr.count;
  501. if ((count < 0) || ((count * 10) > XFS_LITINO(mp))) {
  502. xfs_fs_cmn_err(CE_WARN, mp,
  503. "Invalid shortform count: dp 0x%p", dp);
  504. return(1);
  505. }
  506. if (count == 0) {
  507. return 0;
  508. }
  509. namelen_sum = 0;
  510. sfe = &sf->list[0];
  511. for (i = sf->hdr.count - 1; i >= 0; i--) {
  512. ino = XFS_GET_DIR_INO8(sfe->inumber);
  513. xfs_dir_ino_validate(mp, ino);
  514. if (sfe->namelen >= XFS_LITINO(mp)) {
  515. xfs_fs_cmn_err(CE_WARN, mp,
  516. "Invalid shortform namelen: dp 0x%p", dp);
  517. return 1;
  518. }
  519. namelen_sum += sfe->namelen;
  520. sfe = XFS_DIR_SF_NEXTENTRY(sfe);
  521. }
  522. if (namelen_sum >= XFS_LITINO(mp)) {
  523. xfs_fs_cmn_err(CE_WARN, mp,
  524. "Invalid shortform namelen: dp 0x%p", dp);
  525. return 1;
  526. }
  527. return 0;
  528. }
  529. /*========================================================================
  530. * External routines when dirsize == XFS_LBSIZE(dp->i_mount).
  531. *========================================================================*/
  532. /*
  533. * Add a name to the leaf directory structure
  534. * This is the external routine.
  535. */
  536. int
  537. xfs_dir_leaf_addname(xfs_da_args_t *args)
  538. {
  539. int index, retval;
  540. xfs_dabuf_t *bp;
  541. retval = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp,
  542. XFS_DATA_FORK);
  543. if (retval)
  544. return(retval);
  545. ASSERT(bp != NULL);
  546. retval = xfs_dir_leaf_lookup_int(bp, args, &index);
  547. if (retval == ENOENT)
  548. retval = xfs_dir_leaf_add(bp, args, index);
  549. xfs_da_buf_done(bp);
  550. return(retval);
  551. }
  552. /*
  553. * Remove a name from the leaf directory structure
  554. * This is the external routine.
  555. */
  556. STATIC int
  557. xfs_dir_leaf_removename(xfs_da_args_t *args, int *count, int *totallen)
  558. {
  559. xfs_dir_leafblock_t *leaf;
  560. int index, retval;
  561. xfs_dabuf_t *bp;
  562. retval = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp,
  563. XFS_DATA_FORK);
  564. if (retval)
  565. return(retval);
  566. ASSERT(bp != NULL);
  567. leaf = bp->data;
  568. ASSERT(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT) == XFS_DIR_LEAF_MAGIC);
  569. retval = xfs_dir_leaf_lookup_int(bp, args, &index);
  570. if (retval == EEXIST) {
  571. (void)xfs_dir_leaf_remove(args->trans, bp, index);
  572. *count = INT_GET(leaf->hdr.count, ARCH_CONVERT);
  573. *totallen = INT_GET(leaf->hdr.namebytes, ARCH_CONVERT);
  574. retval = 0;
  575. }
  576. xfs_da_buf_done(bp);
  577. return(retval);
  578. }
  579. /*
  580. * Look up a name in a leaf directory structure.
  581. * This is the external routine.
  582. */
  583. STATIC int
  584. xfs_dir_leaf_lookup(xfs_da_args_t *args)
  585. {
  586. int index, retval;
  587. xfs_dabuf_t *bp;
  588. retval = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp,
  589. XFS_DATA_FORK);
  590. if (retval)
  591. return(retval);
  592. ASSERT(bp != NULL);
  593. retval = xfs_dir_leaf_lookup_int(bp, args, &index);
  594. xfs_da_brelse(args->trans, bp);
  595. return(retval);
  596. }
  597. /*
  598. * Copy out directory entries for getdents(), for leaf directories.
  599. */
  600. STATIC int
  601. xfs_dir_leaf_getdents(xfs_trans_t *trans, xfs_inode_t *dp, uio_t *uio,
  602. int *eofp, xfs_dirent_t *dbp, xfs_dir_put_t put)
  603. {
  604. xfs_dabuf_t *bp;
  605. int retval, eob;
  606. retval = xfs_da_read_buf(dp->i_transp, dp, 0, -1, &bp, XFS_DATA_FORK);
  607. if (retval)
  608. return(retval);
  609. ASSERT(bp != NULL);
  610. retval = xfs_dir_leaf_getdents_int(bp, dp, 0, uio, &eob, dbp, put, -1);
  611. xfs_da_brelse(trans, bp);
  612. *eofp = (eob == 0);
  613. return(retval);
  614. }
  615. /*
  616. * Look up a name in a leaf directory structure, replace the inode number.
  617. * This is the external routine.
  618. */
  619. STATIC int
  620. xfs_dir_leaf_replace(xfs_da_args_t *args)
  621. {
  622. int index, retval;
  623. xfs_dabuf_t *bp;
  624. xfs_ino_t inum;
  625. xfs_dir_leafblock_t *leaf;
  626. xfs_dir_leaf_entry_t *entry;
  627. xfs_dir_leaf_name_t *namest;
  628. inum = args->inumber;
  629. retval = xfs_da_read_buf(args->trans, args->dp, 0, -1, &bp,
  630. XFS_DATA_FORK);
  631. if (retval)
  632. return(retval);
  633. ASSERT(bp != NULL);
  634. retval = xfs_dir_leaf_lookup_int(bp, args, &index);
  635. if (retval == EEXIST) {
  636. leaf = bp->data;
  637. entry = &leaf->entries[index];
  638. namest = XFS_DIR_LEAF_NAMESTRUCT(leaf, INT_GET(entry->nameidx, ARCH_CONVERT));
  639. /* XXX - replace assert? */
  640. XFS_DIR_SF_PUT_DIRINO(&inum, &namest->inumber);
  641. xfs_da_log_buf(args->trans, bp,
  642. XFS_DA_LOGRANGE(leaf, namest, sizeof(namest->inumber)));
  643. xfs_da_buf_done(bp);
  644. retval = 0;
  645. } else
  646. xfs_da_brelse(args->trans, bp);
  647. return(retval);
  648. }
  649. /*========================================================================
  650. * External routines when dirsize > XFS_LBSIZE(mp).
  651. *========================================================================*/
  652. /*
  653. * Add a name to a Btree-format directory.
  654. *
  655. * This will involve walking down the Btree, and may involve splitting
  656. * leaf nodes and even splitting intermediate nodes up to and including
  657. * the root node (a special case of an intermediate node).
  658. */
  659. STATIC int
  660. xfs_dir_node_addname(xfs_da_args_t *args)
  661. {
  662. xfs_da_state_t *state;
  663. xfs_da_state_blk_t *blk;
  664. int retval, error;
  665. /*
  666. * Fill in bucket of arguments/results/context to carry around.
  667. */
  668. state = xfs_da_state_alloc();
  669. state->args = args;
  670. state->mp = args->dp->i_mount;
  671. state->blocksize = state->mp->m_sb.sb_blocksize;
  672. state->node_ents = state->mp->m_dir_node_ents;
  673. /*
  674. * Search to see if name already exists, and get back a pointer
  675. * to where it should go.
  676. */
  677. error = xfs_da_node_lookup_int(state, &retval);
  678. if (error)
  679. retval = error;
  680. if (retval != ENOENT)
  681. goto error;
  682. blk = &state->path.blk[ state->path.active-1 ];
  683. ASSERT(blk->magic == XFS_DIR_LEAF_MAGIC);
  684. retval = xfs_dir_leaf_add(blk->bp, args, blk->index);
  685. if (retval == 0) {
  686. /*
  687. * Addition succeeded, update Btree hashvals.
  688. */
  689. if (!args->justcheck)
  690. xfs_da_fixhashpath(state, &state->path);
  691. } else {
  692. /*
  693. * Addition failed, split as many Btree elements as required.
  694. */
  695. if (args->total == 0) {
  696. ASSERT(retval == ENOSPC);
  697. goto error;
  698. }
  699. retval = xfs_da_split(state);
  700. }
  701. error:
  702. xfs_da_state_free(state);
  703. return(retval);
  704. }
  705. /*
  706. * Remove a name from a B-tree directory.
  707. *
  708. * This will involve walking down the Btree, and may involve joining
  709. * leaf nodes and even joining intermediate nodes up to and including
  710. * the root node (a special case of an intermediate node).
  711. */
  712. STATIC int
  713. xfs_dir_node_removename(xfs_da_args_t *args)
  714. {
  715. xfs_da_state_t *state;
  716. xfs_da_state_blk_t *blk;
  717. int retval, error;
  718. state = xfs_da_state_alloc();
  719. state->args = args;
  720. state->mp = args->dp->i_mount;
  721. state->blocksize = state->mp->m_sb.sb_blocksize;
  722. state->node_ents = state->mp->m_dir_node_ents;
  723. /*
  724. * Search to see if name exists, and get back a pointer to it.
  725. */
  726. error = xfs_da_node_lookup_int(state, &retval);
  727. if (error)
  728. retval = error;
  729. if (retval != EEXIST) {
  730. xfs_da_state_free(state);
  731. return(retval);
  732. }
  733. /*
  734. * Remove the name and update the hashvals in the tree.
  735. */
  736. blk = &state->path.blk[ state->path.active-1 ];
  737. ASSERT(blk->magic == XFS_DIR_LEAF_MAGIC);
  738. retval = xfs_dir_leaf_remove(args->trans, blk->bp, blk->index);
  739. xfs_da_fixhashpath(state, &state->path);
  740. /*
  741. * Check to see if the tree needs to be collapsed.
  742. */
  743. error = 0;
  744. if (retval) {
  745. error = xfs_da_join(state);
  746. }
  747. xfs_da_state_free(state);
  748. if (error)
  749. return(error);
  750. return(0);
  751. }
  752. /*
  753. * Look up a filename in a int directory.
  754. * Use an internal routine to actually do all the work.
  755. */
  756. STATIC int
  757. xfs_dir_node_lookup(xfs_da_args_t *args)
  758. {
  759. xfs_da_state_t *state;
  760. int retval, error, i;
  761. state = xfs_da_state_alloc();
  762. state->args = args;
  763. state->mp = args->dp->i_mount;
  764. state->blocksize = state->mp->m_sb.sb_blocksize;
  765. state->node_ents = state->mp->m_dir_node_ents;
  766. /*
  767. * Search to see if name exists,
  768. * and get back a pointer to it.
  769. */
  770. error = xfs_da_node_lookup_int(state, &retval);
  771. if (error) {
  772. retval = error;
  773. }
  774. /*
  775. * If not in a transaction, we have to release all the buffers.
  776. */
  777. for (i = 0; i < state->path.active; i++) {
  778. xfs_da_brelse(args->trans, state->path.blk[i].bp);
  779. state->path.blk[i].bp = NULL;
  780. }
  781. xfs_da_state_free(state);
  782. return(retval);
  783. }
  784. STATIC int
  785. xfs_dir_node_getdents(xfs_trans_t *trans, xfs_inode_t *dp, uio_t *uio,
  786. int *eofp, xfs_dirent_t *dbp, xfs_dir_put_t put)
  787. {
  788. xfs_da_intnode_t *node;
  789. xfs_da_node_entry_t *btree;
  790. xfs_dir_leafblock_t *leaf = NULL;
  791. xfs_dablk_t bno, nextbno;
  792. xfs_dahash_t cookhash;
  793. xfs_mount_t *mp;
  794. int error, eob, i;
  795. xfs_dabuf_t *bp;
  796. xfs_daddr_t nextda;
  797. /*
  798. * Pick up our context.
  799. */
  800. mp = dp->i_mount;
  801. bp = NULL;
  802. bno = XFS_DA_COOKIE_BNO(mp, uio->uio_offset);
  803. cookhash = XFS_DA_COOKIE_HASH(mp, uio->uio_offset);
  804. xfs_dir_trace_g_du("node: start", dp, uio);
  805. /*
  806. * Re-find our place, even if we're confused about what our place is.
  807. *
  808. * First we check the block number from the magic cookie, it is a
  809. * cache of where we ended last time. If we find a leaf block, and
  810. * the starting hashval in that block is less than our desired
  811. * hashval, then we run with it.
  812. */
  813. if (bno > 0) {
  814. error = xfs_da_read_buf(trans, dp, bno, -2, &bp, XFS_DATA_FORK);
  815. if ((error != 0) && (error != EFSCORRUPTED))
  816. return(error);
  817. if (bp)
  818. leaf = bp->data;
  819. if (bp && INT_GET(leaf->hdr.info.magic, ARCH_CONVERT) != XFS_DIR_LEAF_MAGIC) {
  820. xfs_dir_trace_g_dub("node: block not a leaf",
  821. dp, uio, bno);
  822. xfs_da_brelse(trans, bp);
  823. bp = NULL;
  824. }
  825. if (bp && INT_GET(leaf->entries[0].hashval, ARCH_CONVERT) > cookhash) {
  826. xfs_dir_trace_g_dub("node: leaf hash too large",
  827. dp, uio, bno);
  828. xfs_da_brelse(trans, bp);
  829. bp = NULL;
  830. }
  831. if (bp &&
  832. cookhash > INT_GET(leaf->entries[INT_GET(leaf->hdr.count, ARCH_CONVERT) - 1].hashval, ARCH_CONVERT)) {
  833. xfs_dir_trace_g_dub("node: leaf hash too small",
  834. dp, uio, bno);
  835. xfs_da_brelse(trans, bp);
  836. bp = NULL;
  837. }
  838. }
  839. /*
  840. * If we did not find a leaf block from the blockno in the cookie,
  841. * or we there was no blockno in the cookie (eg: first time thru),
  842. * the we start at the top of the Btree and re-find our hashval.
  843. */
  844. if (bp == NULL) {
  845. xfs_dir_trace_g_du("node: start at root" , dp, uio);
  846. bno = 0;
  847. for (;;) {
  848. error = xfs_da_read_buf(trans, dp, bno, -1, &bp,
  849. XFS_DATA_FORK);
  850. if (error)
  851. return(error);
  852. if (bp == NULL)
  853. return(XFS_ERROR(EFSCORRUPTED));
  854. node = bp->data;
  855. if (INT_GET(node->hdr.info.magic, ARCH_CONVERT) != XFS_DA_NODE_MAGIC)
  856. break;
  857. btree = &node->btree[0];
  858. xfs_dir_trace_g_dun("node: node detail", dp, uio, node);
  859. for (i = 0; i < INT_GET(node->hdr.count, ARCH_CONVERT); btree++, i++) {
  860. if (INT_GET(btree->hashval, ARCH_CONVERT) >= cookhash) {
  861. bno = INT_GET(btree->before, ARCH_CONVERT);
  862. break;
  863. }
  864. }
  865. if (i == INT_GET(node->hdr.count, ARCH_CONVERT)) {
  866. xfs_da_brelse(trans, bp);
  867. xfs_dir_trace_g_du("node: hash beyond EOF",
  868. dp, uio);
  869. uio->uio_offset = XFS_DA_MAKE_COOKIE(mp, 0, 0,
  870. XFS_DA_MAXHASH);
  871. *eofp = 1;
  872. return(0);
  873. }
  874. xfs_dir_trace_g_dub("node: going to block",
  875. dp, uio, bno);
  876. xfs_da_brelse(trans, bp);
  877. }
  878. }
  879. ASSERT(cookhash != XFS_DA_MAXHASH);
  880. /*
  881. * We've dropped down to the (first) leaf block that contains the
  882. * hashval we are interested in. Continue rolling upward thru the
  883. * leaf blocks until we fill up our buffer.
  884. */
  885. for (;;) {
  886. leaf = bp->data;
  887. if (unlikely(INT_GET(leaf->hdr.info.magic, ARCH_CONVERT) != XFS_DIR_LEAF_MAGIC)) {
  888. xfs_dir_trace_g_dul("node: not a leaf", dp, uio, leaf);
  889. xfs_da_brelse(trans, bp);
  890. XFS_CORRUPTION_ERROR("xfs_dir_node_getdents(1)",
  891. XFS_ERRLEVEL_LOW, mp, leaf);
  892. return XFS_ERROR(EFSCORRUPTED);
  893. }
  894. xfs_dir_trace_g_dul("node: leaf detail", dp, uio, leaf);
  895. if ((nextbno = INT_GET(leaf->hdr.info.forw, ARCH_CONVERT))) {
  896. nextda = xfs_da_reada_buf(trans, dp, nextbno,
  897. XFS_DATA_FORK);
  898. } else
  899. nextda = -1;
  900. error = xfs_dir_leaf_getdents_int(bp, dp, bno, uio, &eob, dbp,
  901. put, nextda);
  902. xfs_da_brelse(trans, bp);
  903. bno = nextbno;
  904. if (eob) {
  905. xfs_dir_trace_g_dub("node: E-O-B", dp, uio, bno);
  906. *eofp = 0;
  907. return(error);
  908. }
  909. if (bno == 0)
  910. break;
  911. error = xfs_da_read_buf(trans, dp, bno, nextda, &bp,
  912. XFS_DATA_FORK);
  913. if (error)
  914. return(error);
  915. if (unlikely(bp == NULL)) {
  916. XFS_ERROR_REPORT("xfs_dir_node_getdents(2)",
  917. XFS_ERRLEVEL_LOW, mp);
  918. return(XFS_ERROR(EFSCORRUPTED));
  919. }
  920. }
  921. *eofp = 1;
  922. xfs_dir_trace_g_du("node: E-O-F", dp, uio);
  923. return(0);
  924. }
  925. /*
  926. * Look up a filename in an int directory, replace the inode number.
  927. * Use an internal routine to actually do the lookup.
  928. */
  929. STATIC int
  930. xfs_dir_node_replace(xfs_da_args_t *args)
  931. {
  932. xfs_da_state_t *state;
  933. xfs_da_state_blk_t *blk;
  934. xfs_dir_leafblock_t *leaf;
  935. xfs_dir_leaf_entry_t *entry;
  936. xfs_dir_leaf_name_t *namest;
  937. xfs_ino_t inum;
  938. int retval, error, i;
  939. xfs_dabuf_t *bp;
  940. state = xfs_da_state_alloc();
  941. state->args = args;
  942. state->mp = args->dp->i_mount;
  943. state->blocksize = state->mp->m_sb.sb_blocksize;
  944. state->node_ents = state->mp->m_dir_node_ents;
  945. inum = args->inumber;
  946. /*
  947. * Search to see if name exists,
  948. * and get back a pointer to it.
  949. */
  950. error = xfs_da_node_lookup_int(state, &retval);
  951. if (error) {
  952. retval = error;
  953. }
  954. if (retval == EEXIST) {
  955. blk = &state->path.blk[state->path.active - 1];
  956. ASSERT(blk->magic == XFS_DIR_LEAF_MAGIC);
  957. bp = blk->bp;
  958. leaf = bp->data;
  959. entry = &leaf->entries[blk->index];
  960. namest = XFS_DIR_LEAF_NAMESTRUCT(leaf, INT_GET(entry->nameidx, ARCH_CONVERT));
  961. /* XXX - replace assert ? */
  962. XFS_DIR_SF_PUT_DIRINO(&inum, &namest->inumber);
  963. xfs_da_log_buf(args->trans, bp,
  964. XFS_DA_LOGRANGE(leaf, namest, sizeof(namest->inumber)));
  965. xfs_da_buf_done(bp);
  966. blk->bp = NULL;
  967. retval = 0;
  968. } else {
  969. i = state->path.active - 1;
  970. xfs_da_brelse(args->trans, state->path.blk[i].bp);
  971. state->path.blk[i].bp = NULL;
  972. }
  973. for (i = 0; i < state->path.active - 1; i++) {
  974. xfs_da_brelse(args->trans, state->path.blk[i].bp);
  975. state->path.blk[i].bp = NULL;
  976. }
  977. xfs_da_state_free(state);
  978. return(retval);
  979. }
  980. #if defined(XFS_DIR_TRACE)
  981. /*
  982. * Add a trace buffer entry for an inode and a uio.
  983. */
  984. void
  985. xfs_dir_trace_g_du(char *where, xfs_inode_t *dp, uio_t *uio)
  986. {
  987. xfs_dir_trace_enter(XFS_DIR_KTRACE_G_DU, where,
  988. (void *)dp, (void *)dp->i_mount,
  989. (void *)((unsigned long)(uio->uio_offset >> 32)),
  990. (void *)((unsigned long)(uio->uio_offset & 0xFFFFFFFF)),
  991. (void *)(unsigned long)uio->uio_resid,
  992. NULL, NULL, NULL, NULL, NULL, NULL, NULL);
  993. }
  994. /*
  995. * Add a trace buffer entry for an inode and a uio.
  996. */
  997. void
  998. xfs_dir_trace_g_dub(char *where, xfs_inode_t *dp, uio_t *uio, xfs_dablk_t bno)
  999. {
  1000. xfs_dir_trace_enter(XFS_DIR_KTRACE_G_DUB, where,
  1001. (void *)dp, (void *)dp->i_mount,
  1002. (void *)((unsigned long)(uio->uio_offset >> 32)),
  1003. (void *)((unsigned long)(uio->uio_offset & 0xFFFFFFFF)),
  1004. (void *)(unsigned long)uio->uio_resid,
  1005. (void *)(unsigned long)bno,
  1006. NULL, NULL, NULL, NULL, NULL, NULL);
  1007. }
  1008. /*
  1009. * Add a trace buffer entry for an inode and a uio.
  1010. */
  1011. void
  1012. xfs_dir_trace_g_dun(char *where, xfs_inode_t *dp, uio_t *uio,
  1013. xfs_da_intnode_t *node)
  1014. {
  1015. int last = INT_GET(node->hdr.count, ARCH_CONVERT) - 1;
  1016. xfs_dir_trace_enter(XFS_DIR_KTRACE_G_DUN, where,
  1017. (void *)dp, (void *)dp->i_mount,
  1018. (void *)((unsigned long)(uio->uio_offset >> 32)),
  1019. (void *)((unsigned long)(uio->uio_offset & 0xFFFFFFFF)),
  1020. (void *)(unsigned long)uio->uio_resid,
  1021. (void *)(unsigned long)
  1022. INT_GET(node->hdr.info.forw, ARCH_CONVERT),
  1023. (void *)(unsigned long)
  1024. INT_GET(node->hdr.count, ARCH_CONVERT),
  1025. (void *)(unsigned long)
  1026. INT_GET(node->btree[0].hashval, ARCH_CONVERT),
  1027. (void *)(unsigned long)
  1028. INT_GET(node->btree[last].hashval, ARCH_CONVERT),
  1029. NULL, NULL, NULL);
  1030. }
  1031. /*
  1032. * Add a trace buffer entry for an inode and a uio.
  1033. */
  1034. void
  1035. xfs_dir_trace_g_dul(char *where, xfs_inode_t *dp, uio_t *uio,
  1036. xfs_dir_leafblock_t *leaf)
  1037. {
  1038. int last = INT_GET(leaf->hdr.count, ARCH_CONVERT) - 1;
  1039. xfs_dir_trace_enter(XFS_DIR_KTRACE_G_DUL, where,
  1040. (void *)dp, (void *)dp->i_mount,
  1041. (void *)((unsigned long)(uio->uio_offset >> 32)),
  1042. (void *)((unsigned long)(uio->uio_offset & 0xFFFFFFFF)),
  1043. (void *)(unsigned long)uio->uio_resid,
  1044. (void *)(unsigned long)
  1045. INT_GET(leaf->hdr.info.forw, ARCH_CONVERT),
  1046. (void *)(unsigned long)
  1047. INT_GET(leaf->hdr.count, ARCH_CONVERT),
  1048. (void *)(unsigned long)
  1049. INT_GET(leaf->entries[0].hashval, ARCH_CONVERT),
  1050. (void *)(unsigned long)
  1051. INT_GET(leaf->entries[last].hashval, ARCH_CONVERT),
  1052. NULL, NULL, NULL);
  1053. }
  1054. /*
  1055. * Add a trace buffer entry for an inode and a uio.
  1056. */
  1057. void
  1058. xfs_dir_trace_g_due(char *where, xfs_inode_t *dp, uio_t *uio,
  1059. xfs_dir_leaf_entry_t *entry)
  1060. {
  1061. xfs_dir_trace_enter(XFS_DIR_KTRACE_G_DUE, where,
  1062. (void *)dp, (void *)dp->i_mount,
  1063. (void *)((unsigned long)(uio->uio_offset >> 32)),
  1064. (void *)((unsigned long)(uio->uio_offset & 0xFFFFFFFF)),
  1065. (void *)(unsigned long)uio->uio_resid,
  1066. (void *)(unsigned long)
  1067. INT_GET(entry->hashval, ARCH_CONVERT),
  1068. NULL, NULL, NULL, NULL, NULL, NULL);
  1069. }
  1070. /*
  1071. * Add a trace buffer entry for an inode and a uio.
  1072. */
  1073. void
  1074. xfs_dir_trace_g_duc(char *where, xfs_inode_t *dp, uio_t *uio, xfs_off_t cookie)
  1075. {
  1076. xfs_dir_trace_enter(XFS_DIR_KTRACE_G_DUC, where,
  1077. (void *)dp, (void *)dp->i_mount,
  1078. (void *)((unsigned long)(uio->uio_offset >> 32)),
  1079. (void *)((unsigned long)(uio->uio_offset & 0xFFFFFFFF)),
  1080. (void *)(unsigned long)uio->uio_resid,
  1081. (void *)((unsigned long)(cookie >> 32)),
  1082. (void *)((unsigned long)(cookie & 0xFFFFFFFF)),
  1083. NULL, NULL, NULL, NULL, NULL);
  1084. }
  1085. /*
  1086. * Add a trace buffer entry for the arguments given to the routine,
  1087. * generic form.
  1088. */
  1089. void
  1090. xfs_dir_trace_enter(int type, char *where,
  1091. void * a0, void * a1,
  1092. void * a2, void * a3,
  1093. void * a4, void * a5,
  1094. void * a6, void * a7,
  1095. void * a8, void * a9,
  1096. void * a10, void * a11)
  1097. {
  1098. ASSERT(xfs_dir_trace_buf);
  1099. ktrace_enter(xfs_dir_trace_buf, (void *)(unsigned long)type,
  1100. (void *)where,
  1101. (void *)a0, (void *)a1, (void *)a2,
  1102. (void *)a3, (void *)a4, (void *)a5,
  1103. (void *)a6, (void *)a7, (void *)a8,
  1104. (void *)a9, (void *)a10, (void *)a11,
  1105. NULL, NULL);
  1106. }
  1107. #endif /* XFS_DIR_TRACE */