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"
47 return (ino == mp->m_sb.sb_rbmino || ino == mp->m_sb.sb_rsumino ||
48 (XFS_SB_VERSION_HASQUOTA(&mp->m_sb) &&
49 (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino)));
53 xfs_bulkstat_one_iget(
54 xfs_mount_t *mp, /* mount point for filesystem */
55 xfs_ino_t ino, /* inode number to get data for */
56 xfs_daddr_t bno, /* starting bno of inode cluster */
57 xfs_bstat_t *buf, /* return buffer */
58 int *stat) /* BULKSTAT_RV_... */
60 xfs_dinode_core_t *dic; /* dinode core info pointer */
61 xfs_inode_t *ip; /* incore inode pointer */
65 error = xfs_iget(mp, NULL, ino,
66 XFS_IGET_BULKSTAT, XFS_ILOCK_SHARED, &ip, bno);
68 *stat = BULKSTAT_RV_NOTHING;
73 ASSERT(ip->i_blkno != (xfs_daddr_t)0);
74 if (ip->i_d.di_mode == 0) {
75 *stat = BULKSTAT_RV_NOTHING;
76 error = XFS_ERROR(ENOENT);
83 /* xfs_iget returns the following without needing
86 buf->bs_nlink = dic->di_nlink;
87 buf->bs_projid = dic->di_projid;
89 buf->bs_mode = dic->di_mode;
90 buf->bs_uid = dic->di_uid;
91 buf->bs_gid = dic->di_gid;
92 buf->bs_tag = dic->di_tag;
93 buf->bs_size = dic->di_size;
94 vn_atime_to_bstime(vp, &buf->bs_atime);
95 buf->bs_mtime.tv_sec = dic->di_mtime.t_sec;
96 buf->bs_mtime.tv_nsec = dic->di_mtime.t_nsec;
97 buf->bs_ctime.tv_sec = dic->di_ctime.t_sec;
98 buf->bs_ctime.tv_nsec = dic->di_ctime.t_nsec;
99 buf->bs_xflags = xfs_ip2xflags(ip);
100 buf->bs_extsize = dic->di_extsize << mp->m_sb.sb_blocklog;
101 buf->bs_extents = dic->di_nextents;
102 buf->bs_gen = dic->di_gen;
103 memset(buf->bs_pad, 0, sizeof(buf->bs_pad));
104 buf->bs_dmevmask = dic->di_dmevmask;
105 buf->bs_dmstate = dic->di_dmstate;
106 buf->bs_aextents = dic->di_anextents;
108 switch (dic->di_format) {
109 case XFS_DINODE_FMT_DEV:
110 buf->bs_rdev = ip->i_df.if_u2.if_rdev;
111 buf->bs_blksize = BLKDEV_IOSIZE;
114 case XFS_DINODE_FMT_LOCAL:
115 case XFS_DINODE_FMT_UUID:
117 buf->bs_blksize = mp->m_sb.sb_blocksize;
120 case XFS_DINODE_FMT_EXTENTS:
121 case XFS_DINODE_FMT_BTREE:
123 buf->bs_blksize = mp->m_sb.sb_blocksize;
124 buf->bs_blocks = dic->di_nblocks + ip->i_delayed_blks;
129 xfs_iput(ip, XFS_ILOCK_SHARED);
134 xfs_bulkstat_one_dinode(
135 xfs_mount_t *mp, /* mount point for filesystem */
136 xfs_ino_t ino, /* inode number to get data for */
137 xfs_dinode_t *dip, /* dinode inode pointer */
138 xfs_bstat_t *buf) /* return buffer */
140 xfs_dinode_core_t *dic; /* dinode core info pointer */
145 * The inode format changed when we moved the link count and
146 * made it 32 bits long. If this is an old format inode,
147 * convert it in memory to look like a new one. If it gets
148 * flushed to disk we will convert back before flushing or
149 * logging it. We zero out the new projid field and the old link
150 * count field. We'll handle clearing the pad field (the remains
151 * of the old uuid field) when we actually convert the inode to
152 * the new format. We don't change the version number so that we
153 * can distinguish this from a real new format inode.
155 if (INT_GET(dic->di_version, ARCH_CONVERT) == XFS_DINODE_VERSION_1) {
156 buf->bs_nlink = INT_GET(dic->di_onlink, ARCH_CONVERT);
159 buf->bs_nlink = INT_GET(dic->di_nlink, ARCH_CONVERT);
160 buf->bs_projid = INT_GET(dic->di_projid, ARCH_CONVERT);
164 buf->bs_mode = INT_GET(dic->di_mode, ARCH_CONVERT);
165 buf->bs_uid = INT_GET(dic->di_uid, ARCH_CONVERT);
166 buf->bs_gid = INT_GET(dic->di_gid, ARCH_CONVERT);
167 buf->bs_tag = INT_GET(dic->di_tag, ARCH_CONVERT);
168 buf->bs_size = INT_GET(dic->di_size, ARCH_CONVERT);
169 buf->bs_atime.tv_sec = INT_GET(dic->di_atime.t_sec, ARCH_CONVERT);
170 buf->bs_atime.tv_nsec = INT_GET(dic->di_atime.t_nsec, ARCH_CONVERT);
171 buf->bs_mtime.tv_sec = INT_GET(dic->di_mtime.t_sec, ARCH_CONVERT);
172 buf->bs_mtime.tv_nsec = INT_GET(dic->di_mtime.t_nsec, ARCH_CONVERT);
173 buf->bs_ctime.tv_sec = INT_GET(dic->di_ctime.t_sec, ARCH_CONVERT);
174 buf->bs_ctime.tv_nsec = INT_GET(dic->di_ctime.t_nsec, ARCH_CONVERT);
175 buf->bs_xflags = xfs_dic2xflags(dic);
176 buf->bs_extsize = INT_GET(dic->di_extsize, ARCH_CONVERT) << mp->m_sb.sb_blocklog;
177 buf->bs_extents = INT_GET(dic->di_nextents, ARCH_CONVERT);
178 buf->bs_gen = INT_GET(dic->di_gen, ARCH_CONVERT);
179 memset(buf->bs_pad, 0, sizeof(buf->bs_pad));
180 buf->bs_dmevmask = INT_GET(dic->di_dmevmask, ARCH_CONVERT);
181 buf->bs_dmstate = INT_GET(dic->di_dmstate, ARCH_CONVERT);
182 buf->bs_aextents = INT_GET(dic->di_anextents, ARCH_CONVERT);
184 switch (INT_GET(dic->di_format, ARCH_CONVERT)) {
185 case XFS_DINODE_FMT_DEV:
186 buf->bs_rdev = INT_GET(dip->di_u.di_dev, ARCH_CONVERT);
187 buf->bs_blksize = BLKDEV_IOSIZE;
190 case XFS_DINODE_FMT_LOCAL:
191 case XFS_DINODE_FMT_UUID:
193 buf->bs_blksize = mp->m_sb.sb_blocksize;
196 case XFS_DINODE_FMT_EXTENTS:
197 case XFS_DINODE_FMT_BTREE:
199 buf->bs_blksize = mp->m_sb.sb_blocksize;
200 buf->bs_blocks = INT_GET(dic->di_nblocks, ARCH_CONVERT);
208 * Return stat information for one inode.
209 * Return 0 if ok, else errno.
211 int /* error status */
213 xfs_mount_t *mp, /* mount point for filesystem */
214 xfs_ino_t ino, /* inode number to get data for */
215 void __user *buffer, /* buffer to place output in */
216 int ubsize, /* size of buffer */
217 void *private_data, /* my private data */
218 xfs_daddr_t bno, /* starting bno of inode cluster */
219 int *ubused, /* bytes used by me */
220 void *dibuff, /* on-disk inode buffer */
221 int *stat) /* BULKSTAT_RV_... */
223 xfs_bstat_t *buf; /* return buffer */
224 int error = 0; /* error value */
225 xfs_dinode_t *dip; /* dinode inode pointer */
227 dip = (xfs_dinode_t *)dibuff;
228 *stat = BULKSTAT_RV_NOTHING;
230 if (!buffer || xfs_internal_inum(mp, ino))
231 return XFS_ERROR(EINVAL);
232 if (ubsize < sizeof(*buf))
233 return XFS_ERROR(ENOMEM);
235 buf = kmem_alloc(sizeof(*buf), KM_SLEEP);
238 /* We're not being passed a pointer to a dinode. This happens
239 * if BULKSTAT_FG_IGET is selected. Do the iget.
241 error = xfs_bulkstat_one_iget(mp, ino, bno, buf, stat);
245 xfs_bulkstat_one_dinode(mp, ino, dip, buf);
248 if (copy_to_user(buffer, buf, sizeof(*buf))) {
253 *stat = BULKSTAT_RV_DIDONE;
255 *ubused = sizeof(*buf);
258 kmem_free(buf, sizeof(*buf));
263 * Test to see whether we can use the ondisk inode directly, based
264 * on the given bulkstat flags, filling in dipp accordingly.
265 * Returns zero if the inode is dodgey.
268 xfs_bulkstat_use_dinode(
276 unsigned int aformat;
279 if (!bp || (flags & BULKSTAT_FG_IGET))
281 dip = (xfs_dinode_t *)
282 xfs_buf_offset(bp, clustidx << mp->m_sb.sb_inodelog);
283 if (INT_GET(dip->di_core.di_magic, ARCH_CONVERT) != XFS_DINODE_MAGIC ||
284 !XFS_DINODE_GOOD_VERSION(
285 INT_GET(dip->di_core.di_version, ARCH_CONVERT)))
287 if (flags & BULKSTAT_FG_QUICK) {
291 /* BULKSTAT_FG_INLINE: if attr fork is local, or not there, use it */
292 aformat = INT_GET(dip->di_core.di_aformat, ARCH_CONVERT);
293 if ((XFS_CFORK_Q(&dip->di_core) == 0) ||
294 (aformat == XFS_DINODE_FMT_LOCAL) ||
295 (aformat == XFS_DINODE_FMT_EXTENTS && !dip->di_core.di_anextents)) {
303 * Return stat information in bulk (by-inode) for the filesystem.
305 int /* error status */
307 xfs_mount_t *mp, /* mount point for filesystem */
308 xfs_ino_t *lastinop, /* last inode returned */
309 int *ubcountp, /* size of buffer/count returned */
310 bulkstat_one_pf formatter, /* func that'd fill a single buf */
311 void *private_data,/* private data for formatter */
312 size_t statstruct_size, /* sizeof struct filling */
313 char __user *ubuffer, /* buffer with inode stats */
314 int flags, /* defined in xfs_itable.h */
315 int *done) /* 1 if there are more stats to get */
317 xfs_agblock_t agbno=0;/* allocation group block number */
318 xfs_buf_t *agbp; /* agi header buffer */
319 xfs_agi_t *agi; /* agi header data */
320 xfs_agino_t agino; /* inode # in allocation group */
321 xfs_agnumber_t agno; /* allocation group number */
322 xfs_daddr_t bno; /* inode cluster start daddr */
323 int chunkidx; /* current index into inode chunk */
324 int clustidx; /* current index into inode cluster */
325 xfs_btree_cur_t *cur; /* btree cursor for ialloc btree */
326 int end_of_ag; /* set if we've seen the ag end */
327 int error; /* error code */
328 int fmterror;/* bulkstat formatter result */
329 __int32_t gcnt; /* current btree rec's count */
330 xfs_inofree_t gfree; /* current btree rec's free mask */
331 xfs_agino_t gino; /* current btree rec's start inode */
332 int i; /* loop index */
333 int icount; /* count of inodes good in irbuf */
334 size_t irbsize; /* size of irec buffer in bytes */
335 xfs_ino_t ino; /* inode number (filesystem) */
336 xfs_inobt_rec_incore_t *irbp; /* current irec buffer pointer */
337 xfs_inobt_rec_incore_t *irbuf; /* start of irec buffer */
338 xfs_inobt_rec_incore_t *irbufend; /* end of good irec buffer entries */
339 xfs_ino_t lastino=0; /* last inode number returned */
340 int nbcluster; /* # of blocks in a cluster */
341 int nicluster; /* # of inodes in a cluster */
342 int nimask; /* mask for inode clusters */
343 int nirbuf; /* size of irbuf */
344 int rval; /* return value error code */
345 int tmp; /* result value from btree calls */
346 int ubcount; /* size of user's buffer */
347 int ubleft; /* bytes left in user's buffer */
348 char __user *ubufp; /* pointer into user's buffer */
349 int ubelem; /* spaces used in user's buffer */
350 int ubused; /* bytes used by formatter */
351 xfs_buf_t *bp; /* ptr to on-disk inode cluster buf */
352 xfs_dinode_t *dip; /* ptr into bp for specific inode */
353 xfs_inode_t *ip; /* ptr to in-core inode struct */
356 * Get the last inode value, see if there's nothing to do.
358 ino = (xfs_ino_t)*lastinop;
360 agno = XFS_INO_TO_AGNO(mp, ino);
361 agino = XFS_INO_TO_AGINO(mp, ino);
362 if (agno >= mp->m_sb.sb_agcount ||
363 ino != XFS_AGINO_TO_INO(mp, agno, agino)) {
368 ubcount = *ubcountp; /* statstruct's */
369 ubleft = ubcount * statstruct_size; /* bytes */
370 *ubcountp = ubelem = 0;
374 nicluster = mp->m_sb.sb_blocksize >= XFS_INODE_CLUSTER_SIZE(mp) ?
375 mp->m_sb.sb_inopblock :
376 (XFS_INODE_CLUSTER_SIZE(mp) >> mp->m_sb.sb_inodelog);
377 nimask = ~(nicluster - 1);
378 nbcluster = nicluster >> mp->m_sb.sb_inopblog;
379 irbuf = kmem_zalloc_greedy(&irbsize, NBPC, NBPC * 4,
380 KM_SLEEP | KM_MAYFAIL | KM_LARGE);
381 nirbuf = irbsize / sizeof(*irbuf);
384 * Loop over the allocation groups, starting from the last
385 * inode returned; 0 means start of the allocation group.
388 while (ubleft >= statstruct_size && agno < mp->m_sb.sb_agcount) {
390 down_read(&mp->m_peraglock);
391 error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);
392 up_read(&mp->m_peraglock);
395 * Skip this allocation group and go to the next one.
401 agi = XFS_BUF_TO_AGI(agbp);
403 * Allocate and initialize a btree cursor for ialloc btree.
405 cur = xfs_btree_init_cursor(mp, NULL, agbp, agno, XFS_BTNUM_INO,
406 (xfs_inode_t *)0, 0);
408 irbufend = irbuf + nirbuf;
411 * If we're returning in the middle of an allocation group,
412 * we need to get the remainder of the chunk we're in.
416 * Lookup the inode chunk that this inode lives in.
418 error = xfs_inobt_lookup_le(cur, agino, 0, 0, &tmp);
419 if (!error && /* no I/O error */
420 tmp && /* lookup succeeded */
421 /* got the record, should always work */
422 !(error = xfs_inobt_get_rec(cur, &gino, &gcnt,
425 /* this is the right chunk */
426 agino < gino + XFS_INODES_PER_CHUNK &&
427 /* lastino was not last in chunk */
428 (chunkidx = agino - gino + 1) <
429 XFS_INODES_PER_CHUNK &&
430 /* there are some left allocated */
431 XFS_INOBT_MASKN(chunkidx,
432 XFS_INODES_PER_CHUNK - chunkidx) & ~gfree) {
434 * Grab the chunk record. Mark all the
435 * uninteresting inodes (because they're
436 * before our start point) free.
438 for (i = 0; i < chunkidx; i++) {
439 if (XFS_INOBT_MASK(i) & ~gfree)
442 gfree |= XFS_INOBT_MASKN(0, chunkidx);
443 irbp->ir_startino = gino;
444 irbp->ir_freecount = gcnt;
445 irbp->ir_free = gfree;
447 agino = gino + XFS_INODES_PER_CHUNK;
448 icount = XFS_INODES_PER_CHUNK - gcnt;
451 * If any of those tests failed, bump the
452 * inode number (just in case).
458 * In any case, increment to the next record.
461 error = xfs_inobt_increment(cur, 0, &tmp);
464 * Start of ag. Lookup the first inode chunk.
466 error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &tmp);
470 * Loop through inode btree records in this ag,
471 * until we run out of inodes or space in the buffer.
473 while (irbp < irbufend && icount < ubcount) {
475 * Loop as long as we're unable to read the
479 agino += XFS_INODES_PER_CHUNK;
480 if (XFS_AGINO_TO_AGBNO(mp, agino) >=
481 be32_to_cpu(agi->agi_length))
483 error = xfs_inobt_lookup_ge(cur, agino, 0, 0,
487 * If ran off the end of the ag either with an error,
488 * or the normal way, set end and stop collecting.
491 (error = xfs_inobt_get_rec(cur, &gino, &gcnt,
498 * If this chunk has any allocated inodes, save it.
499 * Also start read-ahead now for this chunk.
501 if (gcnt < XFS_INODES_PER_CHUNK) {
503 * Loop over all clusters in the next chunk.
504 * Do a readahead if there are any allocated
505 * inodes in that cluster.
507 for (agbno = XFS_AGINO_TO_AGBNO(mp, gino),
509 chunkidx < XFS_INODES_PER_CHUNK;
510 chunkidx += nicluster,
511 agbno += nbcluster) {
512 if (XFS_INOBT_MASKN(chunkidx,
514 xfs_btree_reada_bufs(mp, agno,
517 irbp->ir_startino = gino;
518 irbp->ir_freecount = gcnt;
519 irbp->ir_free = gfree;
521 icount += XFS_INODES_PER_CHUNK - gcnt;
524 * Set agino to after this chunk and bump the cursor.
526 agino = gino + XFS_INODES_PER_CHUNK;
527 error = xfs_inobt_increment(cur, 0, &tmp);
530 * Drop the btree buffers and the agi buffer.
531 * We can't hold any of the locks these represent
534 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
537 * Now format all the good inodes into the user's buffer.
541 irbp < irbufend && ubleft >= statstruct_size; irbp++) {
543 * Now process this chunk of inodes.
545 for (agino = irbp->ir_startino, chunkidx = clustidx = 0;
547 irbp->ir_freecount < XFS_INODES_PER_CHUNK;
548 chunkidx++, clustidx++, agino++) {
549 ASSERT(chunkidx < XFS_INODES_PER_CHUNK);
551 * Recompute agbno if this is the
552 * first inode of the cluster.
554 * Careful with clustidx. There can be
555 * multple clusters per chunk, a single
556 * cluster per chunk or a cluster that has
557 * inodes represented from several different
558 * chunks (if blocksize is large).
560 * Because of this, the starting clustidx is
561 * initialized to zero in this loop but must
562 * later be reset after reading in the cluster
565 if ((chunkidx & (nicluster - 1)) == 0) {
566 agbno = XFS_AGINO_TO_AGBNO(mp,
568 ((chunkidx & nimask) >>
569 mp->m_sb.sb_inopblog);
571 if (flags & (BULKSTAT_FG_QUICK |
572 BULKSTAT_FG_INLINE)) {
573 ino = XFS_AGINO_TO_INO(mp, agno,
575 bno = XFS_AGB_TO_DADDR(mp, agno,
579 * Get the inode cluster buffer
581 ASSERT(xfs_inode_zone != NULL);
582 ip = kmem_zone_zalloc(xfs_inode_zone,
586 spin_lock_init(&ip->i_flags_lock);
589 error = xfs_itobp(mp, NULL, ip,
593 clustidx = ip->i_boffset / mp->m_sb.sb_inodesize;
594 kmem_zone_free(xfs_inode_zone, ip);
595 if (XFS_TEST_ERROR(error != 0,
596 mp, XFS_ERRTAG_BULKSTAT_READ_CHUNK,
597 XFS_RANDOM_BULKSTAT_READ_CHUNK)) {
606 * Skip if this inode is free.
608 if (XFS_INOBT_MASK(chunkidx) & irbp->ir_free)
611 * Count used inodes as free so we can tell
612 * when the chunk is used up.
614 irbp->ir_freecount++;
615 ino = XFS_AGINO_TO_INO(mp, agno, agino);
616 bno = XFS_AGB_TO_DADDR(mp, agno, agbno);
617 if (!xfs_bulkstat_use_dinode(mp, flags, bp,
621 * If we need to do an iget, cannot hold bp.
622 * Drop it, until starting the next cluster.
624 if ((flags & BULKSTAT_FG_INLINE) && !dip) {
631 * Get the inode and fill in a single buffer.
632 * BULKSTAT_FG_QUICK uses dip to fill it in.
633 * BULKSTAT_FG_IGET uses igets.
634 * BULKSTAT_FG_INLINE uses dip if we have an
635 * inline attr fork, else igets.
636 * See: xfs_bulkstat_one & xfs_dm_bulkstat_one.
637 * This is also used to count inodes/blks, etc
638 * in xfs_qm_quotacheck.
640 ubused = statstruct_size;
641 error = formatter(mp, ino, ubufp,
642 ubleft, private_data,
643 bno, &ubused, dip, &fmterror);
644 if (fmterror == BULKSTAT_RV_NOTHING) {
645 if (error == EFAULT) {
650 else if (error == ENOMEM)
656 if (fmterror == BULKSTAT_RV_GIVEUP) {
674 * Set up for the next loop iteration.
681 agino = XFS_INO_TO_AGINO(mp, lastino);
686 * Done, we're either out of filesystem or space to put the data.
688 kmem_free(irbuf, irbsize);
690 if (agno >= mp->m_sb.sb_agcount) {
692 * If we ran out of filesystem, mark lastino as off
693 * the end of the filesystem, so the next call
694 * will return immediately.
696 *lastinop = (xfs_ino_t)XFS_AGINO_TO_INO(mp, agno, 0);
699 *lastinop = (xfs_ino_t)lastino;
705 * Return stat information in bulk (by-inode) for the filesystem.
706 * Special case for non-sequential one inode bulkstat.
708 int /* error status */
710 xfs_mount_t *mp, /* mount point for filesystem */
711 xfs_ino_t *lastinop, /* inode to return */
712 char __user *buffer, /* buffer with inode stats */
713 int *done) /* 1 if there are more stats to get */
715 int count; /* count value for bulkstat call */
716 int error; /* return value */
717 xfs_ino_t ino; /* filesystem inode number */
718 int res; /* result from bs1 */
721 * note that requesting valid inode numbers which are not allocated
722 * to inodes will most likely cause xfs_itobp to generate warning
723 * messages about bad magic numbers. This is ok. The fact that
724 * the inode isn't actually an inode is handled by the
725 * error check below. Done this way to make the usual case faster
726 * at the expense of the error case.
729 ino = (xfs_ino_t)*lastinop;
730 error = xfs_bulkstat_one(mp, ino, buffer, sizeof(xfs_bstat_t),
731 NULL, 0, NULL, NULL, &res);
734 * Special case way failed, do it the "long" way
735 * to see if that works.
739 if (xfs_bulkstat(mp, lastinop, &count, xfs_bulkstat_one,
740 NULL, sizeof(xfs_bstat_t), buffer,
741 BULKSTAT_FG_IGET, done))
743 if (count == 0 || (xfs_ino_t)*lastinop != ino)
744 return error == EFSCORRUPTED ?
745 XFS_ERROR(EINVAL) : error;
754 * Return inode number table for the filesystem.
756 int /* error status */
758 xfs_mount_t *mp, /* mount point for filesystem */
759 xfs_ino_t *lastino, /* last inode returned */
760 int *count, /* size of buffer/count returned */
761 xfs_inogrp_t __user *ubuffer)/* buffer with inode descriptions */
767 xfs_inogrp_t *buffer;
769 xfs_btree_cur_t *cur;
779 ino = (xfs_ino_t)*lastino;
780 agno = XFS_INO_TO_AGNO(mp, ino);
781 agino = XFS_INO_TO_AGINO(mp, ino);
784 bcount = MIN(left, (int)(NBPP / sizeof(*buffer)));
785 buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP);
789 while (left > 0 && agno < mp->m_sb.sb_agcount) {
791 down_read(&mp->m_peraglock);
792 error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);
793 up_read(&mp->m_peraglock);
796 * If we can't read the AGI of this ag,
797 * then just skip to the next one.
805 cur = xfs_btree_init_cursor(mp, NULL, agbp, agno,
806 XFS_BTNUM_INO, (xfs_inode_t *)0, 0);
807 error = xfs_inobt_lookup_ge(cur, agino, 0, 0, &tmp);
809 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
814 * Move up the the last inode in the current
815 * chunk. The lookup_ge will always get
816 * us the first inode in the next chunk.
818 agino += XFS_INODES_PER_CHUNK - 1;
822 if ((error = xfs_inobt_get_rec(cur, &gino, &gcnt, &gfree,
827 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
833 agino = gino + XFS_INODES_PER_CHUNK - 1;
834 buffer[bufidx].xi_startino = XFS_AGINO_TO_INO(mp, agno, gino);
835 buffer[bufidx].xi_alloccount = XFS_INODES_PER_CHUNK - gcnt;
836 buffer[bufidx].xi_allocmask = ~gfree;
839 if (bufidx == bcount) {
840 if (copy_to_user(ubuffer, buffer,
841 bufidx * sizeof(*buffer))) {
842 error = XFS_ERROR(EFAULT);
850 error = xfs_inobt_increment(cur, 0, &tmp);
852 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
857 * The agino value has already been bumped.
858 * Just try to skip up to it.
860 agino += XFS_INODES_PER_CHUNK;
867 if (copy_to_user(ubuffer, buffer,
868 bufidx * sizeof(*buffer)))
869 error = XFS_ERROR(EFAULT);
873 *lastino = XFS_AGINO_TO_INO(mp, agno, agino);
875 kmem_free(buffer, bcount * sizeof(*buffer));
877 xfs_btree_del_cursor(cur, (error ? XFS_BTREE_ERROR :