xfs_attr_list.c 16 KB

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