xfs_attr_list.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /*
  2. * Copyright (c) 2000-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_log_format.h"
  22. #include "xfs_trans_resv.h"
  23. #include "xfs_bit.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_ag.h"
  26. #include "xfs_mount.h"
  27. #include "xfs_da_format.h"
  28. #include "xfs_da_btree.h"
  29. #include "xfs_bmap_btree.h"
  30. #include "xfs_alloc_btree.h"
  31. #include "xfs_ialloc_btree.h"
  32. #include "xfs_alloc.h"
  33. #include "xfs_btree.h"
  34. #include "xfs_attr_sf.h"
  35. #include "xfs_attr_remote.h"
  36. #include "xfs_dinode.h"
  37. #include "xfs_inode.h"
  38. #include "xfs_trans.h"
  39. #include "xfs_inode_item.h"
  40. #include "xfs_bmap.h"
  41. #include "xfs_attr.h"
  42. #include "xfs_attr_leaf.h"
  43. #include "xfs_error.h"
  44. #include "xfs_trace.h"
  45. #include "xfs_buf_item.h"
  46. #include "xfs_cksum.h"
  47. STATIC int
  48. xfs_attr_shortform_compare(const void *a, const void *b)
  49. {
  50. xfs_attr_sf_sort_t *sa, *sb;
  51. sa = (xfs_attr_sf_sort_t *)a;
  52. sb = (xfs_attr_sf_sort_t *)b;
  53. if (sa->hash < sb->hash) {
  54. return(-1);
  55. } else if (sa->hash > sb->hash) {
  56. return(1);
  57. } else {
  58. return(sa->entno - sb->entno);
  59. }
  60. }
  61. #define XFS_ISRESET_CURSOR(cursor) \
  62. (!((cursor)->initted) && !((cursor)->hashval) && \
  63. !((cursor)->blkno) && !((cursor)->offset))
  64. /*
  65. * Copy out entries of shortform attribute lists for attr_list().
  66. * Shortform attribute lists are not stored in hashval sorted order.
  67. * If the output buffer is not large enough to hold them all, then we
  68. * we have to calculate each entries' hashvalue and sort them before
  69. * we can begin returning them to the user.
  70. */
  71. int
  72. xfs_attr_shortform_list(xfs_attr_list_context_t *context)
  73. {
  74. attrlist_cursor_kern_t *cursor;
  75. xfs_attr_sf_sort_t *sbuf, *sbp;
  76. xfs_attr_shortform_t *sf;
  77. xfs_attr_sf_entry_t *sfe;
  78. xfs_inode_t *dp;
  79. int sbsize, nsbuf, count, i;
  80. int error;
  81. ASSERT(context != NULL);
  82. dp = context->dp;
  83. ASSERT(dp != NULL);
  84. ASSERT(dp->i_afp != NULL);
  85. sf = (xfs_attr_shortform_t *)dp->i_afp->if_u1.if_data;
  86. ASSERT(sf != NULL);
  87. if (!sf->hdr.count)
  88. return(0);
  89. cursor = context->cursor;
  90. ASSERT(cursor != NULL);
  91. trace_xfs_attr_list_sf(context);
  92. /*
  93. * If the buffer is large enough and the cursor is at the start,
  94. * do not bother with sorting since we will return everything in
  95. * one buffer and another call using the cursor won't need to be
  96. * made.
  97. * Note the generous fudge factor of 16 overhead bytes per entry.
  98. * If bufsize is zero then put_listent must be a search function
  99. * and can just scan through what we have.
  100. */
  101. if (context->bufsize == 0 ||
  102. (XFS_ISRESET_CURSOR(cursor) &&
  103. (dp->i_afp->if_bytes + sf->hdr.count * 16) < context->bufsize)) {
  104. for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
  105. error = context->put_listent(context,
  106. sfe->flags,
  107. sfe->nameval,
  108. (int)sfe->namelen,
  109. (int)sfe->valuelen,
  110. &sfe->nameval[sfe->namelen]);
  111. /*
  112. * Either search callback finished early or
  113. * didn't fit it all in the buffer after all.
  114. */
  115. if (context->seen_enough)
  116. break;
  117. if (error)
  118. return error;
  119. sfe = XFS_ATTR_SF_NEXTENTRY(sfe);
  120. }
  121. trace_xfs_attr_list_sf_all(context);
  122. return(0);
  123. }
  124. /* do no more for a search callback */
  125. if (context->bufsize == 0)
  126. return 0;
  127. /*
  128. * It didn't all fit, so we have to sort everything on hashval.
  129. */
  130. sbsize = sf->hdr.count * sizeof(*sbuf);
  131. sbp = sbuf = kmem_alloc(sbsize, KM_SLEEP | KM_NOFS);
  132. /*
  133. * Scan the attribute list for the rest of the entries, storing
  134. * the relevant info from only those that match into a buffer.
  135. */
  136. nsbuf = 0;
  137. for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
  138. if (unlikely(
  139. ((char *)sfe < (char *)sf) ||
  140. ((char *)sfe >= ((char *)sf + dp->i_afp->if_bytes)))) {
  141. XFS_CORRUPTION_ERROR("xfs_attr_shortform_list",
  142. XFS_ERRLEVEL_LOW,
  143. context->dp->i_mount, sfe);
  144. kmem_free(sbuf);
  145. return XFS_ERROR(EFSCORRUPTED);
  146. }
  147. sbp->entno = i;
  148. sbp->hash = xfs_da_hashname(sfe->nameval, sfe->namelen);
  149. sbp->name = sfe->nameval;
  150. sbp->namelen = sfe->namelen;
  151. /* These are bytes, and both on-disk, don't endian-flip */
  152. sbp->valuelen = sfe->valuelen;
  153. sbp->flags = sfe->flags;
  154. sfe = XFS_ATTR_SF_NEXTENTRY(sfe);
  155. sbp++;
  156. nsbuf++;
  157. }
  158. /*
  159. * Sort the entries on hash then entno.
  160. */
  161. xfs_sort(sbuf, nsbuf, sizeof(*sbuf), xfs_attr_shortform_compare);
  162. /*
  163. * Re-find our place IN THE SORTED LIST.
  164. */
  165. count = 0;
  166. cursor->initted = 1;
  167. cursor->blkno = 0;
  168. for (sbp = sbuf, i = 0; i < nsbuf; i++, sbp++) {
  169. if (sbp->hash == cursor->hashval) {
  170. if (cursor->offset == count) {
  171. break;
  172. }
  173. count++;
  174. } else if (sbp->hash > cursor->hashval) {
  175. break;
  176. }
  177. }
  178. if (i == nsbuf) {
  179. kmem_free(sbuf);
  180. return(0);
  181. }
  182. /*
  183. * Loop putting entries into the user buffer.
  184. */
  185. for ( ; i < nsbuf; i++, sbp++) {
  186. if (cursor->hashval != sbp->hash) {
  187. cursor->hashval = sbp->hash;
  188. cursor->offset = 0;
  189. }
  190. error = context->put_listent(context,
  191. sbp->flags,
  192. sbp->name,
  193. sbp->namelen,
  194. sbp->valuelen,
  195. &sbp->name[sbp->namelen]);
  196. if (error)
  197. return error;
  198. if (context->seen_enough)
  199. break;
  200. cursor->offset++;
  201. }
  202. kmem_free(sbuf);
  203. return(0);
  204. }
  205. STATIC int
  206. xfs_attr_node_list(xfs_attr_list_context_t *context)
  207. {
  208. attrlist_cursor_kern_t *cursor;
  209. xfs_attr_leafblock_t *leaf;
  210. xfs_da_intnode_t *node;
  211. struct xfs_attr3_icleaf_hdr leafhdr;
  212. struct xfs_da3_icnode_hdr nodehdr;
  213. struct xfs_da_node_entry *btree;
  214. int error, i;
  215. struct xfs_buf *bp;
  216. trace_xfs_attr_node_list(context);
  217. cursor = context->cursor;
  218. cursor->initted = 1;
  219. /*
  220. * Do all sorts of validation on the passed-in cursor structure.
  221. * If anything is amiss, ignore the cursor and look up the hashval
  222. * starting from the btree root.
  223. */
  224. bp = NULL;
  225. if (cursor->blkno > 0) {
  226. error = xfs_da3_node_read(NULL, context->dp, cursor->blkno, -1,
  227. &bp, XFS_ATTR_FORK);
  228. if ((error != 0) && (error != EFSCORRUPTED))
  229. return(error);
  230. if (bp) {
  231. struct xfs_attr_leaf_entry *entries;
  232. node = bp->b_addr;
  233. switch (be16_to_cpu(node->hdr.info.magic)) {
  234. case XFS_DA_NODE_MAGIC:
  235. case XFS_DA3_NODE_MAGIC:
  236. trace_xfs_attr_list_wrong_blk(context);
  237. xfs_trans_brelse(NULL, bp);
  238. bp = NULL;
  239. break;
  240. case XFS_ATTR_LEAF_MAGIC:
  241. case XFS_ATTR3_LEAF_MAGIC:
  242. leaf = bp->b_addr;
  243. xfs_attr3_leaf_hdr_from_disk(&leafhdr, leaf);
  244. entries = xfs_attr3_leaf_entryp(leaf);
  245. if (cursor->hashval > be32_to_cpu(
  246. entries[leafhdr.count - 1].hashval)) {
  247. trace_xfs_attr_list_wrong_blk(context);
  248. xfs_trans_brelse(NULL, bp);
  249. bp = NULL;
  250. } else if (cursor->hashval <= be32_to_cpu(
  251. entries[0].hashval)) {
  252. trace_xfs_attr_list_wrong_blk(context);
  253. xfs_trans_brelse(NULL, bp);
  254. bp = NULL;
  255. }
  256. break;
  257. default:
  258. trace_xfs_attr_list_wrong_blk(context);
  259. xfs_trans_brelse(NULL, bp);
  260. bp = NULL;
  261. }
  262. }
  263. }
  264. /*
  265. * We did not find what we expected given the cursor's contents,
  266. * so we start from the top and work down based on the hash value.
  267. * Note that start of node block is same as start of leaf block.
  268. */
  269. if (bp == NULL) {
  270. cursor->blkno = 0;
  271. for (;;) {
  272. __uint16_t magic;
  273. error = xfs_da3_node_read(NULL, context->dp,
  274. cursor->blkno, -1, &bp,
  275. XFS_ATTR_FORK);
  276. if (error)
  277. return(error);
  278. node = bp->b_addr;
  279. magic = be16_to_cpu(node->hdr.info.magic);
  280. if (magic == XFS_ATTR_LEAF_MAGIC ||
  281. magic == XFS_ATTR3_LEAF_MAGIC)
  282. break;
  283. if (magic != XFS_DA_NODE_MAGIC &&
  284. magic != XFS_DA3_NODE_MAGIC) {
  285. XFS_CORRUPTION_ERROR("xfs_attr_node_list(3)",
  286. XFS_ERRLEVEL_LOW,
  287. context->dp->i_mount,
  288. node);
  289. xfs_trans_brelse(NULL, bp);
  290. return XFS_ERROR(EFSCORRUPTED);
  291. }
  292. xfs_da3_node_hdr_from_disk(&nodehdr, node);
  293. btree = xfs_da3_node_tree_p(node);
  294. for (i = 0; i < nodehdr.count; btree++, i++) {
  295. if (cursor->hashval
  296. <= be32_to_cpu(btree->hashval)) {
  297. cursor->blkno = be32_to_cpu(btree->before);
  298. trace_xfs_attr_list_node_descend(context,
  299. btree);
  300. break;
  301. }
  302. }
  303. if (i == nodehdr.count) {
  304. xfs_trans_brelse(NULL, bp);
  305. return 0;
  306. }
  307. xfs_trans_brelse(NULL, bp);
  308. }
  309. }
  310. ASSERT(bp != NULL);
  311. /*
  312. * Roll upward through the blocks, processing each leaf block in
  313. * order. As long as there is space in the result buffer, keep
  314. * adding the information.
  315. */
  316. for (;;) {
  317. leaf = bp->b_addr;
  318. error = xfs_attr3_leaf_list_int(bp, context);
  319. if (error) {
  320. xfs_trans_brelse(NULL, bp);
  321. return error;
  322. }
  323. xfs_attr3_leaf_hdr_from_disk(&leafhdr, leaf);
  324. if (context->seen_enough || leafhdr.forw == 0)
  325. break;
  326. cursor->blkno = leafhdr.forw;
  327. xfs_trans_brelse(NULL, bp);
  328. error = xfs_attr3_leaf_read(NULL, context->dp, cursor->blkno, -1,
  329. &bp);
  330. if (error)
  331. return error;
  332. }
  333. xfs_trans_brelse(NULL, bp);
  334. return 0;
  335. }
  336. /*
  337. * Copy out attribute list entries for attr_list(), for leaf attribute lists.
  338. */
  339. int
  340. xfs_attr3_leaf_list_int(
  341. struct xfs_buf *bp,
  342. struct xfs_attr_list_context *context)
  343. {
  344. struct attrlist_cursor_kern *cursor;
  345. struct xfs_attr_leafblock *leaf;
  346. struct xfs_attr3_icleaf_hdr ichdr;
  347. struct xfs_attr_leaf_entry *entries;
  348. struct xfs_attr_leaf_entry *entry;
  349. int retval;
  350. int i;
  351. trace_xfs_attr_list_leaf(context);
  352. leaf = bp->b_addr;
  353. xfs_attr3_leaf_hdr_from_disk(&ichdr, leaf);
  354. entries = xfs_attr3_leaf_entryp(leaf);
  355. cursor = context->cursor;
  356. cursor->initted = 1;
  357. /*
  358. * Re-find our place in the leaf block if this is a new syscall.
  359. */
  360. if (context->resynch) {
  361. entry = &entries[0];
  362. for (i = 0; i < ichdr.count; entry++, i++) {
  363. if (be32_to_cpu(entry->hashval) == cursor->hashval) {
  364. if (cursor->offset == context->dupcnt) {
  365. context->dupcnt = 0;
  366. break;
  367. }
  368. context->dupcnt++;
  369. } else if (be32_to_cpu(entry->hashval) >
  370. cursor->hashval) {
  371. context->dupcnt = 0;
  372. break;
  373. }
  374. }
  375. if (i == ichdr.count) {
  376. trace_xfs_attr_list_notfound(context);
  377. return 0;
  378. }
  379. } else {
  380. entry = &entries[0];
  381. i = 0;
  382. }
  383. context->resynch = 0;
  384. /*
  385. * We have found our place, start copying out the new attributes.
  386. */
  387. retval = 0;
  388. for (; i < ichdr.count; entry++, i++) {
  389. if (be32_to_cpu(entry->hashval) != cursor->hashval) {
  390. cursor->hashval = be32_to_cpu(entry->hashval);
  391. cursor->offset = 0;
  392. }
  393. if (entry->flags & XFS_ATTR_INCOMPLETE)
  394. continue; /* skip incomplete entries */
  395. if (entry->flags & XFS_ATTR_LOCAL) {
  396. xfs_attr_leaf_name_local_t *name_loc =
  397. xfs_attr3_leaf_name_local(leaf, i);
  398. retval = context->put_listent(context,
  399. entry->flags,
  400. name_loc->nameval,
  401. (int)name_loc->namelen,
  402. be16_to_cpu(name_loc->valuelen),
  403. &name_loc->nameval[name_loc->namelen]);
  404. if (retval)
  405. return retval;
  406. } else {
  407. xfs_attr_leaf_name_remote_t *name_rmt =
  408. xfs_attr3_leaf_name_remote(leaf, i);
  409. int valuelen = be32_to_cpu(name_rmt->valuelen);
  410. if (context->put_value) {
  411. xfs_da_args_t args;
  412. memset((char *)&args, 0, sizeof(args));
  413. args.dp = context->dp;
  414. args.whichfork = XFS_ATTR_FORK;
  415. args.valuelen = valuelen;
  416. args.value = kmem_alloc(valuelen, KM_SLEEP | KM_NOFS);
  417. args.rmtblkno = be32_to_cpu(name_rmt->valueblk);
  418. args.rmtblkcnt = xfs_attr3_rmt_blocks(
  419. args.dp->i_mount, valuelen);
  420. retval = xfs_attr_rmtval_get(&args);
  421. if (retval)
  422. return retval;
  423. retval = context->put_listent(context,
  424. entry->flags,
  425. name_rmt->name,
  426. (int)name_rmt->namelen,
  427. valuelen,
  428. args.value);
  429. kmem_free(args.value);
  430. } else {
  431. retval = context->put_listent(context,
  432. entry->flags,
  433. name_rmt->name,
  434. (int)name_rmt->namelen,
  435. valuelen,
  436. NULL);
  437. }
  438. if (retval)
  439. return retval;
  440. }
  441. if (context->seen_enough)
  442. break;
  443. cursor->offset++;
  444. }
  445. trace_xfs_attr_list_leaf_end(context);
  446. return retval;
  447. }
  448. /*
  449. * Copy out attribute entries for attr_list(), for leaf attribute lists.
  450. */
  451. STATIC int
  452. xfs_attr_leaf_list(xfs_attr_list_context_t *context)
  453. {
  454. int error;
  455. struct xfs_buf *bp;
  456. trace_xfs_attr_leaf_list(context);
  457. context->cursor->blkno = 0;
  458. error = xfs_attr3_leaf_read(NULL, context->dp, 0, -1, &bp);
  459. if (error)
  460. return XFS_ERROR(error);
  461. error = xfs_attr3_leaf_list_int(bp, context);
  462. xfs_trans_brelse(NULL, bp);
  463. return XFS_ERROR(error);
  464. }
  465. int
  466. xfs_attr_list_int(
  467. xfs_attr_list_context_t *context)
  468. {
  469. int error;
  470. xfs_inode_t *dp = context->dp;
  471. XFS_STATS_INC(xs_attr_list);
  472. if (XFS_FORCED_SHUTDOWN(dp->i_mount))
  473. return EIO;
  474. xfs_ilock(dp, XFS_ILOCK_SHARED);
  475. /*
  476. * Decide on what work routines to call based on the inode size.
  477. */
  478. if (!xfs_inode_hasattr(dp)) {
  479. error = 0;
  480. } else if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL) {
  481. error = xfs_attr_shortform_list(context);
  482. } else if (xfs_bmap_one_block(dp, XFS_ATTR_FORK)) {
  483. error = xfs_attr_leaf_list(context);
  484. } else {
  485. error = xfs_attr_node_list(context);
  486. }
  487. xfs_iunlock(dp, XFS_ILOCK_SHARED);
  488. return error;
  489. }
  490. #define ATTR_ENTBASESIZE /* minimum bytes used by an attr */ \
  491. (((struct attrlist_ent *) 0)->a_name - (char *) 0)
  492. #define ATTR_ENTSIZE(namelen) /* actual bytes used by an attr */ \
  493. ((ATTR_ENTBASESIZE + (namelen) + 1 + sizeof(u_int32_t)-1) \
  494. & ~(sizeof(u_int32_t)-1))
  495. /*
  496. * Format an attribute and copy it out to the user's buffer.
  497. * Take care to check values and protect against them changing later,
  498. * we may be reading them directly out of a user buffer.
  499. */
  500. STATIC int
  501. xfs_attr_put_listent(
  502. xfs_attr_list_context_t *context,
  503. int flags,
  504. unsigned char *name,
  505. int namelen,
  506. int valuelen,
  507. unsigned char *value)
  508. {
  509. struct attrlist *alist = (struct attrlist *)context->alist;
  510. attrlist_ent_t *aep;
  511. int arraytop;
  512. ASSERT(!(context->flags & ATTR_KERNOVAL));
  513. ASSERT(context->count >= 0);
  514. ASSERT(context->count < (ATTR_MAX_VALUELEN/8));
  515. ASSERT(context->firstu >= sizeof(*alist));
  516. ASSERT(context->firstu <= context->bufsize);
  517. /*
  518. * Only list entries in the right namespace.
  519. */
  520. if (((context->flags & ATTR_SECURE) == 0) !=
  521. ((flags & XFS_ATTR_SECURE) == 0))
  522. return 0;
  523. if (((context->flags & ATTR_ROOT) == 0) !=
  524. ((flags & XFS_ATTR_ROOT) == 0))
  525. return 0;
  526. arraytop = sizeof(*alist) +
  527. context->count * sizeof(alist->al_offset[0]);
  528. context->firstu -= ATTR_ENTSIZE(namelen);
  529. if (context->firstu < arraytop) {
  530. trace_xfs_attr_list_full(context);
  531. alist->al_more = 1;
  532. context->seen_enough = 1;
  533. return 1;
  534. }
  535. aep = (attrlist_ent_t *)&context->alist[context->firstu];
  536. aep->a_valuelen = valuelen;
  537. memcpy(aep->a_name, name, namelen);
  538. aep->a_name[namelen] = 0;
  539. alist->al_offset[context->count++] = context->firstu;
  540. alist->al_count = context->count;
  541. trace_xfs_attr_list_add(context);
  542. return 0;
  543. }
  544. /*
  545. * Generate a list of extended attribute names and optionally
  546. * also value lengths. Positive return value follows the XFS
  547. * convention of being an error, zero or negative return code
  548. * is the length of the buffer returned (negated), indicating
  549. * success.
  550. */
  551. int
  552. xfs_attr_list(
  553. xfs_inode_t *dp,
  554. char *buffer,
  555. int bufsize,
  556. int flags,
  557. attrlist_cursor_kern_t *cursor)
  558. {
  559. xfs_attr_list_context_t context;
  560. struct attrlist *alist;
  561. int error;
  562. /*
  563. * Validate the cursor.
  564. */
  565. if (cursor->pad1 || cursor->pad2)
  566. return(XFS_ERROR(EINVAL));
  567. if ((cursor->initted == 0) &&
  568. (cursor->hashval || cursor->blkno || cursor->offset))
  569. return XFS_ERROR(EINVAL);
  570. /*
  571. * Check for a properly aligned buffer.
  572. */
  573. if (((long)buffer) & (sizeof(int)-1))
  574. return XFS_ERROR(EFAULT);
  575. if (flags & ATTR_KERNOVAL)
  576. bufsize = 0;
  577. /*
  578. * Initialize the output buffer.
  579. */
  580. memset(&context, 0, sizeof(context));
  581. context.dp = dp;
  582. context.cursor = cursor;
  583. context.resynch = 1;
  584. context.flags = flags;
  585. context.alist = buffer;
  586. context.bufsize = (bufsize & ~(sizeof(int)-1)); /* align */
  587. context.firstu = context.bufsize;
  588. context.put_listent = xfs_attr_put_listent;
  589. alist = (struct attrlist *)context.alist;
  590. alist->al_count = 0;
  591. alist->al_more = 0;
  592. alist->al_offset[0] = context.bufsize;
  593. error = xfs_attr_list_int(&context);
  594. ASSERT(error >= 0);
  595. return error;
  596. }