2 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
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.
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.
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
20 #include "xfs_types.h"
24 #include "xfs_trans.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_mount.h"
30 #include "xfs_bmap_btree.h"
31 #include "xfs_alloc_btree.h"
32 #include "xfs_ialloc_btree.h"
33 #include "xfs_dir2_sf.h"
34 #include "xfs_attr_sf.h"
35 #include "xfs_dinode.h"
36 #include "xfs_inode.h"
37 #include "xfs_ialloc.h"
38 #include "xfs_itable.h"
39 #include "xfs_error.h"
40 #include "xfs_btree.h"
43 xfs_bulkstat_one_iget(
44 xfs_mount_t *mp, /* mount point for filesystem */
45 xfs_ino_t ino, /* inode number to get data for */
46 xfs_daddr_t bno, /* starting bno of inode cluster */
47 xfs_bstat_t *buf, /* return buffer */
48 int *stat) /* BULKSTAT_RV_... */
50 xfs_dinode_core_t *dic; /* dinode core info pointer */
51 xfs_inode_t *ip; /* incore inode pointer */
55 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, bno);
57 *stat = BULKSTAT_RV_NOTHING;
62 ASSERT(ip->i_blkno != (xfs_daddr_t)0);
63 if (ip->i_d.di_mode == 0) {
64 *stat = BULKSTAT_RV_NOTHING;
65 error = XFS_ERROR(ENOENT);
72 /* xfs_iget returns the following without needing
75 buf->bs_nlink = dic->di_nlink;
76 buf->bs_projid = dic->di_projid;
78 buf->bs_mode = dic->di_mode;
79 buf->bs_uid = dic->di_uid;
80 buf->bs_gid = dic->di_gid;
81 buf->bs_xid = dic->di_xid;
82 buf->bs_size = dic->di_size;
83 vn_atime_to_bstime(vp, &buf->bs_atime);
84 buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
85 buf->bs_mtime.tv_nsec = dic->di_mtime.t_nsec;
86 buf->bs_ctime.tv_sec = dic->di_ctime.t_sec;
87 buf->bs_ctime.tv_nsec = dic->di_ctime.t_nsec;
88 buf->bs_xflags = xfs_ip2xflags(ip);
89 buf->bs_extsize = dic->di_extsize << mp->m_sb.sb_blocklog;
90 buf->bs_extents = dic->di_nextents;
91 buf->bs_gen = dic->di_gen;
92 memset(buf->bs_pad, 0, sizeof(buf->bs_pad));
93 buf->bs_dmevmask = dic->di_dmevmask;
94 buf->bs_dmstate = dic->di_dmstate;
95 buf->bs_aextents = dic->di_anextents;
97 switch (dic->di_format) {
98 case XFS_DINODE_FMT_DEV:
99 buf->bs_rdev = ip->i_df.if_u2.if_rdev;
100 buf->bs_blksize = BLKDEV_IOSIZE;
103 case XFS_DINODE_FMT_LOCAL:
104 case XFS_DINODE_FMT_UUID:
106 buf->bs_blksize = mp->m_sb.sb_blocksize;
109 case XFS_DINODE_FMT_EXTENTS:
110 case XFS_DINODE_FMT_BTREE:
112 buf->bs_blksize = mp->m_sb.sb_blocksize;
113 buf->bs_blocks = dic->di_nblocks + ip->i_delayed_blks;
118 xfs_iput(ip, XFS_ILOCK_SHARED);
123 xfs_bulkstat_one_dinode(
124 xfs_mount_t *mp, /* mount point for filesystem */
125 xfs_ino_t ino, /* inode number to get data for */
126 xfs_dinode_t *dip, /* dinode inode pointer */
127 xfs_bstat_t *buf) /* return buffer */
129 xfs_dinode_core_t *dic; /* dinode core info pointer */
134 * The inode format changed when we moved the link count and
135 * made it 32 bits long. If this is an old format inode,
136 * convert it in memory to look like a new one. If it gets
137 * flushed to disk we will convert back before flushing or
138 * logging it. We zero out the new projid field and the old link
139 * count field. We'll handle clearing the pad field (the remains
140 * of the old uuid field) when we actually convert the inode to
141 * the new format. We don't change the version number so that we
142 * can distinguish this from a real new format inode.
144 if (INT_GET(dic->di_version, ARCH_CONVERT) == XFS_DINODE_VERSION_1) {
145 buf->bs_nlink = INT_GET(dic->di_onlink, ARCH_CONVERT);
148 buf->bs_nlink = INT_GET(dic->di_nlink, ARCH_CONVERT);
149 buf->bs_projid = INT_GET(dic->di_projid, ARCH_CONVERT);
153 buf->bs_mode = INT_GET(dic->di_mode, ARCH_CONVERT);
154 buf->bs_uid = INT_GET(dic->di_uid, ARCH_CONVERT);
155 buf->bs_gid = INT_GET(dic->di_gid, ARCH_CONVERT);
156 buf->bs_xid = INT_GET(dic->di_xid, ARCH_CONVERT);
157 buf->bs_size = INT_GET(dic->di_size, ARCH_CONVERT);
158 buf->bs_atime.tv_sec = INT_GET(dic->di_atime.t_sec, ARCH_CONVERT);
159 buf->bs_atime.tv_nsec = INT_GET(dic->di_atime.t_nsec, ARCH_CONVERT);
160 buf->bs_mtime.tv_sec = INT_GET(dic->di_mtime.t_sec, ARCH_CONVERT);
161 buf->bs_mtime.tv_nsec = INT_GET(dic->di_mtime.t_nsec, ARCH_CONVERT);
162 buf->bs_ctime.tv_sec = INT_GET(dic->di_ctime.t_sec, ARCH_CONVERT);
163 buf->bs_ctime.tv_nsec = INT_GET(dic->di_ctime.t_nsec, ARCH_CONVERT);
164 buf->bs_xflags = xfs_dic2xflags(dic);
165 buf->bs_extsize = INT_GET(dic->di_extsize, ARCH_CONVERT) << mp->m_sb.sb_blocklog;
166 buf->bs_extents = INT_GET(dic->di_nextents, ARCH_CONVERT);
167 buf->bs_gen = INT_GET(dic->di_gen, ARCH_CONVERT);
168 memset(buf->bs_pad, 0, sizeof(buf->bs_pad));
169 buf->bs_dmevmask = INT_GET(dic->di_dmevmask, ARCH_CONVERT);
170 buf->bs_dmstate = INT_GET(dic->di_dmstate, ARCH_CONVERT);
171 buf->bs_aextents = INT_GET(dic->di_anextents, ARCH_CONVERT);
173 switch (INT_GET(dic->di_format, ARCH_CONVERT)) {
174 case XFS_DINODE_FMT_DEV:
175 buf->bs_rdev = INT_GET(dip->di_u.di_dev, ARCH_CONVERT);
176 buf->bs_blksize = BLKDEV_IOSIZE;
179 case XFS_DINODE_FMT_LOCAL:
180 case XFS_DINODE_FMT_UUID:
182 buf->bs_blksize = mp->m_sb.sb_blocksize;
185 case XFS_DINODE_FMT_EXTENTS:
186 case XFS_DINODE_FMT_BTREE:
188 buf->bs_blksize = mp->m_sb.sb_blocksize;
189 buf->bs_blocks = INT_GET(dic->di_nblocks, ARCH_CONVERT);
197 * Return stat information for one inode.
198 * Return 0 if ok, else errno.
200 int /* error status */
202 xfs_mount_t *mp, /* mount point for filesystem */
203 xfs_ino_t ino, /* inode number to get data for */
204 void __user *buffer, /* buffer to place output in */
205 int ubsize, /* size of buffer */
206 void *private_data, /* my private data */
207 xfs_daddr_t bno, /* starting bno of inode cluster */
208 int *ubused, /* bytes used by me */
209 void *dibuff, /* on-disk inode buffer */
210 int *stat) /* BULKSTAT_RV_... */
212 xfs_bstat_t *buf; /* return buffer */
213 int error = 0; /* error value */
214 xfs_dinode_t *dip; /* dinode inode pointer */
216 dip = (xfs_dinode_t *)dibuff;
218 if (!buffer || ino == mp->m_sb.sb_rbmino || ino == mp->m_sb.sb_rsumino ||
219 (XFS_SB_VERSION_HASQUOTA(&mp->m_sb) &&
220 (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino))) {
221 *stat = BULKSTAT_RV_NOTHING;
222 return XFS_ERROR(EINVAL);
224 if (ubsize < sizeof(*buf)) {
225 *stat = BULKSTAT_RV_NOTHING;
226 return XFS_ERROR(ENOMEM);
229 buf = kmem_alloc(sizeof(*buf), KM_SLEEP);
232 /* We're not being passed a pointer to a dinode. This happens
233 * if BULKSTAT_FG_IGET is selected. Do the iget.
235 error = xfs_bulkstat_one_iget(mp, ino, bno, buf, stat);
239 xfs_bulkstat_one_dinode(mp, ino, dip, buf);
242 if (copy_to_user(buffer, buf, sizeof(*buf))) {
243 *stat = BULKSTAT_RV_NOTHING;
248 *stat = BULKSTAT_RV_DIDONE;
250 *ubused = sizeof(*buf);
253 kmem_free(buf, sizeof(*buf));
258 * Return stat information in bulk (by-inode) for the filesystem.
260 int /* error status */
262 xfs_mount_t *mp, /* mount point for filesystem */
263 xfs_ino_t *lastinop, /* last inode returned */
264 int *ubcountp, /* size of buffer/count returned */
265 bulkstat_one_pf formatter, /* func that'd fill a single buf */
266 void *private_data,/* private data for formatter */
267 size_t statstruct_size, /* sizeof struct filling */
268 char __user *ubuffer, /* buffer with inode stats */
269 int flags, /* defined in xfs_itable.h */
270 int *done) /* 1 if there are more stats to get */
272 xfs_agblock_t agbno=0;/* allocation group block number */
273 xfs_buf_t *agbp; /* agi header buffer */
274 xfs_agi_t *agi; /* agi header data */
275 xfs_agino_t agino; /* inode # in allocation group */
276 xfs_agnumber_t agno; /* allocation group number */
277 xfs_daddr_t bno; /* inode cluster start daddr */
278 int chunkidx; /* current index into inode chunk */
279 int clustidx; /* current index into inode cluster */
280 xfs_btree_cur_t *cur; /* btree cursor for ialloc btree */
281 int end_of_ag; /* set if we've seen the ag end */
282 int error; /* error code */
283 int fmterror;/* bulkstat formatter result */
284 __int32_t gcnt; /* current btree rec's count */
285 xfs_inofree_t gfree; /* current btree rec's free mask */
286 xfs_agino_t gino; /* current btree rec's start inode */
287 int i; /* loop index */
288 int icount; /* count of inodes good in irbuf */
289 xfs_ino_t ino; /* inode number (filesystem) */
290 xfs_inobt_rec_t *irbp; /* current irec buffer pointer */
291 xfs_inobt_rec_t *irbuf; /* start of irec buffer */
292 xfs_inobt_rec_t *irbufend; /* end of good irec buffer entries */
293 xfs_ino_t lastino=0; /* last inode number returned */
294 int nbcluster; /* # of blocks in a cluster */
295 int nicluster; /* # of inodes in a cluster */
296 int nimask; /* mask for inode clusters */
297 int nirbuf; /* size of irbuf */
298 int rval; /* return value error code */
299 int tmp; /* result value from btree calls */
300 int ubcount; /* size of user's buffer */
301 int ubleft; /* bytes left in user's buffer */
302 char __user *ubufp; /* pointer into user's buffer */
303 int ubelem; /* spaces used in user's buffer */
304 int ubused; /* bytes used by formatter */
305 xfs_buf_t *bp; /* ptr to on-disk inode cluster buf */
306 xfs_dinode_t *dip; /* ptr into bp for specific inode */
307 xfs_inode_t *ip; /* ptr to in-core inode struct */
310 * Get the last inode value, see if there's nothing to do.
312 ino = (xfs_ino_t)*lastinop;
314 agno = XFS_INO_TO_AGNO(mp, ino);
315 agino = XFS_INO_TO_AGINO(mp, ino);
316 if (agno >= mp->m_sb.sb_agcount ||
317 ino != XFS_AGINO_TO_INO(mp, agno, agino)) {
322 ubcount = *ubcountp; /* statstruct's */
323 ubleft = ubcount * statstruct_size; /* bytes */
324 *ubcountp = ubelem = 0;
328 nicluster = mp->m_sb.sb_blocksize >= XFS_INODE_CLUSTER_SIZE(mp) ?
329 mp->m_sb.sb_inopblock :
330 (XFS_INODE_CLUSTER_SIZE(mp) >> mp->m_sb.sb_inodelog);
331 nimask = ~(nicluster - 1);
332 nbcluster = nicluster >> mp->m_sb.sb_inopblog;
334 * Allocate a page-sized buffer for inode btree records.
335 * We could try allocating something smaller, but for normal
336 * calls we'll always (potentially) need the whole page.
338 irbuf = kmem_alloc(NBPC, KM_SLEEP);
339 nirbuf = NBPC / sizeof(*irbuf);
341 * Loop over the allocation groups, starting from the last
342 * inode returned; 0 means start of the allocation group.
345 while (ubleft >= statstruct_size && agno < mp->m_sb.sb_agcount) {
347 down_read(&mp->m_peraglock);
348 error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);
349 up_read(&mp->m_peraglock);
352 * Skip this allocation group and go to the next one.
358 agi = XFS_BUF_TO_AGI(agbp);
360 * Allocate and initialize a btree cursor for ialloc btree.
362 cur = xfs_btree_init_cursor(mp, NULL, agbp, agno, XFS_BTNUM_INO,
363 (xfs_inode_t *)0, 0);
365 irbufend = irbuf + nirbuf;
368 * If we're returning in the middle of an allocation group,
369 * we need to get the remainder of the chunk we're in.
373 * Lookup the inode chunk that this inode lives in.
375 error = xfs_inobt_lookup_le(cur, agino, 0, 0, &tmp);
376 if (!error && /* no I/O error */
377 tmp && /* lookup succeeded */
378 /* got the record, should always work */
379 !(error = xfs_inobt_get_rec(cur, &gino, &gcnt,
382 /* this is the right chunk */
383 agino < gino + XFS_INODES_PER_CHUNK &&
384 /* lastino was not last in chunk */
385 (chunkidx = agino - gino + 1) <
386 XFS_INODES_PER_CHUNK &&
387 /* there are some left allocated */
388 XFS_INOBT_MASKN(chunkidx,
389 XFS_INODES_PER_CHUNK - chunkidx) & ~gfree) {
391 * Grab the chunk record. Mark all the
392 * uninteresting inodes (because they're
393 * before our start point) free.
395 for (i = 0; i < chunkidx; i++) {
396 if (XFS_INOBT_MASK(i) & ~gfree)
399 gfree |= XFS_INOBT_MASKN(0, chunkidx);
400 INT_SET(irbp->ir_startino, ARCH_CONVERT, gino);
401 INT_SET(irbp->ir_freecount, ARCH_CONVERT, gcnt);
402 INT_SET(irbp->ir_free, ARCH_CONVERT, gfree);
404 agino = gino + XFS_INODES_PER_CHUNK;
405 icount = XFS_INODES_PER_CHUNK - gcnt;
408 * If any of those tests failed, bump the
409 * inode number (just in case).
415 * In any case, increment to the next record.
418 error = xfs_inobt_increment(cur, 0, &tmp);
421 * Start of ag. Lookup the first inode chunk.
423 error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &tmp);
427 * Loop through inode btree records in this ag,
428 * until we run out of inodes or space in the buffer.
430 while (irbp < irbufend && icount < ubcount) {
432 * Loop as long as we're unable to read the
436 agino += XFS_INODES_PER_CHUNK;
437 if (XFS_AGINO_TO_AGBNO(mp, agino) >=
438 be32_to_cpu(agi->agi_length))
440 error = xfs_inobt_lookup_ge(cur, agino, 0, 0,
444 * If ran off the end of the ag either with an error,
445 * or the normal way, set end and stop collecting.
448 (error = xfs_inobt_get_rec(cur, &gino, &gcnt,
455 * If this chunk has any allocated inodes, save it.
457 if (gcnt < XFS_INODES_PER_CHUNK) {
458 INT_SET(irbp->ir_startino, ARCH_CONVERT, gino);
459 INT_SET(irbp->ir_freecount, ARCH_CONVERT, gcnt);
460 INT_SET(irbp->ir_free, ARCH_CONVERT, gfree);
462 icount += XFS_INODES_PER_CHUNK - gcnt;
465 * Set agino to after this chunk and bump the cursor.
467 agino = gino + XFS_INODES_PER_CHUNK;
468 error = xfs_inobt_increment(cur, 0, &tmp);
471 * Drop the btree buffers and the agi buffer.
472 * We can't hold any of the locks these represent
475 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
478 * Now format all the good inodes into the user's buffer.
482 irbp < irbufend && ubleft >= statstruct_size; irbp++) {
484 * Read-ahead the next chunk's worth of inodes.
486 if (&irbp[1] < irbufend) {
488 * Loop over all clusters in the next chunk.
489 * Do a readahead if there are any allocated
490 * inodes in that cluster.
492 for (agbno = XFS_AGINO_TO_AGBNO(mp,
493 INT_GET(irbp[1].ir_startino, ARCH_CONVERT)),
495 chunkidx < XFS_INODES_PER_CHUNK;
496 chunkidx += nicluster,
497 agbno += nbcluster) {
498 if (XFS_INOBT_MASKN(chunkidx,
500 ~(INT_GET(irbp[1].ir_free, ARCH_CONVERT)))
501 xfs_btree_reada_bufs(mp, agno,
506 * Now process this chunk of inodes.
508 for (agino = INT_GET(irbp->ir_startino, ARCH_CONVERT), chunkidx = 0, clustidx = 0;
510 INT_GET(irbp->ir_freecount, ARCH_CONVERT) < XFS_INODES_PER_CHUNK;
511 chunkidx++, clustidx++, agino++) {
512 ASSERT(chunkidx < XFS_INODES_PER_CHUNK);
514 * Recompute agbno if this is the
515 * first inode of the cluster.
517 * Careful with clustidx. There can be
518 * multple clusters per chunk, a single
519 * cluster per chunk or a cluster that has
520 * inodes represented from several different
521 * chunks (if blocksize is large).
523 * Because of this, the starting clustidx is
524 * initialized to zero in this loop but must
525 * later be reset after reading in the cluster
528 if ((chunkidx & (nicluster - 1)) == 0) {
529 agbno = XFS_AGINO_TO_AGBNO(mp,
530 INT_GET(irbp->ir_startino, ARCH_CONVERT)) +
531 ((chunkidx & nimask) >>
532 mp->m_sb.sb_inopblog);
534 if (flags & BULKSTAT_FG_QUICK) {
535 ino = XFS_AGINO_TO_INO(mp, agno,
537 bno = XFS_AGB_TO_DADDR(mp, agno,
541 * Get the inode cluster buffer
543 ASSERT(xfs_inode_zone != NULL);
544 ip = kmem_zone_zalloc(xfs_inode_zone,
550 error = xfs_itobp(mp, NULL, ip,
554 clustidx = ip->i_boffset / mp->m_sb.sb_inodesize;
555 kmem_zone_free(xfs_inode_zone, ip);
556 if (XFS_TEST_ERROR(error != 0,
557 mp, XFS_ERRTAG_BULKSTAT_READ_CHUNK,
558 XFS_RANDOM_BULKSTAT_READ_CHUNK)) {
567 * Skip if this inode is free.
569 if (XFS_INOBT_MASK(chunkidx) & INT_GET(irbp->ir_free, ARCH_CONVERT))
572 * Count used inodes as free so we can tell
573 * when the chunk is used up.
575 INT_MOD(irbp->ir_freecount, ARCH_CONVERT, +1);
576 ino = XFS_AGINO_TO_INO(mp, agno, agino);
577 bno = XFS_AGB_TO_DADDR(mp, agno, agbno);
578 if (flags & BULKSTAT_FG_QUICK) {
579 dip = (xfs_dinode_t *)xfs_buf_offset(bp,
580 (clustidx << mp->m_sb.sb_inodelog));
582 if (INT_GET(dip->di_core.di_magic, ARCH_CONVERT)
584 || !XFS_DINODE_GOOD_VERSION(
585 INT_GET(dip->di_core.di_version, ARCH_CONVERT)))
590 * Get the inode and fill in a single buffer.
591 * BULKSTAT_FG_QUICK uses dip to fill it in.
592 * BULKSTAT_FG_IGET uses igets.
593 * See: xfs_bulkstat_one & xfs_dm_bulkstat_one.
594 * This is also used to count inodes/blks, etc
595 * in xfs_qm_quotacheck.
597 ubused = statstruct_size;
598 error = formatter(mp, ino, ubufp,
599 ubleft, private_data,
600 bno, &ubused, dip, &fmterror);
601 if (fmterror == BULKSTAT_RV_NOTHING) {
606 if (fmterror == BULKSTAT_RV_GIVEUP) {
624 * Set up for the next loop iteration.
631 agino = XFS_INO_TO_AGINO(mp, lastino);
636 * Done, we're either out of filesystem or space to put the data.
638 kmem_free(irbuf, NBPC);
640 if (agno >= mp->m_sb.sb_agcount) {
642 * If we ran out of filesystem, mark lastino as off
643 * the end of the filesystem, so the next call
644 * will return immediately.
646 *lastinop = (xfs_ino_t)XFS_AGINO_TO_INO(mp, agno, 0);
649 *lastinop = (xfs_ino_t)lastino;
655 * Return stat information in bulk (by-inode) for the filesystem.
656 * Special case for non-sequential one inode bulkstat.
658 int /* error status */
660 xfs_mount_t *mp, /* mount point for filesystem */
661 xfs_ino_t *lastinop, /* inode to return */
662 char __user *buffer, /* buffer with inode stats */
663 int *done) /* 1 if there are more stats to get */
665 int count; /* count value for bulkstat call */
666 int error; /* return value */
667 xfs_ino_t ino; /* filesystem inode number */
668 int res; /* result from bs1 */
671 * note that requesting valid inode numbers which are not allocated
672 * to inodes will most likely cause xfs_itobp to generate warning
673 * messages about bad magic numbers. This is ok. The fact that
674 * the inode isn't actually an inode is handled by the
675 * error check below. Done this way to make the usual case faster
676 * at the expense of the error case.
679 ino = (xfs_ino_t)*lastinop;
680 error = xfs_bulkstat_one(mp, ino, buffer, sizeof(xfs_bstat_t),
681 NULL, 0, NULL, NULL, &res);
684 * Special case way failed, do it the "long" way
685 * to see if that works.
689 if (xfs_bulkstat(mp, lastinop, &count, xfs_bulkstat_one,
690 NULL, sizeof(xfs_bstat_t), buffer,
691 BULKSTAT_FG_IGET, done))
693 if (count == 0 || (xfs_ino_t)*lastinop != ino)
694 return error == EFSCORRUPTED ?
695 XFS_ERROR(EINVAL) : error;
704 * Return inode number table for the filesystem.
706 int /* error status */
708 xfs_mount_t *mp, /* mount point for filesystem */
709 xfs_ino_t *lastino, /* last inode returned */
710 int *count, /* size of buffer/count returned */
711 xfs_inogrp_t __user *ubuffer)/* buffer with inode descriptions */
717 xfs_inogrp_t *buffer;
719 xfs_btree_cur_t *cur;
729 ino = (xfs_ino_t)*lastino;
730 agno = XFS_INO_TO_AGNO(mp, ino);
731 agino = XFS_INO_TO_AGINO(mp, ino);
734 bcount = MIN(left, (int)(NBPP / sizeof(*buffer)));
735 buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP);
739 while (left > 0 && agno < mp->m_sb.sb_agcount) {
741 down_read(&mp->m_peraglock);
742 error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);
743 up_read(&mp->m_peraglock);
746 * If we can't read the AGI of this ag,
747 * then just skip to the next one.
755 cur = xfs_btree_init_cursor(mp, NULL, agbp, agno,
756 XFS_BTNUM_INO, (xfs_inode_t *)0, 0);
757 error = xfs_inobt_lookup_ge(cur, agino, 0, 0, &tmp);
759 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
764 * Move up the the last inode in the current
765 * chunk. The lookup_ge will always get
766 * us the first inode in the next chunk.
768 agino += XFS_INODES_PER_CHUNK - 1;
772 if ((error = xfs_inobt_get_rec(cur, &gino, &gcnt, &gfree,
777 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
783 agino = gino + XFS_INODES_PER_CHUNK - 1;
784 buffer[bufidx].xi_startino = XFS_AGINO_TO_INO(mp, agno, gino);
785 buffer[bufidx].xi_alloccount = XFS_INODES_PER_CHUNK - gcnt;
786 buffer[bufidx].xi_allocmask = ~gfree;
789 if (bufidx == bcount) {
790 if (copy_to_user(ubuffer, buffer,
791 bufidx * sizeof(*buffer))) {
792 error = XFS_ERROR(EFAULT);
800 error = xfs_inobt_increment(cur, 0, &tmp);
802 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
807 * The agino value has already been bumped.
808 * Just try to skip up to it.
810 agino += XFS_INODES_PER_CHUNK;
817 if (copy_to_user(ubuffer, buffer,
818 bufidx * sizeof(*buffer)))
819 error = XFS_ERROR(EFAULT);
823 *lastino = XFS_AGINO_TO_INO(mp, agno, agino);
825 kmem_free(buffer, bcount * sizeof(*buffer));
827 xfs_btree_del_cursor(cur, (error ? XFS_BTREE_ERROR :