fsstress: translate flags in fiemap_f
[xfstests-dev.git] / ltp / fsstress.c
index d3f15968fb289344202a5d63379cfdef89502ae3..fd258bf25aa912f5a877c09fa5be0c4179706e0c 100644 (file)
@@ -1,45 +1,53 @@
 /*
- * Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
- * 
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
+ * Copyright (c) 2000-2002 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
  * published by the Free Software Foundation.
- * 
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * 
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- * 
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc., 59
- * Temple Place - Suite 330, Boston MA 02111-1307, USA.
- * 
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- * 
- * http://www.sgi.com 
- * 
- * For further information regarding this notice, see: 
- * 
- * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <xfs/libxfs.h>
+#include "global.h"
+
+#ifdef HAVE_ATTR_XATTR_H
 #include <attr/xattr.h>
+#endif
+#ifdef HAVE_ATTR_ATTRIBUTES_H
 #include <attr/attributes.h>
-#include <sys/statvfs.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-#include <dirent.h>
+#endif
+#ifdef HAVE_LINUX_FIEMAP_H
+#include <linux/fiemap.h>
+#endif
+#ifndef HAVE_ATTR_LIST
+#define attr_list(path, buf, size, flags, cursor) (errno = -ENOSYS, -1)
+#endif
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
 
+#include <linux/fs.h>
+#ifndef FS_IOC_GETFLAGS
+#define FS_IOC_GETFLAGS                 _IOR('f', 1, long)
+#endif
+#ifndef FS_IOC_SETFLAGS
+#define FS_IOC_SETFLAGS                 _IOW('f', 2, long)
+#endif
+
+#include <math.h>
 #define XFS_ERRTAG_MAX         17
-#define XFS_IDMODULO_MAX       32
+#define XFS_IDMODULO_MAX       31      /* user/group IDs (1 << x)  */
+#define XFS_PROJIDMODULO_MAX   16      /* project IDs (1 << x)     */
+
+#define FILELEN_MAX            (32*4096)
 
 typedef enum {
        OP_ALLOCSP,
@@ -51,18 +59,25 @@ typedef enum {
        OP_CREAT,
        OP_DREAD,
        OP_DWRITE,
+       OP_FALLOCATE,
        OP_FDATASYNC,
+       OP_FIEMAP,
        OP_FREESP,
        OP_FSYNC,
+       OP_GETATTR,
        OP_GETDENTS,
        OP_LINK,
        OP_MKDIR,
        OP_MKNOD,
+       OP_PUNCH,
+       OP_ZERO,
        OP_READ,
        OP_READLINK,
        OP_RENAME,
        OP_RESVSP,
        OP_RMDIR,
+       OP_SETATTR,
+       OP_SETXATTR,
        OP_STAT,
        OP_SYMLINK,
        OP_SYNC,
@@ -100,6 +115,17 @@ typedef struct pathname {
        char    *path;
 } pathname_t;
 
+struct print_flags {
+       unsigned long mask;
+       const char *name;
+};
+
+struct print_string {
+       char *buffer;
+       int len;
+       int max;
+};
+
 #define        FT_DIR  0
 #define        FT_DIRm (1 << FT_DIR)
 #define        FT_REG  1
@@ -130,18 +156,25 @@ void      chown_f(int, long);
 void   creat_f(int, long);
 void   dread_f(int, long);
 void   dwrite_f(int, long);
+void   fallocate_f(int, long);
 void   fdatasync_f(int, long);
+void   fiemap_f(int, long);
 void   freesp_f(int, long);
 void   fsync_f(int, long);
+void   getattr_f(int, long);
 void   getdents_f(int, long);
 void   link_f(int, long);
 void   mkdir_f(int, long);
 void   mknod_f(int, long);
+void   punch_f(int, long);
+void   zero_f(int, long);
 void   read_f(int, long);
 void   readlink_f(int, long);
 void   rename_f(int, long);
 void   resvsp_f(int, long);
 void   rmdir_f(int, long);
+void   setattr_f(int, long);
+void   setxattr_f(int, long);
 void   stat_f(int, long);
 void   symlink_f(int, long);
 void   sync_f(int, long);
@@ -151,6 +184,7 @@ void        unresvsp_f(int, long);
 void   write_f(int, long);
 
 opdesc_t       ops[] = {
+     /* { OP_ENUM, "name", function, freq, iswrite }, */
        { OP_ALLOCSP, "allocsp", allocsp_f, 1, 1 },
        { OP_ATTR_REMOVE, "attr_remove", attr_remove_f, /* 1 */ 0, 1 },
        { OP_ATTR_SET, "attr_set", attr_set_f, /* 2 */ 0, 1 },
@@ -160,21 +194,28 @@ opdesc_t  ops[] = {
        { OP_CREAT, "creat", creat_f, 4, 1 },
        { OP_DREAD, "dread", dread_f, 4, 0 },
        { OP_DWRITE, "dwrite", dwrite_f, 4, 1 },
+       { OP_FALLOCATE, "fallocate", fallocate_f, 1, 1 },
        { OP_FDATASYNC, "fdatasync", fdatasync_f, 1, 1 },
+       { OP_FIEMAP, "fiemap", fiemap_f, 1, 1 },
        { OP_FREESP, "freesp", freesp_f, 1, 1 },
        { OP_FSYNC, "fsync", fsync_f, 1, 1 },
+       { OP_GETATTR, "getattr", getattr_f, 1, 0 },
        { OP_GETDENTS, "getdents", getdents_f, 1, 0 },
        { OP_LINK, "link", link_f, 1, 1 },
        { OP_MKDIR, "mkdir", mkdir_f, 2, 1 },
        { OP_MKNOD, "mknod", mknod_f, 2, 1 },
+       { OP_PUNCH, "punch", punch_f, 1, 1 },
+       { OP_ZERO, "zero", zero_f, 1, 1 },
        { OP_READ, "read", read_f, 1, 0 },
        { OP_READLINK, "readlink", readlink_f, 1, 0 },
        { OP_RENAME, "rename", rename_f, 2, 1 },
        { OP_RESVSP, "resvsp", resvsp_f, 1, 1 },
        { OP_RMDIR, "rmdir", rmdir_f, 1, 1 },
+       { OP_SETATTR, "setattr", setattr_f, 0, 1 },
+       { OP_SETXATTR, "setxattr", setxattr_f, 1, 1 },
        { OP_STAT, "stat", stat_f, 1, 0 },
        { OP_SYMLINK, "symlink", symlink_f, 2, 1 },
-       { OP_SYNC, "sync", sync_f, 1, 0 },
+       { OP_SYNC, "sync", sync_f, 1, 1 },
        { OP_TRUNCATE, "truncate", truncate_f, 2, 1 },
        { OP_UNLINK, "unlink", unlink_f, 1, 1 },
        { OP_UNRESVSP, "unresvsp", unresvsp_f, 1, 1 },
@@ -206,15 +247,21 @@ int               nops;
 int            nproc = 1;
 int            operations = 1;
 unsigned int   idmodulo = XFS_IDMODULO_MAX;
+unsigned int   attr_mask = ~0;
 int            procid;
 int            rtpct;
 unsigned long  seed = 0;
 ino_t          top_ino;
 int            verbose = 0;
+int            verifiable_log = 0;
+sig_atomic_t   should_stop = 0;
+char           *execute_cmd = NULL;
+int            execute_freq = 1;
+struct print_string    flag_str = {0};
 
 void   add_to_flist(int, int, int);
 void   append_pathname(pathname_t *, char *);
-int    attr_list_path(pathname_t *, char *, const int, int);
+int    attr_list_path(pathname_t *, char *, const int, int, attrlist_cursor_t *);
 int    attr_remove_path(pathname_t *, const char *, int);
 int    attr_set_path(pathname_t *, const char *, const char *, const int, int);
 void   check_cwd(void);
@@ -226,7 +273,7 @@ void        dcache_purge(int);
 void   del_from_flist(int, int);
 int    dirid_to_name(char *, int);
 void   doproc(void);
-void   fent_to_name(pathname_t *, flist_t *, fent_t *);
+int    fent_to_name(pathname_t *, flist_t *, fent_t *);
 void   fix_parent(int, int);
 void   free_pathname(pathname_t *);
 int    generate_fname(fent_t *, int, pathname_t *, int *, int *);
@@ -255,11 +302,18 @@ void      usage(void);
 void   write_freq(void);
 void   zero_freq(void);
 
+void sg_handler(int signum)
+{
+       should_stop = 1;
+}
+
 int main(int argc, char **argv)
 {
        char            buf[10];
        int             c;
        char            *dirname = NULL;
+       char            *logname = NULL;
+       char            rpath[PATH_MAX];
        int             fd;
        int             i;
        int             j;
@@ -268,14 +322,16 @@ int main(int argc, char **argv)
        struct timeval  t;
        ptrdiff_t       srval;
        int             nousage = 0;
-       xfs_error_injection_t   err_inj;
+       xfs_error_injection_t           err_inj;
+       struct sigaction action;
+       const char      *allopts = "d:e:f:i:m:M:n:o:p:rs:S:vVwx:X:zH";
 
        errrange = errtag = 0;
        umask(0);
        nops = sizeof(ops) / sizeof(ops[0]);
        ops_end = &ops[nops];
        myprog = argv[0];
-       while ((c = getopt(argc, argv, "d:e:f:i:m:n:p:rs:vwzHS")) != -1) {
+       while ((c = getopt(argc, argv, allopts)) != -1) {
                switch (c) {
                case 'd':
                        dirname = optarg;
@@ -313,6 +369,10 @@ int main(int argc, char **argv)
                case 'n':
                        operations = atoi(optarg);
                        break;
+               case 'o':
+                       logname = optarg;
+                       break;
+
                case 'p':
                        nproc = atoi(optarg);
                        break;
@@ -328,14 +388,30 @@ int main(int argc, char **argv)
                case 'w':
                        write_freq();
                        break;
+               case 'x':
+                       execute_cmd = optarg;
+                       break;
                case 'z':
                        zero_freq();
                        break;
+               case 'M':
+                       attr_mask = strtoul(optarg, NULL, 0);
+                       break;
                case 'S':
-                       show_ops(0, NULL);
+                       i = 0;
+                       if (optarg[0] == 'c')
+                               i = 1;
+                       show_ops(i, NULL);
                        printf("\n");
                         nousage=1;
                        break;
+               case 'V':
+                       verifiable_log = 1;
+                       break;
+
+               case 'X':
+                       execute_freq = strtoul(optarg, NULL, 0);
+                       break;
                case '?':
                        fprintf(stderr, "%s - invalid parameters\n",
                                myprog);
@@ -345,19 +421,35 @@ int main(int argc, char **argv)
                        exit(1);
                }
        }
-        
+
         if (!dirname) {
             /* no directory specified */
             if (!nousage) usage();
             exit(1);
         }
-        
+
        (void)mkdir(dirname, 0777);
+       if (logname && logname[0] != '/') {
+               if (getcwd(rpath, sizeof(rpath)) < 0){
+                       perror("getcwd failed");
+                       exit(1);
+               }
+       } else {
+               rpath[0] = '\0';
+       }
        if (chdir(dirname) < 0) {
                perror(dirname);
                exit(1);
        }
-       sprintf(buf, "fss%x", getpid());
+       if (logname) {
+               char path[PATH_MAX];
+               snprintf(path, sizeof(path), "%s/%s", rpath, logname);
+               if (freopen(path, "a", stdout) == NULL) {
+                       perror("freopen logfile failed");
+                       exit(1);
+               }
+       }
+       sprintf(buf, "fss%x", (unsigned int)getpid());
        fd = creat(buf, 0666);
        if (lseek64(fd, (off64_t)(MAXFSIZE32 + 1ULL), SEEK_SET) < 0)
                maxfsize = (off64_t)MAXFSIZE32;
@@ -409,15 +501,50 @@ int main(int argc, char **argv)
                }
        } else
                close(fd);
+
+       setpgid(0, 0);
+       action.sa_handler = sg_handler;
+       sigemptyset(&action.sa_mask);
+       action.sa_flags = 0;
+       if (sigaction(SIGTERM, &action, 0)) {
+               perror("sigaction failed");
+               exit(1);
+       }
+
        for (i = 0; i < nproc; i++) {
                if (fork() == 0) {
+                       action.sa_handler = SIG_DFL;
+                       sigemptyset(&action.sa_mask);
+                       if (sigaction(SIGTERM, &action, 0))
+                               return 1;
+#ifdef HAVE_SYS_PRCTL_H
+                       prctl(PR_SET_PDEATHSIG, SIGKILL);
+                       if (getppid() == 1) /* parent died already? */
+                               return 0;
+#endif
+                       if (logname) {
+                               char path[PATH_MAX];
+                               snprintf(path, sizeof(path), "%s/%s.%d",
+                                        rpath, logname, i);
+                               if (freopen(path, "a", stdout) == NULL) {
+                                       perror("freopen logfile failed");
+                                       exit(1);
+                               }
+                       }
                        procid = i;
                        doproc();
                        return 0;
                }
        }
+       while (wait(&stat) > 0 && !should_stop) {
+               continue;
+       }
+       action.sa_flags = SA_RESTART;
+       sigaction(SIGTERM, &action, 0);
+       kill(-getpid(), SIGTERM);
        while (wait(&stat) > 0)
                continue;
+
        if (errtag != 0) {
                err_inj.errtag = 0;
                err_inj.fd = fd;
@@ -436,6 +563,73 @@ int main(int argc, char **argv)
        return 0;
 }
 
+int
+add_string(struct print_string *str, const char *add)
+{
+       int len = strlen(add);
+
+       if (len <= 0)
+               return 0;
+
+       if (len > (str->max - 1) - str->len) {
+               str->len = str->max - 1;
+               return 0;
+       }
+
+       memcpy(str->buffer + str->len, add, len);
+       str->len += len;
+       str->buffer[str->len] = '\0';
+
+       return len;
+}
+
+char *
+translate_flags(int flags, const char *delim,
+               const struct print_flags *flag_array)
+{
+       int i, mask, first = 1;
+       const char *add;
+
+       if (!flag_str.buffer) {
+               flag_str.buffer = malloc(4096);
+               flag_str.max = 4096;
+               flag_str.len = 0;
+       }
+       if (!flag_str.buffer)
+               return NULL;
+       flag_str.len = 0;
+       flag_str.buffer[0] = '\0';
+
+       for (i = 0;  flag_array[i].name && flags; i++) {
+               mask = flag_array[i].mask;
+               if ((flags & mask) != mask)
+                       continue;
+
+               add = flag_array[i].name;
+               flags &= ~mask;
+               if (!first && delim)
+                       add_string(&flag_str, delim);
+               else
+                       first = 0;
+               add_string(&flag_str, add);
+       }
+
+       /* Check whether there are any leftover flags. */
+       if (flags) {
+               int ret;
+               char number[11];
+
+               if (!first && delim)
+                       add_string(&flag_str, delim);
+
+               ret = snprintf(number, 11, "0x%x", flags) > 0;
+               if (ret > 0 && ret <= 11)
+                       add_string(&flag_str, number);
+       }
+
+       return flag_str.buffer;
+}
+
 void
 add_to_flist(int ft, int id, int parent)
 {
@@ -459,6 +653,7 @@ append_pathname(pathname_t *name, char *str)
 
        len = strlen(str);
 #ifdef DEBUG
+       /* attempting to append to a dir a zero length path */
        if (len && *str == '/' && name->len == 0) {
                fprintf(stderr, "fsstress: append_pathname failure\n");
                chdir(homedir);
@@ -472,9 +667,13 @@ append_pathname(pathname_t *name, char *str)
 }
 
 int
-attr_list_path(pathname_t *name, char *buffer, const int buffersize, int flags)
+attr_list_path(pathname_t *name,
+              char *buffer,
+              const int buffersize,
+              int flags,
+              attrlist_cursor_t *cursor)
 {
-       char            buf[MAXNAMELEN];
+       char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
@@ -482,12 +681,13 @@ attr_list_path(pathname_t *name, char *buffer, const int buffersize, int flags)
                errno = EINVAL;
                return -1;
        }
-       rval = llistxattr(name->path, buffer, buffersize);
+
+       rval = attr_list(name->path, buffer, buffersize, flags, cursor);
        if (rval >= 0 || errno != ENAMETOOLONG)
                return rval;
        separate_pathname(name, buf, &newname);
        if (chdir(buf) == 0) {
-               rval = attr_list_path(&newname, buffer, buffersize, flags);
+               rval = attr_list_path(&newname, buffer, buffersize, flags, cursor);
                chdir("..");
        }
        free_pathname(&newname);
@@ -497,7 +697,7 @@ attr_list_path(pathname_t *name, char *buffer, const int buffersize, int flags)
 int
 attr_remove_path(pathname_t *name, const char *attrname, int flags)
 {
-       char            buf[MAXNAMELEN];
+       char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
@@ -517,7 +717,7 @@ int
 attr_set_path(pathname_t *name, const char *attrname, const char *attrvalue,
              const int valuelength, int flags)
 {
-       char            buf[MAXNAMELEN];
+       char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
@@ -552,7 +752,7 @@ check_cwd(void)
 int
 creat_path(pathname_t *name, mode_t mode)
 {
-       char            buf[MAXNAMELEN];
+       char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
@@ -605,6 +805,12 @@ dcache_purge(int dirid)
                *dcp = -1;
 }
 
+/*
+ * Delete the item from the list by
+ * moving last entry over the deleted one;
+ * unless deleted entry is the last one.
+ * Input: which file list array and which slot in array
+ */
 void
 del_from_flist(int ft, int slot)
 {
@@ -648,7 +854,9 @@ doproc(void)
        int             opno;
        int             rval;
        opdesc_t        *p;
+       int             dividend;
 
+       dividend = (operations + execute_freq) / (execute_freq + 1);
        sprintf(buf, "p%x", procid);
        (void)mkdir(buf, 0777);
        if (chdir(buf) < 0 || stat64(".", &statbuf) < 0) {
@@ -662,6 +870,15 @@ doproc(void)
        if (namerand)
                namerand = random();
        for (opno = 0; opno < operations; opno++) {
+               if (execute_cmd && opno && opno % dividend == 0) {
+                       if (verbose)
+                               printf("%d: execute command %s\n", opno,
+                                       execute_cmd);
+                       rval = system(execute_cmd);
+                       if (rval)
+                               fprintf(stderr, "execute command failed with "
+                                       "%d\n", rval);
+               }
                p = &ops[freq_table[random() % freq_table_size]];
                p->func(opno, random());
                /*
@@ -679,23 +896,43 @@ doproc(void)
        }
 }
 
-void
+/*
+ * build up a pathname going thru the file entry and all
+ * its parent entries
+ * Return 0 on error, 1 on success;
+ */
+int
 fent_to_name(pathname_t *name, flist_t *flp, fent_t *fep)
 {
-       char    buf[MAXNAMELEN];
+       char    buf[NAME_MAX + 1];
        int     i;
        fent_t  *pfep;
+       int     e;
 
        if (fep == NULL)
-               return;
+               return 0;
+
+       /* build up parent directory name */
        if (fep->parent != -1) {
                pfep = dirid_to_fent(fep->parent);
-               fent_to_name(name, &flist[FT_DIR], pfep);
+#ifdef DEBUG
+               if (pfep == NULL) {
+                       fprintf(stderr, "%d: fent-id = %d: can't find parent id: %d\n",
+                               procid, fep->id, fep->parent);
+               } 
+#endif
+               if (pfep == NULL)
+                       return 0;
+               e = fent_to_name(name, &flist[FT_DIR], pfep);
+               if (!e)
+                       return 0;
                append_pathname(name, "/");
        }
+
        i = sprintf(buf, "%c%x", flp->tag, fep->id);
        namerandpad(fep->id, buf, i);
        append_pathname(name, buf);
+       return 1;
 }
 
 void
@@ -724,23 +961,35 @@ free_pathname(pathname_t *name)
        }
 }
 
+/*
+ * Generate a filename of type ft.
+ * If we have a fep which should be a directory then use it
+ * as the parent path for this new filename i.e. prepend with it.
+ */
 int
 generate_fname(fent_t *fep, int ft, pathname_t *name, int *idp, int *v)
 {
-       char    buf[MAXNAMELEN];
+       char    buf[NAME_MAX + 1];
        flist_t *flp;
        int     id;
        int     j;
        int     len;
+       int     e;
 
+       /* create name */
        flp = &flist[ft];
        len = sprintf(buf, "%c%x", flp->tag, id = nameseq++);
        namerandpad(id, buf, len);
+
+       /* prepend fep parent dir-name to it */
        if (fep) {
-               fent_to_name(name, &flist[FT_DIR], fep);
+               e = fent_to_name(name, &flist[FT_DIR], fep);
+               if (!e)
+                       return 0;
                append_pathname(name, "/");
        }
        append_pathname(name, buf);
+
        *idp = id;
        *v = verbose;
        for (j = 0; !*v && j < ilistlen; j++) {
@@ -752,22 +1001,35 @@ generate_fname(fent_t *fep, int ft, pathname_t *name, int *idp, int *v)
        return 1;
 }
 
+/*
+ * Get file 
+ * Input: "which" to choose the file-types eg. non-directory
+ * Input: "r" to choose which file
+ * Output: file-list, file-entry, name for the chosen file.
+ * Output: verbose if chosen file is on the ilist.
+ */
 int
 get_fname(int which, long r, pathname_t *name, flist_t **flpp, fent_t **fepp,
          int *v)
 {
-       int     c;
+       int     totalsum = 0; /* total number of matching files */
+       int     partialsum = 0; /* partial sum of matching files */
        fent_t  *fep;
        flist_t *flp;
        int     i;
        int     j;
        int     x;
+       int     e = 1; /* success */
 
-       for (i = 0, c = 0, flp = flist; i < FT_nft; i++, flp++) {
+       /*
+        * go thru flist and add up number of files for each
+        * category that matches with <which>.
+        */
+       for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
                if (which & (1 << i))
-                       c += flp->nfiles;
+                       totalsum += flp->nfiles;
        }
-       if (c == 0) {
+       if (totalsum == 0) {
                if (flpp)
                        *flpp = NULL;
                if (fepp)
@@ -775,17 +1037,37 @@ get_fname(int which, long r, pathname_t *name, flist_t **flpp, fent_t **fepp,
                *v = verbose;
                return 0;
        }
-       x = (int)(r % c);
-       for (i = 0, c = 0, flp = flist; i < FT_nft; i++, flp++) {
+
+       /*
+        * Now we have possible matches between 0..totalsum-1.
+        * And we use r to help us choose which one we want,
+        * which when bounded by totalsum becomes x.
+        */ 
+       x = (int)(r % totalsum);
+       for (i = 0, flp = flist; i < FT_nft; i++, flp++) {
                if (which & (1 << i)) {
-                       if (x < c + flp->nfiles) {
-                               fep = &flp->fents[x - c];
-                               if (name)
-                                       fent_to_name(name, flp, fep);
+                       if (x < partialsum + flp->nfiles) {
+
+                               /* found the matching file entry */
+                               fep = &flp->fents[x - partialsum];
+
+                               /* fill-in what we were asked for */
+                               if (name) {
+                                       e = fent_to_name(name, flp, fep);
+#ifdef DEBUG
+                                       if (!e) {
+                                               fprintf(stderr, "%d: failed to get path for entry:"
+                                                               " id=%d,parent=%d\n",   
+                                                       procid, fep->id, fep->parent);
+                                       }
+#endif
+                               }
                                if (flpp)
                                        *flpp = flp;
                                if (fepp)
                                        *fepp = fep;
+
+                               /* turn on verbose if its an ilisted file */
                                *v = verbose;
                                for (j = 0; !*v && j < ilistlen; j++) {
                                        if (ilist[j] == fep->id) {
@@ -793,17 +1075,16 @@ get_fname(int which, long r, pathname_t *name, flist_t **flpp, fent_t **fepp,
                                                break;
                                        }
                                }
-                               return 1;
+                               return e;
                        }
-                       c += flp->nfiles;
+                       partialsum += flp->nfiles;
                }
        }
 #ifdef DEBUG
        fprintf(stderr, "fsstress: get_fname failure\n");
        abort();
 #endif
-        return -1;
-       /* NOTREACHED */
+        return 0;
 }
 
 void
@@ -816,7 +1097,7 @@ init_pathname(pathname_t *name)
 int
 lchown_path(pathname_t *name, uid_t owner, gid_t group)
 {
-       char            buf[MAXNAMELEN];
+       char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
@@ -835,8 +1116,8 @@ lchown_path(pathname_t *name, uid_t owner, gid_t group)
 int
 link_path(pathname_t *name1, pathname_t *name2)
 {
-       char            buf1[MAXNAMELEN];
-       char            buf2[MAXNAMELEN];
+       char            buf1[NAME_MAX + 1];
+       char            buf2[NAME_MAX + 1];
        int             down1;
        pathname_t      newname1;
        pathname_t      newname2;
@@ -890,7 +1171,7 @@ link_path(pathname_t *name1, pathname_t *name2)
 int
 lstat64_path(pathname_t *name, struct stat64 *sbuf)
 {
-       char            buf[MAXNAMELEN];
+       char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
@@ -926,7 +1207,7 @@ make_freq_table(void)
 int
 mkdir_path(pathname_t *name, mode_t mode)
 {
-       char            buf[MAXNAMELEN];
+       char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
@@ -945,7 +1226,7 @@ mkdir_path(pathname_t *name, mode_t mode)
 int
 mknod_path(pathname_t *name, mode_t mode, dev_t dev)
 {
-       char            buf[MAXNAMELEN];
+       char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
@@ -966,7 +1247,7 @@ namerandpad(int id, char *buf, int i)
 {
        int             bucket;
        static int      buckets[] =
-                               { 2, 4, 8, 16, 32, 64, 128, MAXNAMELEN - 1 };
+                               { 2, 4, 8, 16, 32, 64, 128, NAME_MAX };
        int             padlen;
        int             padmod;
 
@@ -986,7 +1267,7 @@ namerandpad(int id, char *buf, int i)
 int
 open_path(pathname_t *name, int oflag)
 {
-       char            buf[MAXNAMELEN];
+       char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
@@ -1005,7 +1286,7 @@ open_path(pathname_t *name, int oflag)
 DIR *
 opendir_path(pathname_t *name)
 {
-       char            buf[MAXNAMELEN];
+       char            buf[NAME_MAX + 1];
        pathname_t      newname;
        DIR             *rval;
 
@@ -1046,7 +1327,7 @@ process_freq(char *arg)
 int
 readlink_path(pathname_t *name, char *lbuf, size_t lbufsiz)
 {
-       char            buf[MAXNAMELEN];
+       char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
@@ -1065,8 +1346,8 @@ readlink_path(pathname_t *name, char *lbuf, size_t lbufsiz)
 int
 rename_path(pathname_t *name1, pathname_t *name2)
 {
-       char            buf1[MAXNAMELEN];
-       char            buf2[MAXNAMELEN];
+       char            buf1[NAME_MAX + 1];
+       char            buf2[NAME_MAX + 1];
        int             down1;
        pathname_t      newname1;
        pathname_t      newname2;
@@ -1120,7 +1401,7 @@ rename_path(pathname_t *name1, pathname_t *name2)
 int
 rmdir_path(pathname_t *name)
 {
-       char            buf[MAXNAMELEN];
+       char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
@@ -1170,7 +1451,8 @@ show_ops(int flag, char *lead_str)
                         x+=printf("%s ", p->name);
                 }
                 printf("\n");
-        } else {
+        } else if (flag == 0) {
+               /* Table view style */
                int             f;
                for (f = 0, p = ops; p < ops_end; p++)
                        f += p->freq;
@@ -1187,13 +1469,22 @@ show_ops(int flag, char *lead_str)
                                (p->iswrite == 0) ? " " : "write op");
                        }
                 }
+       } else {
+               /* Command line style */
+               if (lead_str != NULL)
+                       printf("%s", lead_str);
+               printf ("-z -s %ld -m %d -n %d -p %d \\\n", seed, idmodulo,
+                       operations, nproc);
+               for (p = ops; p < ops_end; p++)
+                       if (p->freq > 0)
+                               printf("-f %s=%d \\\n",p->name, p->freq);
        }
 }
 
 int
 stat64_path(pathname_t *name, struct stat64 *sbuf)
 {
-       char            buf[MAXNAMELEN];
+       char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
@@ -1212,7 +1503,7 @@ stat64_path(pathname_t *name, struct stat64 *sbuf)
 int
 symlink_path(const char *name1, pathname_t *name)
 {
-       char            buf[MAXNAMELEN];
+       char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
         
@@ -1236,7 +1527,7 @@ symlink_path(const char *name1, pathname_t *name)
 int
 truncate64_path(pathname_t *name, off64_t length)
 {
-       char            buf[MAXNAMELEN];
+       char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
@@ -1255,7 +1546,7 @@ truncate64_path(pathname_t *name, off64_t length)
 int
 unlink_path(pathname_t *name)
 {
-       char            buf[MAXNAMELEN];
+       char            buf[NAME_MAX + 1];
        pathname_t      newname;
        int             rval;
 
@@ -1277,22 +1568,27 @@ usage(void)
        printf("Usage: %s -H   or\n", myprog);
        printf("       %s [-d dir][-e errtg][-f op_name=freq][-n nops]\n",
                myprog);
-       printf("          [-p nproc][-r len][-s seed][-v][-w][-z][-S]\n");
+       printf("          [-p nproc][-r len][-s seed][-v][-w][-x cmd][-z][-S][-X ncmd]\n");
        printf("where\n");
        printf("   -d dir           specifies the base directory for operations\n");
        printf("   -e errtg         specifies error injection stuff\n");
        printf("   -f op_name=freq  changes the frequency of option name to freq\n");
        printf("                    the valid operation names are:\n");
        show_ops(-1, "                        ");
+       printf("   -i filenum       get verbose output for this nth file object\n");
        printf("   -m modulo        uid/gid modulo for chown/chgrp (default 32)\n");
        printf("   -n nops          specifies the no. of operations per process (default 1)\n");
+       printf("   -o logfile       specifies logfile name\n");
        printf("   -p nproc         specifies the no. of processes (default 1)\n");
        printf("   -r               specifies random name padding\n");
        printf("   -s seed          specifies the seed for the random generator (default random)\n");
        printf("   -v               specifies verbose mode\n");
        printf("   -w               zeros frequencies of non-write operations\n");
+       printf("   -x cmd           execute command in the middle of operations\n");
        printf("   -z               zeros frequencies of all operations\n");
-       printf("   -S               prints the table of operations (omitting zero frequency)\n");
+       printf("   -S [c,t]         prints the list of operations (omitting zero frequency) in command line or table style\n");
+       printf("   -V               specifies verifiable logging mode (omitting inode numbers)\n");
+       printf("   -X ncmd          number of calls to the -x command (default 1)\n");
        printf("   -H               prints usage and exits\n");
 }
 
@@ -1316,17 +1612,27 @@ zero_freq(void)
                p->freq = 0;
 }
 
+void inode_info(char *str, size_t sz, struct stat64 *s, int verbose)
+{
+       if (verbose)
+               snprintf(str, sz, "[%ld %ld %d %d %lld %lld]",
+                        verifiable_log ? -1: (long)s->st_ino,
+                        (long)s->st_nlink,  s->st_uid, s->st_gid,
+                        (long long) s->st_blocks, (long long) s->st_size);
+}
+
 void
 allocsp_f(int opno, long r)
 {
        int             e;
        pathname_t      f;
        int             fd;
-       struct flock64  fl;
+       struct xfs_flock64      fl;
        __int64_t       lr;
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
 
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
@@ -1353,6 +1659,7 @@ allocsp_f(int opno, long r)
                close(fd);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
@@ -1360,9 +1667,10 @@ allocsp_f(int opno, long r)
        fl.l_start = off;
        fl.l_len = 0;
        e = xfsctl(f.path, fd, XFS_IOC_ALLOCSP64, &fl) < 0 ? errno : 0;
-       if (v)
-               printf("%d/%d: xfsctl(XFS_IOC_ALLOCSP64) %s %lld 0 %d\n",
-                       procid, opno, f.path, (long long)off, e);
+       if (v) {
+               printf("%d/%d: xfsctl(XFS_IOC_ALLOCSP64) %s%s %lld 0 %d\n",
+                      procid, opno, f.path, st, (long long)off, e);
+       }
        free_pathname(&f);
        close(fd);
 }
@@ -1370,8 +1678,11 @@ allocsp_f(int opno, long r)
 void
 attr_remove_f(int opno, long r)
 {
-       char                    *aname, *l;
+       attrlist_ent_t          *aep;
+       attrlist_t              *alist;
+       char                    *aname;
        char                    buf[4096];
+       attrlist_cursor_t       cursor;
        int                     e;
        int                     ent;
        pathname_t              f;
@@ -1383,13 +1694,16 @@ attr_remove_f(int opno, long r)
        if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
                append_pathname(&f, ".");
        total = 0;
-       e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW);
-       check_cwd();
-       if (e > 0) {
-               for (l = buf; l - buf <= e; l += strlen(l)+1)
-                       if (strncmp(l, "user.",5) == 0)
-                               total++;
-       }
+       bzero(&cursor, sizeof(cursor));
+       do {
+               bzero(buf, sizeof(buf));
+               e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW, &cursor);
+               check_cwd();
+               if (e)
+                       break;
+               alist = (attrlist_t *)buf;
+               total += alist->al_count;
+       } while (alist->al_more);
        if (total == 0) {
                if (v)
                        printf("%d/%d: attr_remove - no attrs for %s\n",
@@ -1398,24 +1712,28 @@ attr_remove_f(int opno, long r)
                return;
        }
        which = (int)(random() % total);
+       bzero(&cursor, sizeof(cursor));
        ent = 0;
        aname = NULL;
-       e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW);
-       check_cwd();
-       if (e <= 0)
-               return;
-       for (l = buf; l - buf <= e; l += strlen(l)+1) {
-               if (strncmp(l, "user.",5) == 0) {
-                       if (++ent == which) {
-                               aname = l;
-                               break;
-                       }
+       do {
+               bzero(buf, sizeof(buf));
+               e = attr_list_path(&f, buf, sizeof(buf), ATTR_DONTFOLLOW, &cursor);
+               check_cwd();
+               if (e)
+                       break;
+               alist = (attrlist_t *)buf;
+               if (which < ent + alist->al_count) {
+                       aep = (attrlist_ent_t *)
+                               &buf[alist->al_offset[which - ent]];
+                       aname = aep->a_name;
+                       break;
                }
-       }
+               ent += alist->al_count;
+       } while (alist->al_more);
        if (aname == NULL) {
                if (v)
                        printf(
-                       "%d/%d: attr_remove - name %d not found at %s\n",       
+                       "%d/%d: attr_remove - name %d not found at %s\n",
                                procid, opno, which, f.path);
                free_pathname(&f);
                return;
@@ -1465,7 +1783,7 @@ bulkstat_f(int opno, long r)
 {
        int             count;
        int             fd;
-       __uint64_t      last;
+       __u64           last;
        int             nent;
        xfs_bstat_t     *t;
        __int64_t       total;
@@ -1476,7 +1794,7 @@ bulkstat_f(int opno, long r)
        t = malloc(nent * sizeof(*t));
        fd = open(".", O_RDONLY);
        total = 0;
-    
+
         bsr.lastip=&last;
         bsr.icount=nent;
         bsr.ubuffer=t;
@@ -1486,7 +1804,7 @@ bulkstat_f(int opno, long r)
                total += count;
        free(t);
        if (verbose)
-               printf("%d/%d: bulkstat nent %d total %llu\n",
+               printf("%d/%d: bulkstat nent %d total %lld\n",
                        procid, opno, nent, (long long)total);
        close(fd);
 }
@@ -1498,7 +1816,7 @@ bulkstat1_f(int opno, long r)
        pathname_t      f;
        int             fd;
        int             good;
-       __uint64_t      ino;
+       __u64           ino;
        struct stat64   s;
        xfs_bstat_t     t;
        int             v;
@@ -1538,11 +1856,11 @@ bulkstat1_f(int opno, long r)
         bsr.icount=1;
         bsr.ubuffer=&t;
         bsr.ocount=NULL;
-        
        e = xfsctl(".", fd, XFS_IOC_FSBULKSTAT_SINGLE, &bsr) < 0 ? errno : 0;
        if (v)
                printf("%d/%d: bulkstat1 %s ino %lld %d\n", 
-                    procid, opno, good?"real":"random", (long long)ino, e);
+                      procid, opno, good?"real":"random",
+                      verifiable_log ? -1LL : (long long)ino, e);
        close(fd);
 }
 
@@ -1567,10 +1885,46 @@ chown_f(int opno, long r)
        e = lchown_path(&f, u, g) < 0 ? errno : 0;
        check_cwd();
        if (v)
-               printf("%d/%d: chown %s %d/%d %d\n", procid, opno, f.path, u, g, e);
+               printf("%d/%d: chown %s %d/%d %d\n", procid, opno, f.path, (int)u, (int)g, e);
        free_pathname(&f);
 }
 
+void
+setxattr_f(int opno, long r)
+{
+#ifdef XFS_XFLAG_EXTSIZE
+       struct fsxattr  fsx;
+       int             fd;
+       int             e;
+       pathname_t      f;
+       int             nbits;
+       uint            p;
+       int             v;
+
+       init_pathname(&f);
+       if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
+               append_pathname(&f, ".");
+       fd = open_path(&f, O_RDWR);
+       e = fd < 0 ? errno : 0;
+       check_cwd();
+
+       /* project ID */
+       p = (uint)random();
+       e = MIN(idmodulo, XFS_PROJIDMODULO_MAX);
+       nbits = (int)(random() % e);
+       p &= (1 << nbits) - 1;
+
+       if ((e = xfsctl(f.path, fd, XFS_IOC_FSGETXATTR, &fsx)) == 0) {
+               fsx.fsx_projid = p;
+               e = xfsctl(f.path, fd, XFS_IOC_FSSETXATTR, &fsx);
+       }
+       if (v)
+               printf("%d/%d: setxattr %s %u %d\n", procid, opno, f.path, p, e);
+       free_pathname(&f);
+       close(fd);
+#endif
+}
+
 void
 creat_f(int opno, long r)
 {
@@ -1592,16 +1946,21 @@ creat_f(int opno, long r)
        else
                parid = fep->id;
        init_pathname(&f);
-       type = rtpct ? ((random() % 100) > rtpct ? FT_REG : FT_RTF) : FT_REG;
-       if (type == FT_RTF)
+       e1 = (random() % 100);
+       type = rtpct ? ((e1 > rtpct) ? FT_REG : FT_RTF) : FT_REG;
+#ifdef NOTYET
+       if (type == FT_RTF)     /* rt always gets an extsize */
                extsize = (random() % 10) + 1;
+       else if (e1 < 10)       /* one-in-ten get an extsize */
+               extsize = random() % 1024;
        else
+#endif
                extsize = 0;
        e = generate_fname(fep, type, &f, &id, &v);
        v |= v1;
        if (!e) {
                if (v) {
-                       fent_to_name(&f, &flist[FT_DIR], fep);
+                       (void)fent_to_name(&f, &flist[FT_DIR], fep);
                        printf("%d/%d: creat - no filename from %s\n",
                                procid, opno, f.path);
                }
@@ -1615,18 +1974,27 @@ creat_f(int opno, long r)
        if (fd >= 0) {
                if (extsize &&
                    xfsctl(f.path, fd, XFS_IOC_FSGETXATTR, &a) >= 0) {
-                       a.fsx_xflags |= XFS_XFLAG_REALTIME;
-                       a.fsx_extsize =
-                               geom.rtextsize * geom.blocksize * extsize;
+                       if (type == FT_RTF) {
+                               a.fsx_xflags |= XFS_XFLAG_REALTIME;
+                               a.fsx_extsize = extsize *
+                                               geom.rtextsize * geom.blocksize;
+#ifdef NOTYET
+                       } else if (extsize) {
+                               a.fsx_xflags |= XFS_XFLAG_EXTSIZE;
+                               a.fsx_extsize = extsize * geom.blocksize;
+#endif
+                       }
                        if (xfsctl(f.path, fd, XFS_IOC_FSSETXATTR, &a) < 0)
                                e1 = errno;
                }
                add_to_flist(type, id, parid);
                close(fd);
        }
-       if (v)
+       if (v) {
                printf("%d/%d: creat %s x:%d %d %d\n", procid, opno, f.path,
                        extsize ? a.fsx_extsize : 0, e, e1);
+               printf("%d/%d: creat add id=%d,parent=%d\n", procid, opno, id, parid);
+       }
        free_pathname(&f);
 }
 
@@ -1644,6 +2012,8 @@ dread_f(int opno, long r)
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
+       char            *dio_env;
 
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
@@ -1665,15 +2035,16 @@ dread_f(int opno, long r)
        if (fstat64(fd, &stb) < 0) {
                if (v)
                        printf("%d/%d: dread - fstat64 %s failed %d\n",
-                               procid, opno, f.path, errno);
+                              procid, opno, f.path, errno);
                free_pathname(&f);
                close(fd);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        if (stb.st_size == 0) {
                if (v)
-                       printf("%d/%d: dread - %s zero size\n", procid, opno,
-                               f.path);
+                       printf("%d/%d: dread - %s%s zero size\n", procid, opno,
+                              f.path, st);
                free_pathname(&f);
                close(fd);
                return;
@@ -1681,18 +2052,23 @@ dread_f(int opno, long r)
        if (xfsctl(f.path, fd, XFS_IOC_DIOINFO, &diob) < 0) {
                if (v)
                        printf(
-                       "%d/%d: dread - xfsctl(XFS_IOC_DIOINFO) %s failed %d\n",
-                               procid, opno, f.path, errno);
+                       "%d/%d: dread - xfsctl(XFS_IOC_DIOINFO) %s%s failed %d\n",
+                               procid, opno, f.path, st, errno);
                free_pathname(&f);
                close(fd);
                return;
        }
+
+       dio_env = getenv("XFS_DIO_MIN");
+       if (dio_env)
+               diob.d_mem = diob.d_miniosz = atoi(dio_env);
+
        align = (__int64_t)diob.d_miniosz;
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % stb.st_size);
        off -= (off % align);
        lseek64(fd, off, SEEK_SET);
-       len = (random() % (getpagesize() * 32)) + 1;
+       len = (random() % FILELEN_MAX) + 1;
        len -= (len % align);
        if (len <= 0)
                len = align;
@@ -1702,8 +2078,8 @@ dread_f(int opno, long r)
        e = read(fd, buf, len) < 0 ? errno : 0;
        free(buf);
        if (v)
-               printf("%d/%d: dread %s [%lld,%d] %d\n",
-                       procid, opno, f.path, (long long)off, (int)len, e);
+               printf("%d/%d: dread %s%s [%lld,%d] %d\n",
+                      procid, opno, f.path, st, (long long)off, (int)len, e);
        free_pathname(&f);
        close(fd);
 }
@@ -1722,6 +2098,8 @@ dwrite_f(int opno, long r)
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
+       char            *dio_env;
 
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
@@ -1748,21 +2126,27 @@ dwrite_f(int opno, long r)
                close(fd);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        if (xfsctl(f.path, fd, XFS_IOC_DIOINFO, &diob) < 0) {
                if (v)
                        printf("%d/%d: dwrite - xfsctl(XFS_IOC_DIOINFO)"
-                               " %s failed %d\n",
-                               procid, opno, f.path, errno);
+                               " %s%s failed %d\n",
+                              procid, opno, f.path, st, errno);
                free_pathname(&f);
                close(fd);
                return;
        }
+
+       dio_env = getenv("XFS_DIO_MIN");
+       if (dio_env)
+               diob.d_mem = diob.d_miniosz = atoi(dio_env);
+
        align = (__int64_t)diob.d_miniosz;
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off -= (off % align);
        lseek64(fd, off, SEEK_SET);
-       len = (random() % (getpagesize() * 32)) + 1;
+       len = (random() % FILELEN_MAX) + 1;
        len -= (len % align);
        if (len <= 0)
                len = align;
@@ -1775,10 +2159,87 @@ dwrite_f(int opno, long r)
        e = write(fd, buf, len) < 0 ? errno : 0;
        free(buf);
        if (v)
-               printf("%d/%d: dwrite %s [%lld,%d] %d\n",
-                       procid, opno, f.path, (long long)off, (int)len, e);
+               printf("%d/%d: dwrite %s%s [%lld,%d] %d\n",
+                      procid, opno, f.path, st, (long long)off, (int)len, e);
+       free_pathname(&f);
+       close(fd);
+}
+
+
+#ifdef HAVE_LINUX_FALLOC_H
+struct print_flags falloc_flags [] = {
+       { FALLOC_FL_KEEP_SIZE, "KEEP_SIZE"},
+       { FALLOC_FL_PUNCH_HOLE, "PUNCH_HOLE"},
+       { FALLOC_FL_NO_HIDE_STALE, "NO_HIDE_STALE"},
+       { FALLOC_FL_COLLAPSE_RANGE, "COLLAPSE_RANGE"},
+       { FALLOC_FL_ZERO_RANGE, "ZERO_RANGE"},
+       { -1, NULL}
+};
+
+#define translate_falloc_flags(mode)   \
+       ({translate_flags(mode, "|", falloc_flags);})
+#endif
+
+void
+do_fallocate(int opno, long r, int mode)
+{
+#ifdef HAVE_LINUX_FALLOC_H
+       int             e;
+       pathname_t      f;
+       int             fd;
+       __int64_t       lr;
+       off64_t         off;
+       off64_t         len;
+       struct stat64   stb;
+       int             v;
+       char            st[1024];
+
+       init_pathname(&f);
+       if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
+               if (v)
+                       printf("%d/%d: do_fallocate - no filename\n", procid, opno);
+               free_pathname(&f);
+               return;
+       }
+       fd = open_path(&f, O_RDWR);
+       if (fd < 0) {
+               if (v)
+                       printf("%d/%d: do_fallocate - open %s failed %d\n",
+                               procid, opno, f.path, errno);
+               free_pathname(&f);
+               return;
+       }
+       check_cwd();
+       if (fstat64(fd, &stb) < 0) {
+               if (v)
+                       printf("%d/%d: do_fallocate - fstat64 %s failed %d\n",
+                               procid, opno, f.path, errno);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+       inode_info(st, sizeof(st), &stb, v);
+       lr = ((__int64_t)random() << 32) + random();
+       off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
+       off %= maxfsize;
+       len = (off64_t)(random() % (1024 * 1024));
+       mode |= FALLOC_FL_KEEP_SIZE & random();
+       e = fallocate(fd, mode, (loff_t)off, (loff_t)len) < 0 ? errno : 0;
+       if (v)
+               printf("%d/%d: fallocate(%s) %s %st %lld %lld %d\n",
+                      procid, opno, translate_falloc_flags(mode),
+                      f.path, st, (long long)off, (long long)len, e);
        free_pathname(&f);
        close(fd);
+#endif
+}
+
+void
+fallocate_f(int opno, long r)
+{
+#ifdef HAVE_LINUX_FALLOC_H
+       do_fallocate(opno, r, 0);
+#endif
 }
 
 void
@@ -1814,17 +2275,101 @@ fdatasync_f(int opno, long r)
        close(fd);
 }
 
+#ifdef HAVE_LINUX_FIEMAP_H
+struct print_flags fiemap_flags[] = {
+       { FIEMAP_FLAG_SYNC, "SYNC"},
+       { FIEMAP_FLAG_XATTR, "XATTR"},
+       { -1, NULL}
+};
+
+#define translate_fiemap_flags(mode)   \
+       ({translate_flags(mode, "|", fiemap_flags);})
+#endif
+
+void
+fiemap_f(int opno, long r)
+{
+#ifdef HAVE_LINUX_FIEMAP_H
+       int             e;
+       pathname_t      f;
+       int             fd;
+       __int64_t       lr;
+       off64_t         off;
+       struct stat64   stb;
+       int             v;
+       char            st[1024];
+       int blocks_to_map;
+       struct fiemap *fiemap;
+
+       init_pathname(&f);
+       if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
+               if (v)
+                       printf("%d/%d: fiemap - no filename\n", procid, opno);
+               free_pathname(&f);
+               return;
+       }
+       fd = open_path(&f, O_RDWR);
+       e = fd < 0 ? errno : 0;
+       check_cwd();
+       if (fd < 0) {
+               if (v)
+                       printf("%d/%d: fiemap - open %s failed %d\n",
+                               procid, opno, f.path, e);
+               free_pathname(&f);
+               return;
+       }
+       if (fstat64(fd, &stb) < 0) {
+               if (v)
+                       printf("%d/%d: fiemap - fstat64 %s failed %d\n",
+                               procid, opno, f.path, errno);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+       inode_info(st, sizeof(st), &stb, v);
+       blocks_to_map = random() & 0xffff;
+       fiemap = (struct fiemap *)malloc(sizeof(struct fiemap) +
+                       (blocks_to_map * sizeof(struct fiemap_extent)));
+       if (!fiemap) {
+               if (v)
+                       printf("%d/%d: malloc failed \n", procid, opno);
+               free_pathname(&f);
+               close(fd);
+               return;
+       }
+       lr = ((__int64_t)random() << 32) + random();
+       off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
+       off %= maxfsize;
+       fiemap->fm_flags = random() & (FIEMAP_FLAGS_COMPAT | 0x10000);
+       fiemap->fm_extent_count = blocks_to_map;
+       fiemap->fm_mapped_extents = random() & 0xffff;
+       fiemap->fm_start = off;
+       fiemap->fm_length = ((__int64_t)random() << 32) + random();
+
+       e = ioctl(fd, FS_IOC_FIEMAP, (unsigned long)fiemap);
+       if (v)
+               printf("%d/%d: ioctl(FIEMAP) %s%s %lld %lld (%s) %d\n",
+                      procid, opno, f.path, st, (long long)fiemap->fm_start,
+                      (long long) fiemap->fm_length,
+                      translate_fiemap_flags(fiemap->fm_flags), e);
+       free(fiemap);
+       free_pathname(&f);
+       close(fd);
+#endif
+}
+
 void
 freesp_f(int opno, long r)
 {
        int             e;
        pathname_t      f;
        int             fd;
-       struct flock64  fl;
+       struct xfs_flock64      fl;
        __int64_t       lr;
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
 
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
@@ -1851,6 +2396,7 @@ freesp_f(int opno, long r)
                close(fd);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
@@ -1859,8 +2405,8 @@ freesp_f(int opno, long r)
        fl.l_len = 0;
        e = xfsctl(f.path, fd, XFS_IOC_FREESP64, &fl) < 0 ? errno : 0;
        if (v)
-               printf("%d/%d: xfsctl(XFS_IOC_FREESP64) %s %lld 0 %d\n",
-                       procid, opno, f.path, (long long)off, e);
+               printf("%d/%d: xfsctl(XFS_IOC_FREESP64) %s%s %lld 0 %d\n",
+                      procid, opno, f.path, st, (long long)off, e);
        free_pathname(&f);
        close(fd);
 }
@@ -1897,6 +2443,29 @@ fsync_f(int opno, long r)
        close(fd);
 }
 
+void
+getattr_f(int opno, long r)
+{
+       int             fd;
+       int             e;
+       pathname_t      f;
+       uint            fl;
+       int             v;
+
+       init_pathname(&f);
+       if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
+               append_pathname(&f, ".");
+       fd = open_path(&f, O_RDWR);
+       e = fd < 0 ? errno : 0;
+       check_cwd();
+
+       e = ioctl(fd, FS_IOC_GETFLAGS, &fl);
+       if (v)
+               printf("%d/%d: getattr %s %u %d\n", procid, opno, f.path, fl, e);
+       free_pathname(&f);
+       close(fd);
+}
+
 void
 getdents_f(int opno, long r)
 {
@@ -1954,7 +2523,7 @@ link_f(int opno, long r)
        v |= v1;
        if (!e) {
                if (v) {
-                       fent_to_name(&l, &flist[FT_DIR], fep);
+                       (void)fent_to_name(&l, &flist[FT_DIR], fep);
                        printf("%d/%d: link - no filename from %s\n",
                                procid, opno, l.path);
                }
@@ -1966,9 +2535,11 @@ link_f(int opno, long r)
        check_cwd();
        if (e == 0)
                add_to_flist(flp - flist, id, parid);
-       if (v)
+       if (v) {
                printf("%d/%d: link %s %s %d\n", procid, opno, f.path, l.path,
                        e);
+               printf("%d/%d: link add id=%d,parent=%d\n", procid, opno, id, parid);
+       }
        free_pathname(&l);
        free_pathname(&f);
 }
@@ -1993,7 +2564,7 @@ mkdir_f(int opno, long r)
        v |= v1;
        if (!e) {
                if (v) {
-                       fent_to_name(&f, &flist[FT_DIR], fep);
+                       (void)fent_to_name(&f, &flist[FT_DIR], fep);
                        printf("%d/%d: mkdir - no filename from %s\n",
                                procid, opno, f.path);
                }
@@ -2004,8 +2575,10 @@ mkdir_f(int opno, long r)
        check_cwd();
        if (e == 0)
                add_to_flist(FT_DIR, id, parid);
-       if (v)
+       if (v) {
                printf("%d/%d: mkdir %s %d\n", procid, opno, f.path, e);
+               printf("%d/%d: mkdir add id=%d,parent=%d\n", procid, opno, id, parid);
+       }
        free_pathname(&f);
 }
 
@@ -2029,7 +2602,7 @@ mknod_f(int opno, long r)
        v |= v1;
        if (!e) {
                if (v) {
-                       fent_to_name(&f, &flist[FT_DIR], fep);
+                       (void)fent_to_name(&f, &flist[FT_DIR], fep);
                        printf("%d/%d: mknod - no filename from %s\n",
                                procid, opno, f.path);
                }
@@ -2040,11 +2613,29 @@ mknod_f(int opno, long r)
        check_cwd();
        if (e == 0)
                add_to_flist(FT_DEV, id, parid);
-       if (v)
+       if (v) {
                printf("%d/%d: mknod %s %d\n", procid, opno, f.path, e);
+               printf("%d/%d: mknod add id=%d,parent=%d\n", procid, opno, id, parid);
+       }
        free_pathname(&f);
 }
 
+void
+punch_f(int opno, long r)
+{
+#ifdef HAVE_LINUX_FALLOC_H
+       do_fallocate(opno, r, FALLOC_FL_PUNCH_HOLE);
+#endif
+}
+
+void
+zero_f(int opno, long r)
+{
+#ifdef HAVE_LINUX_FALLOC_H
+       do_fallocate(opno, r, FALLOC_FL_ZERO_RANGE);
+#endif
+}
+
 void
 read_f(int opno, long r)
 {
@@ -2057,6 +2648,7 @@ read_f(int opno, long r)
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
 
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
@@ -2083,10 +2675,11 @@ read_f(int opno, long r)
                close(fd);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        if (stb.st_size == 0) {
                if (v)
-                       printf("%d/%d: read - %s zero size\n", procid, opno,
-                               f.path);
+                       printf("%d/%d: read - %s%s zero size\n", procid, opno,
+                              f.path, st);
                free_pathname(&f);
                close(fd);
                return;
@@ -2094,13 +2687,13 @@ read_f(int opno, long r)
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % stb.st_size);
        lseek64(fd, off, SEEK_SET);
-       len = (random() % (getpagesize() * 32)) + 1;
+       len = (random() % FILELEN_MAX) + 1;
        buf = malloc(len);
        e = read(fd, buf, len) < 0 ? errno : 0;
        free(buf);
        if (v)
-               printf("%d/%d: read %s [%lld,%d] %d\n",
-                       procid, opno, f.path, (long long)off, (int)len, e);
+               printf("%d/%d: read %s%s [%lld,%d] %d\n",
+                      procid, opno, f.path, st, (long long)off, (int)len, e);
        free_pathname(&f);
        close(fd);
 }
@@ -2142,6 +2735,7 @@ rename_f(int opno, long r)
        int             v;
        int             v1;
 
+       /* get an existing path for the source of the rename */
        init_pathname(&f);
        if (!get_fname(FT_ANYm, r, &f, &flp, &fep, &v1)) {
                if (v1)
@@ -2149,17 +2743,21 @@ rename_f(int opno, long r)
                free_pathname(&f);
                return;
        }
+
+       /* get an existing directory for the destination parent directory name */
        if (!get_fname(FT_DIRm, random(), NULL, NULL, &dfep, &v))
                parid = -1;
        else
                parid = dfep->id;
        v |= v1;
+
+       /* generate a new path using an existing parent directory in name */
        init_pathname(&newf);
        e = generate_fname(dfep, flp - flist, &newf, &id, &v1);
        v |= v1;
        if (!e) {
                if (v) {
-                       fent_to_name(&f, &flist[FT_DIR], dfep);
+                       (void)fent_to_name(&f, &flist[FT_DIR], dfep);
                        printf("%d/%d: rename - no filename from %s\n",
                                procid, opno, f.path);
                }
@@ -2177,9 +2775,16 @@ rename_f(int opno, long r)
                del_from_flist(flp - flist, fep - flp->fents);
                add_to_flist(flp - flist, id, parid);
        }
-       if (v)
+       if (v) {
                printf("%d/%d: rename %s to %s %d\n", procid, opno, f.path,
                        newf.path, e);
+               if (e == 0) {
+                       printf("%d/%d: rename del entry: id=%d,parent=%d\n",
+                               procid, opno, fep->id, fep->parent);
+                       printf("%d/%d: rename add entry: id=%d,parent=%d\n",
+                               procid, opno, id, parid);
+               }
+       }
        free_pathname(&newf);
        free_pathname(&f);
 }
@@ -2190,11 +2795,12 @@ resvsp_f(int opno, long r)
        int             e;
        pathname_t      f;
        int             fd;
-       struct flock64  fl;
+       struct xfs_flock64      fl;
        __int64_t       lr;
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
 
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
@@ -2221,6 +2827,7 @@ resvsp_f(int opno, long r)
                close(fd);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
@@ -2229,8 +2836,8 @@ resvsp_f(int opno, long r)
        fl.l_len = (off64_t)(random() % (1024 * 1024));
        e = xfsctl(f.path, fd, XFS_IOC_RESVSP64, &fl) < 0 ? errno : 0;
        if (v)
-               printf("%d/%d: xfsctl(XFS_IOC_RESVSP64) %s %lld %lld %d\n",
-                       procid, opno, f.path,
+               printf("%d/%d: xfsctl(XFS_IOC_RESVSP64) %s%s %lld %lld %d\n",
+                      procid, opno, f.path, st,
                        (long long)off, (long long)fl.l_len, e);
        free_pathname(&f);
        close(fd);
@@ -2255,11 +2862,39 @@ rmdir_f(int opno, long r)
        check_cwd();
        if (e == 0)
                del_from_flist(FT_DIR, fep - flist[FT_DIR].fents);
-       if (v)
+       if (v) {
                printf("%d/%d: rmdir %s %d\n", procid, opno, f.path, e);
+               if (e == 0)
+                       printf("%d/%d: rmdir del entry: id=%d,parent=%d\n",
+                               procid, opno, fep->id, fep->parent);
+       }
        free_pathname(&f);
 }
 
+void
+setattr_f(int opno, long r)
+{
+       int             fd;
+       int             e;
+       pathname_t      f;
+       uint            fl;
+       int             v;
+
+       init_pathname(&f);
+       if (!get_fname(FT_ANYm, r, &f, NULL, NULL, &v))
+               append_pathname(&f, ".");
+       fd = open_path(&f, O_RDWR);
+       e = fd < 0 ? errno : 0;
+       check_cwd();
+
+       fl = attr_mask & (uint)random();
+       e = ioctl(fd, FS_IOC_SETFLAGS, &fl);
+       if (v)
+               printf("%d/%d: setattr %s %x %d\n", procid, opno, f.path, fl, e);
+       free_pathname(&f);
+       close(fd);
+}
+
 void
 stat_f(int opno, long r)
 {
@@ -2305,7 +2940,7 @@ symlink_f(int opno, long r)
        v |= v1;
        if (!e) {
                if (v) {
-                       fent_to_name(&f, &flist[FT_DIR], fep);
+                       (void)fent_to_name(&f, &flist[FT_DIR], fep);
                        printf("%d/%d: symlink - no filename from %s\n",
                                procid, opno, f.path);
                }
@@ -2324,8 +2959,10 @@ symlink_f(int opno, long r)
        if (e == 0)
                add_to_flist(FT_SYM, id, parid);
        free(val);
-       if (v)
+       if (v) {
                printf("%d/%d: symlink %s %d\n", procid, opno, f.path, e);
+               printf("%d/%d: symlink add id=%d,parent=%d\n", procid, opno, id, parid);
+       }
        free_pathname(&f);
 }
 
@@ -2347,6 +2984,7 @@ truncate_f(int opno, long r)
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
 
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
@@ -2364,14 +3002,15 @@ truncate_f(int opno, long r)
                free_pathname(&f);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
        e = truncate64_path(&f, off) < 0 ? errno : 0;
        check_cwd();
        if (v)
-               printf("%d/%d: truncate %s %lld %d\n", procid, opno, f.path,
-                       (long long)off, e);
+               printf("%d/%d: truncate %s%s %lld %d\n", procid, opno, f.path,
+                      st, (long long)off, e);
        free_pathname(&f);
 }
 
@@ -2395,8 +3034,12 @@ unlink_f(int opno, long r)
        check_cwd();
        if (e == 0)
                del_from_flist(flp - flist, fep - flp->fents);
-       if (v)
+       if (v) {
                printf("%d/%d: unlink %s %d\n", procid, opno, f.path, e);
+               if (e == 0)
+                       printf("%d/%d: unlink del entry: id=%d,parent=%d\n",
+                               procid, opno, fep->id, fep->parent);
+       }
        free_pathname(&f);
 }
 
@@ -2406,11 +3049,12 @@ unresvsp_f(int opno, long r)
        int             e;
        pathname_t      f;
        int             fd;
-       struct flock64  fl;
+       struct xfs_flock64      fl;
        __int64_t       lr;
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
 
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
@@ -2437,6 +3081,7 @@ unresvsp_f(int opno, long r)
                close(fd);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
@@ -2445,8 +3090,8 @@ unresvsp_f(int opno, long r)
        fl.l_len = (off64_t)(random() % (1 << 20));
        e = xfsctl(f.path, fd, XFS_IOC_UNRESVSP64, &fl) < 0 ? errno : 0;
        if (v)
-               printf("%d/%d: xfsctl(XFS_IOC_UNRESVSP64) %s %lld %lld %d\n",
-                       procid, opno, f.path,
+               printf("%d/%d: xfsctl(XFS_IOC_UNRESVSP64) %s%s %lld %lld %d\n",
+                      procid, opno, f.path, st,
                        (long long)off, (long long)fl.l_len, e);
        free_pathname(&f);
        close(fd);
@@ -2464,6 +3109,7 @@ write_f(int opno, long r)
        off64_t         off;
        struct stat64   stb;
        int             v;
+       char            st[1024];
 
        init_pathname(&f);
        if (!get_fname(FT_REGm, r, &f, NULL, NULL, &v)) {
@@ -2490,18 +3136,19 @@ write_f(int opno, long r)
                close(fd);
                return;
        }
+       inode_info(st, sizeof(st), &stb, v);
        lr = ((__int64_t)random() << 32) + random();
        off = (off64_t)(lr % MIN(stb.st_size + (1024 * 1024), MAXFSIZE));
        off %= maxfsize;
        lseek64(fd, off, SEEK_SET);
-       len = (random() % (getpagesize() * 32)) + 1;
+       len = (random() % FILELEN_MAX) + 1;
        buf = malloc(len);
        memset(buf, nameseq & 0xff, len);
        e = write(fd, buf, len) < 0 ? errno : 0;
        free(buf);
        if (v)
-               printf("%d/%d: write %s [%lld,%d] %d\n",
-                       procid, opno, f.path, (long long)off, (int)len, e);
+               printf("%d/%d: write %s%s [%lld,%d] %d\n",
+                      procid, opno, f.path, st, (long long)off, (int)len, e);
        free_pathname(&f);
        close(fd);
 }