eCryptfs: remove netlink transport
[safe/jmp/linux-2.6] / fs / ecryptfs / inode.c
index 0a13973..89209f0 100644 (file)
 #include <linux/mount.h>
 #include <linux/crypto.h>
 #include <linux/fs_stack.h>
+#include <asm/unaligned.h>
 #include "ecryptfs_kernel.h"
 
 static struct dentry *lock_parent(struct dentry *dentry)
 {
        struct dentry *dir;
 
-       dir = dget(dentry->d_parent);
+       dir = dget_parent(dentry);
        mutex_lock_nested(&(dir->d_inode->i_mutex), I_MUTEX_PARENT);
        return dir;
 }
 
-static void unlock_parent(struct dentry *dentry)
-{
-       mutex_unlock(&(dentry->d_parent->d_inode->i_mutex));
-       dput(dentry->d_parent);
-}
-
 static void unlock_dir(struct dentry *dir)
 {
        mutex_unlock(&dir->d_inode->i_mutex);
@@ -194,6 +189,16 @@ static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry)
                                "context; rc = [%d]\n", rc);
                goto out;
        }
+       if (!ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->lower_file) {
+               rc = ecryptfs_init_persistent_file(ecryptfs_dentry);
+               if (rc) {
+                       printk(KERN_ERR "%s: Error attempting to initialize "
+                              "the persistent file for the dentry with name "
+                              "[%s]; rc = [%d]\n", __func__,
+                              ecryptfs_dentry->d_name.name, rc);
+                       goto out;
+               }
+       }
        rc = ecryptfs_write_metadata(ecryptfs_dentry);
        if (rc) {
                printk(KERN_ERR "Error writing headers; rc = [%d]\n", rc);
@@ -313,10 +318,11 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry,
                d_add(dentry, NULL);
                goto out;
        }
-       rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 1);
+       rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb,
+                               ECRYPTFS_INTERPOSE_FLAG_D_ADD);
        if (rc) {
                ecryptfs_printk(KERN_ERR, "Error interposing\n");
-               goto out_dput;
+               goto out;
        }
        if (S_ISDIR(lower_inode->i_mode)) {
                ecryptfs_printk(KERN_DEBUG, "Is a directory; returning\n");
@@ -342,11 +348,21 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry,
                rc = -ENOMEM;
                ecryptfs_printk(KERN_ERR,
                                "Cannot ecryptfs_kmalloc a page\n");
-               goto out_dput;
+               goto out;
        }
        crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat;
        if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED))
                ecryptfs_set_default_sizes(crypt_stat);
+       if (!ecryptfs_inode_to_private(dentry->d_inode)->lower_file) {
+               rc = ecryptfs_init_persistent_file(dentry);
+               if (rc) {
+                       printk(KERN_ERR "%s: Error attempting to initialize "
+                              "the persistent file for the dentry with name "
+                              "[%s]; rc = [%d]\n", __func__,
+                              dentry->d_name.name, rc);
+                       goto out;
+               }
+       }
        rc = ecryptfs_read_and_validate_header_region(page_virt,
                                                      dentry->d_inode);
        if (rc) {
@@ -370,8 +386,7 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry,
                else
                        file_size = i_size_read(lower_dentry->d_inode);
        } else {
-               memcpy(&file_size, page_virt, sizeof(file_size));
-               file_size = be64_to_cpu(file_size);
+               file_size = get_unaligned_be64(page_virt);
        }
        i_size_write(dentry->d_inode, (loff_t)file_size);
        kmem_cache_free(ecryptfs_header_cache_2, page_virt);
@@ -426,8 +441,9 @@ static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry)
        int rc = 0;
        struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry);
        struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir);
+       struct dentry *lower_dir_dentry;
 
-       lock_parent(lower_dentry);
+       lower_dir_dentry = lock_parent(lower_dentry);
        rc = vfs_unlink(lower_dir_inode, lower_dentry);
        if (rc) {
                printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
@@ -439,7 +455,7 @@ static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry)
        dentry->d_inode->i_ctime = dir->i_ctime;
        d_drop(dentry);
 out_unlock:
-       unlock_parent(lower_dentry);
+       unlock_dir(lower_dir_dentry);
        return rc;
 }
 
@@ -449,7 +465,6 @@ static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry,
        int rc;
        struct dentry *lower_dentry;
        struct dentry *lower_dir_dentry;
-       umode_t mode;
        char *encoded_symname;
        int encoded_symlen;
        struct ecryptfs_crypt_stat *crypt_stat = NULL;
@@ -457,7 +472,6 @@ static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry,
        lower_dentry = ecryptfs_dentry_to_lower(dentry);
        dget(lower_dentry);
        lower_dir_dentry = lock_parent(lower_dentry);
-       mode = S_IALLUGO;
        encoded_symlen = ecryptfs_encode_filename(crypt_stat, symname,
                                                  strlen(symname),
                                                  &encoded_symname);
@@ -466,7 +480,7 @@ static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry,
                goto out_lock;
        }
        rc = vfs_symlink(lower_dir_dentry->d_inode, lower_dentry,
-                        encoded_symname, mode);
+                        encoded_symname);
        kfree(encoded_symname);
        if (rc || !lower_dentry->d_inode)
                goto out_lock;
@@ -814,22 +828,9 @@ out:
 }
 
 static int
-ecryptfs_permission(struct inode *inode, int mask, struct nameidata *nd)
+ecryptfs_permission(struct inode *inode, int mask)
 {
-       int rc;
-
-        if (nd) {
-               struct vfsmount *vfsmnt_save = nd->path.mnt;
-               struct dentry *dentry_save = nd->path.dentry;
-
-               nd->path.mnt = ecryptfs_dentry_to_lower_mnt(nd->path.dentry);
-               nd->path.dentry = ecryptfs_dentry_to_lower(nd->path.dentry);
-               rc = permission(ecryptfs_inode_to_lower(inode), mask, nd);
-               nd->path.mnt = vfsmnt_save;
-               nd->path.dentry = dentry_save;
-        } else
-               rc = permission(ecryptfs_inode_to_lower(inode), mask, NULL);
-        return rc;
+       return inode_permission(ecryptfs_inode_to_lower(inode), mask);
 }
 
 /**