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,
56 XFS_IGET_BULKSTAT, XFS_ILOCK_SHARED, &ip, bno);
58 *stat = BULKSTAT_RV_NOTHING;
63 ASSERT(ip->i_blkno != (xfs_daddr_t)0);
64 if (ip->i_d.di_mode == 0) {
65 *stat = BULKSTAT_RV_NOTHING;
66 error = XFS_ERROR(ENOENT);
73 /* xfs_iget returns the following without needing
76 buf->bs_nlink = dic->di_nlink;
77 buf->bs_projid = dic->di_projid;
79 buf->bs_mode = dic->di_mode;
80 buf->bs_uid = dic->di_uid;
81 buf->bs_gid = dic->di_gid;
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_size = INT_GET(dic->di_size, ARCH_CONVERT);
157 buf->bs_atime.tv_sec = INT_GET(dic->di_atime.t_sec, ARCH_CONVERT);
158 buf->bs_atime.tv_nsec = INT_GET(dic->di_atime.t_nsec, ARCH_CONVERT);
159 buf->bs_mtime.tv_sec = INT_GET(dic->di_mtime.t_sec, ARCH_CONVERT);
160 buf->bs_mtime.tv_nsec = INT_GET(dic->di_mtime.t_nsec, ARCH_CONVERT);
161 buf->bs_ctime.tv_sec = INT_GET(dic->di_ctime.t_sec, ARCH_CONVERT);
162 buf->bs_ctime.tv_nsec = INT_GET(dic->di_ctime.t_nsec, ARCH_CONVERT);
163 buf->bs_xflags = xfs_dic2xflags(dic);
164 buf->bs_extsize = INT_GET(dic->di_extsize, ARCH_CONVERT) << mp->m_sb.sb_blocklog;
165 buf->bs_extents = INT_GET(dic->di_nextents, ARCH_CONVERT);
166 buf->bs_gen = INT_GET(dic->di_gen, ARCH_CONVERT);
167 memset(buf->bs_pad, 0, sizeof(buf->bs_pad));
168 buf->bs_dmevmask = INT_GET(dic->di_dmevmask, ARCH_CONVERT);
169 buf->bs_dmstate = INT_GET(dic->di_dmstate, ARCH_CONVERT);
170 buf->bs_aextents = INT_GET(dic->di_anextents, ARCH_CONVERT);
172 switch (INT_GET(dic->di_format, ARCH_CONVERT)) {
173 case XFS_DINODE_FMT_DEV:
174 buf->bs_rdev = INT_GET(dip->di_u.di_dev, ARCH_CONVERT);
175 buf->bs_blksize = BLKDEV_IOSIZE;
178 case XFS_DINODE_FMT_LOCAL:
179 case XFS_DINODE_FMT_UUID:
181 buf->bs_blksize = mp->m_sb.sb_blocksize;
184 case XFS_DINODE_FMT_EXTENTS:
185 case XFS_DINODE_FMT_BTREE:
187 buf->bs_blksize = mp->m_sb.sb_blocksize;
188 buf->bs_blocks = INT_GET(dic->di_nblocks, ARCH_CONVERT);
196 * Return stat information for one inode.
197 * Return 0 if ok, else errno.
199 int /* error status */
201 xfs_mount_t *mp, /* mount point for filesystem */
202 xfs_ino_t ino, /* inode number to get data for */
203 void __user *buffer, /* buffer to place output in */
204 int ubsize, /* size of buffer */
205 void *private_data, /* my private data */
206 xfs_daddr_t bno, /* starting bno of inode cluster */
207 int *ubused, /* bytes used by me */
208 void *dibuff, /* on-disk inode buffer */
209 int *stat) /* BULKSTAT_RV_... */
211 xfs_bstat_t *buf; /* return buffer */
212 int error = 0; /* error value */
213 xfs_dinode_t *dip; /* dinode inode pointer */
215 dip = (xfs_dinode_t *)dibuff;
217 if (!buffer || ino == mp->m_sb.sb_rbmino || ino == mp->m_sb.sb_rsumino ||
218 (XFS_SB_VERSION_HASQUOTA(&mp->m_sb) &&
219 (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino))) {
220 *stat = BULKSTAT_RV_NOTHING;
221 return XFS_ERROR(EINVAL);
223 if (ubsize < sizeof(*buf)) {
224 *stat = BULKSTAT_RV_NOTHING;
225 return XFS_ERROR(ENOMEM);
228 buf = kmem_alloc(sizeof(*buf), KM_SLEEP);
231 /* We're not being passed a pointer to a dinode. This happens
232 * if BULKSTAT_FG_IGET is selected. Do the iget.
234 error = xfs_bulkstat_one_iget(mp, ino, bno, buf, stat);
238 xfs_bulkstat_one_dinode(mp, ino, dip, buf);
241 if (copy_to_user(buffer, buf, sizeof(*buf))) {
242 *stat = BULKSTAT_RV_NOTHING;
247 *stat = BULKSTAT_RV_DIDONE;
249 *ubused = sizeof(*buf);
252 kmem_free(buf, sizeof(*buf));
257 * Test to see whether we can use the ondisk inode directly, based
258 * on the given bulkstat flags, filling in dipp accordingly.
259 * Returns zero if the inode is dodgey.
262 xfs_bulkstat_use_dinode(
270 unsigned int aformat;
273 if (!bp || (flags & BULKSTAT_FG_IGET))
275 dip = (xfs_dinode_t *)
276 xfs_buf_offset(bp, clustidx << mp->m_sb.sb_inodelog);
277 if (INT_GET(dip->di_core.di_magic, ARCH_CONVERT) != XFS_DINODE_MAGIC ||
278 !XFS_DINODE_GOOD_VERSION(
279 INT_GET(dip->di_core.di_version, ARCH_CONVERT)))
281 if (flags & BULKSTAT_FG_QUICK) {
285 /* BULKSTAT_FG_INLINE: if attr fork is local, or not there, use it */
286 aformat = INT_GET(dip->di_core.di_aformat, ARCH_CONVERT);
287 if ((XFS_CFORK_Q(&dip->di_core) == 0) ||
288 (aformat == XFS_DINODE_FMT_LOCAL) ||
289 (aformat == XFS_DINODE_FMT_EXTENTS && !dip->di_core.di_anextents)) {
297 * Return stat information in bulk (by-inode) for the filesystem.
299 int /* error status */
301 xfs_mount_t *mp, /* mount point for filesystem */
302 xfs_ino_t *lastinop, /* last inode returned */
303 int *ubcountp, /* size of buffer/count returned */
304 bulkstat_one_pf formatter, /* func that'd fill a single buf */
305 void *private_data,/* private data for formatter */
306 size_t statstruct_size, /* sizeof struct filling */
307 char __user *ubuffer, /* buffer with inode stats */
308 int flags, /* defined in xfs_itable.h */
309 int *done) /* 1 if there are more stats to get */
311 xfs_agblock_t agbno=0;/* allocation group block number */
312 xfs_buf_t *agbp; /* agi header buffer */
313 xfs_agi_t *agi; /* agi header data */
314 xfs_agino_t agino; /* inode # in allocation group */
315 xfs_agnumber_t agno; /* allocation group number */
316 xfs_daddr_t bno; /* inode cluster start daddr */
317 int chunkidx; /* current index into inode chunk */
318 int clustidx; /* current index into inode cluster */
319 xfs_btree_cur_t *cur; /* btree cursor for ialloc btree */
320 int end_of_ag; /* set if we've seen the ag end */
321 int error; /* error code */
322 int fmterror;/* bulkstat formatter result */
323 __int32_t gcnt; /* current btree rec's count */
324 xfs_inofree_t gfree; /* current btree rec's free mask */
325 xfs_agino_t gino; /* current btree rec's start inode */
326 int i; /* loop index */
327 int icount; /* count of inodes good in irbuf */
328 int irbsize; /* size of irec buffer in bytes */
329 unsigned int kmflags; /* flags for allocating irec buffer */
330 xfs_ino_t ino; /* inode number (filesystem) */
331 xfs_inobt_rec_incore_t *irbp; /* current irec buffer pointer */
332 xfs_inobt_rec_incore_t *irbuf; /* start of irec buffer */
333 xfs_inobt_rec_incore_t *irbufend; /* end of good irec buffer entries */
334 xfs_ino_t lastino=0; /* last inode number returned */
335 int nbcluster; /* # of blocks in a cluster */
336 int nicluster; /* # of inodes in a cluster */
337 int nimask; /* mask for inode clusters */
338 int nirbuf; /* size of irbuf */
339 int rval; /* return value error code */
340 int tmp; /* result value from btree calls */
341 int ubcount; /* size of user's buffer */
342 int ubleft; /* bytes left in user's buffer */
343 char __user *ubufp; /* pointer into user's buffer */
344 int ubelem; /* spaces used in user's buffer */
345 int ubused; /* bytes used by formatter */
346 xfs_buf_t *bp; /* ptr to on-disk inode cluster buf */
347 xfs_dinode_t *dip; /* ptr into bp for specific inode */
348 xfs_inode_t *ip; /* ptr to in-core inode struct */
351 * Get the last inode value, see if there's nothing to do.
353 ino = (xfs_ino_t)*lastinop;
355 agno = XFS_INO_TO_AGNO(mp, ino);
356 agino = XFS_INO_TO_AGINO(mp, ino);
357 if (agno >= mp->m_sb.sb_agcount ||
358 ino != XFS_AGINO_TO_INO(mp, agno, agino)) {
363 ubcount = *ubcountp; /* statstruct's */
364 ubleft = ubcount * statstruct_size; /* bytes */
365 *ubcountp = ubelem = 0;
369 nicluster = mp->m_sb.sb_blocksize >= XFS_INODE_CLUSTER_SIZE(mp) ?
370 mp->m_sb.sb_inopblock :
371 (XFS_INODE_CLUSTER_SIZE(mp) >> mp->m_sb.sb_inodelog);
372 nimask = ~(nicluster - 1);
373 nbcluster = nicluster >> mp->m_sb.sb_inopblog;
375 * Allocate a local buffer for inode cluster btree records.
376 * This caps our maximum readahead window (so don't be stingy)
377 * but we must handle the case where we can't get a contiguous
378 * multi-page buffer, so we drop back toward pagesize; the end
379 * case we ensure succeeds, via appropriate allocation flags.
382 kmflags = KM_SLEEP | KM_MAYFAIL;
383 while (!(irbuf = kmem_alloc(irbsize, kmflags))) {
384 if ((irbsize >>= 1) <= NBPP)
387 nirbuf = irbsize / sizeof(*irbuf);
390 * Loop over the allocation groups, starting from the last
391 * inode returned; 0 means start of the allocation group.
394 while (ubleft >= statstruct_size && agno < mp->m_sb.sb_agcount) {
396 down_read(&mp->m_peraglock);
397 error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);
398 up_read(&mp->m_peraglock);
401 * Skip this allocation group and go to the next one.
407 agi = XFS_BUF_TO_AGI(agbp);
409 * Allocate and initialize a btree cursor for ialloc btree.
411 cur = xfs_btree_init_cursor(mp, NULL, agbp, agno, XFS_BTNUM_INO,
412 (xfs_inode_t *)0, 0);
414 irbufend = irbuf + nirbuf;
417 * If we're returning in the middle of an allocation group,
418 * we need to get the remainder of the chunk we're in.
422 * Lookup the inode chunk that this inode lives in.
424 error = xfs_inobt_lookup_le(cur, agino, 0, 0, &tmp);
425 if (!error && /* no I/O error */
426 tmp && /* lookup succeeded */
427 /* got the record, should always work */
428 !(error = xfs_inobt_get_rec(cur, &gino, &gcnt,
431 /* this is the right chunk */
432 agino < gino + XFS_INODES_PER_CHUNK &&
433 /* lastino was not last in chunk */
434 (chunkidx = agino - gino + 1) <
435 XFS_INODES_PER_CHUNK &&
436 /* there are some left allocated */
437 XFS_INOBT_MASKN(chunkidx,
438 XFS_INODES_PER_CHUNK - chunkidx) & ~gfree) {
440 * Grab the chunk record. Mark all the
441 * uninteresting inodes (because they're
442 * before our start point) free.
444 for (i = 0; i < chunkidx; i++) {
445 if (XFS_INOBT_MASK(i) & ~gfree)
448 gfree |= XFS_INOBT_MASKN(0, chunkidx);
449 irbp->ir_startino = gino;
450 irbp->ir_freecount = gcnt;
451 irbp->ir_free = gfree;
453 agino = gino + XFS_INODES_PER_CHUNK;
454 icount = XFS_INODES_PER_CHUNK - gcnt;
457 * If any of those tests failed, bump the
458 * inode number (just in case).
464 * In any case, increment to the next record.
467 error = xfs_inobt_increment(cur, 0, &tmp);
470 * Start of ag. Lookup the first inode chunk.
472 error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &tmp);
476 * Loop through inode btree records in this ag,
477 * until we run out of inodes or space in the buffer.
479 while (irbp < irbufend && icount < ubcount) {
481 * Loop as long as we're unable to read the
485 agino += XFS_INODES_PER_CHUNK;
486 if (XFS_AGINO_TO_AGBNO(mp, agino) >=
487 be32_to_cpu(agi->agi_length))
489 error = xfs_inobt_lookup_ge(cur, agino, 0, 0,
493 * If ran off the end of the ag either with an error,
494 * or the normal way, set end and stop collecting.
497 (error = xfs_inobt_get_rec(cur, &gino, &gcnt,
504 * If this chunk has any allocated inodes, save it.
505 * Also start read-ahead now for this chunk.
507 if (gcnt < XFS_INODES_PER_CHUNK) {
509 * Loop over all clusters in the next chunk.
510 * Do a readahead if there are any allocated
511 * inodes in that cluster.
513 for (agbno = XFS_AGINO_TO_AGBNO(mp, gino),
515 chunkidx < XFS_INODES_PER_CHUNK;
516 chunkidx += nicluster,
517 agbno += nbcluster) {
518 if (XFS_INOBT_MASKN(chunkidx,
520 xfs_btree_reada_bufs(mp, agno,
523 irbp->ir_startino = gino;
524 irbp->ir_freecount = gcnt;
525 irbp->ir_free = gfree;
527 icount += XFS_INODES_PER_CHUNK - gcnt;
530 * Set agino to after this chunk and bump the cursor.
532 agino = gino + XFS_INODES_PER_CHUNK;
533 error = xfs_inobt_increment(cur, 0, &tmp);
536 * Drop the btree buffers and the agi buffer.
537 * We can't hold any of the locks these represent
540 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
543 * Now format all the good inodes into the user's buffer.
547 irbp < irbufend && ubleft >= statstruct_size; irbp++) {
549 * Now process this chunk of inodes.
551 for (agino = irbp->ir_startino, chunkidx = clustidx = 0;
553 irbp->ir_freecount < XFS_INODES_PER_CHUNK;
554 chunkidx++, clustidx++, agino++) {
555 ASSERT(chunkidx < XFS_INODES_PER_CHUNK);
557 * Recompute agbno if this is the
558 * first inode of the cluster.
560 * Careful with clustidx. There can be
561 * multple clusters per chunk, a single
562 * cluster per chunk or a cluster that has
563 * inodes represented from several different
564 * chunks (if blocksize is large).
566 * Because of this, the starting clustidx is
567 * initialized to zero in this loop but must
568 * later be reset after reading in the cluster
571 if ((chunkidx & (nicluster - 1)) == 0) {
572 agbno = XFS_AGINO_TO_AGBNO(mp,
574 ((chunkidx & nimask) >>
575 mp->m_sb.sb_inopblog);
577 if (flags & (BULKSTAT_FG_QUICK |
578 BULKSTAT_FG_INLINE)) {
579 ino = XFS_AGINO_TO_INO(mp, agno,
581 bno = XFS_AGB_TO_DADDR(mp, agno,
585 * Get the inode cluster buffer
587 ASSERT(xfs_inode_zone != NULL);
588 ip = kmem_zone_zalloc(xfs_inode_zone,
594 error = xfs_itobp(mp, NULL, ip,
598 clustidx = ip->i_boffset / mp->m_sb.sb_inodesize;
599 kmem_zone_free(xfs_inode_zone, ip);
600 if (XFS_TEST_ERROR(error != 0,
601 mp, XFS_ERRTAG_BULKSTAT_READ_CHUNK,
602 XFS_RANDOM_BULKSTAT_READ_CHUNK)) {
611 * Skip if this inode is free.
613 if (XFS_INOBT_MASK(chunkidx) & irbp->ir_free)
616 * Count used inodes as free so we can tell
617 * when the chunk is used up.
619 irbp->ir_freecount++;
620 ino = XFS_AGINO_TO_INO(mp, agno, agino);
621 bno = XFS_AGB_TO_DADDR(mp, agno, agbno);
622 if (!xfs_bulkstat_use_dinode(mp, flags, bp,
626 * If we need to do an iget, cannot hold bp.
627 * Drop it, until starting the next cluster.
629 if ((flags & BULKSTAT_FG_INLINE) && !dip) {
636 * Get the inode and fill in a single buffer.
637 * BULKSTAT_FG_QUICK uses dip to fill it in.
638 * BULKSTAT_FG_IGET uses igets.
639 * BULKSTAT_FG_INLINE uses dip if we have an
640 * inline attr fork, else igets.
641 * See: xfs_bulkstat_one & xfs_dm_bulkstat_one.
642 * This is also used to count inodes/blks, etc
643 * in xfs_qm_quotacheck.
645 ubused = statstruct_size;
646 error = formatter(mp, ino, ubufp,
647 ubleft, private_data,
648 bno, &ubused, dip, &fmterror);
649 if (fmterror == BULKSTAT_RV_NOTHING) {
654 if (fmterror == BULKSTAT_RV_GIVEUP) {
672 * Set up for the next loop iteration.
679 agino = XFS_INO_TO_AGINO(mp, lastino);
684 * Done, we're either out of filesystem or space to put the data.
686 kmem_free(irbuf, irbsize);
688 if (agno >= mp->m_sb.sb_agcount) {
690 * If we ran out of filesystem, mark lastino as off
691 * the end of the filesystem, so the next call
692 * will return immediately.
694 *lastinop = (xfs_ino_t)XFS_AGINO_TO_INO(mp, agno, 0);
697 *lastinop = (xfs_ino_t)lastino;
703 * Return stat information in bulk (by-inode) for the filesystem.
704 * Special case for non-sequential one inode bulkstat.
706 int /* error status */
708 xfs_mount_t *mp, /* mount point for filesystem */
709 xfs_ino_t *lastinop, /* inode to return */
710 char __user *buffer, /* buffer with inode stats */
711 int *done) /* 1 if there are more stats to get */
713 int count; /* count value for bulkstat call */
714 int error; /* return value */
715 xfs_ino_t ino; /* filesystem inode number */
716 int res; /* result from bs1 */
719 * note that requesting valid inode numbers which are not allocated
720 * to inodes will most likely cause xfs_itobp to generate warning
721 * messages about bad magic numbers. This is ok. The fact that
722 * the inode isn't actually an inode is handled by the
723 * error check below. Done this way to make the usual case faster
724 * at the expense of the error case.
727 ino = (xfs_ino_t)*lastinop;
728 error = xfs_bulkstat_one(mp, ino, buffer, sizeof(xfs_bstat_t),
729 NULL, 0, NULL, NULL, &res);
732 * Special case way failed, do it the "long" way
733 * to see if that works.
737 if (xfs_bulkstat(mp, lastinop, &count, xfs_bulkstat_one,
738 NULL, sizeof(xfs_bstat_t), buffer,
739 BULKSTAT_FG_IGET, done))
741 if (count == 0 || (xfs_ino_t)*lastinop != ino)
742 return error == EFSCORRUPTED ?
743 XFS_ERROR(EINVAL) : error;
752 * Return inode number table for the filesystem.
754 int /* error status */
756 xfs_mount_t *mp, /* mount point for filesystem */
757 xfs_ino_t *lastino, /* last inode returned */
758 int *count, /* size of buffer/count returned */
759 xfs_inogrp_t __user *ubuffer)/* buffer with inode descriptions */
765 xfs_inogrp_t *buffer;
767 xfs_btree_cur_t *cur;
777 ino = (xfs_ino_t)*lastino;
778 agno = XFS_INO_TO_AGNO(mp, ino);
779 agino = XFS_INO_TO_AGINO(mp, ino);
782 bcount = MIN(left, (int)(NBPP / sizeof(*buffer)));
783 buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP);
787 while (left > 0 && agno < mp->m_sb.sb_agcount) {
789 down_read(&mp->m_peraglock);
790 error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);
791 up_read(&mp->m_peraglock);
794 * If we can't read the AGI of this ag,
795 * then just skip to the next one.
803 cur = xfs_btree_init_cursor(mp, NULL, agbp, agno,
804 XFS_BTNUM_INO, (xfs_inode_t *)0, 0);
805 error = xfs_inobt_lookup_ge(cur, agino, 0, 0, &tmp);
807 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
812 * Move up the the last inode in the current
813 * chunk. The lookup_ge will always get
814 * us the first inode in the next chunk.
816 agino += XFS_INODES_PER_CHUNK - 1;
820 if ((error = xfs_inobt_get_rec(cur, &gino, &gcnt, &gfree,
825 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
831 agino = gino + XFS_INODES_PER_CHUNK - 1;
832 buffer[bufidx].xi_startino = XFS_AGINO_TO_INO(mp, agno, gino);
833 buffer[bufidx].xi_alloccount = XFS_INODES_PER_CHUNK - gcnt;
834 buffer[bufidx].xi_allocmask = ~gfree;
837 if (bufidx == bcount) {
838 if (copy_to_user(ubuffer, buffer,
839 bufidx * sizeof(*buffer))) {
840 error = XFS_ERROR(EFAULT);
848 error = xfs_inobt_increment(cur, 0, &tmp);
850 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
855 * The agino value has already been bumped.
856 * Just try to skip up to it.
858 agino += XFS_INODES_PER_CHUNK;
865 if (copy_to_user(ubuffer, buffer,
866 bufidx * sizeof(*buffer)))
867 error = XFS_ERROR(EFAULT);
871 *lastino = XFS_AGINO_TO_INO(mp, agno, agino);
873 kmem_free(buffer, bcount * sizeof(*buffer));
875 xfs_btree_del_cursor(cur, (error ? XFS_BTREE_ERROR :