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 */
61 error
= xfs_iget(mp
, NULL
, ino
, 0, XFS_ILOCK_SHARED
, &ip
, bno
);
63 *stat
= BULKSTAT_RV_NOTHING
;
68 ASSERT(ip
->i_blkno
!= (xfs_daddr_t
)0);
69 if (ip
->i_d
.di_mode
== 0) {
70 *stat
= BULKSTAT_RV_NOTHING
;
71 error
= XFS_ERROR(ENOENT
);
77 /* xfs_iget returns the following without needing
80 buf
->bs_nlink
= dic
->di_nlink
;
81 buf
->bs_projid
= dic
->di_projid
;
83 buf
->bs_mode
= dic
->di_mode
;
84 buf
->bs_uid
= dic
->di_uid
;
85 buf
->bs_gid
= dic
->di_gid
;
86 buf
->bs_size
= dic
->di_size
;
87 buf
->bs_atime
.tv_sec
= dic
->di_atime
.t_sec
;
88 buf
->bs_atime
.tv_nsec
= dic
->di_atime
.t_nsec
;
89 buf
->bs_mtime
.tv_sec
= dic
->di_mtime
.t_sec
;
90 buf
->bs_mtime
.tv_nsec
= dic
->di_mtime
.t_nsec
;
91 buf
->bs_ctime
.tv_sec
= dic
->di_ctime
.t_sec
;
92 buf
->bs_ctime
.tv_nsec
= dic
->di_ctime
.t_nsec
;
93 buf
->bs_xflags
= xfs_ip2xflags(ip
);
94 buf
->bs_extsize
= dic
->di_extsize
<< mp
->m_sb
.sb_blocklog
;
95 buf
->bs_extents
= dic
->di_nextents
;
96 buf
->bs_gen
= dic
->di_gen
;
97 memset(buf
->bs_pad
, 0, sizeof(buf
->bs_pad
));
98 buf
->bs_dmevmask
= dic
->di_dmevmask
;
99 buf
->bs_dmstate
= dic
->di_dmstate
;
100 buf
->bs_aextents
= dic
->di_anextents
;
102 switch (dic
->di_format
) {
103 case XFS_DINODE_FMT_DEV
:
104 buf
->bs_rdev
= ip
->i_df
.if_u2
.if_rdev
;
105 buf
->bs_blksize
= BLKDEV_IOSIZE
;
108 case XFS_DINODE_FMT_LOCAL
:
109 case XFS_DINODE_FMT_UUID
:
111 buf
->bs_blksize
= mp
->m_sb
.sb_blocksize
;
114 case XFS_DINODE_FMT_EXTENTS
:
115 case XFS_DINODE_FMT_BTREE
:
117 buf
->bs_blksize
= mp
->m_sb
.sb_blocksize
;
118 buf
->bs_blocks
= dic
->di_nblocks
+ ip
->i_delayed_blks
;
123 xfs_iput(ip
, XFS_ILOCK_SHARED
);
128 xfs_bulkstat_one_dinode(
129 xfs_mount_t
*mp
, /* mount point for filesystem */
130 xfs_ino_t ino
, /* inode number to get data for */
131 xfs_dinode_t
*dip
, /* dinode inode pointer */
132 xfs_bstat_t
*buf
) /* return buffer */
134 xfs_dinode_core_t
*dic
; /* dinode core info pointer */
139 * The inode format changed when we moved the link count and
140 * made it 32 bits long. If this is an old format inode,
141 * convert it in memory to look like a new one. If it gets
142 * flushed to disk we will convert back before flushing or
143 * logging it. We zero out the new projid field and the old link
144 * count field. We'll handle clearing the pad field (the remains
145 * of the old uuid field) when we actually convert the inode to
146 * the new format. We don't change the version number so that we
147 * can distinguish this from a real new format inode.
149 if (INT_GET(dic
->di_version
, ARCH_CONVERT
) == XFS_DINODE_VERSION_1
) {
150 buf
->bs_nlink
= INT_GET(dic
->di_onlink
, ARCH_CONVERT
);
153 buf
->bs_nlink
= INT_GET(dic
->di_nlink
, ARCH_CONVERT
);
154 buf
->bs_projid
= INT_GET(dic
->di_projid
, ARCH_CONVERT
);
158 buf
->bs_mode
= INT_GET(dic
->di_mode
, ARCH_CONVERT
);
159 buf
->bs_uid
= INT_GET(dic
->di_uid
, ARCH_CONVERT
);
160 buf
->bs_gid
= INT_GET(dic
->di_gid
, ARCH_CONVERT
);
161 buf
->bs_size
= INT_GET(dic
->di_size
, ARCH_CONVERT
);
162 buf
->bs_atime
.tv_sec
= INT_GET(dic
->di_atime
.t_sec
, ARCH_CONVERT
);
163 buf
->bs_atime
.tv_nsec
= INT_GET(dic
->di_atime
.t_nsec
, ARCH_CONVERT
);
164 buf
->bs_mtime
.tv_sec
= INT_GET(dic
->di_mtime
.t_sec
, ARCH_CONVERT
);
165 buf
->bs_mtime
.tv_nsec
= INT_GET(dic
->di_mtime
.t_nsec
, ARCH_CONVERT
);
166 buf
->bs_ctime
.tv_sec
= INT_GET(dic
->di_ctime
.t_sec
, ARCH_CONVERT
);
167 buf
->bs_ctime
.tv_nsec
= INT_GET(dic
->di_ctime
.t_nsec
, ARCH_CONVERT
);
168 buf
->bs_xflags
= xfs_dic2xflags(dic
);
169 buf
->bs_extsize
= INT_GET(dic
->di_extsize
, ARCH_CONVERT
) << mp
->m_sb
.sb_blocklog
;
170 buf
->bs_extents
= INT_GET(dic
->di_nextents
, ARCH_CONVERT
);
171 buf
->bs_gen
= INT_GET(dic
->di_gen
, ARCH_CONVERT
);
172 memset(buf
->bs_pad
, 0, sizeof(buf
->bs_pad
));
173 buf
->bs_dmevmask
= INT_GET(dic
->di_dmevmask
, ARCH_CONVERT
);
174 buf
->bs_dmstate
= INT_GET(dic
->di_dmstate
, ARCH_CONVERT
);
175 buf
->bs_aextents
= INT_GET(dic
->di_anextents
, ARCH_CONVERT
);
177 switch (INT_GET(dic
->di_format
, ARCH_CONVERT
)) {
178 case XFS_DINODE_FMT_DEV
:
179 buf
->bs_rdev
= INT_GET(dip
->di_u
.di_dev
, ARCH_CONVERT
);
180 buf
->bs_blksize
= BLKDEV_IOSIZE
;
183 case XFS_DINODE_FMT_LOCAL
:
184 case XFS_DINODE_FMT_UUID
:
186 buf
->bs_blksize
= mp
->m_sb
.sb_blocksize
;
189 case XFS_DINODE_FMT_EXTENTS
:
190 case XFS_DINODE_FMT_BTREE
:
192 buf
->bs_blksize
= mp
->m_sb
.sb_blocksize
;
193 buf
->bs_blocks
= INT_GET(dic
->di_nblocks
, ARCH_CONVERT
);
201 * Return stat information for one inode.
202 * Return 0 if ok, else errno.
204 int /* error status */
206 xfs_mount_t
*mp
, /* mount point for filesystem */
207 xfs_ino_t ino
, /* inode number to get data for */
208 void __user
*buffer
, /* buffer to place output in */
209 int ubsize
, /* size of buffer */
210 void *private_data
, /* my private data */
211 xfs_daddr_t bno
, /* starting bno of inode cluster */
212 int *ubused
, /* bytes used by me */
213 void *dibuff
, /* on-disk inode buffer */
214 int *stat
) /* BULKSTAT_RV_... */
216 xfs_bstat_t
*buf
; /* return buffer */
217 int error
= 0; /* error value */
218 xfs_dinode_t
*dip
; /* dinode inode pointer */
220 dip
= (xfs_dinode_t
*)dibuff
;
222 if (!buffer
|| ino
== mp
->m_sb
.sb_rbmino
|| ino
== mp
->m_sb
.sb_rsumino
||
223 (XFS_SB_VERSION_HASQUOTA(&mp
->m_sb
) &&
224 (ino
== mp
->m_sb
.sb_uquotino
|| ino
== mp
->m_sb
.sb_gquotino
))) {
225 *stat
= BULKSTAT_RV_NOTHING
;
226 return XFS_ERROR(EINVAL
);
228 if (ubsize
< sizeof(*buf
)) {
229 *stat
= BULKSTAT_RV_NOTHING
;
230 return XFS_ERROR(ENOMEM
);
233 buf
= kmem_alloc(sizeof(*buf
), KM_SLEEP
);
236 /* We're not being passed a pointer to a dinode. This happens
237 * if BULKSTAT_FG_IGET is selected. Do the iget.
239 error
= xfs_bulkstat_one_iget(mp
, ino
, bno
, buf
, stat
);
243 xfs_bulkstat_one_dinode(mp
, ino
, dip
, buf
);
246 if (copy_to_user(buffer
, buf
, sizeof(*buf
))) {
247 *stat
= BULKSTAT_RV_NOTHING
;
252 *stat
= BULKSTAT_RV_DIDONE
;
254 *ubused
= sizeof(*buf
);
257 kmem_free(buf
, sizeof(*buf
));
262 * Return stat information in bulk (by-inode) for the filesystem.
264 int /* error status */
266 xfs_mount_t
*mp
, /* mount point for filesystem */
267 xfs_ino_t
*lastinop
, /* last inode returned */
268 int *ubcountp
, /* size of buffer/count returned */
269 bulkstat_one_pf formatter
, /* func that'd fill a single buf */
270 void *private_data
,/* private data for formatter */
271 size_t statstruct_size
, /* sizeof struct filling */
272 char __user
*ubuffer
, /* buffer with inode stats */
273 int flags
, /* defined in xfs_itable.h */
274 int *done
) /* 1 if there're more stats to get */
276 xfs_agblock_t agbno
=0;/* allocation group block number */
277 xfs_buf_t
*agbp
; /* agi header buffer */
278 xfs_agi_t
*agi
; /* agi header data */
279 xfs_agino_t agino
; /* inode # in allocation group */
280 xfs_agnumber_t agno
; /* allocation group number */
281 xfs_daddr_t bno
; /* inode cluster start daddr */
282 int chunkidx
; /* current index into inode chunk */
283 int clustidx
; /* current index into inode cluster */
284 xfs_btree_cur_t
*cur
; /* btree cursor for ialloc btree */
285 int end_of_ag
; /* set if we've seen the ag end */
286 int error
; /* error code */
287 int fmterror
;/* bulkstat formatter result */
288 __int32_t gcnt
; /* current btree rec's count */
289 xfs_inofree_t gfree
; /* current btree rec's free mask */
290 xfs_agino_t gino
; /* current btree rec's start inode */
291 int i
; /* loop index */
292 int icount
; /* count of inodes good in irbuf */
293 xfs_ino_t ino
; /* inode number (filesystem) */
294 xfs_inobt_rec_t
*irbp
; /* current irec buffer pointer */
295 xfs_inobt_rec_t
*irbuf
; /* start of irec buffer */
296 xfs_inobt_rec_t
*irbufend
; /* end of good irec buffer entries */
297 xfs_ino_t lastino
=0; /* last inode number returned */
298 int nbcluster
; /* # of blocks in a cluster */
299 int nicluster
; /* # of inodes in a cluster */
300 int nimask
; /* mask for inode clusters */
301 int nirbuf
; /* size of irbuf */
302 int rval
; /* return value error code */
303 int tmp
; /* result value from btree calls */
304 int ubcount
; /* size of user's buffer */
305 int ubleft
; /* bytes left in user's buffer */
306 char __user
*ubufp
; /* pointer into user's buffer */
307 int ubelem
; /* spaces used in user's buffer */
308 int ubused
; /* bytes used by formatter */
309 xfs_buf_t
*bp
; /* ptr to on-disk inode cluster buf */
310 xfs_dinode_t
*dip
; /* ptr into bp for specific inode */
311 xfs_inode_t
*ip
; /* ptr to in-core inode struct */
314 * Get the last inode value, see if there's nothing to do.
316 ino
= (xfs_ino_t
)*lastinop
;
318 agno
= XFS_INO_TO_AGNO(mp
, ino
);
319 agino
= XFS_INO_TO_AGINO(mp
, ino
);
320 if (agno
>= mp
->m_sb
.sb_agcount
||
321 ino
!= XFS_AGINO_TO_INO(mp
, agno
, agino
)) {
326 ubcount
= *ubcountp
; /* statstruct's */
327 ubleft
= ubcount
* statstruct_size
; /* bytes */
328 *ubcountp
= ubelem
= 0;
332 nicluster
= mp
->m_sb
.sb_blocksize
>= XFS_INODE_CLUSTER_SIZE(mp
) ?
333 mp
->m_sb
.sb_inopblock
:
334 (XFS_INODE_CLUSTER_SIZE(mp
) >> mp
->m_sb
.sb_inodelog
);
335 nimask
= ~(nicluster
- 1);
336 nbcluster
= nicluster
>> mp
->m_sb
.sb_inopblog
;
338 * Lock down the user's buffer. If a buffer was not sent, as in the case
339 * disk quota code calls here, we skip this.
342 (error
= useracc(ubuffer
, ubcount
* statstruct_size
,
343 (B_READ
|B_PHYS
), NULL
))) {
347 * Allocate a page-sized buffer for inode btree records.
348 * We could try allocating something smaller, but for normal
349 * calls we'll always (potentially) need the whole page.
351 irbuf
= kmem_alloc(NBPC
, KM_SLEEP
);
352 nirbuf
= NBPC
/ sizeof(*irbuf
);
354 * Loop over the allocation groups, starting from the last
355 * inode returned; 0 means start of the allocation group.
358 while (ubleft
>= statstruct_size
&& agno
< mp
->m_sb
.sb_agcount
) {
360 down_read(&mp
->m_peraglock
);
361 error
= xfs_ialloc_read_agi(mp
, NULL
, agno
, &agbp
);
362 up_read(&mp
->m_peraglock
);
365 * Skip this allocation group and go to the next one.
371 agi
= XFS_BUF_TO_AGI(agbp
);
373 * Allocate and initialize a btree cursor for ialloc btree.
375 cur
= xfs_btree_init_cursor(mp
, NULL
, agbp
, agno
, XFS_BTNUM_INO
,
376 (xfs_inode_t
*)0, 0);
378 irbufend
= irbuf
+ nirbuf
;
381 * If we're returning in the middle of an allocation group,
382 * we need to get the remainder of the chunk we're in.
386 * Lookup the inode chunk that this inode lives in.
388 error
= xfs_inobt_lookup_le(cur
, agino
, 0, 0, &tmp
);
389 if (!error
&& /* no I/O error */
390 tmp
&& /* lookup succeeded */
391 /* got the record, should always work */
392 !(error
= xfs_inobt_get_rec(cur
, &gino
, &gcnt
,
395 /* this is the right chunk */
396 agino
< gino
+ XFS_INODES_PER_CHUNK
&&
397 /* lastino was not last in chunk */
398 (chunkidx
= agino
- gino
+ 1) <
399 XFS_INODES_PER_CHUNK
&&
400 /* there are some left allocated */
401 XFS_INOBT_MASKN(chunkidx
,
402 XFS_INODES_PER_CHUNK
- chunkidx
) & ~gfree
) {
404 * Grab the chunk record. Mark all the
405 * uninteresting inodes (because they're
406 * before our start point) free.
408 for (i
= 0; i
< chunkidx
; i
++) {
409 if (XFS_INOBT_MASK(i
) & ~gfree
)
412 gfree
|= XFS_INOBT_MASKN(0, chunkidx
);
413 INT_SET(irbp
->ir_startino
, ARCH_CONVERT
, gino
);
414 INT_SET(irbp
->ir_freecount
, ARCH_CONVERT
, gcnt
);
415 INT_SET(irbp
->ir_free
, ARCH_CONVERT
, gfree
);
417 agino
= gino
+ XFS_INODES_PER_CHUNK
;
418 icount
= XFS_INODES_PER_CHUNK
- gcnt
;
421 * If any of those tests failed, bump the
422 * inode number (just in case).
428 * In any case, increment to the next record.
431 error
= xfs_inobt_increment(cur
, 0, &tmp
);
434 * Start of ag. Lookup the first inode chunk.
436 error
= xfs_inobt_lookup_ge(cur
, 0, 0, 0, &tmp
);
440 * Loop through inode btree records in this ag,
441 * until we run out of inodes or space in the buffer.
443 while (irbp
< irbufend
&& icount
< ubcount
) {
445 * Loop as long as we're unable to read the
449 agino
+= XFS_INODES_PER_CHUNK
;
450 if (XFS_AGINO_TO_AGBNO(mp
, agino
) >=
451 be32_to_cpu(agi
->agi_length
))
453 error
= xfs_inobt_lookup_ge(cur
, agino
, 0, 0,
457 * If ran off the end of the ag either with an error,
458 * or the normal way, set end and stop collecting.
461 (error
= xfs_inobt_get_rec(cur
, &gino
, &gcnt
,
468 * If this chunk has any allocated inodes, save it.
470 if (gcnt
< XFS_INODES_PER_CHUNK
) {
471 INT_SET(irbp
->ir_startino
, ARCH_CONVERT
, gino
);
472 INT_SET(irbp
->ir_freecount
, ARCH_CONVERT
, gcnt
);
473 INT_SET(irbp
->ir_free
, ARCH_CONVERT
, gfree
);
475 icount
+= XFS_INODES_PER_CHUNK
- gcnt
;
478 * Set agino to after this chunk and bump the cursor.
480 agino
= gino
+ XFS_INODES_PER_CHUNK
;
481 error
= xfs_inobt_increment(cur
, 0, &tmp
);
484 * Drop the btree buffers and the agi buffer.
485 * We can't hold any of the locks these represent
488 xfs_btree_del_cursor(cur
, XFS_BTREE_NOERROR
);
491 * Now format all the good inodes into the user's buffer.
495 irbp
< irbufend
&& ubleft
>= statstruct_size
; irbp
++) {
497 * Read-ahead the next chunk's worth of inodes.
499 if (&irbp
[1] < irbufend
) {
501 * Loop over all clusters in the next chunk.
502 * Do a readahead if there are any allocated
503 * inodes in that cluster.
505 for (agbno
= XFS_AGINO_TO_AGBNO(mp
,
506 INT_GET(irbp
[1].ir_startino
, ARCH_CONVERT
)),
508 chunkidx
< XFS_INODES_PER_CHUNK
;
509 chunkidx
+= nicluster
,
510 agbno
+= nbcluster
) {
511 if (XFS_INOBT_MASKN(chunkidx
,
513 ~(INT_GET(irbp
[1].ir_free
, ARCH_CONVERT
)))
514 xfs_btree_reada_bufs(mp
, agno
,
519 * Now process this chunk of inodes.
521 for (agino
= INT_GET(irbp
->ir_startino
, ARCH_CONVERT
), chunkidx
= 0, clustidx
= 0;
523 INT_GET(irbp
->ir_freecount
, ARCH_CONVERT
) < XFS_INODES_PER_CHUNK
;
524 chunkidx
++, clustidx
++, agino
++) {
525 ASSERT(chunkidx
< XFS_INODES_PER_CHUNK
);
527 * Recompute agbno if this is the
528 * first inode of the cluster.
530 * Careful with clustidx. There can be
531 * multple clusters per chunk, a single
532 * cluster per chunk or a cluster that has
533 * inodes represented from several different
534 * chunks (if blocksize is large).
536 * Because of this, the starting clustidx is
537 * initialized to zero in this loop but must
538 * later be reset after reading in the cluster
541 if ((chunkidx
& (nicluster
- 1)) == 0) {
542 agbno
= XFS_AGINO_TO_AGBNO(mp
,
543 INT_GET(irbp
->ir_startino
, ARCH_CONVERT
)) +
544 ((chunkidx
& nimask
) >>
545 mp
->m_sb
.sb_inopblog
);
547 if (flags
& BULKSTAT_FG_QUICK
) {
548 ino
= XFS_AGINO_TO_INO(mp
, agno
,
550 bno
= XFS_AGB_TO_DADDR(mp
, agno
,
554 * Get the inode cluster buffer
556 ASSERT(xfs_inode_zone
!= NULL
);
557 ip
= kmem_zone_zalloc(xfs_inode_zone
,
563 error
= xfs_itobp(mp
, NULL
, ip
,
566 clustidx
= ip
->i_boffset
/ mp
->m_sb
.sb_inodesize
;
567 kmem_zone_free(xfs_inode_zone
, ip
);
568 if (XFS_TEST_ERROR(error
!= 0,
569 mp
, XFS_ERRTAG_BULKSTAT_READ_CHUNK
,
570 XFS_RANDOM_BULKSTAT_READ_CHUNK
)) {
577 * Skip if this inode is free.
579 if (XFS_INOBT_MASK(chunkidx
) & INT_GET(irbp
->ir_free
, ARCH_CONVERT
))
582 * Count used inodes as free so we can tell
583 * when the chunk is used up.
585 INT_MOD(irbp
->ir_freecount
, ARCH_CONVERT
, +1);
586 ino
= XFS_AGINO_TO_INO(mp
, agno
, agino
);
587 bno
= XFS_AGB_TO_DADDR(mp
, agno
, agbno
);
588 if (flags
& BULKSTAT_FG_QUICK
) {
589 dip
= (xfs_dinode_t
*)xfs_buf_offset(bp
,
590 (clustidx
<< mp
->m_sb
.sb_inodelog
));
592 if (INT_GET(dip
->di_core
.di_magic
, ARCH_CONVERT
)
594 || !XFS_DINODE_GOOD_VERSION(
595 INT_GET(dip
->di_core
.di_version
, ARCH_CONVERT
)))
600 * Get the inode and fill in a single buffer.
601 * BULKSTAT_FG_QUICK uses dip to fill it in.
602 * BULKSTAT_FG_IGET uses igets.
603 * See: xfs_bulkstat_one & xfs_dm_bulkstat_one.
604 * This is also used to count inodes/blks, etc
605 * in xfs_qm_quotacheck.
607 ubused
= statstruct_size
;
608 error
= formatter(mp
, ino
, ubufp
,
609 ubleft
, private_data
,
610 bno
, &ubused
, dip
, &fmterror
);
611 if (fmterror
== BULKSTAT_RV_NOTHING
) {
616 if (fmterror
== BULKSTAT_RV_GIVEUP
) {
634 * Set up for the next loop iteration.
641 agino
= XFS_INO_TO_AGINO(mp
, lastino
);
646 * Done, we're either out of filesystem or space to put the data.
648 kmem_free(irbuf
, NBPC
);
650 unuseracc(ubuffer
, ubcount
* statstruct_size
, (B_READ
|B_PHYS
));
652 if (agno
>= mp
->m_sb
.sb_agcount
) {
654 * If we ran out of filesystem, mark lastino as off
655 * the end of the filesystem, so the next call
656 * will return immediately.
658 *lastinop
= (xfs_ino_t
)XFS_AGINO_TO_INO(mp
, agno
, 0);
661 *lastinop
= (xfs_ino_t
)lastino
;
667 * Return stat information in bulk (by-inode) for the filesystem.
668 * Special case for non-sequential one inode bulkstat.
670 int /* error status */
672 xfs_mount_t
*mp
, /* mount point for filesystem */
673 xfs_ino_t
*lastinop
, /* inode to return */
674 char __user
*buffer
, /* buffer with inode stats */
675 int *done
) /* 1 if there're more stats to get */
677 int count
; /* count value for bulkstat call */
678 int error
; /* return value */
679 xfs_ino_t ino
; /* filesystem inode number */
680 int res
; /* result from bs1 */
683 * note that requesting valid inode numbers which are not allocated
684 * to inodes will most likely cause xfs_itobp to generate warning
685 * messages about bad magic numbers. This is ok. The fact that
686 * the inode isn't actually an inode is handled by the
687 * error check below. Done this way to make the usual case faster
688 * at the expense of the error case.
691 ino
= (xfs_ino_t
)*lastinop
;
692 error
= xfs_bulkstat_one(mp
, ino
, buffer
, sizeof(xfs_bstat_t
),
693 NULL
, 0, NULL
, NULL
, &res
);
696 * Special case way failed, do it the "long" way
697 * to see if that works.
701 if (xfs_bulkstat(mp
, lastinop
, &count
, xfs_bulkstat_one
,
702 NULL
, sizeof(xfs_bstat_t
), buffer
,
703 BULKSTAT_FG_IGET
, done
))
705 if (count
== 0 || (xfs_ino_t
)*lastinop
!= ino
)
706 return error
== EFSCORRUPTED
?
707 XFS_ERROR(EINVAL
) : error
;
716 * Return inode number table for the filesystem.
718 int /* error status */
720 xfs_mount_t
*mp
, /* mount point for filesystem */
721 xfs_ino_t
*lastino
, /* last inode returned */
722 int *count
, /* size of buffer/count returned */
723 xfs_inogrp_t __user
*ubuffer
)/* buffer with inode descriptions */
729 xfs_inogrp_t
*buffer
;
731 xfs_btree_cur_t
*cur
;
741 ino
= (xfs_ino_t
)*lastino
;
742 agno
= XFS_INO_TO_AGNO(mp
, ino
);
743 agino
= XFS_INO_TO_AGINO(mp
, ino
);
746 bcount
= MIN(left
, (int)(NBPP
/ sizeof(*buffer
)));
747 buffer
= kmem_alloc(bcount
* sizeof(*buffer
), KM_SLEEP
);
751 while (left
> 0 && agno
< mp
->m_sb
.sb_agcount
) {
753 down_read(&mp
->m_peraglock
);
754 error
= xfs_ialloc_read_agi(mp
, NULL
, agno
, &agbp
);
755 up_read(&mp
->m_peraglock
);
758 * If we can't read the AGI of this ag,
759 * then just skip to the next one.
767 cur
= xfs_btree_init_cursor(mp
, NULL
, agbp
, agno
,
768 XFS_BTNUM_INO
, (xfs_inode_t
*)0, 0);
769 error
= xfs_inobt_lookup_ge(cur
, agino
, 0, 0, &tmp
);
771 xfs_btree_del_cursor(cur
, XFS_BTREE_ERROR
);
776 * Move up the the last inode in the current
777 * chunk. The lookup_ge will always get
778 * us the first inode in the next chunk.
780 agino
+= XFS_INODES_PER_CHUNK
- 1;
784 if ((error
= xfs_inobt_get_rec(cur
, &gino
, &gcnt
, &gfree
,
789 xfs_btree_del_cursor(cur
, XFS_BTREE_NOERROR
);
795 agino
= gino
+ XFS_INODES_PER_CHUNK
- 1;
796 buffer
[bufidx
].xi_startino
= XFS_AGINO_TO_INO(mp
, agno
, gino
);
797 buffer
[bufidx
].xi_alloccount
= XFS_INODES_PER_CHUNK
- gcnt
;
798 buffer
[bufidx
].xi_allocmask
= ~gfree
;
801 if (bufidx
== bcount
) {
802 if (copy_to_user(ubuffer
, buffer
,
803 bufidx
* sizeof(*buffer
))) {
804 error
= XFS_ERROR(EFAULT
);
812 error
= xfs_inobt_increment(cur
, 0, &tmp
);
814 xfs_btree_del_cursor(cur
, XFS_BTREE_ERROR
);
819 * The agino value has already been bumped.
820 * Just try to skip up to it.
822 agino
+= XFS_INODES_PER_CHUNK
;
829 if (copy_to_user(ubuffer
, buffer
,
830 bufidx
* sizeof(*buffer
)))
831 error
= XFS_ERROR(EFAULT
);
835 *lastino
= XFS_AGINO_TO_INO(mp
, agno
, agino
);
837 kmem_free(buffer
, bcount
* sizeof(*buffer
));
839 xfs_btree_del_cursor(cur
, (error
? XFS_BTREE_ERROR
: