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 /* atime is only kept uptodate in the Linux inode */
90 buf
->bs_atime
.tv_sec
= vp
->v_inode
.i_atime
.tv_sec
;
91 buf
->bs_atime
.tv_nsec
= vp
->v_inode
.i_atime
.tv_nsec
;
92 buf
->bs_mtime
.tv_sec
= dic
->di_mtime
.t_sec
;
93 buf
->bs_mtime
.tv_nsec
= dic
->di_mtime
.t_nsec
;
94 buf
->bs_ctime
.tv_sec
= dic
->di_ctime
.t_sec
;
95 buf
->bs_ctime
.tv_nsec
= dic
->di_ctime
.t_nsec
;
96 buf
->bs_xflags
= xfs_ip2xflags(ip
);
97 buf
->bs_extsize
= dic
->di_extsize
<< mp
->m_sb
.sb_blocklog
;
98 buf
->bs_extents
= dic
->di_nextents
;
99 buf
->bs_gen
= dic
->di_gen
;
100 memset(buf
->bs_pad
, 0, sizeof(buf
->bs_pad
));
101 buf
->bs_dmevmask
= dic
->di_dmevmask
;
102 buf
->bs_dmstate
= dic
->di_dmstate
;
103 buf
->bs_aextents
= dic
->di_anextents
;
105 switch (dic
->di_format
) {
106 case XFS_DINODE_FMT_DEV
:
107 buf
->bs_rdev
= ip
->i_df
.if_u2
.if_rdev
;
108 buf
->bs_blksize
= BLKDEV_IOSIZE
;
111 case XFS_DINODE_FMT_LOCAL
:
112 case XFS_DINODE_FMT_UUID
:
114 buf
->bs_blksize
= mp
->m_sb
.sb_blocksize
;
117 case XFS_DINODE_FMT_EXTENTS
:
118 case XFS_DINODE_FMT_BTREE
:
120 buf
->bs_blksize
= mp
->m_sb
.sb_blocksize
;
121 buf
->bs_blocks
= dic
->di_nblocks
+ ip
->i_delayed_blks
;
126 xfs_iput(ip
, XFS_ILOCK_SHARED
);
131 xfs_bulkstat_one_dinode(
132 xfs_mount_t
*mp
, /* mount point for filesystem */
133 xfs_ino_t ino
, /* inode number to get data for */
134 xfs_dinode_t
*dip
, /* dinode inode pointer */
135 xfs_bstat_t
*buf
) /* return buffer */
137 xfs_dinode_core_t
*dic
; /* dinode core info pointer */
142 * The inode format changed when we moved the link count and
143 * made it 32 bits long. If this is an old format inode,
144 * convert it in memory to look like a new one. If it gets
145 * flushed to disk we will convert back before flushing or
146 * logging it. We zero out the new projid field and the old link
147 * count field. We'll handle clearing the pad field (the remains
148 * of the old uuid field) when we actually convert the inode to
149 * the new format. We don't change the version number so that we
150 * can distinguish this from a real new format inode.
152 if (INT_GET(dic
->di_version
, ARCH_CONVERT
) == XFS_DINODE_VERSION_1
) {
153 buf
->bs_nlink
= INT_GET(dic
->di_onlink
, ARCH_CONVERT
);
156 buf
->bs_nlink
= INT_GET(dic
->di_nlink
, ARCH_CONVERT
);
157 buf
->bs_projid
= INT_GET(dic
->di_projid
, ARCH_CONVERT
);
161 buf
->bs_mode
= INT_GET(dic
->di_mode
, ARCH_CONVERT
);
162 buf
->bs_uid
= INT_GET(dic
->di_uid
, ARCH_CONVERT
);
163 buf
->bs_gid
= INT_GET(dic
->di_gid
, ARCH_CONVERT
);
164 buf
->bs_size
= INT_GET(dic
->di_size
, ARCH_CONVERT
);
165 buf
->bs_atime
.tv_sec
= INT_GET(dic
->di_atime
.t_sec
, ARCH_CONVERT
);
166 buf
->bs_atime
.tv_nsec
= INT_GET(dic
->di_atime
.t_nsec
, ARCH_CONVERT
);
167 buf
->bs_mtime
.tv_sec
= INT_GET(dic
->di_mtime
.t_sec
, ARCH_CONVERT
);
168 buf
->bs_mtime
.tv_nsec
= INT_GET(dic
->di_mtime
.t_nsec
, ARCH_CONVERT
);
169 buf
->bs_ctime
.tv_sec
= INT_GET(dic
->di_ctime
.t_sec
, ARCH_CONVERT
);
170 buf
->bs_ctime
.tv_nsec
= INT_GET(dic
->di_ctime
.t_nsec
, ARCH_CONVERT
);
171 buf
->bs_xflags
= xfs_dic2xflags(dic
);
172 buf
->bs_extsize
= INT_GET(dic
->di_extsize
, ARCH_CONVERT
) << mp
->m_sb
.sb_blocklog
;
173 buf
->bs_extents
= INT_GET(dic
->di_nextents
, ARCH_CONVERT
);
174 buf
->bs_gen
= INT_GET(dic
->di_gen
, ARCH_CONVERT
);
175 memset(buf
->bs_pad
, 0, sizeof(buf
->bs_pad
));
176 buf
->bs_dmevmask
= INT_GET(dic
->di_dmevmask
, ARCH_CONVERT
);
177 buf
->bs_dmstate
= INT_GET(dic
->di_dmstate
, ARCH_CONVERT
);
178 buf
->bs_aextents
= INT_GET(dic
->di_anextents
, ARCH_CONVERT
);
180 switch (INT_GET(dic
->di_format
, ARCH_CONVERT
)) {
181 case XFS_DINODE_FMT_DEV
:
182 buf
->bs_rdev
= INT_GET(dip
->di_u
.di_dev
, ARCH_CONVERT
);
183 buf
->bs_blksize
= BLKDEV_IOSIZE
;
186 case XFS_DINODE_FMT_LOCAL
:
187 case XFS_DINODE_FMT_UUID
:
189 buf
->bs_blksize
= mp
->m_sb
.sb_blocksize
;
192 case XFS_DINODE_FMT_EXTENTS
:
193 case XFS_DINODE_FMT_BTREE
:
195 buf
->bs_blksize
= mp
->m_sb
.sb_blocksize
;
196 buf
->bs_blocks
= INT_GET(dic
->di_nblocks
, ARCH_CONVERT
);
204 * Return stat information for one inode.
205 * Return 0 if ok, else errno.
207 int /* error status */
209 xfs_mount_t
*mp
, /* mount point for filesystem */
210 xfs_ino_t ino
, /* inode number to get data for */
211 void __user
*buffer
, /* buffer to place output in */
212 int ubsize
, /* size of buffer */
213 void *private_data
, /* my private data */
214 xfs_daddr_t bno
, /* starting bno of inode cluster */
215 int *ubused
, /* bytes used by me */
216 void *dibuff
, /* on-disk inode buffer */
217 int *stat
) /* BULKSTAT_RV_... */
219 xfs_bstat_t
*buf
; /* return buffer */
220 int error
= 0; /* error value */
221 xfs_dinode_t
*dip
; /* dinode inode pointer */
223 dip
= (xfs_dinode_t
*)dibuff
;
225 if (!buffer
|| ino
== mp
->m_sb
.sb_rbmino
|| ino
== mp
->m_sb
.sb_rsumino
||
226 (XFS_SB_VERSION_HASQUOTA(&mp
->m_sb
) &&
227 (ino
== mp
->m_sb
.sb_uquotino
|| ino
== mp
->m_sb
.sb_gquotino
))) {
228 *stat
= BULKSTAT_RV_NOTHING
;
229 return XFS_ERROR(EINVAL
);
231 if (ubsize
< sizeof(*buf
)) {
232 *stat
= BULKSTAT_RV_NOTHING
;
233 return XFS_ERROR(ENOMEM
);
236 buf
= kmem_alloc(sizeof(*buf
), KM_SLEEP
);
239 /* We're not being passed a pointer to a dinode. This happens
240 * if BULKSTAT_FG_IGET is selected. Do the iget.
242 error
= xfs_bulkstat_one_iget(mp
, ino
, bno
, buf
, stat
);
246 xfs_bulkstat_one_dinode(mp
, ino
, dip
, buf
);
249 if (copy_to_user(buffer
, buf
, sizeof(*buf
))) {
250 *stat
= BULKSTAT_RV_NOTHING
;
255 *stat
= BULKSTAT_RV_DIDONE
;
257 *ubused
= sizeof(*buf
);
260 kmem_free(buf
, sizeof(*buf
));
265 * Return stat information in bulk (by-inode) for the filesystem.
267 int /* error status */
269 xfs_mount_t
*mp
, /* mount point for filesystem */
270 xfs_ino_t
*lastinop
, /* last inode returned */
271 int *ubcountp
, /* size of buffer/count returned */
272 bulkstat_one_pf formatter
, /* func that'd fill a single buf */
273 void *private_data
,/* private data for formatter */
274 size_t statstruct_size
, /* sizeof struct filling */
275 char __user
*ubuffer
, /* buffer with inode stats */
276 int flags
, /* defined in xfs_itable.h */
277 int *done
) /* 1 if there're more stats to get */
279 xfs_agblock_t agbno
=0;/* allocation group block number */
280 xfs_buf_t
*agbp
; /* agi header buffer */
281 xfs_agi_t
*agi
; /* agi header data */
282 xfs_agino_t agino
; /* inode # in allocation group */
283 xfs_agnumber_t agno
; /* allocation group number */
284 xfs_daddr_t bno
; /* inode cluster start daddr */
285 int chunkidx
; /* current index into inode chunk */
286 int clustidx
; /* current index into inode cluster */
287 xfs_btree_cur_t
*cur
; /* btree cursor for ialloc btree */
288 int end_of_ag
; /* set if we've seen the ag end */
289 int error
; /* error code */
290 int fmterror
;/* bulkstat formatter result */
291 __int32_t gcnt
; /* current btree rec's count */
292 xfs_inofree_t gfree
; /* current btree rec's free mask */
293 xfs_agino_t gino
; /* current btree rec's start inode */
294 int i
; /* loop index */
295 int icount
; /* count of inodes good in irbuf */
296 xfs_ino_t ino
; /* inode number (filesystem) */
297 xfs_inobt_rec_t
*irbp
; /* current irec buffer pointer */
298 xfs_inobt_rec_t
*irbuf
; /* start of irec buffer */
299 xfs_inobt_rec_t
*irbufend
; /* end of good irec buffer entries */
300 xfs_ino_t lastino
=0; /* last inode number returned */
301 int nbcluster
; /* # of blocks in a cluster */
302 int nicluster
; /* # of inodes in a cluster */
303 int nimask
; /* mask for inode clusters */
304 int nirbuf
; /* size of irbuf */
305 int rval
; /* return value error code */
306 int tmp
; /* result value from btree calls */
307 int ubcount
; /* size of user's buffer */
308 int ubleft
; /* bytes left in user's buffer */
309 char __user
*ubufp
; /* pointer into user's buffer */
310 int ubelem
; /* spaces used in user's buffer */
311 int ubused
; /* bytes used by formatter */
312 xfs_buf_t
*bp
; /* ptr to on-disk inode cluster buf */
313 xfs_dinode_t
*dip
; /* ptr into bp for specific inode */
314 xfs_inode_t
*ip
; /* ptr to in-core inode struct */
317 * Get the last inode value, see if there's nothing to do.
319 ino
= (xfs_ino_t
)*lastinop
;
321 agno
= XFS_INO_TO_AGNO(mp
, ino
);
322 agino
= XFS_INO_TO_AGINO(mp
, ino
);
323 if (agno
>= mp
->m_sb
.sb_agcount
||
324 ino
!= XFS_AGINO_TO_INO(mp
, agno
, agino
)) {
329 ubcount
= *ubcountp
; /* statstruct's */
330 ubleft
= ubcount
* statstruct_size
; /* bytes */
331 *ubcountp
= ubelem
= 0;
335 nicluster
= mp
->m_sb
.sb_blocksize
>= XFS_INODE_CLUSTER_SIZE(mp
) ?
336 mp
->m_sb
.sb_inopblock
:
337 (XFS_INODE_CLUSTER_SIZE(mp
) >> mp
->m_sb
.sb_inodelog
);
338 nimask
= ~(nicluster
- 1);
339 nbcluster
= nicluster
>> mp
->m_sb
.sb_inopblog
;
341 * Lock down the user's buffer. If a buffer was not sent, as in the case
342 * disk quota code calls here, we skip this.
345 (error
= useracc(ubuffer
, ubcount
* statstruct_size
,
346 (B_READ
|B_PHYS
), NULL
))) {
350 * Allocate a page-sized buffer for inode btree records.
351 * We could try allocating something smaller, but for normal
352 * calls we'll always (potentially) need the whole page.
354 irbuf
= kmem_alloc(NBPC
, KM_SLEEP
);
355 nirbuf
= NBPC
/ sizeof(*irbuf
);
357 * Loop over the allocation groups, starting from the last
358 * inode returned; 0 means start of the allocation group.
361 while (ubleft
>= statstruct_size
&& agno
< mp
->m_sb
.sb_agcount
) {
363 down_read(&mp
->m_peraglock
);
364 error
= xfs_ialloc_read_agi(mp
, NULL
, agno
, &agbp
);
365 up_read(&mp
->m_peraglock
);
368 * Skip this allocation group and go to the next one.
374 agi
= XFS_BUF_TO_AGI(agbp
);
376 * Allocate and initialize a btree cursor for ialloc btree.
378 cur
= xfs_btree_init_cursor(mp
, NULL
, agbp
, agno
, XFS_BTNUM_INO
,
379 (xfs_inode_t
*)0, 0);
381 irbufend
= irbuf
+ nirbuf
;
384 * If we're returning in the middle of an allocation group,
385 * we need to get the remainder of the chunk we're in.
389 * Lookup the inode chunk that this inode lives in.
391 error
= xfs_inobt_lookup_le(cur
, agino
, 0, 0, &tmp
);
392 if (!error
&& /* no I/O error */
393 tmp
&& /* lookup succeeded */
394 /* got the record, should always work */
395 !(error
= xfs_inobt_get_rec(cur
, &gino
, &gcnt
,
398 /* this is the right chunk */
399 agino
< gino
+ XFS_INODES_PER_CHUNK
&&
400 /* lastino was not last in chunk */
401 (chunkidx
= agino
- gino
+ 1) <
402 XFS_INODES_PER_CHUNK
&&
403 /* there are some left allocated */
404 XFS_INOBT_MASKN(chunkidx
,
405 XFS_INODES_PER_CHUNK
- chunkidx
) & ~gfree
) {
407 * Grab the chunk record. Mark all the
408 * uninteresting inodes (because they're
409 * before our start point) free.
411 for (i
= 0; i
< chunkidx
; i
++) {
412 if (XFS_INOBT_MASK(i
) & ~gfree
)
415 gfree
|= XFS_INOBT_MASKN(0, chunkidx
);
416 INT_SET(irbp
->ir_startino
, ARCH_CONVERT
, gino
);
417 INT_SET(irbp
->ir_freecount
, ARCH_CONVERT
, gcnt
);
418 INT_SET(irbp
->ir_free
, ARCH_CONVERT
, gfree
);
420 agino
= gino
+ XFS_INODES_PER_CHUNK
;
421 icount
= XFS_INODES_PER_CHUNK
- gcnt
;
424 * If any of those tests failed, bump the
425 * inode number (just in case).
431 * In any case, increment to the next record.
434 error
= xfs_inobt_increment(cur
, 0, &tmp
);
437 * Start of ag. Lookup the first inode chunk.
439 error
= xfs_inobt_lookup_ge(cur
, 0, 0, 0, &tmp
);
443 * Loop through inode btree records in this ag,
444 * until we run out of inodes or space in the buffer.
446 while (irbp
< irbufend
&& icount
< ubcount
) {
448 * Loop as long as we're unable to read the
452 agino
+= XFS_INODES_PER_CHUNK
;
453 if (XFS_AGINO_TO_AGBNO(mp
, agino
) >=
454 be32_to_cpu(agi
->agi_length
))
456 error
= xfs_inobt_lookup_ge(cur
, agino
, 0, 0,
460 * If ran off the end of the ag either with an error,
461 * or the normal way, set end and stop collecting.
464 (error
= xfs_inobt_get_rec(cur
, &gino
, &gcnt
,
471 * If this chunk has any allocated inodes, save it.
473 if (gcnt
< XFS_INODES_PER_CHUNK
) {
474 INT_SET(irbp
->ir_startino
, ARCH_CONVERT
, gino
);
475 INT_SET(irbp
->ir_freecount
, ARCH_CONVERT
, gcnt
);
476 INT_SET(irbp
->ir_free
, ARCH_CONVERT
, gfree
);
478 icount
+= XFS_INODES_PER_CHUNK
- gcnt
;
481 * Set agino to after this chunk and bump the cursor.
483 agino
= gino
+ XFS_INODES_PER_CHUNK
;
484 error
= xfs_inobt_increment(cur
, 0, &tmp
);
487 * Drop the btree buffers and the agi buffer.
488 * We can't hold any of the locks these represent
491 xfs_btree_del_cursor(cur
, XFS_BTREE_NOERROR
);
494 * Now format all the good inodes into the user's buffer.
498 irbp
< irbufend
&& ubleft
>= statstruct_size
; irbp
++) {
500 * Read-ahead the next chunk's worth of inodes.
502 if (&irbp
[1] < irbufend
) {
504 * Loop over all clusters in the next chunk.
505 * Do a readahead if there are any allocated
506 * inodes in that cluster.
508 for (agbno
= XFS_AGINO_TO_AGBNO(mp
,
509 INT_GET(irbp
[1].ir_startino
, ARCH_CONVERT
)),
511 chunkidx
< XFS_INODES_PER_CHUNK
;
512 chunkidx
+= nicluster
,
513 agbno
+= nbcluster
) {
514 if (XFS_INOBT_MASKN(chunkidx
,
516 ~(INT_GET(irbp
[1].ir_free
, ARCH_CONVERT
)))
517 xfs_btree_reada_bufs(mp
, agno
,
522 * Now process this chunk of inodes.
524 for (agino
= INT_GET(irbp
->ir_startino
, ARCH_CONVERT
), chunkidx
= 0, clustidx
= 0;
526 INT_GET(irbp
->ir_freecount
, ARCH_CONVERT
) < XFS_INODES_PER_CHUNK
;
527 chunkidx
++, clustidx
++, agino
++) {
528 ASSERT(chunkidx
< XFS_INODES_PER_CHUNK
);
530 * Recompute agbno if this is the
531 * first inode of the cluster.
533 * Careful with clustidx. There can be
534 * multple clusters per chunk, a single
535 * cluster per chunk or a cluster that has
536 * inodes represented from several different
537 * chunks (if blocksize is large).
539 * Because of this, the starting clustidx is
540 * initialized to zero in this loop but must
541 * later be reset after reading in the cluster
544 if ((chunkidx
& (nicluster
- 1)) == 0) {
545 agbno
= XFS_AGINO_TO_AGBNO(mp
,
546 INT_GET(irbp
->ir_startino
, ARCH_CONVERT
)) +
547 ((chunkidx
& nimask
) >>
548 mp
->m_sb
.sb_inopblog
);
550 if (flags
& BULKSTAT_FG_QUICK
) {
551 ino
= XFS_AGINO_TO_INO(mp
, agno
,
553 bno
= XFS_AGB_TO_DADDR(mp
, agno
,
557 * Get the inode cluster buffer
559 ASSERT(xfs_inode_zone
!= NULL
);
560 ip
= kmem_zone_zalloc(xfs_inode_zone
,
566 error
= xfs_itobp(mp
, NULL
, ip
,
569 clustidx
= ip
->i_boffset
/ mp
->m_sb
.sb_inodesize
;
570 kmem_zone_free(xfs_inode_zone
, ip
);
571 if (XFS_TEST_ERROR(error
!= 0,
572 mp
, XFS_ERRTAG_BULKSTAT_READ_CHUNK
,
573 XFS_RANDOM_BULKSTAT_READ_CHUNK
)) {
580 * Skip if this inode is free.
582 if (XFS_INOBT_MASK(chunkidx
) & INT_GET(irbp
->ir_free
, ARCH_CONVERT
))
585 * Count used inodes as free so we can tell
586 * when the chunk is used up.
588 INT_MOD(irbp
->ir_freecount
, ARCH_CONVERT
, +1);
589 ino
= XFS_AGINO_TO_INO(mp
, agno
, agino
);
590 bno
= XFS_AGB_TO_DADDR(mp
, agno
, agbno
);
591 if (flags
& BULKSTAT_FG_QUICK
) {
592 dip
= (xfs_dinode_t
*)xfs_buf_offset(bp
,
593 (clustidx
<< mp
->m_sb
.sb_inodelog
));
595 if (INT_GET(dip
->di_core
.di_magic
, ARCH_CONVERT
)
597 || !XFS_DINODE_GOOD_VERSION(
598 INT_GET(dip
->di_core
.di_version
, ARCH_CONVERT
)))
603 * Get the inode and fill in a single buffer.
604 * BULKSTAT_FG_QUICK uses dip to fill it in.
605 * BULKSTAT_FG_IGET uses igets.
606 * See: xfs_bulkstat_one & xfs_dm_bulkstat_one.
607 * This is also used to count inodes/blks, etc
608 * in xfs_qm_quotacheck.
610 ubused
= statstruct_size
;
611 error
= formatter(mp
, ino
, ubufp
,
612 ubleft
, private_data
,
613 bno
, &ubused
, dip
, &fmterror
);
614 if (fmterror
== BULKSTAT_RV_NOTHING
) {
619 if (fmterror
== BULKSTAT_RV_GIVEUP
) {
637 * Set up for the next loop iteration.
644 agino
= XFS_INO_TO_AGINO(mp
, lastino
);
649 * Done, we're either out of filesystem or space to put the data.
651 kmem_free(irbuf
, NBPC
);
653 unuseracc(ubuffer
, ubcount
* statstruct_size
, (B_READ
|B_PHYS
));
655 if (agno
>= mp
->m_sb
.sb_agcount
) {
657 * If we ran out of filesystem, mark lastino as off
658 * the end of the filesystem, so the next call
659 * will return immediately.
661 *lastinop
= (xfs_ino_t
)XFS_AGINO_TO_INO(mp
, agno
, 0);
664 *lastinop
= (xfs_ino_t
)lastino
;
670 * Return stat information in bulk (by-inode) for the filesystem.
671 * Special case for non-sequential one inode bulkstat.
673 int /* error status */
675 xfs_mount_t
*mp
, /* mount point for filesystem */
676 xfs_ino_t
*lastinop
, /* inode to return */
677 char __user
*buffer
, /* buffer with inode stats */
678 int *done
) /* 1 if there're more stats to get */
680 int count
; /* count value for bulkstat call */
681 int error
; /* return value */
682 xfs_ino_t ino
; /* filesystem inode number */
683 int res
; /* result from bs1 */
686 * note that requesting valid inode numbers which are not allocated
687 * to inodes will most likely cause xfs_itobp to generate warning
688 * messages about bad magic numbers. This is ok. The fact that
689 * the inode isn't actually an inode is handled by the
690 * error check below. Done this way to make the usual case faster
691 * at the expense of the error case.
694 ino
= (xfs_ino_t
)*lastinop
;
695 error
= xfs_bulkstat_one(mp
, ino
, buffer
, sizeof(xfs_bstat_t
),
696 NULL
, 0, NULL
, NULL
, &res
);
699 * Special case way failed, do it the "long" way
700 * to see if that works.
704 if (xfs_bulkstat(mp
, lastinop
, &count
, xfs_bulkstat_one
,
705 NULL
, sizeof(xfs_bstat_t
), buffer
,
706 BULKSTAT_FG_IGET
, done
))
708 if (count
== 0 || (xfs_ino_t
)*lastinop
!= ino
)
709 return error
== EFSCORRUPTED
?
710 XFS_ERROR(EINVAL
) : error
;
719 * Return inode number table for the filesystem.
721 int /* error status */
723 xfs_mount_t
*mp
, /* mount point for filesystem */
724 xfs_ino_t
*lastino
, /* last inode returned */
725 int *count
, /* size of buffer/count returned */
726 xfs_inogrp_t __user
*ubuffer
)/* buffer with inode descriptions */
732 xfs_inogrp_t
*buffer
;
734 xfs_btree_cur_t
*cur
;
744 ino
= (xfs_ino_t
)*lastino
;
745 agno
= XFS_INO_TO_AGNO(mp
, ino
);
746 agino
= XFS_INO_TO_AGINO(mp
, ino
);
749 bcount
= MIN(left
, (int)(NBPP
/ sizeof(*buffer
)));
750 buffer
= kmem_alloc(bcount
* sizeof(*buffer
), KM_SLEEP
);
754 while (left
> 0 && agno
< mp
->m_sb
.sb_agcount
) {
756 down_read(&mp
->m_peraglock
);
757 error
= xfs_ialloc_read_agi(mp
, NULL
, agno
, &agbp
);
758 up_read(&mp
->m_peraglock
);
761 * If we can't read the AGI of this ag,
762 * then just skip to the next one.
770 cur
= xfs_btree_init_cursor(mp
, NULL
, agbp
, agno
,
771 XFS_BTNUM_INO
, (xfs_inode_t
*)0, 0);
772 error
= xfs_inobt_lookup_ge(cur
, agino
, 0, 0, &tmp
);
774 xfs_btree_del_cursor(cur
, XFS_BTREE_ERROR
);
779 * Move up the the last inode in the current
780 * chunk. The lookup_ge will always get
781 * us the first inode in the next chunk.
783 agino
+= XFS_INODES_PER_CHUNK
- 1;
787 if ((error
= xfs_inobt_get_rec(cur
, &gino
, &gcnt
, &gfree
,
792 xfs_btree_del_cursor(cur
, XFS_BTREE_NOERROR
);
798 agino
= gino
+ XFS_INODES_PER_CHUNK
- 1;
799 buffer
[bufidx
].xi_startino
= XFS_AGINO_TO_INO(mp
, agno
, gino
);
800 buffer
[bufidx
].xi_alloccount
= XFS_INODES_PER_CHUNK
- gcnt
;
801 buffer
[bufidx
].xi_allocmask
= ~gfree
;
804 if (bufidx
== bcount
) {
805 if (copy_to_user(ubuffer
, buffer
,
806 bufidx
* sizeof(*buffer
))) {
807 error
= XFS_ERROR(EFAULT
);
815 error
= xfs_inobt_increment(cur
, 0, &tmp
);
817 xfs_btree_del_cursor(cur
, XFS_BTREE_ERROR
);
822 * The agino value has already been bumped.
823 * Just try to skip up to it.
825 agino
+= XFS_INODES_PER_CHUNK
;
832 if (copy_to_user(ubuffer
, buffer
,
833 bufidx
* sizeof(*buffer
)))
834 error
= XFS_ERROR(EFAULT
);
838 *lastino
= XFS_AGINO_TO_INO(mp
, agno
, agino
);
840 kmem_free(buffer
, bcount
* sizeof(*buffer
));
842 xfs_btree_del_cursor(cur
, (error
? XFS_BTREE_ERROR
: