1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2003 Silicon Graphics, Inc.
11 dotime(void *ti, char *s)
16 t = (xfs_bstime_t *)ti;
18 c = ctime(&t->tv_sec);
19 printf("\t%s %19.19s.%09d %s", s, c, t->tv_nsec, c + 20);
23 printbstat(struct xfs_bstat *sp)
25 printf("ino %lld mode %#o nlink %d uid %d gid %d rdev %#x\n",
26 (long long)sp->bs_ino, sp->bs_mode, sp->bs_nlink,
27 sp->bs_uid, sp->bs_gid, sp->bs_rdev);
28 printf("\tblksize %d size %lld blocks %lld xflags %#x extsize %d\n",
29 sp->bs_blksize, (long long)sp->bs_size, (long long)sp->bs_blocks,
30 sp->bs_xflags, sp->bs_extsize);
31 dotime(&sp->bs_atime, "atime");
32 dotime(&sp->bs_mtime, "mtime");
33 dotime(&sp->bs_ctime, "ctime");
34 printf( "\textents %d %d gen %d\n",
35 sp->bs_extents, sp->bs_aextents, sp->bs_gen);
36 printf( "\tDMI: event mask 0x%08x state 0x%04x\n",
37 sp->bs_dmevmask, sp->bs_dmstate);
41 printstat(struct stat64 *sp)
43 printf("ino %lld mode %#o nlink %d uid %d gid %d rdev %#x\n",
44 (long long)sp->st_ino, (unsigned int)sp->st_mode, (int)sp->st_nlink,
45 (int)sp->st_uid, (int)sp->st_gid, (int)sp->st_rdev);
46 printf("\tblksize %llu size %lld blocks %lld\n",
47 (unsigned long long)sp->st_blksize, (long long)sp->st_size, (long long)sp->st_blocks);
48 dotime(&sp->st_atime, "atime");
49 dotime(&sp->st_mtime, "mtime");
50 dotime(&sp->st_ctime, "ctime");
54 main(int argc, char **argv)
69 jdm_fshandle_t *fshandlep = NULL;
73 char *cc_readlinkbufp;
76 struct xfs_fsop_bulkreq bulkreq;
78 while ((c = getopt(argc, argv, "cdl:qv")) != -1) {
96 printf("usage: xfs_bstat [-c] [-q] [-v] [ dir [ batch_size ]]\n");
97 printf(" -c Check the results against stat(3) output\n");
98 printf(" -q Quiet\n");
99 printf(" -l _num_ Inode to start with\n");
100 printf(" -v Verbose output\n");
112 fsfd = open(name, O_RDONLY);
120 nent = atoi(*++argv);
123 printf("Bulkstat test on %s, batch size=%d statcheck=%d\n",
127 fshandlep = jdm_getfshandle( name );
129 printf("unable to construct sys handle for %s: %s\n",
130 name, strerror(errno));
135 t = malloc(nent * sizeof(*t));
139 "XFS_IOC_FSBULKSTAT test: last=%lld nent=%d\n", (long long)last, nent);
141 bulkreq.lastip = &last;
142 bulkreq.icount = nent;
144 bulkreq.ocount = &count;
146 while ((ret = xfsctl(name, fsfd, XFS_IOC_FSBULKSTAT, &bulkreq)) == 0) {
151 "XFS_IOC_FSBULKSTAT test: last=%lld ret=%d count=%d total=%d\n",
152 (long long)last, ret, count, total);
156 if ( quiet && ! statit )
159 for (i = 0; i < count; i++) {
165 switch(t[i].bs_mode & S_IFMT) {
167 cc_readlinkbufsz = MAXPATHLEN;
168 cc_readlinkbufp = (char *)calloc(
171 nread = jdm_readlink(
176 if (verbose && nread > 0)
178 "readlink: ino %lld: <%*s>\n",
179 (long long)t[i].bs_ino,
182 free(cc_readlinkbufp);
185 "could not read symlink ino %llu\n",
186 (unsigned long long)t[i].bs_ino );
199 fd = jdm_open( fshandlep, &t[i], O_RDONLY);
202 "unable to open handle ino %lld: %s\n",
203 (long long)t[i].bs_ino, strerror(errno));
206 if (fstat64(fd, &sb) < 0) {
208 "unable to stat ino %lld: %s\n",
209 (long long)t[i].bs_ino, strerror(errno));
214 * Don't compare blksize or blocks,
215 * they are used differently by stat
218 if ( (t[i].bs_ino != sb.st_ino) ||
219 (t[i].bs_mode != sb.st_mode) ||
220 (t[i].bs_nlink != sb.st_nlink) ||
221 (t[i].bs_uid != sb.st_uid) ||
222 (t[i].bs_gid != sb.st_gid) ||
223 (t[i].bs_rdev != sb.st_rdev) ||
224 (t[i].bs_size != sb.st_size) ||
225 /* (t[i].bs_blksize != sb.st_blksize) || */
226 (t[i].bs_mtime.tv_sec != sb.st_mtime) ||
227 (t[i].bs_ctime.tv_sec != sb.st_ctime) ) {
228 printf("\nstat/bstat missmatch\n");
244 perror("xfsctl(XFS_IOC_FSBULKSTAT)");
248 "XFS_IOC_FSBULKSTAT test: last=%lld nent=%d ret=%d count=%d\n",
249 (long long)last, nent, ret, count);