2 * Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
34 #include "xfs_macros.h"
35 #include "xfs_types.h"
38 #include "xfs_trans.h"
42 #include "xfs_dmapi.h"
43 #include "xfs_mount.h"
45 #include "xfs_alloc_btree.h"
46 #include "xfs_bmap_btree.h"
47 #include "xfs_ialloc_btree.h"
48 #include "xfs_btree.h"
49 #include "xfs_attr_sf.h"
50 #include "xfs_dir_sf.h"
51 #include "xfs_dir2_sf.h"
52 #include "xfs_dinode.h"
53 #include "xfs_inode.h"
54 #include "xfs_ialloc.h"
55 #include "xfs_itable.h"
56 #include "xfs_error.h"
59 #define useracc(ubuffer, size, flags, foo) (0)
60 #define unuseracc(ubuffer, size, flags)
64 xfs_bulkstat_one_iget(
65 xfs_mount_t *mp, /* mount point for filesystem */
66 xfs_ino_t ino, /* inode number to get data for */
67 xfs_daddr_t bno, /* starting bno of inode cluster */
68 xfs_bstat_t *buf, /* return buffer */
69 int *stat) /* BULKSTAT_RV_... */
71 xfs_dinode_core_t *dic; /* dinode core info pointer */
72 xfs_inode_t *ip; /* incore inode pointer */
75 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, bno);
77 *stat = BULKSTAT_RV_NOTHING;
82 ASSERT(ip->i_blkno != (xfs_daddr_t)0);
83 if (ip->i_d.di_mode == 0) {
84 *stat = BULKSTAT_RV_NOTHING;
85 error = XFS_ERROR(ENOENT);
91 /* xfs_iget returns the following without needing
94 buf->bs_nlink = dic->di_nlink;
95 buf->bs_projid = dic->di_projid;
97 buf->bs_mode = dic->di_mode;
98 buf->bs_uid = dic->di_uid;
99 buf->bs_gid = dic->di_gid;
100 buf->bs_xid = dic->di_xid;
101 buf->bs_size = dic->di_size;
102 buf->bs_atime.tv_sec = dic->di_atime.t_sec;
103 buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
104 buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
105 buf->bs_mtime.tv_nsec = dic->di_mtime.t_nsec;
106 buf->bs_ctime.tv_sec = dic->di_ctime.t_sec;
107 buf->bs_ctime.tv_nsec = dic->di_ctime.t_nsec;
108 buf->bs_xflags = xfs_ip2xflags(ip);
109 buf->bs_extsize = dic->di_extsize << mp->m_sb.sb_blocklog;
110 buf->bs_extents = dic->di_nextents;
111 buf->bs_gen = dic->di_gen;
112 memset(buf->bs_pad, 0, sizeof(buf->bs_pad));
113 buf->bs_dmevmask = dic->di_dmevmask;
114 buf->bs_dmstate = dic->di_dmstate;
115 buf->bs_aextents = dic->di_anextents;
117 switch (dic->di_format) {
118 case XFS_DINODE_FMT_DEV:
119 buf->bs_rdev = ip->i_df.if_u2.if_rdev;
120 buf->bs_blksize = BLKDEV_IOSIZE;
123 case XFS_DINODE_FMT_LOCAL:
124 case XFS_DINODE_FMT_UUID:
126 buf->bs_blksize = mp->m_sb.sb_blocksize;
129 case XFS_DINODE_FMT_EXTENTS:
130 case XFS_DINODE_FMT_BTREE:
132 buf->bs_blksize = mp->m_sb.sb_blocksize;
133 buf->bs_blocks = dic->di_nblocks + ip->i_delayed_blks;
138 xfs_iput(ip, XFS_ILOCK_SHARED);
143 xfs_bulkstat_one_dinode(
144 xfs_mount_t *mp, /* mount point for filesystem */
145 xfs_ino_t ino, /* inode number to get data for */
146 xfs_dinode_t *dip, /* dinode inode pointer */
147 xfs_bstat_t *buf) /* return buffer */
149 xfs_dinode_core_t *dic; /* dinode core info pointer */
154 * The inode format changed when we moved the link count and
155 * made it 32 bits long. If this is an old format inode,
156 * convert it in memory to look like a new one. If it gets
157 * flushed to disk we will convert back before flushing or
158 * logging it. We zero out the new projid field and the old link
159 * count field. We'll handle clearing the pad field (the remains
160 * of the old uuid field) when we actually convert the inode to
161 * the new format. We don't change the version number so that we
162 * can distinguish this from a real new format inode.
164 if (INT_GET(dic->di_version, ARCH_CONVERT) == XFS_DINODE_VERSION_1) {
165 buf->bs_nlink = INT_GET(dic->di_onlink, ARCH_CONVERT);
168 buf->bs_nlink = INT_GET(dic->di_nlink, ARCH_CONVERT);
169 buf->bs_projid = INT_GET(dic->di_projid, ARCH_CONVERT);
173 buf->bs_mode = INT_GET(dic->di_mode, ARCH_CONVERT);
174 buf->bs_uid = INT_GET(dic->di_uid, ARCH_CONVERT);
175 buf->bs_gid = INT_GET(dic->di_gid, ARCH_CONVERT);
176 buf->bs_xid = INT_GET(dic->di_xid, ARCH_CONVERT);
177 buf->bs_size = INT_GET(dic->di_size, ARCH_CONVERT);
178 buf->bs_atime.tv_sec = INT_GET(dic->di_atime.t_sec, ARCH_CONVERT);
179 buf->bs_atime.tv_nsec = INT_GET(dic->di_atime.t_nsec, ARCH_CONVERT);
180 buf->bs_mtime.tv_sec = INT_GET(dic->di_mtime.t_sec, ARCH_CONVERT);
181 buf->bs_mtime.tv_nsec = INT_GET(dic->di_mtime.t_nsec, ARCH_CONVERT);
182 buf->bs_ctime.tv_sec = INT_GET(dic->di_ctime.t_sec, ARCH_CONVERT);
183 buf->bs_ctime.tv_nsec = INT_GET(dic->di_ctime.t_nsec, ARCH_CONVERT);
184 buf->bs_xflags = xfs_dic2xflags(dic);
185 buf->bs_extsize = INT_GET(dic->di_extsize, ARCH_CONVERT) << mp->m_sb.sb_blocklog;
186 buf->bs_extents = INT_GET(dic->di_nextents, ARCH_CONVERT);
187 buf->bs_gen = INT_GET(dic->di_gen, ARCH_CONVERT);
188 memset(buf->bs_pad, 0, sizeof(buf->bs_pad));
189 buf->bs_dmevmask = INT_GET(dic->di_dmevmask, ARCH_CONVERT);
190 buf->bs_dmstate = INT_GET(dic->di_dmstate, ARCH_CONVERT);
191 buf->bs_aextents = INT_GET(dic->di_anextents, ARCH_CONVERT);
193 switch (INT_GET(dic->di_format, ARCH_CONVERT)) {
194 case XFS_DINODE_FMT_DEV:
195 buf->bs_rdev = INT_GET(dip->di_u.di_dev, ARCH_CONVERT);
196 buf->bs_blksize = BLKDEV_IOSIZE;
199 case XFS_DINODE_FMT_LOCAL:
200 case XFS_DINODE_FMT_UUID:
202 buf->bs_blksize = mp->m_sb.sb_blocksize;
205 case XFS_DINODE_FMT_EXTENTS:
206 case XFS_DINODE_FMT_BTREE:
208 buf->bs_blksize = mp->m_sb.sb_blocksize;
209 buf->bs_blocks = INT_GET(dic->di_nblocks, ARCH_CONVERT);
217 * Return stat information for one inode.
218 * Return 0 if ok, else errno.
220 int /* error status */
222 xfs_mount_t *mp, /* mount point for filesystem */
223 xfs_ino_t ino, /* inode number to get data for */
224 void __user *buffer, /* buffer to place output in */
225 int ubsize, /* size of buffer */
226 void *private_data, /* my private data */
227 xfs_daddr_t bno, /* starting bno of inode cluster */
228 int *ubused, /* bytes used by me */
229 void *dibuff, /* on-disk inode buffer */
230 int *stat) /* BULKSTAT_RV_... */
232 xfs_bstat_t *buf; /* return buffer */
233 int error = 0; /* error value */
234 xfs_dinode_t *dip; /* dinode inode pointer */
236 dip = (xfs_dinode_t *)dibuff;
238 if (!buffer || ino == mp->m_sb.sb_rbmino || ino == mp->m_sb.sb_rsumino ||
239 (XFS_SB_VERSION_HASQUOTA(&mp->m_sb) &&
240 (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino))) {
241 *stat = BULKSTAT_RV_NOTHING;
242 return XFS_ERROR(EINVAL);
244 if (ubsize < sizeof(*buf)) {
245 *stat = BULKSTAT_RV_NOTHING;
246 return XFS_ERROR(ENOMEM);
249 buf = kmem_alloc(sizeof(*buf), KM_SLEEP);
252 /* We're not being passed a pointer to a dinode. This happens
253 * if BULKSTAT_FG_IGET is selected. Do the iget.
255 error = xfs_bulkstat_one_iget(mp, ino, bno, buf, stat);
259 xfs_bulkstat_one_dinode(mp, ino, dip, buf);
262 if (copy_to_user(buffer, buf, sizeof(*buf))) {
263 *stat = BULKSTAT_RV_NOTHING;
268 *stat = BULKSTAT_RV_DIDONE;
270 *ubused = sizeof(*buf);
273 kmem_free(buf, sizeof(*buf));
278 * Return stat information in bulk (by-inode) for the filesystem.
280 int /* error status */
282 xfs_mount_t *mp, /* mount point for filesystem */
283 xfs_ino_t *lastinop, /* last inode returned */
284 int *ubcountp, /* size of buffer/count returned */
285 bulkstat_one_pf formatter, /* func that'd fill a single buf */
286 void *private_data,/* private data for formatter */
287 size_t statstruct_size, /* sizeof struct filling */
288 char __user *ubuffer, /* buffer with inode stats */
289 int flags, /* defined in xfs_itable.h */
290 int *done) /* 1 if there're more stats to get */
292 xfs_agblock_t agbno=0;/* allocation group block number */
293 xfs_buf_t *agbp; /* agi header buffer */
294 xfs_agi_t *agi; /* agi header data */
295 xfs_agino_t agino; /* inode # in allocation group */
296 xfs_agnumber_t agno; /* allocation group number */
297 xfs_daddr_t bno; /* inode cluster start daddr */
298 int chunkidx; /* current index into inode chunk */
299 int clustidx; /* current index into inode cluster */
300 xfs_btree_cur_t *cur; /* btree cursor for ialloc btree */
301 int end_of_ag; /* set if we've seen the ag end */
302 int error; /* error code */
303 int fmterror;/* bulkstat formatter result */
304 __int32_t gcnt; /* current btree rec's count */
305 xfs_inofree_t gfree; /* current btree rec's free mask */
306 xfs_agino_t gino; /* current btree rec's start inode */
307 int i; /* loop index */
308 int icount; /* count of inodes good in irbuf */
309 xfs_ino_t ino; /* inode number (filesystem) */
310 xfs_inobt_rec_t *irbp; /* current irec buffer pointer */
311 xfs_inobt_rec_t *irbuf; /* start of irec buffer */
312 xfs_inobt_rec_t *irbufend; /* end of good irec buffer entries */
313 xfs_ino_t lastino=0; /* last inode number returned */
314 int nbcluster; /* # of blocks in a cluster */
315 int nicluster; /* # of inodes in a cluster */
316 int nimask; /* mask for inode clusters */
317 int nirbuf; /* size of irbuf */
318 int rval; /* return value error code */
319 int tmp; /* result value from btree calls */
320 int ubcount; /* size of user's buffer */
321 int ubleft; /* bytes left in user's buffer */
322 char __user *ubufp; /* pointer into user's buffer */
323 int ubelem; /* spaces used in user's buffer */
324 int ubused; /* bytes used by formatter */
325 xfs_buf_t *bp; /* ptr to on-disk inode cluster buf */
326 xfs_dinode_t *dip; /* ptr into bp for specific inode */
327 xfs_inode_t *ip; /* ptr to in-core inode struct */
330 * Get the last inode value, see if there's nothing to do.
332 ino = (xfs_ino_t)*lastinop;
334 agno = XFS_INO_TO_AGNO(mp, ino);
335 agino = XFS_INO_TO_AGINO(mp, ino);
336 if (agno >= mp->m_sb.sb_agcount ||
337 ino != XFS_AGINO_TO_INO(mp, agno, agino)) {
342 ubcount = *ubcountp; /* statstruct's */
343 ubleft = ubcount * statstruct_size; /* bytes */
344 *ubcountp = ubelem = 0;
348 nicluster = mp->m_sb.sb_blocksize >= XFS_INODE_CLUSTER_SIZE(mp) ?
349 mp->m_sb.sb_inopblock :
350 (XFS_INODE_CLUSTER_SIZE(mp) >> mp->m_sb.sb_inodelog);
351 nimask = ~(nicluster - 1);
352 nbcluster = nicluster >> mp->m_sb.sb_inopblog;
354 * Lock down the user's buffer. If a buffer was not sent, as in the case
355 * disk quota code calls here, we skip this.
358 (error = useracc(ubuffer, ubcount * statstruct_size,
359 (B_READ|B_PHYS), NULL))) {
363 * Allocate a page-sized buffer for inode btree records.
364 * We could try allocating something smaller, but for normal
365 * calls we'll always (potentially) need the whole page.
367 irbuf = kmem_alloc(NBPC, KM_SLEEP);
368 nirbuf = NBPC / sizeof(*irbuf);
370 * Loop over the allocation groups, starting from the last
371 * inode returned; 0 means start of the allocation group.
374 while (ubleft >= statstruct_size && agno < mp->m_sb.sb_agcount) {
376 down_read(&mp->m_peraglock);
377 error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);
378 up_read(&mp->m_peraglock);
381 * Skip this allocation group and go to the next one.
387 agi = XFS_BUF_TO_AGI(agbp);
389 * Allocate and initialize a btree cursor for ialloc btree.
391 cur = xfs_btree_init_cursor(mp, NULL, agbp, agno, XFS_BTNUM_INO,
392 (xfs_inode_t *)0, 0);
394 irbufend = irbuf + nirbuf;
397 * If we're returning in the middle of an allocation group,
398 * we need to get the remainder of the chunk we're in.
402 * Lookup the inode chunk that this inode lives in.
404 error = xfs_inobt_lookup_le(cur, agino, 0, 0, &tmp);
405 if (!error && /* no I/O error */
406 tmp && /* lookup succeeded */
407 /* got the record, should always work */
408 !(error = xfs_inobt_get_rec(cur, &gino, &gcnt,
411 /* this is the right chunk */
412 agino < gino + XFS_INODES_PER_CHUNK &&
413 /* lastino was not last in chunk */
414 (chunkidx = agino - gino + 1) <
415 XFS_INODES_PER_CHUNK &&
416 /* there are some left allocated */
417 XFS_INOBT_MASKN(chunkidx,
418 XFS_INODES_PER_CHUNK - chunkidx) & ~gfree) {
420 * Grab the chunk record. Mark all the
421 * uninteresting inodes (because they're
422 * before our start point) free.
424 for (i = 0; i < chunkidx; i++) {
425 if (XFS_INOBT_MASK(i) & ~gfree)
428 gfree |= XFS_INOBT_MASKN(0, chunkidx);
429 INT_SET(irbp->ir_startino, ARCH_CONVERT, gino);
430 INT_SET(irbp->ir_freecount, ARCH_CONVERT, gcnt);
431 INT_SET(irbp->ir_free, ARCH_CONVERT, gfree);
433 agino = gino + XFS_INODES_PER_CHUNK;
434 icount = XFS_INODES_PER_CHUNK - gcnt;
437 * If any of those tests failed, bump the
438 * inode number (just in case).
444 * In any case, increment to the next record.
447 error = xfs_inobt_increment(cur, 0, &tmp);
450 * Start of ag. Lookup the first inode chunk.
452 error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &tmp);
456 * Loop through inode btree records in this ag,
457 * until we run out of inodes or space in the buffer.
459 while (irbp < irbufend && icount < ubcount) {
461 * Loop as long as we're unable to read the
465 agino += XFS_INODES_PER_CHUNK;
466 if (XFS_AGINO_TO_AGBNO(mp, agino) >=
467 INT_GET(agi->agi_length, ARCH_CONVERT))
469 error = xfs_inobt_lookup_ge(cur, agino, 0, 0,
473 * If ran off the end of the ag either with an error,
474 * or the normal way, set end and stop collecting.
477 (error = xfs_inobt_get_rec(cur, &gino, &gcnt,
484 * If this chunk has any allocated inodes, save it.
486 if (gcnt < XFS_INODES_PER_CHUNK) {
487 INT_SET(irbp->ir_startino, ARCH_CONVERT, gino);
488 INT_SET(irbp->ir_freecount, ARCH_CONVERT, gcnt);
489 INT_SET(irbp->ir_free, ARCH_CONVERT, gfree);
491 icount += XFS_INODES_PER_CHUNK - gcnt;
494 * Set agino to after this chunk and bump the cursor.
496 agino = gino + XFS_INODES_PER_CHUNK;
497 error = xfs_inobt_increment(cur, 0, &tmp);
500 * Drop the btree buffers and the agi buffer.
501 * We can't hold any of the locks these represent
504 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
507 * Now format all the good inodes into the user's buffer.
511 irbp < irbufend && ubleft >= statstruct_size; irbp++) {
513 * Read-ahead the next chunk's worth of inodes.
515 if (&irbp[1] < irbufend) {
517 * Loop over all clusters in the next chunk.
518 * Do a readahead if there are any allocated
519 * inodes in that cluster.
521 for (agbno = XFS_AGINO_TO_AGBNO(mp,
522 INT_GET(irbp[1].ir_startino, ARCH_CONVERT)),
524 chunkidx < XFS_INODES_PER_CHUNK;
525 chunkidx += nicluster,
526 agbno += nbcluster) {
527 if (XFS_INOBT_MASKN(chunkidx,
529 ~(INT_GET(irbp[1].ir_free, ARCH_CONVERT)))
530 xfs_btree_reada_bufs(mp, agno,
535 * Now process this chunk of inodes.
537 for (agino = INT_GET(irbp->ir_startino, ARCH_CONVERT), chunkidx = 0, clustidx = 0;
539 INT_GET(irbp->ir_freecount, ARCH_CONVERT) < XFS_INODES_PER_CHUNK;
540 chunkidx++, clustidx++, agino++) {
541 ASSERT(chunkidx < XFS_INODES_PER_CHUNK);
543 * Recompute agbno if this is the
544 * first inode of the cluster.
546 * Careful with clustidx. There can be
547 * multple clusters per chunk, a single
548 * cluster per chunk or a cluster that has
549 * inodes represented from several different
550 * chunks (if blocksize is large).
552 * Because of this, the starting clustidx is
553 * initialized to zero in this loop but must
554 * later be reset after reading in the cluster
557 if ((chunkidx & (nicluster - 1)) == 0) {
558 agbno = XFS_AGINO_TO_AGBNO(mp,
559 INT_GET(irbp->ir_startino, ARCH_CONVERT)) +
560 ((chunkidx & nimask) >>
561 mp->m_sb.sb_inopblog);
563 if (flags & BULKSTAT_FG_QUICK) {
564 ino = XFS_AGINO_TO_INO(mp, agno,
566 bno = XFS_AGB_TO_DADDR(mp, agno,
570 * Get the inode cluster buffer
572 ASSERT(xfs_inode_zone != NULL);
573 ip = kmem_zone_zalloc(xfs_inode_zone,
579 error = xfs_itobp(mp, NULL, ip,
582 clustidx = ip->i_boffset / mp->m_sb.sb_inodesize;
583 kmem_zone_free(xfs_inode_zone, ip);
584 if (XFS_TEST_ERROR(error != 0,
585 mp, XFS_ERRTAG_BULKSTAT_READ_CHUNK,
586 XFS_RANDOM_BULKSTAT_READ_CHUNK)) {
593 * Skip if this inode is free.
595 if (XFS_INOBT_MASK(chunkidx) & INT_GET(irbp->ir_free, ARCH_CONVERT))
598 * Count used inodes as free so we can tell
599 * when the chunk is used up.
601 INT_MOD(irbp->ir_freecount, ARCH_CONVERT, +1);
602 ino = XFS_AGINO_TO_INO(mp, agno, agino);
603 bno = XFS_AGB_TO_DADDR(mp, agno, agbno);
604 if (flags & BULKSTAT_FG_QUICK) {
605 dip = (xfs_dinode_t *)xfs_buf_offset(bp,
606 (clustidx << mp->m_sb.sb_inodelog));
608 if (INT_GET(dip->di_core.di_magic, ARCH_CONVERT)
610 || !XFS_DINODE_GOOD_VERSION(
611 INT_GET(dip->di_core.di_version, ARCH_CONVERT)))
616 * Get the inode and fill in a single buffer.
617 * BULKSTAT_FG_QUICK uses dip to fill it in.
618 * BULKSTAT_FG_IGET uses igets.
619 * See: xfs_bulkstat_one & xfs_dm_bulkstat_one.
620 * This is also used to count inodes/blks, etc
621 * in xfs_qm_quotacheck.
623 ubused = statstruct_size;
624 error = formatter(mp, ino, ubufp,
625 ubleft, private_data,
626 bno, &ubused, dip, &fmterror);
627 if (fmterror == BULKSTAT_RV_NOTHING) {
632 if (fmterror == BULKSTAT_RV_GIVEUP) {
650 * Set up for the next loop iteration.
657 agino = XFS_INO_TO_AGINO(mp, lastino);
662 * Done, we're either out of filesystem or space to put the data.
664 kmem_free(irbuf, NBPC);
666 unuseracc(ubuffer, ubcount * statstruct_size, (B_READ|B_PHYS));
668 if (agno >= mp->m_sb.sb_agcount) {
670 * If we ran out of filesystem, mark lastino as off
671 * the end of the filesystem, so the next call
672 * will return immediately.
674 *lastinop = (xfs_ino_t)XFS_AGINO_TO_INO(mp, agno, 0);
677 *lastinop = (xfs_ino_t)lastino;
683 * Return stat information in bulk (by-inode) for the filesystem.
684 * Special case for non-sequential one inode bulkstat.
686 int /* error status */
688 xfs_mount_t *mp, /* mount point for filesystem */
689 xfs_ino_t *lastinop, /* inode to return */
690 char __user *buffer, /* buffer with inode stats */
691 int *done) /* 1 if there're more stats to get */
693 int count; /* count value for bulkstat call */
694 int error; /* return value */
695 xfs_ino_t ino; /* filesystem inode number */
696 int res; /* result from bs1 */
699 * note that requesting valid inode numbers which are not allocated
700 * to inodes will most likely cause xfs_itobp to generate warning
701 * messages about bad magic numbers. This is ok. The fact that
702 * the inode isn't actually an inode is handled by the
703 * error check below. Done this way to make the usual case faster
704 * at the expense of the error case.
707 ino = (xfs_ino_t)*lastinop;
708 error = xfs_bulkstat_one(mp, ino, buffer, sizeof(xfs_bstat_t),
709 NULL, 0, NULL, NULL, &res);
712 * Special case way failed, do it the "long" way
713 * to see if that works.
717 if (xfs_bulkstat(mp, lastinop, &count, xfs_bulkstat_one,
718 NULL, sizeof(xfs_bstat_t), buffer,
719 BULKSTAT_FG_IGET, done))
721 if (count == 0 || (xfs_ino_t)*lastinop != ino)
722 return error == EFSCORRUPTED ?
723 XFS_ERROR(EINVAL) : error;
732 * Return inode number table for the filesystem.
734 int /* error status */
736 xfs_mount_t *mp, /* mount point for filesystem */
737 xfs_ino_t *lastino, /* last inode returned */
738 int *count, /* size of buffer/count returned */
739 xfs_inogrp_t __user *ubuffer)/* buffer with inode descriptions */
745 xfs_inogrp_t *buffer;
747 xfs_btree_cur_t *cur;
757 ino = (xfs_ino_t)*lastino;
758 agno = XFS_INO_TO_AGNO(mp, ino);
759 agino = XFS_INO_TO_AGINO(mp, ino);
762 bcount = MIN(left, (int)(NBPP / sizeof(*buffer)));
763 buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP);
767 while (left > 0 && agno < mp->m_sb.sb_agcount) {
769 down_read(&mp->m_peraglock);
770 error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);
771 up_read(&mp->m_peraglock);
774 * If we can't read the AGI of this ag,
775 * then just skip to the next one.
783 cur = xfs_btree_init_cursor(mp, NULL, agbp, agno,
784 XFS_BTNUM_INO, (xfs_inode_t *)0, 0);
785 error = xfs_inobt_lookup_ge(cur, agino, 0, 0, &tmp);
787 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
792 * Move up the the last inode in the current
793 * chunk. The lookup_ge will always get
794 * us the first inode in the next chunk.
796 agino += XFS_INODES_PER_CHUNK - 1;
800 if ((error = xfs_inobt_get_rec(cur, &gino, &gcnt, &gfree,
805 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
811 agino = gino + XFS_INODES_PER_CHUNK - 1;
812 buffer[bufidx].xi_startino = XFS_AGINO_TO_INO(mp, agno, gino);
813 buffer[bufidx].xi_alloccount = XFS_INODES_PER_CHUNK - gcnt;
814 buffer[bufidx].xi_allocmask = ~gfree;
817 if (bufidx == bcount) {
818 if (copy_to_user(ubuffer, buffer,
819 bufidx * sizeof(*buffer))) {
820 error = XFS_ERROR(EFAULT);
828 error = xfs_inobt_increment(cur, 0, &tmp);
830 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
835 * The agino value has already been bumped.
836 * Just try to skip up to it.
838 agino += XFS_INODES_PER_CHUNK;
845 if (copy_to_user(ubuffer, buffer,
846 bufidx * sizeof(*buffer)))
847 error = XFS_ERROR(EFAULT);
851 *lastino = XFS_AGINO_TO_INO(mp, agno, agino);
853 kmem_free(buffer, bcount * sizeof(*buffer));
855 xfs_btree_del_cursor(cur, (error ? XFS_BTREE_ERROR :