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 * Return stat information for one inode.
60 * Return 0 if ok, else errno.
62 int /* error status */
64 xfs_mount_t *mp, /* mount point for filesystem */
65 xfs_trans_t *tp, /* transaction pointer */
66 xfs_ino_t ino, /* inode number to get data for */
67 void *buffer, /* buffer to place output in */
68 int ubsize, /* size of buffer */
69 void *private_data, /* my private data */
70 xfs_daddr_t bno, /* starting bno of inode cluster */
71 int *ubused, /* bytes used by me */
72 void *dibuff, /* on-disk inode buffer */
73 int *stat) /* BULKSTAT_RV_... */
75 xfs_bstat_t *buf; /* return buffer */
76 int error; /* error value */
77 xfs_dinode_t *dip; /* dinode inode pointer */
78 xfs_dinode_core_t *dic; /* dinode core info pointer */
79 xfs_inode_t *ip = NULL; /* incore inode pointer */
80 xfs_arch_t arch; /* these are set according to */
81 __uint16_t di_flags; /* temp */
83 buf = (xfs_bstat_t *)buffer;
84 dip = (xfs_dinode_t *)dibuff;
86 if (! buf || ino == mp->m_sb.sb_rbmino || ino == mp->m_sb.sb_rsumino ||
87 (XFS_SB_VERSION_HASQUOTA(&mp->m_sb) &&
88 (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino))) {
89 *stat = BULKSTAT_RV_NOTHING;
90 return XFS_ERROR(EINVAL);
92 if (ubsize < sizeof(*buf)) {
93 *stat = BULKSTAT_RV_NOTHING;
94 return XFS_ERROR(ENOMEM);
98 /* We're not being passed a pointer to a dinode. This happens
99 * if BULKSTAT_FG_IGET is selected. Do the iget.
101 error = xfs_iget(mp, tp, ino, XFS_ILOCK_SHARED, &ip, bno);
103 *stat = BULKSTAT_RV_NOTHING;
107 ASSERT(ip->i_blkno != (xfs_daddr_t)0);
108 if (ip->i_d.di_mode == 0) {
109 xfs_iput_new(ip, XFS_ILOCK_SHARED);
110 *stat = BULKSTAT_RV_NOTHING;
111 return XFS_ERROR(ENOENT);
114 arch = ARCH_NOCONVERT; /* in-core! */
117 /* xfs_iget returns the following without needing
120 buf->bs_nlink = dic->di_nlink;
121 buf->bs_projid = dic->di_projid;
127 /* buffer dinode_core is in on-disk arch */
131 * The inode format changed when we moved the link count and
132 * made it 32 bits long. If this is an old format inode,
133 * convert it in memory to look like a new one. If it gets
134 * flushed to disk we will convert back before flushing or
135 * logging it. We zero out the new projid field and the old link
136 * count field. We'll handle clearing the pad field (the remains
137 * of the old uuid field) when we actually convert the inode to
138 * the new format. We don't change the version number so that we
139 * can distinguish this from a real new format inode.
141 if (INT_GET(dic->di_version, arch) == XFS_DINODE_VERSION_1) {
142 buf->bs_nlink = INT_GET(dic->di_onlink, arch);
146 buf->bs_nlink = INT_GET(dic->di_nlink, arch);
147 buf->bs_projid = INT_GET(dic->di_projid, arch);
153 buf->bs_mode = INT_GET(dic->di_mode, arch);
154 buf->bs_uid = INT_GET(dic->di_uid, arch);
155 buf->bs_gid = INT_GET(dic->di_gid, arch);
156 buf->bs_size = INT_GET(dic->di_size, arch);
157 buf->bs_atime.tv_sec = INT_GET(dic->di_atime.t_sec, arch);
158 buf->bs_atime.tv_nsec = INT_GET(dic->di_atime.t_nsec, arch);
159 buf->bs_mtime.tv_sec = INT_GET(dic->di_mtime.t_sec, arch);
160 buf->bs_mtime.tv_nsec = INT_GET(dic->di_mtime.t_nsec, arch);
161 buf->bs_ctime.tv_sec = INT_GET(dic->di_ctime.t_sec, arch);
162 buf->bs_ctime.tv_nsec = INT_GET(dic->di_ctime.t_nsec, arch);
164 * convert di_flags to bs_xflags.
166 di_flags = INT_GET(dic->di_flags, arch);
169 ((di_flags & XFS_DIFLAG_REALTIME) ?
170 XFS_XFLAG_REALTIME : 0) |
171 ((di_flags & XFS_DIFLAG_PREALLOC) ?
172 XFS_XFLAG_PREALLOC : 0) |
173 ((di_flags & XFS_DIFLAG_IMMUTABLE) ?
174 XFS_XFLAG_IMMUTABLE : 0) |
175 ((di_flags & XFS_DIFLAG_APPEND) ?
176 XFS_XFLAG_APPEND : 0) |
177 ((di_flags & XFS_DIFLAG_SYNC) ?
178 XFS_XFLAG_SYNC : 0) |
179 ((di_flags & XFS_DIFLAG_NOATIME) ?
180 XFS_XFLAG_NOATIME : 0) |
181 ((di_flags & XFS_DIFLAG_NODUMP) ?
182 XFS_XFLAG_NODUMP : 0) |
183 (XFS_CFORK_Q_ARCH(dic, arch) ?
184 XFS_XFLAG_HASATTR : 0);
186 buf->bs_extsize = INT_GET(dic->di_extsize, arch) << mp->m_sb.sb_blocklog;
187 buf->bs_extents = INT_GET(dic->di_nextents, arch);
188 buf->bs_gen = INT_GET(dic->di_gen, arch);
189 memset(buf->bs_pad, 0, sizeof(buf->bs_pad));
190 buf->bs_dmevmask = INT_GET(dic->di_dmevmask, arch);
191 buf->bs_dmstate = INT_GET(dic->di_dmstate, arch);
192 buf->bs_aextents = INT_GET(dic->di_anextents, arch);
194 switch (INT_GET(dic->di_format, arch)) {
195 case XFS_DINODE_FMT_DEV:
197 buf->bs_rdev = ip->i_df.if_u2.if_rdev;
199 buf->bs_rdev = INT_GET(dip->di_u.di_dev, arch);
202 buf->bs_blksize = BLKDEV_IOSIZE;
205 case XFS_DINODE_FMT_LOCAL:
206 case XFS_DINODE_FMT_UUID:
208 buf->bs_blksize = mp->m_sb.sb_blocksize;
211 case XFS_DINODE_FMT_EXTENTS:
212 case XFS_DINODE_FMT_BTREE:
214 buf->bs_blksize = mp->m_sb.sb_blocksize;
216 buf->bs_blocks = INT_GET(dic->di_nblocks, arch) + ip->i_delayed_blks;
218 buf->bs_blocks = INT_GET(dic->di_nblocks, arch);
224 xfs_iput(ip, XFS_ILOCK_SHARED);
227 *stat = BULKSTAT_RV_DIDONE;
229 *ubused = sizeof(*buf);
234 * Return stat information in bulk (by-inode) for the filesystem.
236 int /* error status */
238 xfs_mount_t *mp, /* mount point for filesystem */
239 xfs_trans_t *tp, /* transaction pointer */
240 xfs_ino_t *lastinop, /* last inode returned */
241 int *ubcountp, /* size of buffer/count returned */
242 bulkstat_one_pf formatter, /* func that'd fill a single buf */
243 void *private_data,/* private data for formatter */
244 size_t statstruct_size, /* sizeof struct filling */
245 xfs_caddr_t ubuffer, /* buffer with inode stats */
246 int flags, /* defined in xfs_itable.h */
247 int *done) /* 1 if there're more stats to get */
249 xfs_agblock_t agbno=0;/* allocation group block number */
250 xfs_buf_t *agbp; /* agi header buffer */
251 xfs_agi_t *agi; /* agi header data */
252 xfs_agino_t agino; /* inode # in allocation group */
253 xfs_agnumber_t agno; /* allocation group number */
254 xfs_daddr_t bno; /* inode cluster start daddr */
255 int chunkidx; /* current index into inode chunk */
256 int clustidx; /* current index into inode cluster */
257 xfs_btree_cur_t *cur; /* btree cursor for ialloc btree */
258 int end_of_ag; /* set if we've seen the ag end */
259 int error; /* error code */
260 int fmterror;/* bulkstat formatter result */
261 __int32_t gcnt; /* current btree rec's count */
262 xfs_inofree_t gfree; /* current btree rec's free mask */
263 xfs_agino_t gino; /* current btree rec's start inode */
264 int i; /* loop index */
265 int icount; /* count of inodes good in irbuf */
266 xfs_ino_t ino; /* inode number (filesystem) */
267 xfs_inobt_rec_t *irbp; /* current irec buffer pointer */
268 xfs_inobt_rec_t *irbuf; /* start of irec buffer */
269 xfs_inobt_rec_t *irbufend; /* end of good irec buffer entries */
270 xfs_ino_t lastino=0; /* last inode number returned */
271 int nbcluster; /* # of blocks in a cluster */
272 int nicluster; /* # of inodes in a cluster */
273 int nimask; /* mask for inode clusters */
274 int nirbuf; /* size of irbuf */
275 int rval; /* return value error code */
276 int tmp; /* result value from btree calls */
277 int ubcount; /* size of user's buffer */
278 int ubleft; /* bytes left in user's buffer */
279 xfs_caddr_t ubufp; /* current pointer into user's buffer */
280 int ubelem; /* spaces used in user's buffer */
281 int ubused; /* bytes used by formatter */
282 xfs_buf_t *bp; /* ptr to on-disk inode cluster buf */
283 xfs_dinode_t *dip; /* ptr into bp for specific inode */
284 xfs_inode_t *ip; /* ptr to in-core inode struct */
287 * Get the last inode value, see if there's nothing to do.
289 ino = (xfs_ino_t)*lastinop;
291 agno = XFS_INO_TO_AGNO(mp, ino);
292 agino = XFS_INO_TO_AGINO(mp, ino);
293 if (agno >= mp->m_sb.sb_agcount ||
294 ino != XFS_AGINO_TO_INO(mp, agno, agino)) {
299 ubcount = *ubcountp; /* statstruct's */
300 ubleft = ubcount * statstruct_size; /* bytes */
301 *ubcountp = ubelem = 0;
305 nicluster = mp->m_sb.sb_blocksize >= XFS_INODE_CLUSTER_SIZE(mp) ?
306 mp->m_sb.sb_inopblock :
307 (XFS_INODE_CLUSTER_SIZE(mp) >> mp->m_sb.sb_inodelog);
308 nimask = ~(nicluster - 1);
309 nbcluster = nicluster >> mp->m_sb.sb_inopblog;
311 * Lock down the user's buffer. If a buffer was not sent, as in the case
312 * disk quota code calls here, we skip this.
314 #if defined(HAVE_USERACC)
316 (error = useracc(ubuffer, ubcount * statstruct_size,
317 (B_READ|B_PHYS), NULL))) {
322 * Allocate a page-sized buffer for inode btree records.
323 * We could try allocating something smaller, but for normal
324 * calls we'll always (potentially) need the whole page.
326 irbuf = kmem_alloc(NBPC, KM_SLEEP);
327 nirbuf = NBPC / sizeof(*irbuf);
329 * Loop over the allocation groups, starting from the last
330 * inode returned; 0 means start of the allocation group.
333 while (ubleft >= statstruct_size && agno < mp->m_sb.sb_agcount) {
335 down_read(&mp->m_peraglock);
336 error = xfs_ialloc_read_agi(mp, tp, agno, &agbp);
337 up_read(&mp->m_peraglock);
340 * Skip this allocation group and go to the next one.
346 agi = XFS_BUF_TO_AGI(agbp);
348 * Allocate and initialize a btree cursor for ialloc btree.
350 cur = xfs_btree_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_INO,
351 (xfs_inode_t *)0, 0);
353 irbufend = irbuf + nirbuf;
356 * If we're returning in the middle of an allocation group,
357 * we need to get the remainder of the chunk we're in.
361 * Lookup the inode chunk that this inode lives in.
363 error = xfs_inobt_lookup_le(cur, agino, 0, 0, &tmp);
364 if (!error && /* no I/O error */
365 tmp && /* lookup succeeded */
366 /* got the record, should always work */
367 !(error = xfs_inobt_get_rec(cur, &gino, &gcnt,
368 &gfree, &i, ARCH_NOCONVERT)) &&
370 /* this is the right chunk */
371 agino < gino + XFS_INODES_PER_CHUNK &&
372 /* lastino was not last in chunk */
373 (chunkidx = agino - gino + 1) <
374 XFS_INODES_PER_CHUNK &&
375 /* there are some left allocated */
376 XFS_INOBT_MASKN(chunkidx,
377 XFS_INODES_PER_CHUNK - chunkidx) & ~gfree) {
379 * Grab the chunk record. Mark all the
380 * uninteresting inodes (because they're
381 * before our start point) free.
383 for (i = 0; i < chunkidx; i++) {
384 if (XFS_INOBT_MASK(i) & ~gfree)
387 gfree |= XFS_INOBT_MASKN(0, chunkidx);
388 INT_SET(irbp->ir_startino, ARCH_CONVERT, gino);
389 INT_SET(irbp->ir_freecount, ARCH_CONVERT, gcnt);
390 INT_SET(irbp->ir_free, ARCH_CONVERT, gfree);
392 agino = gino + XFS_INODES_PER_CHUNK;
393 icount = XFS_INODES_PER_CHUNK - gcnt;
396 * If any of those tests failed, bump the
397 * inode number (just in case).
403 * In any case, increment to the next record.
406 error = xfs_inobt_increment(cur, 0, &tmp);
409 * Start of ag. Lookup the first inode chunk.
411 error = xfs_inobt_lookup_ge(cur, 0, 0, 0, &tmp);
415 * Loop through inode btree records in this ag,
416 * until we run out of inodes or space in the buffer.
418 while (irbp < irbufend && icount < ubcount) {
420 * Loop as long as we're unable to read the
424 agino += XFS_INODES_PER_CHUNK;
425 if (XFS_AGINO_TO_AGBNO(mp, agino) >=
426 INT_GET(agi->agi_length, ARCH_CONVERT))
428 error = xfs_inobt_lookup_ge(cur, agino, 0, 0,
432 * If ran off the end of the ag either with an error,
433 * or the normal way, set end and stop collecting.
436 (error = xfs_inobt_get_rec(cur, &gino, &gcnt,
437 &gfree, &i, ARCH_NOCONVERT)) ||
443 * If this chunk has any allocated inodes, save it.
445 if (gcnt < XFS_INODES_PER_CHUNK) {
446 INT_SET(irbp->ir_startino, ARCH_CONVERT, gino);
447 INT_SET(irbp->ir_freecount, ARCH_CONVERT, gcnt);
448 INT_SET(irbp->ir_free, ARCH_CONVERT, gfree);
450 icount += XFS_INODES_PER_CHUNK - gcnt;
453 * Set agino to after this chunk and bump the cursor.
455 agino = gino + XFS_INODES_PER_CHUNK;
456 error = xfs_inobt_increment(cur, 0, &tmp);
459 * Drop the btree buffers and the agi buffer.
460 * We can't hold any of the locks these represent
463 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
464 xfs_trans_brelse(tp, agbp);
466 * Now format all the good inodes into the user's buffer.
470 irbp < irbufend && ubleft >= statstruct_size; irbp++) {
472 * Read-ahead the next chunk's worth of inodes.
474 if (&irbp[1] < irbufend) {
476 * Loop over all clusters in the next chunk.
477 * Do a readahead if there are any allocated
478 * inodes in that cluster.
480 for (agbno = XFS_AGINO_TO_AGBNO(mp,
481 INT_GET(irbp[1].ir_startino, ARCH_CONVERT)),
483 chunkidx < XFS_INODES_PER_CHUNK;
484 chunkidx += nicluster,
485 agbno += nbcluster) {
486 if (XFS_INOBT_MASKN(chunkidx,
488 ~(INT_GET(irbp[1].ir_free, ARCH_CONVERT)))
489 xfs_btree_reada_bufs(mp, agno,
494 * Now process this chunk of inodes.
496 for (agino = INT_GET(irbp->ir_startino, ARCH_CONVERT), chunkidx = 0, clustidx = 0;
498 INT_GET(irbp->ir_freecount, ARCH_CONVERT) < XFS_INODES_PER_CHUNK;
499 chunkidx++, clustidx++, agino++) {
500 ASSERT(chunkidx < XFS_INODES_PER_CHUNK);
502 * Recompute agbno if this is the
503 * first inode of the cluster.
505 * Careful with clustidx. There can be
506 * multple clusters per chunk, a single
507 * cluster per chunk or a cluster that has
508 * inodes represented from several different
509 * chunks (if blocksize is large).
511 * Because of this, the starting clustidx is
512 * initialized to zero in this loop but must
513 * later be reset after reading in the cluster
516 if ((chunkidx & (nicluster - 1)) == 0) {
517 agbno = XFS_AGINO_TO_AGBNO(mp,
518 INT_GET(irbp->ir_startino, ARCH_CONVERT)) +
519 ((chunkidx & nimask) >>
520 mp->m_sb.sb_inopblog);
522 if (flags & BULKSTAT_FG_QUICK) {
523 ino = XFS_AGINO_TO_INO(mp, agno,
525 bno = XFS_AGB_TO_DADDR(mp, agno,
529 * Get the inode cluster buffer
531 ASSERT(xfs_inode_zone != NULL);
532 ip = kmem_zone_zalloc(xfs_inode_zone,
537 xfs_trans_brelse(tp, bp);
538 error = xfs_itobp(mp, tp, ip,
541 clustidx = ip->i_boffset / mp->m_sb.sb_inodesize;
542 kmem_zone_free(xfs_inode_zone, ip);
543 if (XFS_TEST_ERROR(error != 0,
544 mp, XFS_ERRTAG_BULKSTAT_READ_CHUNK,
545 XFS_RANDOM_BULKSTAT_READ_CHUNK)) {
552 * Skip if this inode is free.
554 if (XFS_INOBT_MASK(chunkidx) & INT_GET(irbp->ir_free, ARCH_CONVERT))
557 * Count used inodes as free so we can tell
558 * when the chunk is used up.
560 INT_MOD(irbp->ir_freecount, ARCH_CONVERT, +1);
561 ino = XFS_AGINO_TO_INO(mp, agno, agino);
562 bno = XFS_AGB_TO_DADDR(mp, agno, agbno);
563 if (flags & BULKSTAT_FG_QUICK) {
564 dip = (xfs_dinode_t *)xfs_buf_offset(bp,
565 (clustidx << mp->m_sb.sb_inodelog));
567 if (INT_GET(dip->di_core.di_magic, ARCH_CONVERT)
569 || !XFS_DINODE_GOOD_VERSION(
570 INT_GET(dip->di_core.di_version, ARCH_CONVERT)))
575 * Get the inode and fill in a single buffer.
576 * BULKSTAT_FG_QUICK uses dip to fill it in.
577 * BULKSTAT_FG_IGET uses igets.
578 * See: xfs_bulkstat_one & xfs_dm_bulkstat_one.
579 * This is also used to count inodes/blks, etc
580 * in xfs_qm_quotacheck.
582 ubused = statstruct_size;
583 error = formatter(mp, tp, ino, ubufp,
584 ubleft, private_data,
585 bno, &ubused, dip, &fmterror);
586 if (fmterror == BULKSTAT_RV_NOTHING) {
591 if (fmterror == BULKSTAT_RV_GIVEUP) {
606 xfs_trans_brelse(tp, bp);
609 * Set up for the next loop iteration.
616 agino = XFS_INO_TO_AGINO(mp, lastino);
621 * Done, we're either out of filesystem or space to put the data.
623 kmem_free(irbuf, NBPC);
624 #if defined(HAVE_USERACC)
626 unuseracc(ubuffer, ubcount * statstruct_size, (B_READ|B_PHYS));
629 if (agno >= mp->m_sb.sb_agcount) {
631 * If we ran out of filesystem, mark lastino as off
632 * the end of the filesystem, so the next call
633 * will return immediately.
635 *lastinop = (xfs_ino_t)XFS_AGINO_TO_INO(mp, agno, 0);
638 *lastinop = (xfs_ino_t)lastino;
644 * Return stat information in bulk (by-inode) for the filesystem.
645 * Special case for non-sequential one inode bulkstat.
647 int /* error status */
649 xfs_mount_t *mp, /* mount point for filesystem */
650 xfs_ino_t *lastinop, /* inode to return */
651 xfs_caddr_t buffer, /* buffer with inode stats */
652 int *done) /* 1 if there're more stats to get */
654 xfs_bstat_t bstat; /* one bulkstat result structure */
655 int count; /* count value for bulkstat call */
656 int error; /* return value */
657 xfs_ino_t ino; /* filesystem inode number */
658 int res; /* result from bs1 */
661 * note that requesting valid inode numbers which are not allocated
662 * to inodes will most likely cause xfs_itobp to generate warning
663 * messages about bad magic numbers. This is ok. The fact that
664 * the inode isn't actually an inode is handled by the
665 * error check below. Done this way to make the usual case faster
666 * at the expense of the error case.
669 ino = (xfs_ino_t)*lastinop;
670 error = xfs_bulkstat_one(mp, NULL, ino, &bstat, sizeof(bstat),
671 NULL, 0, NULL, NULL, &res);
674 * Special case way failed, do it the "long" way
675 * to see if that works.
679 if (xfs_bulkstat(mp, NULL, lastinop, &count, xfs_bulkstat_one,
681 sizeof(bstat), buffer, BULKSTAT_FG_IGET, done))
683 if (count == 0 || (xfs_ino_t)*lastinop != ino)
684 return error == EFSCORRUPTED ?
685 XFS_ERROR(EINVAL) : error;
690 if (copy_to_user(buffer, &bstat, sizeof(bstat)))
691 return XFS_ERROR(EFAULT);
696 * Return inode number table for the filesystem.
698 int /* error status */
700 xfs_mount_t *mp, /* mount point for filesystem */
701 xfs_trans_t *tp, /* transaction pointer */
702 xfs_ino_t *lastino, /* last inode returned */
703 int *count, /* size of buffer/count returned */
704 xfs_caddr_t ubuffer) /* buffer with inode descriptions */
710 xfs_inogrp_t *buffer;
712 xfs_btree_cur_t *cur;
722 ino = (xfs_ino_t)*lastino;
723 agno = XFS_INO_TO_AGNO(mp, ino);
724 agino = XFS_INO_TO_AGINO(mp, ino);
727 bcount = MIN(left, (int)(NBPP / sizeof(*buffer)));
728 buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP);
732 while (left > 0 && agno < mp->m_sb.sb_agcount) {
734 down_read(&mp->m_peraglock);
735 error = xfs_ialloc_read_agi(mp, tp, agno, &agbp);
736 up_read(&mp->m_peraglock);
739 * If we can't read the AGI of this ag,
740 * then just skip to the next one.
748 cur = xfs_btree_init_cursor(mp, tp, agbp, agno,
749 XFS_BTNUM_INO, (xfs_inode_t *)0, 0);
750 error = xfs_inobt_lookup_ge(cur, agino, 0, 0, &tmp);
752 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
754 xfs_trans_brelse(tp, agbp);
757 * Move up the the last inode in the current
758 * chunk. The lookup_ge will always get
759 * us the first inode in the next chunk.
761 agino += XFS_INODES_PER_CHUNK - 1;
765 if ((error = xfs_inobt_get_rec(cur, &gino, &gcnt, &gfree,
766 &i, ARCH_NOCONVERT)) ||
768 xfs_trans_brelse(tp, agbp);
770 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
776 agino = gino + XFS_INODES_PER_CHUNK - 1;
777 buffer[bufidx].xi_startino = XFS_AGINO_TO_INO(mp, agno, gino);
778 buffer[bufidx].xi_alloccount = XFS_INODES_PER_CHUNK - gcnt;
779 buffer[bufidx].xi_allocmask = ~gfree;
782 if (bufidx == bcount) {
783 if (copy_to_user(ubuffer, buffer,
784 bufidx * sizeof(*buffer))) {
785 error = XFS_ERROR(EFAULT);
788 ubuffer += bufidx * sizeof(*buffer);
793 error = xfs_inobt_increment(cur, 0, &tmp);
795 xfs_btree_del_cursor(cur, XFS_BTREE_ERROR);
797 xfs_trans_brelse(tp, agbp);
800 * The agino value has already been bumped.
801 * Just try to skip up to it.
803 agino += XFS_INODES_PER_CHUNK;
810 if (copy_to_user(ubuffer, buffer,
811 bufidx * sizeof(*buffer)))
812 error = XFS_ERROR(EFAULT);
816 *lastino = XFS_AGINO_TO_INO(mp, agno, agino);
818 kmem_free(buffer, bcount * sizeof(*buffer));
820 xfs_btree_del_cursor(cur, (error ? XFS_BTREE_ERROR :
823 xfs_trans_brelse(tp, agbp);