2 * Copyright (c) 2000-2003 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/
33 #include <xfs/libxfs.h>
37 dotime(void *ti, char *s)
42 t = (xfs_bstime_t *)ti;
44 c = ctime(&t->tv_sec);
45 printf("\t%s %19.19s.%09d %s", s, c, t->tv_nsec, c + 20);
49 printbstat(xfs_bstat_t *sp)
51 printf("ino %lld mode %#o nlink %d uid %d gid %d rdev %#x\n",
52 sp->bs_ino, sp->bs_mode, sp->bs_nlink,
53 sp->bs_uid, sp->bs_gid, sp->bs_rdev);
54 printf("\tblksize %d size %lld blocks %lld xflags %#x extsize %d\n",
55 sp->bs_blksize, sp->bs_size, sp->bs_blocks,
56 sp->bs_xflags, sp->bs_extsize);
57 dotime(&sp->bs_atime, "atime");
58 dotime(&sp->bs_mtime, "mtime");
59 dotime(&sp->bs_ctime, "ctime");
60 printf( "\textents %d %d gen %d\n",
61 sp->bs_extents, sp->bs_aextents, sp->bs_gen);
62 printf( "\tDMI: event mask 0x%08x state 0x%04x\n",
63 sp->bs_dmevmask, sp->bs_dmstate);
67 printstat(struct stat64 *sp)
69 printf("ino %lld mode %#o nlink %d uid %d gid %d rdev %#x\n",
70 (xfs_ino_t)sp->st_ino, sp->st_mode, sp->st_nlink,
71 sp->st_uid, sp->st_gid, (unsigned int)sp->st_rdev);
72 printf("\tblksize %llu size %lld blocks %lld\n",
73 (__uint64_t)sp->st_blksize, sp->st_size, sp->st_blocks);
74 dotime(&sp->st_atime, "atime");
75 dotime(&sp->st_mtime, "mtime");
76 dotime(&sp->st_ctime, "ctime");
80 main(int argc, char **argv)
95 jdm_fshandle_t *fshandlep = NULL;
99 char *cc_readlinkbufp;
100 int cc_readlinkbufsz;
102 xfs_fsop_bulkreq_t bulkreq;
104 while ((c = getopt(argc, argv, "cdl:qv")) != -1) {
122 printf("usage: xfs_bstat [-c] [-q] [-v] [ dir [ batch_size ]]\n");
123 printf(" -c Check the results against stat(3) output\n");
124 printf(" -q Quiet\n");
125 printf(" -l _num_ Inode to start with\n");
126 printf(" -v Verbose output\n");
138 fsfd = open(name, O_RDONLY);
146 nent = atoi(*++argv);
149 printf("Bulkstat test on %s, batch size=%d statcheck=%d\n",
153 fshandlep = jdm_getfshandle( name );
155 printf("unable to construct sys handle for %s: %s\n",
156 name, strerror(errno));
161 t = malloc(nent * sizeof(*t));
165 "XFS_IOC_FSBULKSTAT test: last=%lld nent=%d\n", last, nent);
167 bulkreq.lastip = &last;
168 bulkreq.icount = nent;
170 bulkreq.ocount = &count;
172 while ((ret = xfsctl(name, fsfd, XFS_IOC_FSBULKSTAT, &bulkreq)) == 0) {
177 "XFS_IOC_FSBULKSTAT test: last=%lld ret=%d count=%d total=%d\n",
178 last, ret, count, total);
182 if ( quiet && ! statit )
185 for (i = 0; i < count; i++) {
191 switch(t[i].bs_mode & S_IFMT) {
193 cc_readlinkbufsz = MAXPATHLEN;
194 cc_readlinkbufp = (char *)calloc(
197 nread = jdm_readlink(
202 if (verbose && nread > 0)
204 "readlink: ino %lld: <%*s>\n",
208 free(cc_readlinkbufp);
211 "could not read symlink ino %llu\n",
225 fd = jdm_open( fshandlep, &t[i], O_RDONLY);
228 "unable to open handle ino %lld: %s\n",
229 t[i].bs_ino, strerror(errno));
232 if (fstat64(fd, &sb) < 0) {
234 "unable to stat ino %lld: %s\n",
235 t[i].bs_ino, strerror(errno));
240 * Don't compare blksize or blocks,
241 * they are used differently by stat
244 if ( (t[i].bs_ino != sb.st_ino) ||
245 (t[i].bs_mode != sb.st_mode) ||
246 (t[i].bs_nlink != sb.st_nlink) ||
247 (t[i].bs_uid != sb.st_uid) ||
248 (t[i].bs_gid != sb.st_gid) ||
249 (t[i].bs_rdev != sb.st_rdev) ||
250 (t[i].bs_size != sb.st_size) ||
251 /* (t[i].bs_blksize != sb.st_blksize) || */
252 (t[i].bs_mtime.tv_sec != sb.st_mtime) ||
253 (t[i].bs_ctime.tv_sec != sb.st_ctime) ) {
254 printf("\nstat/bstat missmatch\n");
270 perror("xfsctl(XFS_IOC_FSBULKSTAT)");
274 "XFS_IOC_FSBULKSTAT test: last=%lld nent=%d ret=%d count=%d\n",
275 last, nent, ret, count);