fuse: another open-coded file_inode()
[linux-2.6-block.git] / fs / ecryptfs / file.c
index 201f0a0d6b0a2a2be8a2983d2fb63ef27dacc0d8..9aa05e08060b507f05f17a5b464fb1f695c7e3e4 100644 (file)
@@ -68,9 +68,9 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb,
 }
 
 struct ecryptfs_getdents_callback {
-       void *dirent;
+       struct dir_context ctx;
+       struct dir_context *caller;
        struct dentry *dentry;
-       filldir_t filldir;
        int filldir_called;
        int entries_written;
 };
@@ -96,9 +96,10 @@ ecryptfs_filldir(void *dirent, const char *lower_name, int lower_namelen,
                       rc);
                goto out;
        }
-       rc = buf->filldir(buf->dirent, name, name_size, offset, ino, d_type);
+       buf->caller->pos = buf->ctx.pos;
+       rc = !dir_emit(buf->caller, name, name_size, ino, d_type);
        kfree(name);
-       if (rc >= 0)
+       if (!rc)
                buf->entries_written++;
 out:
        return rc;
@@ -107,27 +108,23 @@ out:
 /**
  * ecryptfs_readdir
  * @file: The eCryptfs directory file
- * @dirent: Directory entry handle
- * @filldir: The filldir callback function
+ * @ctx: The actor to feed the entries to
  */
-static int ecryptfs_readdir(struct file *file, void *dirent, filldir_t filldir)
+static int ecryptfs_readdir(struct file *file, struct dir_context *ctx)
 {
        int rc;
        struct file *lower_file;
        struct inode *inode;
-       struct ecryptfs_getdents_callback buf;
-
+       struct ecryptfs_getdents_callback buf = {
+               .ctx.actor = ecryptfs_filldir,
+               .caller = ctx,
+               .dentry = file->f_path.dentry
+       };
        lower_file = ecryptfs_file_to_lower(file);
-       lower_file->f_pos = file->f_pos;
+       lower_file->f_pos = ctx->pos;
        inode = file_inode(file);
-       memset(&buf, 0, sizeof(buf));
-       buf.dirent = dirent;
-       buf.dentry = file->f_path.dentry;
-       buf.filldir = filldir;
-       buf.filldir_called = 0;
-       buf.entries_written = 0;
-       rc = vfs_readdir(lower_file, ecryptfs_filldir, (void *)&buf);
-       file->f_pos = lower_file->f_pos;
+       rc = iterate_dir(lower_file, &buf.ctx);
+       ctx->pos = buf.ctx.pos;
        if (rc < 0)
                goto out;
        if (buf.filldir_called && !buf.entries_written)
@@ -295,6 +292,12 @@ static int ecryptfs_release(struct inode *inode, struct file *file)
 static int
 ecryptfs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
 {
+       int rc;
+
+       rc = filemap_write_and_wait(file->f_mapping);
+       if (rc)
+               return rc;
+
        return vfs_fsync(ecryptfs_file_to_lower(file), datasync);
 }
 
@@ -338,7 +341,7 @@ ecryptfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 #endif
 
 const struct file_operations ecryptfs_dir_fops = {
-       .readdir = ecryptfs_readdir,
+       .iterate = ecryptfs_readdir,
        .read = generic_read_dir,
        .unlocked_ioctl = ecryptfs_unlocked_ioctl,
 #ifdef CONFIG_COMPAT
@@ -359,7 +362,7 @@ const struct file_operations ecryptfs_main_fops = {
        .aio_read = ecryptfs_read_update_atime,
        .write = do_sync_write,
        .aio_write = generic_file_aio_write,
-       .readdir = ecryptfs_readdir,
+       .iterate = ecryptfs_readdir,
        .unlocked_ioctl = ecryptfs_unlocked_ioctl,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = ecryptfs_compat_ioctl,