2 * Copyright (c) 2000-2003 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
23 dotime(void *ti, char *s)
28 t = (xfs_bstime_t *)ti;
30 c = ctime(&t->tv_sec);
31 printf("\t%s %19.19s.%09d %s", s, c, t->tv_nsec, c + 20);
35 printbstat(xfs_bstat_t *sp)
37 printf("ino %lld mode %#o nlink %d uid %d gid %d rdev %#x\n",
38 (long long)sp->bs_ino, sp->bs_mode, sp->bs_nlink,
39 sp->bs_uid, sp->bs_gid, sp->bs_rdev);
40 printf("\tblksize %d size %lld blocks %lld xflags %#x extsize %d\n",
41 sp->bs_blksize, (long long)sp->bs_size, (long long)sp->bs_blocks,
42 sp->bs_xflags, sp->bs_extsize);
43 dotime(&sp->bs_atime, "atime");
44 dotime(&sp->bs_mtime, "mtime");
45 dotime(&sp->bs_ctime, "ctime");
46 printf( "\textents %d %d gen %d\n",
47 sp->bs_extents, sp->bs_aextents, sp->bs_gen);
48 printf( "\tDMI: event mask 0x%08x state 0x%04x\n",
49 sp->bs_dmevmask, sp->bs_dmstate);
53 printstat(struct stat64 *sp)
55 printf("ino %lld mode %#o nlink %d uid %d gid %d rdev %#x\n",
56 (long long)sp->st_ino, (unsigned int)sp->st_mode, (int)sp->st_nlink,
57 (int)sp->st_uid, (int)sp->st_gid, (int)sp->st_rdev);
58 printf("\tblksize %llu size %lld blocks %lld\n",
59 (unsigned long long)sp->st_blksize, (long long)sp->st_size, (long long)sp->st_blocks);
60 dotime(&sp->st_atime, "atime");
61 dotime(&sp->st_mtime, "mtime");
62 dotime(&sp->st_ctime, "ctime");
66 main(int argc, char **argv)
81 jdm_fshandle_t *fshandlep = NULL;
85 char *cc_readlinkbufp;
88 xfs_fsop_bulkreq_t bulkreq;
90 while ((c = getopt(argc, argv, "cdl:qv")) != -1) {
108 printf("usage: xfs_bstat [-c] [-q] [-v] [ dir [ batch_size ]]\n");
109 printf(" -c Check the results against stat(3) output\n");
110 printf(" -q Quiet\n");
111 printf(" -l _num_ Inode to start with\n");
112 printf(" -v Verbose output\n");
124 fsfd = open(name, O_RDONLY);
132 nent = atoi(*++argv);
135 printf("Bulkstat test on %s, batch size=%d statcheck=%d\n",
139 fshandlep = jdm_getfshandle( name );
141 printf("unable to construct sys handle for %s: %s\n",
142 name, strerror(errno));
147 t = malloc(nent * sizeof(*t));
151 "XFS_IOC_FSBULKSTAT test: last=%lld nent=%d\n", (long long)last, nent);
153 bulkreq.lastip = &last;
154 bulkreq.icount = nent;
156 bulkreq.ocount = &count;
158 while ((ret = xfsctl(name, fsfd, XFS_IOC_FSBULKSTAT, &bulkreq)) == 0) {
163 "XFS_IOC_FSBULKSTAT test: last=%lld ret=%d count=%d total=%d\n",
164 (long long)last, ret, count, total);
168 if ( quiet && ! statit )
171 for (i = 0; i < count; i++) {
177 switch(t[i].bs_mode & S_IFMT) {
179 cc_readlinkbufsz = MAXPATHLEN;
180 cc_readlinkbufp = (char *)calloc(
183 nread = jdm_readlink(
188 if (verbose && nread > 0)
190 "readlink: ino %lld: <%*s>\n",
191 (long long)t[i].bs_ino,
194 free(cc_readlinkbufp);
197 "could not read symlink ino %llu\n",
198 (unsigned long long)t[i].bs_ino );
211 fd = jdm_open( fshandlep, &t[i], O_RDONLY);
214 "unable to open handle ino %lld: %s\n",
215 (long long)t[i].bs_ino, strerror(errno));
218 if (fstat64(fd, &sb) < 0) {
220 "unable to stat ino %lld: %s\n",
221 (long long)t[i].bs_ino, strerror(errno));
226 * Don't compare blksize or blocks,
227 * they are used differently by stat
230 if ( (t[i].bs_ino != sb.st_ino) ||
231 (t[i].bs_mode != sb.st_mode) ||
232 (t[i].bs_nlink != sb.st_nlink) ||
233 (t[i].bs_uid != sb.st_uid) ||
234 (t[i].bs_gid != sb.st_gid) ||
235 (t[i].bs_rdev != sb.st_rdev) ||
236 (t[i].bs_size != sb.st_size) ||
237 /* (t[i].bs_blksize != sb.st_blksize) || */
238 (t[i].bs_mtime.tv_sec != sb.st_mtime) ||
239 (t[i].bs_ctime.tv_sec != sb.st_ctime) ) {
240 printf("\nstat/bstat missmatch\n");
256 perror("xfsctl(XFS_IOC_FSBULKSTAT)");
260 "XFS_IOC_FSBULKSTAT test: last=%lld nent=%d ret=%d count=%d\n",
261 (long long)last, nent, ret, count);