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"
29 #include "xfs_dmapi.h"
30 #include "xfs_mount.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_alloc_btree.h"
33 #include "xfs_ialloc_btree.h"
34 #include "xfs_dir_sf.h"
35 #include "xfs_dir2_sf.h"
36 #include "xfs_attr_sf.h"
37 #include "xfs_dinode.h"
38 #include "xfs_inode.h"
39 #include "xfs_ialloc.h"
40 #include "xfs_itable.h"
41 #include "xfs_error.h"
42 #include "xfs_btree.h"
45 #define useracc(ubuffer, size, flags, foo) (0)
46 #define unuseracc(ubuffer, size, flags)
50 xfs_bulkstat_one_iget(
51 xfs_mount_t
*mp
, /* mount point for filesystem */
52 xfs_ino_t ino
, /* inode number to get data for */
53 xfs_daddr_t bno
, /* starting bno of inode cluster */
54 xfs_bstat_t
*buf
, /* return buffer */
55 int *stat
) /* BULKSTAT_RV_... */
57 xfs_dinode_core_t
*dic
; /* dinode core info pointer */
58 xfs_inode_t
*ip
; /* incore inode pointer */
62 error
= xfs_iget(mp
, NULL
, ino
, 0, XFS_ILOCK_SHARED
, &ip
, bno
);
64 *stat
= BULKSTAT_RV_NOTHING
;
69 ASSERT(ip
->i_blkno
!= (xfs_daddr_t
)0);
70 if (ip
->i_d
.di_mode
== 0) {
71 *stat
= BULKSTAT_RV_NOTHING
;
72 error
= XFS_ERROR(ENOENT
);
79 /* xfs_iget returns the following without needing
82 buf
->bs_nlink
= dic
->di_nlink
;
83 buf
->bs_projid
= dic
->di_projid
;
85 buf
->bs_mode
= dic
->di_mode
;
86 buf
->bs_uid
= dic
->di_uid
;
87 buf
->bs_gid
= dic
->di_gid
;
88 buf
->bs_size
= dic
->di_size
;
89 vn_atime_to_bstime(vp
, &buf
->bs_atime
);
90 buf
->bs_mtime
.tv_sec
= dic
->di_mtime
.t_sec
;
91 buf
->bs_mtime
.tv_nsec
= dic
->di_mtime
.t_nsec
;
92 buf
->bs_ctime
.tv_sec
= dic
->di_ctime
.t_sec
;
93 buf
->bs_ctime
.tv_nsec
= dic
->di_ctime
.t_nsec
;
94 buf
->bs_xflags
= xfs_ip2xflags(ip
);
95 buf
->bs_extsize
= dic
->di_extsize
<< mp
->m_sb
.sb_blocklog
;
96 buf
->bs_extents
= dic
->di_nextents
;
97 buf
->bs_gen
= dic
->di_gen
;
98 memset(buf
->bs_pad
, 0, sizeof(buf
->bs_pad
));
99 buf
->bs_dmevmask
= dic
->di_dmevmask
;
100 buf
->bs_dmstate
= dic
->di_dmstate
;
101 buf
->bs_aextents
= dic
->di_anextents
;
103 switch (dic
->di_format
) {
104 case XFS_DINODE_FMT_DEV
:
105 buf
->bs_rdev
= ip
->i_df
.if_u2
.if_rdev
;
106 buf
->bs_blksize
= BLKDEV_IOSIZE
;
109 case XFS_DINODE_FMT_LOCAL
:
110 case XFS_DINODE_FMT_UUID
:
112 buf
->bs_blksize
= mp
->m_sb
.sb_blocksize
;
115 case XFS_DINODE_FMT_EXTENTS
:
116 case XFS_DINODE_FMT_BTREE
:
118 buf
->bs_blksize
= mp
->m_sb
.sb_blocksize
;
119 buf
->bs_blocks
= dic
->di_nblocks
+ ip
->i_delayed_blks
;
124 xfs_iput(ip
, XFS_ILOCK_SHARED
);
129 xfs_bulkstat_one_dinode(
130 xfs_mount_t
*mp
, /* mount point for filesystem */
131 xfs_ino_t ino
, /* inode number to get data for */
132 xfs_dinode_t
*dip
, /* dinode inode pointer */
133 xfs_bstat_t
*buf
) /* return buffer */
135 xfs_dinode_core_t
*dic
; /* dinode core info pointer */
140 * The inode format changed when we moved the link count and
141 * made it 32 bits long. If this is an old format inode,
142 * convert it in memory to look like a new one. If it gets
143 * flushed to disk we will convert back before flushing or
144 * logging it. We zero out the new projid field and the old link
145 * count field. We'll handle clearing the pad field (the remains
146 * of the old uuid field) when we actually convert the inode to
147 * the new format. We don't change the version number so that we
148 * can distinguish this from a real new format inode.
150 if (INT_GET(dic
->di_version
, ARCH_CONVERT
) == XFS_DINODE_VERSION_1
) {
151 buf
->bs_nlink
= INT_GET(dic
->di_onlink
, ARCH_CONVERT
);
154 buf
->bs_nlink
= INT_GET(dic
->di_nlink
, ARCH_CONVERT
);
155 buf
->bs_projid
= INT_GET(dic
->di_projid
, ARCH_CONVERT
);
159 buf
->bs_mode
= INT_GET(dic
->di_mode
, ARCH_CONVERT
);
160 buf
->bs_uid
= INT_GET(dic
->di_uid
, ARCH_CONVERT
);
161 buf
->bs_gid
= INT_GET(dic
->di_gid
, ARCH_CONVERT
);
162 buf
->bs_size
= INT_GET(dic
->di_size
, ARCH_CONVERT
);
163 buf
->bs_atime
.tv_sec
= INT_GET(dic
->di_atime
.t_sec
, ARCH_CONVERT
);
164 buf
->bs_atime
.tv_nsec
= INT_GET(dic
->di_atime
.t_nsec
, ARCH_CONVERT
);
165 buf
->bs_mtime
.tv_sec
= INT_GET(dic
->di_mtime
.t_sec
, ARCH_CONVERT
);
166 buf
->bs_mtime
.tv_nsec
= INT_GET(dic
->di_mtime
.t_nsec
, ARCH_CONVERT
);
167 buf
->bs_ctime
.tv_sec
= INT_GET(dic
->di_ctime
.t_sec
, ARCH_CONVERT
);
168 buf
->bs_ctime
.tv_nsec
= INT_GET(dic
->di_ctime
.t_nsec
, ARCH_CONVERT
);
169 buf
->bs_xflags
= xfs_dic2xflags(dic
);
170 buf
->bs_extsize
= INT_GET(dic
->di_extsize
, ARCH_CONVERT
) << mp
->m_sb
.sb_blocklog
;
171 buf
->bs_extents
= INT_GET(dic
->di_nextents
, ARCH_CONVERT
);
172 buf
->bs_gen
= INT_GET(dic
->di_gen
, ARCH_CONVERT
);
173 memset(buf
->bs_pad
, 0, sizeof(buf
->bs_pad
));
174 buf
->bs_dmevmask
= INT_GET(dic
->di_dmevmask
, ARCH_CONVERT
);
175 buf
->bs_dmstate
= INT_GET(dic
->di_dmstate
, ARCH_CONVERT
);
176 buf
->bs_aextents
= INT_GET(dic
->di_anextents
, ARCH_CONVERT
);
178 switch (INT_GET(dic
->di_format
, ARCH_CONVERT
)) {
179 case XFS_DINODE_FMT_DEV
:
180 buf
->bs_rdev
= INT_GET(dip
->di_u
.di_dev
, ARCH_CONVERT
);
181 buf
->bs_blksize
= BLKDEV_IOSIZE
;
184 case XFS_DINODE_FMT_LOCAL
:
185 case XFS_DINODE_FMT_UUID
:
187 buf
->bs_blksize
= mp
->m_sb
.sb_blocksize
;
190 case XFS_DINODE_FMT_EXTENTS
:
191 case XFS_DINODE_FMT_BTREE
:
193 buf
->bs_blksize
= mp
->m_sb
.sb_blocksize
;
194 buf
->bs_blocks
= INT_GET(dic
->di_nblocks
, ARCH_CONVERT
);
202 * Return stat information for one inode.
203 * Return 0 if ok, else errno.
205 int /* error status */
207 xfs_mount_t
*mp
, /* mount point for filesystem */
208 xfs_ino_t ino
, /* inode number to get data for */
209 void __user
*buffer
, /* buffer to place output in */
210 int ubsize
, /* size of buffer */
211 void *private_data
, /* my private data */
212 xfs_daddr_t bno
, /* starting bno of inode cluster */
213 int *ubused
, /* bytes used by me */
214 void *dibuff
, /* on-disk inode buffer */
215 int *stat
) /* BULKSTAT_RV_... */
217 xfs_bstat_t
*buf
; /* return buffer */
218 int error
= 0; /* error value */
219 xfs_dinode_t
*dip
; /* dinode inode pointer */
221 dip
= (xfs_dinode_t
*)dibuff
;
223 if (!buffer
|| ino
== mp
->m_sb
.sb_rbmino
|| ino
== mp
->m_sb
.sb_rsumino
||
224 (XFS_SB_VERSION_HASQUOTA(&mp
->m_sb
) &&
225 (ino
== mp
->m_sb
.sb_uquotino
|| ino
== mp
->m_sb
.sb_gquotino
))) {
226 *stat
= BULKSTAT_RV_NOTHING
;
227 return XFS_ERROR(EINVAL
);
229 if (ubsize
< sizeof(*buf
)) {
230 *stat
= BULKSTAT_RV_NOTHING
;
231 return XFS_ERROR(ENOMEM
);
234 buf
= kmem_alloc(sizeof(*buf
), KM_SLEEP
);
237 /* We're not being passed a pointer to a dinode. This happens
238 * if BULKSTAT_FG_IGET is selected. Do the iget.
240 error
= xfs_bulkstat_one_iget(mp
, ino
, bno
, buf
, stat
);
244 xfs_bulkstat_one_dinode(mp
, ino
, dip
, buf
);
247 if (copy_to_user(buffer
, buf
, sizeof(*buf
))) {
248 *stat
= BULKSTAT_RV_NOTHING
;
253 *stat
= BULKSTAT_RV_DIDONE
;
255 *ubused
= sizeof(*buf
);
258 kmem_free(buf
, sizeof(*buf
));
263 * Return stat information in bulk (by-inode) for the filesystem.
265 int /* error status */
267 xfs_mount_t
*mp
, /* mount point for filesystem */
268 xfs_ino_t
*lastinop
, /* last inode returned */
269 int *ubcountp
, /* size of buffer/count returned */
270 bulkstat_one_pf formatter
, /* func that'd fill a single buf */
271 void *private_data
,/* private data for formatter */
272 size_t statstruct_size
, /* sizeof struct filling */
273 char __user
*ubuffer
, /* buffer with inode stats */
274 int flags
, /* defined in xfs_itable.h */
275 int *done
) /* 1 if there are more stats to get */
277 xfs_agblock_t agbno
=0;/* allocation group block number */
278 xfs_buf_t
*agbp
; /* agi header buffer */
279 xfs_agi_t
*agi
; /* agi header data */
280 xfs_agino_t agino
; /* inode # in allocation group */
281 xfs_agnumber_t agno
; /* allocation group number */
282 xfs_daddr_t bno
; /* inode cluster start daddr */
283 int chunkidx
; /* current index into inode chunk */
284 int clustidx
; /* current index into inode cluster */
285 xfs_btree_cur_t
*cur
; /* btree cursor for ialloc btree */
286 int end_of_ag
; /* set if we've seen the ag end */
287 int error
; /* error code */
288 int fmterror
;/* bulkstat formatter result */
289 __int32_t gcnt
; /* current btree rec's count */
290 xfs_inofree_t gfree
; /* current btree rec's free mask */
291 xfs_agino_t gino
; /* current btree rec's start inode */
292 int i
; /* loop index */
293 int icount
; /* count of inodes good in irbuf */
294 xfs_ino_t ino
; /* inode number (filesystem) */
295 xfs_inobt_rec_t
*irbp
; /* current irec buffer pointer */
296 xfs_inobt_rec_t
*irbuf
; /* start of irec buffer */
297 xfs_inobt_rec_t
*irbufend
; /* end of good irec buffer entries */
298 xfs_ino_t lastino
=0; /* last inode number returned */
299 int nbcluster
; /* # of blocks in a cluster */
300 int nicluster
; /* # of inodes in a cluster */
301 int nimask
; /* mask for inode clusters */
302 int nirbuf
; /* size of irbuf */
303 int rval
; /* return value error code */
304 int tmp
; /* result value from btree calls */
305 int ubcount
; /* size of user's buffer */
306 int ubleft
; /* bytes left in user's buffer */
307 char __user
*ubufp
; /* pointer into user's buffer */
308 int ubelem
; /* spaces used in user's buffer */
309 int ubused
; /* bytes used by formatter */
310 xfs_buf_t
*bp
; /* ptr to on-disk inode cluster buf */
311 xfs_dinode_t
*dip
; /* ptr into bp for specific inode */
312 xfs_inode_t
*ip
; /* ptr to in-core inode struct */
315 * Get the last inode value, see if there's nothing to do.
317 ino
= (xfs_ino_t
)*lastinop
;
319 agno
= XFS_INO_TO_AGNO(mp
, ino
);
320 agino
= XFS_INO_TO_AGINO(mp
, ino
);
321 if (agno
>= mp
->m_sb
.sb_agcount
||
322 ino
!= XFS_AGINO_TO_INO(mp
, agno
, agino
)) {
327 ubcount
= *ubcountp
; /* statstruct's */
328 ubleft
= ubcount
* statstruct_size
; /* bytes */
329 *ubcountp
= ubelem
= 0;
333 nicluster
= mp
->m_sb
.sb_blocksize
>= XFS_INODE_CLUSTER_SIZE(mp
) ?
334 mp
->m_sb
.sb_inopblock
:
335 (XFS_INODE_CLUSTER_SIZE(mp
) >> mp
->m_sb
.sb_inodelog
);
336 nimask
= ~(nicluster
- 1);
337 nbcluster
= nicluster
>> mp
->m_sb
.sb_inopblog
;
339 * Lock down the user's buffer. If a buffer was not sent, as in the case
340 * disk quota code calls here, we skip this.
343 (error
= useracc(ubuffer
, ubcount
* statstruct_size
,
344 (B_READ
|B_PHYS
), NULL
))) {
348 * Allocate a page-sized buffer for inode btree records.
349 * We could try allocating something smaller, but for normal
350 * calls we'll always (potentially) need the whole page.
352 irbuf
= kmem_alloc(NBPC
, KM_SLEEP
);
353 nirbuf
= NBPC
/ sizeof(*irbuf
);
355 * Loop over the allocation groups, starting from the last
356 * inode returned; 0 means start of the allocation group.
359 while (ubleft
>= statstruct_size
&& agno
< mp
->m_sb
.sb_agcount
) {
361 down_read(&mp
->m_peraglock
);
362 error
= xfs_ialloc_read_agi(mp
, NULL
, agno
, &agbp
);
363 up_read(&mp
->m_peraglock
);
366 * Skip this allocation group and go to the next one.
372 agi
= XFS_BUF_TO_AGI(agbp
);
374 * Allocate and initialize a btree cursor for ialloc btree.
376 cur
= xfs_btree_init_cursor(mp
, NULL
, agbp
, agno
, XFS_BTNUM_INO
,
377 (xfs_inode_t
*)0, 0);
379 irbufend
= irbuf
+ nirbuf
;
382 * If we're returning in the middle of an allocation group,
383 * we need to get the remainder of the chunk we're in.
387 * Lookup the inode chunk that this inode lives in.
389 error
= xfs_inobt_lookup_le(cur
, agino
, 0, 0, &tmp
);
390 if (!error
&& /* no I/O error */
391 tmp
&& /* lookup succeeded */
392 /* got the record, should always work */
393 !(error
= xfs_inobt_get_rec(cur
, &gino
, &gcnt
,
396 /* this is the right chunk */
397 agino
< gino
+ XFS_INODES_PER_CHUNK
&&
398 /* lastino was not last in chunk */
399 (chunkidx
= agino
- gino
+ 1) <
400 XFS_INODES_PER_CHUNK
&&
401 /* there are some left allocated */
402 XFS_INOBT_MASKN(chunkidx
,
403 XFS_INODES_PER_CHUNK
- chunkidx
) & ~gfree
) {
405 * Grab the chunk record. Mark all the
406 * uninteresting inodes (because they're
407 * before our start point) free.
409 for (i
= 0; i
< chunkidx
; i
++) {
410 if (XFS_INOBT_MASK(i
) & ~gfree
)
413 gfree
|= XFS_INOBT_MASKN(0, chunkidx
);
414 INT_SET(irbp
->ir_startino
, ARCH_CONVERT
, gino
);
415 INT_SET(irbp
->ir_freecount
, ARCH_CONVERT
, gcnt
);
416 INT_SET(irbp
->ir_free
, ARCH_CONVERT
, gfree
);
418 agino
= gino
+ XFS_INODES_PER_CHUNK
;
419 icount
= XFS_INODES_PER_CHUNK
- gcnt
;
422 * If any of those tests failed, bump the
423 * inode number (just in case).
429 * In any case, increment to the next record.
432 error
= xfs_inobt_increment(cur
, 0, &tmp
);
435 * Start of ag. Lookup the first inode chunk.
437 error
= xfs_inobt_lookup_ge(cur
, 0, 0, 0, &tmp
);
441 * Loop through inode btree records in this ag,
442 * until we run out of inodes or space in the buffer.
444 while (irbp
< irbufend
&& icount
< ubcount
) {
446 * Loop as long as we're unable to read the
450 agino
+= XFS_INODES_PER_CHUNK
;
451 if (XFS_AGINO_TO_AGBNO(mp
, agino
) >=
452 be32_to_cpu(agi
->agi_length
))
454 error
= xfs_inobt_lookup_ge(cur
, agino
, 0, 0,
458 * If ran off the end of the ag either with an error,
459 * or the normal way, set end and stop collecting.
462 (error
= xfs_inobt_get_rec(cur
, &gino
, &gcnt
,
469 * If this chunk has any allocated inodes, save it.
471 if (gcnt
< XFS_INODES_PER_CHUNK
) {
472 INT_SET(irbp
->ir_startino
, ARCH_CONVERT
, gino
);
473 INT_SET(irbp
->ir_freecount
, ARCH_CONVERT
, gcnt
);
474 INT_SET(irbp
->ir_free
, ARCH_CONVERT
, gfree
);
476 icount
+= XFS_INODES_PER_CHUNK
- gcnt
;
479 * Set agino to after this chunk and bump the cursor.
481 agino
= gino
+ XFS_INODES_PER_CHUNK
;
482 error
= xfs_inobt_increment(cur
, 0, &tmp
);
485 * Drop the btree buffers and the agi buffer.
486 * We can't hold any of the locks these represent
489 xfs_btree_del_cursor(cur
, XFS_BTREE_NOERROR
);
492 * Now format all the good inodes into the user's buffer.
496 irbp
< irbufend
&& ubleft
>= statstruct_size
; irbp
++) {
498 * Read-ahead the next chunk's worth of inodes.
500 if (&irbp
[1] < irbufend
) {
502 * Loop over all clusters in the next chunk.
503 * Do a readahead if there are any allocated
504 * inodes in that cluster.
506 for (agbno
= XFS_AGINO_TO_AGBNO(mp
,
507 INT_GET(irbp
[1].ir_startino
, ARCH_CONVERT
)),
509 chunkidx
< XFS_INODES_PER_CHUNK
;
510 chunkidx
+= nicluster
,
511 agbno
+= nbcluster
) {
512 if (XFS_INOBT_MASKN(chunkidx
,
514 ~(INT_GET(irbp
[1].ir_free
, ARCH_CONVERT
)))
515 xfs_btree_reada_bufs(mp
, agno
,
520 * Now process this chunk of inodes.
522 for (agino
= INT_GET(irbp
->ir_startino
, ARCH_CONVERT
), chunkidx
= 0, clustidx
= 0;
524 INT_GET(irbp
->ir_freecount
, ARCH_CONVERT
) < XFS_INODES_PER_CHUNK
;
525 chunkidx
++, clustidx
++, agino
++) {
526 ASSERT(chunkidx
< XFS_INODES_PER_CHUNK
);
528 * Recompute agbno if this is the
529 * first inode of the cluster.
531 * Careful with clustidx. There can be
532 * multple clusters per chunk, a single
533 * cluster per chunk or a cluster that has
534 * inodes represented from several different
535 * chunks (if blocksize is large).
537 * Because of this, the starting clustidx is
538 * initialized to zero in this loop but must
539 * later be reset after reading in the cluster
542 if ((chunkidx
& (nicluster
- 1)) == 0) {
543 agbno
= XFS_AGINO_TO_AGBNO(mp
,
544 INT_GET(irbp
->ir_startino
, ARCH_CONVERT
)) +
545 ((chunkidx
& nimask
) >>
546 mp
->m_sb
.sb_inopblog
);
548 if (flags
& BULKSTAT_FG_QUICK
) {
549 ino
= XFS_AGINO_TO_INO(mp
, agno
,
551 bno
= XFS_AGB_TO_DADDR(mp
, agno
,
555 * Get the inode cluster buffer
557 ASSERT(xfs_inode_zone
!= NULL
);
558 ip
= kmem_zone_zalloc(xfs_inode_zone
,
564 error
= xfs_itobp(mp
, NULL
, ip
,
568 clustidx
= ip
->i_boffset
/ mp
->m_sb
.sb_inodesize
;
569 kmem_zone_free(xfs_inode_zone
, ip
);
570 if (XFS_TEST_ERROR(error
!= 0,
571 mp
, XFS_ERRTAG_BULKSTAT_READ_CHUNK
,
572 XFS_RANDOM_BULKSTAT_READ_CHUNK
)) {
581 * Skip if this inode is free.
583 if (XFS_INOBT_MASK(chunkidx
) & INT_GET(irbp
->ir_free
, ARCH_CONVERT
))
586 * Count used inodes as free so we can tell
587 * when the chunk is used up.
589 INT_MOD(irbp
->ir_freecount
, ARCH_CONVERT
, +1);
590 ino
= XFS_AGINO_TO_INO(mp
, agno
, agino
);
591 bno
= XFS_AGB_TO_DADDR(mp
, agno
, agbno
);
592 if (flags
& BULKSTAT_FG_QUICK
) {
593 dip
= (xfs_dinode_t
*)xfs_buf_offset(bp
,
594 (clustidx
<< mp
->m_sb
.sb_inodelog
));
596 if (INT_GET(dip
->di_core
.di_magic
, ARCH_CONVERT
)
598 || !XFS_DINODE_GOOD_VERSION(
599 INT_GET(dip
->di_core
.di_version
, ARCH_CONVERT
)))
604 * Get the inode and fill in a single buffer.
605 * BULKSTAT_FG_QUICK uses dip to fill it in.
606 * BULKSTAT_FG_IGET uses igets.
607 * See: xfs_bulkstat_one & xfs_dm_bulkstat_one.
608 * This is also used to count inodes/blks, etc
609 * in xfs_qm_quotacheck.
611 ubused
= statstruct_size
;
612 error
= formatter(mp
, ino
, ubufp
,
613 ubleft
, private_data
,
614 bno
, &ubused
, dip
, &fmterror
);
615 if (fmterror
== BULKSTAT_RV_NOTHING
) {
620 if (fmterror
== BULKSTAT_RV_GIVEUP
) {
638 * Set up for the next loop iteration.
645 agino
= XFS_INO_TO_AGINO(mp
, lastino
);
650 * Done, we're either out of filesystem or space to put the data.
652 kmem_free(irbuf
, NBPC
);
654 unuseracc(ubuffer
, ubcount
* statstruct_size
, (B_READ
|B_PHYS
));
656 if (agno
>= mp
->m_sb
.sb_agcount
) {
658 * If we ran out of filesystem, mark lastino as off
659 * the end of the filesystem, so the next call
660 * will return immediately.
662 *lastinop
= (xfs_ino_t
)XFS_AGINO_TO_INO(mp
, agno
, 0);
665 *lastinop
= (xfs_ino_t
)lastino
;
671 * Return stat information in bulk (by-inode) for the filesystem.
672 * Special case for non-sequential one inode bulkstat.
674 int /* error status */
676 xfs_mount_t
*mp
, /* mount point for filesystem */
677 xfs_ino_t
*lastinop
, /* inode to return */
678 char __user
*buffer
, /* buffer with inode stats */
679 int *done
) /* 1 if there are more stats to get */
681 int count
; /* count value for bulkstat call */
682 int error
; /* return value */
683 xfs_ino_t ino
; /* filesystem inode number */
684 int res
; /* result from bs1 */
687 * note that requesting valid inode numbers which are not allocated
688 * to inodes will most likely cause xfs_itobp to generate warning
689 * messages about bad magic numbers. This is ok. The fact that
690 * the inode isn't actually an inode is handled by the
691 * error check below. Done this way to make the usual case faster
692 * at the expense of the error case.
695 ino
= (xfs_ino_t
)*lastinop
;
696 error
= xfs_bulkstat_one(mp
, ino
, buffer
, sizeof(xfs_bstat_t
),
697 NULL
, 0, NULL
, NULL
, &res
);
700 * Special case way failed, do it the "long" way
701 * to see if that works.
705 if (xfs_bulkstat(mp
, lastinop
, &count
, xfs_bulkstat_one
,
706 NULL
, sizeof(xfs_bstat_t
), buffer
,
707 BULKSTAT_FG_IGET
, done
))
709 if (count
== 0 || (xfs_ino_t
)*lastinop
!= ino
)
710 return error
== EFSCORRUPTED
?
711 XFS_ERROR(EINVAL
) : error
;
720 * Return inode number table for the filesystem.
722 int /* error status */
724 xfs_mount_t
*mp
, /* mount point for filesystem */
725 xfs_ino_t
*lastino
, /* last inode returned */
726 int *count
, /* size of buffer/count returned */
727 xfs_inogrp_t __user
*ubuffer
)/* buffer with inode descriptions */
733 xfs_inogrp_t
*buffer
;
735 xfs_btree_cur_t
*cur
;
745 ino
= (xfs_ino_t
)*lastino
;
746 agno
= XFS_INO_TO_AGNO(mp
, ino
);
747 agino
= XFS_INO_TO_AGINO(mp
, ino
);
750 bcount
= MIN(left
, (int)(NBPP
/ sizeof(*buffer
)));
751 buffer
= kmem_alloc(bcount
* sizeof(*buffer
), KM_SLEEP
);
755 while (left
> 0 && agno
< mp
->m_sb
.sb_agcount
) {
757 down_read(&mp
->m_peraglock
);
758 error
= xfs_ialloc_read_agi(mp
, NULL
, agno
, &agbp
);
759 up_read(&mp
->m_peraglock
);
762 * If we can't read the AGI of this ag,
763 * then just skip to the next one.
771 cur
= xfs_btree_init_cursor(mp
, NULL
, agbp
, agno
,
772 XFS_BTNUM_INO
, (xfs_inode_t
*)0, 0);
773 error
= xfs_inobt_lookup_ge(cur
, agino
, 0, 0, &tmp
);
775 xfs_btree_del_cursor(cur
, XFS_BTREE_ERROR
);
780 * Move up the the last inode in the current
781 * chunk. The lookup_ge will always get
782 * us the first inode in the next chunk.
784 agino
+= XFS_INODES_PER_CHUNK
- 1;
788 if ((error
= xfs_inobt_get_rec(cur
, &gino
, &gcnt
, &gfree
,
793 xfs_btree_del_cursor(cur
, XFS_BTREE_NOERROR
);
799 agino
= gino
+ XFS_INODES_PER_CHUNK
- 1;
800 buffer
[bufidx
].xi_startino
= XFS_AGINO_TO_INO(mp
, agno
, gino
);
801 buffer
[bufidx
].xi_alloccount
= XFS_INODES_PER_CHUNK
- gcnt
;
802 buffer
[bufidx
].xi_allocmask
= ~gfree
;
805 if (bufidx
== bcount
) {
806 if (copy_to_user(ubuffer
, buffer
,
807 bufidx
* sizeof(*buffer
))) {
808 error
= XFS_ERROR(EFAULT
);
816 error
= xfs_inobt_increment(cur
, 0, &tmp
);
818 xfs_btree_del_cursor(cur
, XFS_BTREE_ERROR
);
823 * The agino value has already been bumped.
824 * Just try to skip up to it.
826 agino
+= XFS_INODES_PER_CHUNK
;
833 if (copy_to_user(ubuffer
, buffer
,
834 bufidx
* sizeof(*buffer
)))
835 error
= XFS_ERROR(EFAULT
);
839 *lastino
= XFS_AGINO_TO_INO(mp
, agno
, agino
);
841 kmem_free(buffer
, bcount
* sizeof(*buffer
));
843 xfs_btree_del_cursor(cur
, (error
? XFS_BTREE_ERROR
: