error = buf.error;
        lastdirent = buf.previous;
        if (lastdirent) {
-               if (put_user(arg.file->f_pos, &lastdirent->d_off))
+               if (put_user(buf.ctx.pos, &lastdirent->d_off))
                        error = -EFAULT;
                else
                        error = count - buf.count;
 
        if (!host_file->f_op)
                return -ENOTDIR;
 
-       if (host_file->f_op->readdir)
-       {
+       if (host_file->f_op->readdir) {
                /* potemkin case: we were handed a directory inode.
                 * We can't use vfs_readdir because we have to keep the file
                 * position in sync between the coda_file and the host_file.
 
                coda_file->f_pos = host_file->f_pos;
                mutex_unlock(&host_inode->i_mutex);
-       }
-       else /* Venus: we must read Venus dirents from a file */
+       } else if (host_file->f_op->iterate) {
+               struct inode *host_inode = file_inode(host_file);
+               struct dir_context *ctx = buf;
+
+               mutex_lock(&host_inode->i_mutex);
+               ret = -ENOENT;
+               if (!IS_DEADDIR(host_inode)) {
+                       ret = host_file->f_op->iterate(host_file, ctx);
+                       file_accessed(host_file);
+               }
+               mutex_unlock(&host_inode->i_mutex);
+
+               coda_file->f_pos = ctx->pos;
+       } else /* Venus: we must read Venus dirents from a file */
                ret = coda_venus_readdir(coda_file, buf, filldir);
 
        return ret;
 
                error = buf.error;
        lastdirent = buf.previous;
        if (lastdirent) {
-               if (put_user(f.file->f_pos, &lastdirent->d_off))
+               if (put_user(buf.ctx.pos, &lastdirent->d_off))
                        error = -EFAULT;
                else
                        error = count - buf.count;
                error = buf.error;
        lastdirent = buf.previous;
        if (lastdirent) {
-               typeof(lastdirent->d_off) d_off = f.file->f_pos;
+               typeof(lastdirent->d_off) d_off = buf.ctx.pos;
                if (__put_user_unaligned(d_off, &lastdirent->d_off))
                        error = -EFAULT;
                else
 
                goto out;
 
        error = -EINVAL;
-       if (!file->f_op->readdir)
+       if (!file->f_op->readdir && !file->f_op->iterate)
                goto out_close;
 
        buffer.name = name;
 
        struct list_head list;
 };
 
+struct nfs4_dir_ctx {
+       struct dir_context ctx;
+       struct list_head names;
+};
+
 static int
 nfsd4_build_namelist(void *arg, const char *name, int namlen,
                loff_t offset, u64 ino, unsigned int d_type)
 {
-       struct list_head *names = arg;
+       struct nfs4_dir_ctx *ctx = arg;
        struct name_list *entry;
 
        if (namlen != HEXDIR_LEN - 1)
                return -ENOMEM;
        memcpy(entry->name, name, HEXDIR_LEN - 1);
        entry->name[HEXDIR_LEN - 1] = '\0';
-       list_add(&entry->list, names);
+       list_add(&entry->list, &ctx->names);
        return 0;
 }
 
 {
        const struct cred *original_cred;
        struct dentry *dir = nn->rec_file->f_path.dentry;
-       struct {
-               struct dir_context ctx;
-               struct list_head names;
-       } ctx;
+       struct nfs4_dir_ctx ctx;
        int status;
 
        status = nfs4_save_creds(&original_cred);
 
 {
        struct inode *inode = file_inode(file);
        int res = -ENOTDIR;
-       if (!file->f_op || !file->f_op->readdir)
+       if (!file->f_op || (!file->f_op->readdir && !file->f_op->iterate))
                goto out;
 
        res = security_file_permission(file, MAY_READ);
 
        res = -ENOENT;
        if (!IS_DEADDIR(inode)) {
-               res = file->f_op->readdir(file, ctx, ctx->actor);
+               if (file->f_op->iterate) {
+                       ctx->pos = file->f_pos;
+                       res = file->f_op->iterate(file, ctx);
+                       file->f_pos = ctx->pos;
+               } else {
+                       res = file->f_op->readdir(file, ctx, ctx->actor);
+                       ctx->pos = file->f_pos;
+               }
                file_accessed(file);
        }
        mutex_unlock(&inode->i_mutex);
                error = buf.error;
        lastdirent = buf.previous;
        if (lastdirent) {
-               if (put_user(f.file->f_pos, &lastdirent->d_off))
+               if (put_user(buf.ctx.pos, &lastdirent->d_off))
                        error = -EFAULT;
                else
                        error = count - buf.count;
                error = buf.error;
        lastdirent = buf.previous;
        if (lastdirent) {
-               typeof(lastdirent->d_off) d_off = f.file->f_pos;
+               typeof(lastdirent->d_off) d_off = buf.ctx.pos;
                if (__put_user(d_off, &lastdirent->d_off))
                        error = -EFAULT;
                else
 
 typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned);
 struct dir_context {
        filldir_t actor;
+       loff_t pos;
 };
+
+static inline bool dir_emit(struct dir_context *ctx,
+                           const char *name, int namelen,
+                           u64 ino, unsigned type)
+{
+       return ctx->actor(ctx, name, namelen, ctx->pos, ino, type) == 0;
+}
 struct block_device_operations;
 
 /* These macros are for out of kernel modules to test that
        ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
        ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
        int (*readdir) (struct file *, void *, filldir_t);
+       int (*iterate) (struct file *, struct dir_context *);
        unsigned int (*poll) (struct file *, struct poll_table_struct *);
        long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
        long (*compat_ioctl) (struct file *, unsigned int, unsigned long);