]> Pileus Git - ~andy/linux/blobdiff - fs/ecryptfs/file.c
file->f_op is never NULL...
[~andy/linux] / fs / ecryptfs / file.c
index a7abbea2c09638ef8c190555ec466834c0c06edf..6b1cd2b0c75179f822319c6ae7a28c06fb108b53 100644 (file)
@@ -49,7 +49,7 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb,
                                unsigned long nr_segs, loff_t pos)
 {
        ssize_t rc;
-       struct path lower;
+       struct path *path;
        struct file *file = iocb->ki_filp;
 
        rc = generic_file_aio_read(iocb, iov, nr_segs, pos);
@@ -60,17 +60,16 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb,
        if (-EIOCBQUEUED == rc)
                rc = wait_on_sync_kiocb(iocb);
        if (rc >= 0) {
-               lower.dentry = ecryptfs_dentry_to_lower(file->f_path.dentry);
-               lower.mnt = ecryptfs_dentry_to_lower_mnt(file->f_path.dentry);
-               touch_atime(&lower);
+               path = ecryptfs_dentry_to_lower_path(file->f_path.dentry);
+               touch_atime(path);
        }
        return rc;
 }
 
 struct ecryptfs_getdents_callback {
-       void *dirent;
-       struct dentry *dentry;
-       filldir_t filldir;
+       struct dir_context ctx;
+       struct dir_context *caller;
+       struct super_block *sb;
        int filldir_called;
        int entries_written;
 };
@@ -88,7 +87,7 @@ ecryptfs_filldir(void *dirent, const char *lower_name, int lower_namelen,
 
        buf->filldir_called++;
        rc = ecryptfs_decode_and_decrypt_filename(&name, &name_size,
-                                                 buf->dentry, lower_name,
+                                                 buf->sb, lower_name,
                                                  lower_namelen);
        if (rc) {
                printk(KERN_ERR "%s: Error attempting to decode and decrypt "
@@ -96,9 +95,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 +107,22 @@ 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 inode *inode = file_inode(file);
+       struct ecryptfs_getdents_callback buf = {
+               .ctx.actor = ecryptfs_filldir,
+               .caller = ctx,
+               .sb = inode->i_sb,
+       };
        lower_file = ecryptfs_file_to_lower(file);
-       lower_file->f_pos = file->f_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;
+       lower_file->f_pos = ctx->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)
@@ -276,7 +271,7 @@ static int ecryptfs_flush(struct file *file, fl_owner_t td)
 {
        struct file *lower_file = ecryptfs_file_to_lower(file);
 
-       if (lower_file->f_op && lower_file->f_op->flush) {
+       if (lower_file->f_op->flush) {
                filemap_write_and_wait(file->f_mapping);
                return lower_file->f_op->flush(lower_file, td);
        }
@@ -310,7 +305,7 @@ static int ecryptfs_fasync(int fd, struct file *file, int flag)
        struct file *lower_file = NULL;
 
        lower_file = ecryptfs_file_to_lower(file);
-       if (lower_file->f_op && lower_file->f_op->fasync)
+       if (lower_file->f_op->fasync)
                rc = lower_file->f_op->fasync(fd, lower_file, flag);
        return rc;
 }
@@ -323,7 +318,7 @@ ecryptfs_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
        if (ecryptfs_file_to_private(file))
                lower_file = ecryptfs_file_to_lower(file);
-       if (lower_file && lower_file->f_op && lower_file->f_op->unlocked_ioctl)
+       if (lower_file->f_op && lower_file->f_op->unlocked_ioctl)
                rc = lower_file->f_op->unlocked_ioctl(lower_file, cmd, arg);
        return rc;
 }
@@ -337,14 +332,14 @@ ecryptfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
        if (ecryptfs_file_to_private(file))
                lower_file = ecryptfs_file_to_lower(file);
-       if (lower_file && lower_file->f_op && lower_file->f_op->compat_ioctl)
+       if (lower_file->f_op && lower_file->f_op->compat_ioctl)
                rc = lower_file->f_op->compat_ioctl(lower_file, cmd, arg);
        return rc;
 }
 #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
@@ -365,7 +360,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,