/* * linda-test.c * * quick hack mangled from other code to make sure this works all * happy for linda * * use this code as you will, no warranty, etc. --- if it breaks, you * get to keep all the peices * * cw@xxxxxxxx * */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #define NINODE (256) int main() { struct timeval before, after; xfs_fsop_bulkreq_t brq; xfs_bstat_t buf[NINODE]; xfs_ino_t lastino = 0; size_t ocount, total = 0; int fd; int i; int ndir = 0, nfdir = 0; int nfile = 0, nffile = 0; if ((fd = open("/", O_RDONLY)) == -1) { perror("open"); exit(1); } printf("stating (please wait)....\n"); gettimeofday(&before, NULL); do { brq.lastip = &lastino; brq.icount = NINODE; brq.ubuffer = buf; brq.ocount = &ocount; if (-1 == ioctl(fd, XFS_IOC_FSBULKSTAT, &brq)) { perror("ioctl"); exit(1); } total += ocount; /* copy useful inodes out, we only care about fragemented files and directories. later, we can prune and directories that have no fragmented files and nlink==2 (ie. no sub directories) */ for (i=0; i 1) nfdir++; } if (S_ISREG(buf[i].bs_mode)) { nfile++; if (buf[i].bs_extents > 1) nffile++; } } } while(ocount); gettimeofday(&after, NULL); printf("\nbulkstat of %d total inodes took %0.3f seconds\n\n", total, ((double)(after.tv_sec - before.tv_sec) + (double)(after.tv_usec - before.tv_usec) / 1000000.0)); printf("Total files: %8d\n", nfile); printf("Total fragmented files: %8d\n", nffile); printf("Total directories: %8d\n", ndir); printf("Total fragmented directories: %8d\n", nfdir); close(fd); return 0; }