xfs_itable.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. /*
  2. * Copyright (c) 2000-2002,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_shared.h"
  21. #include "xfs_format.h"
  22. #include "xfs_log_format.h"
  23. #include "xfs_trans_resv.h"
  24. #include "xfs_inum.h"
  25. #include "xfs_sb.h"
  26. #include "xfs_ag.h"
  27. #include "xfs_mount.h"
  28. #include "xfs_inode.h"
  29. #include "xfs_btree.h"
  30. #include "xfs_ialloc.h"
  31. #include "xfs_ialloc_btree.h"
  32. #include "xfs_itable.h"
  33. #include "xfs_error.h"
  34. #include "xfs_trace.h"
  35. #include "xfs_icache.h"
  36. #include "xfs_dinode.h"
  37. STATIC int
  38. xfs_internal_inum(
  39. xfs_mount_t *mp,
  40. xfs_ino_t ino)
  41. {
  42. return (ino == mp->m_sb.sb_rbmino || ino == mp->m_sb.sb_rsumino ||
  43. (xfs_sb_version_hasquota(&mp->m_sb) &&
  44. xfs_is_quota_inode(&mp->m_sb, ino)));
  45. }
  46. /*
  47. * Return stat information for one inode.
  48. * Return 0 if ok, else errno.
  49. */
  50. int
  51. xfs_bulkstat_one_int(
  52. struct xfs_mount *mp, /* mount point for filesystem */
  53. xfs_ino_t ino, /* inode to get data for */
  54. void __user *buffer, /* buffer to place output in */
  55. int ubsize, /* size of buffer */
  56. bulkstat_one_fmt_pf formatter, /* formatter, copy to user */
  57. int *ubused, /* bytes used by me */
  58. int *stat) /* BULKSTAT_RV_... */
  59. {
  60. struct xfs_icdinode *dic; /* dinode core info pointer */
  61. struct xfs_inode *ip; /* incore inode pointer */
  62. struct xfs_bstat *buf; /* return buffer */
  63. int error = 0; /* error value */
  64. *stat = BULKSTAT_RV_NOTHING;
  65. if (!buffer || xfs_internal_inum(mp, ino))
  66. return -EINVAL;
  67. buf = kmem_alloc(sizeof(*buf), KM_SLEEP | KM_MAYFAIL);
  68. if (!buf)
  69. return -ENOMEM;
  70. error = xfs_iget(mp, NULL, ino,
  71. (XFS_IGET_DONTCACHE | XFS_IGET_UNTRUSTED),
  72. XFS_ILOCK_SHARED, &ip);
  73. if (error)
  74. goto out_free;
  75. ASSERT(ip != NULL);
  76. ASSERT(ip->i_imap.im_blkno != 0);
  77. dic = &ip->i_d;
  78. /* xfs_iget returns the following without needing
  79. * further change.
  80. */
  81. buf->bs_nlink = dic->di_nlink;
  82. buf->bs_projid_lo = dic->di_projid_lo;
  83. buf->bs_projid_hi = dic->di_projid_hi;
  84. buf->bs_ino = ino;
  85. buf->bs_mode = dic->di_mode;
  86. buf->bs_uid = dic->di_uid;
  87. buf->bs_gid = dic->di_gid;
  88. buf->bs_size = dic->di_size;
  89. buf->bs_atime.tv_sec = dic->di_atime.t_sec;
  90. buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
  91. buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
  92. buf->bs_mtime.tv_nsec = dic->di_mtime.t_nsec;
  93. buf->bs_ctime.tv_sec = dic->di_ctime.t_sec;
  94. buf->bs_ctime.tv_nsec = dic->di_ctime.t_nsec;
  95. buf->bs_xflags = xfs_ip2xflags(ip);
  96. buf->bs_extsize = dic->di_extsize << mp->m_sb.sb_blocklog;
  97. buf->bs_extents = dic->di_nextents;
  98. buf->bs_gen = dic->di_gen;
  99. memset(buf->bs_pad, 0, sizeof(buf->bs_pad));
  100. buf->bs_dmevmask = dic->di_dmevmask;
  101. buf->bs_dmstate = dic->di_dmstate;
  102. buf->bs_aextents = dic->di_anextents;
  103. buf->bs_forkoff = XFS_IFORK_BOFF(ip);
  104. switch (dic->di_format) {
  105. case XFS_DINODE_FMT_DEV:
  106. buf->bs_rdev = ip->i_df.if_u2.if_rdev;
  107. buf->bs_blksize = BLKDEV_IOSIZE;
  108. buf->bs_blocks = 0;
  109. break;
  110. case XFS_DINODE_FMT_LOCAL:
  111. case XFS_DINODE_FMT_UUID:
  112. buf->bs_rdev = 0;
  113. buf->bs_blksize = mp->m_sb.sb_blocksize;
  114. buf->bs_blocks = 0;
  115. break;
  116. case XFS_DINODE_FMT_EXTENTS:
  117. case XFS_DINODE_FMT_BTREE:
  118. buf->bs_rdev = 0;
  119. buf->bs_blksize = mp->m_sb.sb_blocksize;
  120. buf->bs_blocks = dic->di_nblocks + ip->i_delayed_blks;
  121. break;
  122. }
  123. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  124. IRELE(ip);
  125. error = formatter(buffer, ubsize, ubused, buf);
  126. if (!error)
  127. *stat = BULKSTAT_RV_DIDONE;
  128. out_free:
  129. kmem_free(buf);
  130. return error;
  131. }
  132. /* Return 0 on success or positive error */
  133. STATIC int
  134. xfs_bulkstat_one_fmt(
  135. void __user *ubuffer,
  136. int ubsize,
  137. int *ubused,
  138. const xfs_bstat_t *buffer)
  139. {
  140. if (ubsize < sizeof(*buffer))
  141. return -ENOMEM;
  142. if (copy_to_user(ubuffer, buffer, sizeof(*buffer)))
  143. return -EFAULT;
  144. if (ubused)
  145. *ubused = sizeof(*buffer);
  146. return 0;
  147. }
  148. int
  149. xfs_bulkstat_one(
  150. xfs_mount_t *mp, /* mount point for filesystem */
  151. xfs_ino_t ino, /* inode number to get data for */
  152. void __user *buffer, /* buffer to place output in */
  153. int ubsize, /* size of buffer */
  154. int *ubused, /* bytes used by me */
  155. int *stat) /* BULKSTAT_RV_... */
  156. {
  157. return xfs_bulkstat_one_int(mp, ino, buffer, ubsize,
  158. xfs_bulkstat_one_fmt, ubused, stat);
  159. }
  160. /*
  161. * Loop over all clusters in a chunk for a given incore inode allocation btree
  162. * record. Do a readahead if there are any allocated inodes in that cluster.
  163. */
  164. STATIC void
  165. xfs_bulkstat_ichunk_ra(
  166. struct xfs_mount *mp,
  167. xfs_agnumber_t agno,
  168. struct xfs_inobt_rec_incore *irec)
  169. {
  170. xfs_agblock_t agbno;
  171. struct blk_plug plug;
  172. int blks_per_cluster;
  173. int inodes_per_cluster;
  174. int i; /* inode chunk index */
  175. agbno = XFS_AGINO_TO_AGBNO(mp, irec->ir_startino);
  176. blks_per_cluster = xfs_icluster_size_fsb(mp);
  177. inodes_per_cluster = blks_per_cluster << mp->m_sb.sb_inopblog;
  178. blk_start_plug(&plug);
  179. for (i = 0; i < XFS_INODES_PER_CHUNK;
  180. i += inodes_per_cluster, agbno += blks_per_cluster) {
  181. if (xfs_inobt_maskn(i, inodes_per_cluster) & ~irec->ir_free) {
  182. xfs_btree_reada_bufs(mp, agno, agbno, blks_per_cluster,
  183. &xfs_inode_buf_ops);
  184. }
  185. }
  186. blk_finish_plug(&plug);
  187. }
  188. /*
  189. * Lookup the inode chunk that the given inode lives in and then get the record
  190. * if we found the chunk. If the inode was not the last in the chunk and there
  191. * are some left allocated, update the data for the pointed-to record as well as
  192. * return the count of grabbed inodes.
  193. */
  194. STATIC int
  195. xfs_bulkstat_grab_ichunk(
  196. struct xfs_btree_cur *cur, /* btree cursor */
  197. xfs_agino_t agino, /* starting inode of chunk */
  198. int *icount,/* return # of inodes grabbed */
  199. struct xfs_inobt_rec_incore *irec) /* btree record */
  200. {
  201. int idx; /* index into inode chunk */
  202. int stat;
  203. int error = 0;
  204. /* Lookup the inode chunk that this inode lives in */
  205. error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &stat);
  206. if (error)
  207. return error;
  208. if (!stat) {
  209. *icount = 0;
  210. return error;
  211. }
  212. /* Get the record, should always work */
  213. error = xfs_inobt_get_rec(cur, irec, &stat);
  214. if (error)
  215. return error;
  216. XFS_WANT_CORRUPTED_RETURN(stat == 1);
  217. /* Check if the record contains the inode in request */
  218. if (irec->ir_startino + XFS_INODES_PER_CHUNK <= agino) {
  219. *icount = 0;
  220. return 0;
  221. }
  222. idx = agino - irec->ir_startino + 1;
  223. if (idx < XFS_INODES_PER_CHUNK &&
  224. (xfs_inobt_maskn(idx, XFS_INODES_PER_CHUNK - idx) & ~irec->ir_free)) {
  225. int i;
  226. /* We got a right chunk with some left inodes allocated at it.
  227. * Grab the chunk record. Mark all the uninteresting inodes
  228. * free -- because they're before our start point.
  229. */
  230. for (i = 0; i < idx; i++) {
  231. if (XFS_INOBT_MASK(i) & ~irec->ir_free)
  232. irec->ir_freecount++;
  233. }
  234. irec->ir_free |= xfs_inobt_maskn(0, idx);
  235. *icount = XFS_INODES_PER_CHUNK - irec->ir_freecount;
  236. }
  237. return 0;
  238. }
  239. #define XFS_BULKSTAT_UBLEFT(ubleft) ((ubleft) >= statstruct_size)
  240. struct xfs_bulkstat_agichunk {
  241. char __user **ac_ubuffer;/* pointer into user's buffer */
  242. int ac_ubleft; /* bytes left in user's buffer */
  243. int ac_ubelem; /* spaces used in user's buffer */
  244. };
  245. /*
  246. * Process inodes in chunk with a pointer to a formatter function
  247. * that will iget the inode and fill in the appropriate structure.
  248. */
  249. static int
  250. xfs_bulkstat_ag_ichunk(
  251. struct xfs_mount *mp,
  252. xfs_agnumber_t agno,
  253. struct xfs_inobt_rec_incore *irbp,
  254. bulkstat_one_pf formatter,
  255. size_t statstruct_size,
  256. struct xfs_bulkstat_agichunk *acp,
  257. xfs_agino_t *last_agino)
  258. {
  259. char __user **ubufp = acp->ac_ubuffer;
  260. int chunkidx;
  261. int error = 0;
  262. xfs_agino_t agino = irbp->ir_startino;
  263. for (chunkidx = 0; chunkidx < XFS_INODES_PER_CHUNK;
  264. chunkidx++, agino++) {
  265. int fmterror;
  266. int ubused;
  267. /* inode won't fit in buffer, we are done */
  268. if (acp->ac_ubleft < statstruct_size)
  269. break;
  270. /* Skip if this inode is free */
  271. if (XFS_INOBT_MASK(chunkidx) & irbp->ir_free)
  272. continue;
  273. /* Get the inode and fill in a single buffer */
  274. ubused = statstruct_size;
  275. error = formatter(mp, XFS_AGINO_TO_INO(mp, agno, agino),
  276. *ubufp, acp->ac_ubleft, &ubused, &fmterror);
  277. if (fmterror == BULKSTAT_RV_GIVEUP ||
  278. (error && error != -ENOENT && error != -EINVAL)) {
  279. acp->ac_ubleft = 0;
  280. ASSERT(error);
  281. break;
  282. }
  283. /* be careful not to leak error if at end of chunk */
  284. if (fmterror == BULKSTAT_RV_NOTHING || error) {
  285. error = 0;
  286. continue;
  287. }
  288. *ubufp += ubused;
  289. acp->ac_ubleft -= ubused;
  290. acp->ac_ubelem++;
  291. }
  292. /*
  293. * Post-update *last_agino. At this point, agino will always point one
  294. * inode past the last inode we processed successfully. Hence we
  295. * substract that inode when setting the *last_agino cursor so that we
  296. * return the correct cookie to userspace. On the next bulkstat call,
  297. * the inode under the lastino cookie will be skipped as we have already
  298. * processed it here.
  299. */
  300. *last_agino = agino - 1;
  301. return error;
  302. }
  303. /*
  304. * Return stat information in bulk (by-inode) for the filesystem.
  305. */
  306. int /* error status */
  307. xfs_bulkstat(
  308. xfs_mount_t *mp, /* mount point for filesystem */
  309. xfs_ino_t *lastinop, /* last inode returned */
  310. int *ubcountp, /* size of buffer/count returned */
  311. bulkstat_one_pf formatter, /* func that'd fill a single buf */
  312. size_t statstruct_size, /* sizeof struct filling */
  313. char __user *ubuffer, /* buffer with inode stats */
  314. int *done) /* 1 if there are more stats to get */
  315. {
  316. xfs_buf_t *agbp; /* agi header buffer */
  317. xfs_agi_t *agi; /* agi header data */
  318. xfs_agino_t agino; /* inode # in allocation group */
  319. xfs_agnumber_t agno; /* allocation group number */
  320. xfs_btree_cur_t *cur; /* btree cursor for ialloc btree */
  321. size_t irbsize; /* size of irec buffer in bytes */
  322. xfs_inobt_rec_incore_t *irbuf; /* start of irec buffer */
  323. int nirbuf; /* size of irbuf */
  324. int ubcount; /* size of user's buffer */
  325. struct xfs_bulkstat_agichunk ac;
  326. int error = 0;
  327. /*
  328. * Get the last inode value, see if there's nothing to do.
  329. */
  330. agno = XFS_INO_TO_AGNO(mp, *lastinop);
  331. agino = XFS_INO_TO_AGINO(mp, *lastinop);
  332. if (agno >= mp->m_sb.sb_agcount ||
  333. *lastinop != XFS_AGINO_TO_INO(mp, agno, agino)) {
  334. *done = 1;
  335. *ubcountp = 0;
  336. return 0;
  337. }
  338. ubcount = *ubcountp; /* statstruct's */
  339. ac.ac_ubuffer = &ubuffer;
  340. ac.ac_ubleft = ubcount * statstruct_size; /* bytes */;
  341. ac.ac_ubelem = 0;
  342. *ubcountp = 0;
  343. *done = 0;
  344. irbuf = kmem_zalloc_greedy(&irbsize, PAGE_SIZE, PAGE_SIZE * 4);
  345. if (!irbuf)
  346. return -ENOMEM;
  347. nirbuf = irbsize / sizeof(*irbuf);
  348. /*
  349. * Loop over the allocation groups, starting from the last
  350. * inode returned; 0 means start of the allocation group.
  351. */
  352. while (agno < mp->m_sb.sb_agcount) {
  353. struct xfs_inobt_rec_incore *irbp = irbuf;
  354. struct xfs_inobt_rec_incore *irbufend = irbuf + nirbuf;
  355. bool end_of_ag = false;
  356. int icount = 0;
  357. int stat;
  358. error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);
  359. if (error)
  360. break;
  361. agi = XFS_BUF_TO_AGI(agbp);
  362. /*
  363. * Allocate and initialize a btree cursor for ialloc btree.
  364. */
  365. cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno,
  366. XFS_BTNUM_INO);
  367. if (agino > 0) {
  368. /*
  369. * In the middle of an allocation group, we need to get
  370. * the remainder of the chunk we're in.
  371. */
  372. struct xfs_inobt_rec_incore r;
  373. error = xfs_bulkstat_grab_ichunk(cur, agino, &icount, &r);
  374. if (error)
  375. goto del_cursor;
  376. if (icount) {
  377. irbp->ir_startino = r.ir_startino;
  378. irbp->ir_freecount = r.ir_freecount;
  379. irbp->ir_free = r.ir_free;
  380. irbp++;
  381. }
  382. /* Increment to the next record */
  383. error = xfs_btree_increment(cur, 0, &stat);
  384. } else {
  385. /* Start of ag. Lookup the first inode chunk */
  386. error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &stat);
  387. }
  388. if (error || stat == 0) {
  389. end_of_ag = true;
  390. goto del_cursor;
  391. }
  392. /*
  393. * Loop through inode btree records in this ag,
  394. * until we run out of inodes or space in the buffer.
  395. */
  396. while (irbp < irbufend && icount < ubcount) {
  397. struct xfs_inobt_rec_incore r;
  398. error = xfs_inobt_get_rec(cur, &r, &stat);
  399. if (error || stat == 0) {
  400. end_of_ag = true;
  401. goto del_cursor;
  402. }
  403. /*
  404. * If this chunk has any allocated inodes, save it.
  405. * Also start read-ahead now for this chunk.
  406. */
  407. if (r.ir_freecount < XFS_INODES_PER_CHUNK) {
  408. xfs_bulkstat_ichunk_ra(mp, agno, &r);
  409. irbp->ir_startino = r.ir_startino;
  410. irbp->ir_freecount = r.ir_freecount;
  411. irbp->ir_free = r.ir_free;
  412. irbp++;
  413. icount += XFS_INODES_PER_CHUNK - r.ir_freecount;
  414. }
  415. error = xfs_btree_increment(cur, 0, &stat);
  416. if (error || stat == 0) {
  417. end_of_ag = true;
  418. goto del_cursor;
  419. }
  420. cond_resched();
  421. }
  422. /*
  423. * Drop the btree buffers and the agi buffer as we can't hold any
  424. * of the locks these represent when calling iget. If there is a
  425. * pending error, then we are done.
  426. */
  427. del_cursor:
  428. xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
  429. xfs_buf_relse(agbp);
  430. if (error)
  431. break;
  432. /*
  433. * Now format all the good inodes into the user's buffer. The
  434. * call to xfs_bulkstat_ag_ichunk() sets up the agino pointer
  435. * for the next loop iteration.
  436. */
  437. irbufend = irbp;
  438. for (irbp = irbuf;
  439. irbp < irbufend && ac.ac_ubleft >= statstruct_size;
  440. irbp++) {
  441. error = xfs_bulkstat_ag_ichunk(mp, agno, irbp,
  442. formatter, statstruct_size, &ac,
  443. &agino);
  444. if (error)
  445. break;
  446. cond_resched();
  447. }
  448. /*
  449. * If we've run out of space or had a formatting error, we
  450. * are now done
  451. */
  452. if (ac.ac_ubleft < statstruct_size || error)
  453. break;
  454. if (end_of_ag) {
  455. agno++;
  456. agino = 0;
  457. }
  458. }
  459. /*
  460. * Done, we're either out of filesystem or space to put the data.
  461. */
  462. kmem_free(irbuf);
  463. *ubcountp = ac.ac_ubelem;
  464. /*
  465. * We found some inodes, so clear the error status and return them.
  466. * The lastino pointer will point directly at the inode that triggered
  467. * any error that occurred, so on the next call the error will be
  468. * triggered again and propagated to userspace as there will be no
  469. * formatted inodes in the buffer.
  470. */
  471. if (ac.ac_ubelem)
  472. error = 0;
  473. /*
  474. * If we ran out of filesystem, lastino will point off the end of
  475. * the filesystem so the next call will return immediately.
  476. */
  477. *lastinop = XFS_AGINO_TO_INO(mp, agno, agino);
  478. if (agno >= mp->m_sb.sb_agcount)
  479. *done = 1;
  480. return error;
  481. }
  482. int
  483. xfs_inumbers_fmt(
  484. void __user *ubuffer, /* buffer to write to */
  485. const struct xfs_inogrp *buffer, /* buffer to read from */
  486. long count, /* # of elements to read */
  487. long *written) /* # of bytes written */
  488. {
  489. if (copy_to_user(ubuffer, buffer, count * sizeof(*buffer)))
  490. return -EFAULT;
  491. *written = count * sizeof(*buffer);
  492. return 0;
  493. }
  494. /*
  495. * Return inode number table for the filesystem.
  496. */
  497. int /* error status */
  498. xfs_inumbers(
  499. struct xfs_mount *mp,/* mount point for filesystem */
  500. xfs_ino_t *lastino,/* last inode returned */
  501. int *count,/* size of buffer/count returned */
  502. void __user *ubuffer,/* buffer with inode descriptions */
  503. inumbers_fmt_pf formatter)
  504. {
  505. xfs_agnumber_t agno = XFS_INO_TO_AGNO(mp, *lastino);
  506. xfs_agino_t agino = XFS_INO_TO_AGINO(mp, *lastino);
  507. struct xfs_btree_cur *cur = NULL;
  508. struct xfs_buf *agbp = NULL;
  509. struct xfs_inogrp *buffer;
  510. int bcount;
  511. int left = *count;
  512. int bufidx = 0;
  513. int error = 0;
  514. *count = 0;
  515. if (agno >= mp->m_sb.sb_agcount ||
  516. *lastino != XFS_AGINO_TO_INO(mp, agno, agino))
  517. return error;
  518. bcount = MIN(left, (int)(PAGE_SIZE / sizeof(*buffer)));
  519. buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP);
  520. do {
  521. struct xfs_inobt_rec_incore r;
  522. int stat;
  523. if (!agbp) {
  524. error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);
  525. if (error)
  526. break;
  527. cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno,
  528. XFS_BTNUM_INO);
  529. error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_GE,
  530. &stat);
  531. if (error)
  532. break;
  533. if (!stat)
  534. goto next_ag;
  535. }
  536. error = xfs_inobt_get_rec(cur, &r, &stat);
  537. if (error)
  538. break;
  539. if (!stat)
  540. goto next_ag;
  541. agino = r.ir_startino + XFS_INODES_PER_CHUNK - 1;
  542. buffer[bufidx].xi_startino =
  543. XFS_AGINO_TO_INO(mp, agno, r.ir_startino);
  544. buffer[bufidx].xi_alloccount =
  545. XFS_INODES_PER_CHUNK - r.ir_freecount;
  546. buffer[bufidx].xi_allocmask = ~r.ir_free;
  547. if (++bufidx == bcount) {
  548. long written;
  549. error = formatter(ubuffer, buffer, bufidx, &written);
  550. if (error)
  551. break;
  552. ubuffer += written;
  553. *count += bufidx;
  554. bufidx = 0;
  555. }
  556. if (!--left)
  557. break;
  558. error = xfs_btree_increment(cur, 0, &stat);
  559. if (error)
  560. break;
  561. if (stat)
  562. continue;
  563. next_ag:
  564. xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
  565. cur = NULL;
  566. xfs_buf_relse(agbp);
  567. agbp = NULL;
  568. agino = 0;
  569. agno++;
  570. } while (agno < mp->m_sb.sb_agcount);
  571. if (!error) {
  572. if (bufidx) {
  573. long written;
  574. error = formatter(ubuffer, buffer, bufidx, &written);
  575. if (!error)
  576. *count += bufidx;
  577. }
  578. *lastino = XFS_AGINO_TO_INO(mp, agno, agino);
  579. }
  580. kmem_free(buffer);
  581. if (cur)
  582. xfs_btree_del_cursor(cur, (error ? XFS_BTREE_ERROR :
  583. XFS_BTREE_NOERROR));
  584. if (agbp)
  585. xfs_buf_relse(agbp);
  586. return error;
  587. }