xfs_dir.c 33 KB

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