diff options
Diffstat (limited to 'fs/ecryptfs/inode.c')
| -rw-r--r-- | fs/ecryptfs/inode.c | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index f99051b7adab..4d4cc6a90cd5 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c | |||
| @@ -168,19 +168,18 @@ static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry) | |||
| 168 | "context; rc = [%d]\n", rc); | 168 | "context; rc = [%d]\n", rc); |
| 169 | goto out; | 169 | goto out; |
| 170 | } | 170 | } |
| 171 | rc = ecryptfs_init_persistent_file(ecryptfs_dentry); | 171 | rc = ecryptfs_get_lower_file(ecryptfs_dentry); |
| 172 | if (rc) { | 172 | if (rc) { |
| 173 | printk(KERN_ERR "%s: Error attempting to initialize " | 173 | printk(KERN_ERR "%s: Error attempting to initialize " |
| 174 | "the persistent file for the dentry with name " | 174 | "the lower file for the dentry with name " |
| 175 | "[%s]; rc = [%d]\n", __func__, | 175 | "[%s]; rc = [%d]\n", __func__, |
| 176 | ecryptfs_dentry->d_name.name, rc); | 176 | ecryptfs_dentry->d_name.name, rc); |
| 177 | goto out; | 177 | goto out; |
| 178 | } | 178 | } |
| 179 | rc = ecryptfs_write_metadata(ecryptfs_dentry); | 179 | rc = ecryptfs_write_metadata(ecryptfs_dentry); |
| 180 | if (rc) { | 180 | if (rc) |
| 181 | printk(KERN_ERR "Error writing headers; rc = [%d]\n", rc); | 181 | printk(KERN_ERR "Error writing headers; rc = [%d]\n", rc); |
| 182 | goto out; | 182 | ecryptfs_put_lower_file(ecryptfs_dentry->d_inode); |
| 183 | } | ||
| 184 | out: | 183 | out: |
| 185 | return rc; | 184 | return rc; |
| 186 | } | 185 | } |
| @@ -226,11 +225,9 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry, | |||
| 226 | struct dentry *lower_dir_dentry; | 225 | struct dentry *lower_dir_dentry; |
| 227 | struct vfsmount *lower_mnt; | 226 | struct vfsmount *lower_mnt; |
| 228 | struct inode *lower_inode; | 227 | struct inode *lower_inode; |
| 229 | struct ecryptfs_mount_crypt_stat *mount_crypt_stat; | ||
| 230 | struct ecryptfs_crypt_stat *crypt_stat; | 228 | struct ecryptfs_crypt_stat *crypt_stat; |
| 231 | char *page_virt = NULL; | 229 | char *page_virt = NULL; |
| 232 | u64 file_size; | 230 | int put_lower = 0, rc = 0; |
| 233 | int rc = 0; | ||
| 234 | 231 | ||
| 235 | lower_dir_dentry = lower_dentry->d_parent; | 232 | lower_dir_dentry = lower_dentry->d_parent; |
| 236 | lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt( | 233 | lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt( |
| @@ -277,14 +274,15 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry, | |||
| 277 | rc = -ENOMEM; | 274 | rc = -ENOMEM; |
| 278 | goto out; | 275 | goto out; |
| 279 | } | 276 | } |
| 280 | rc = ecryptfs_init_persistent_file(ecryptfs_dentry); | 277 | rc = ecryptfs_get_lower_file(ecryptfs_dentry); |
| 281 | if (rc) { | 278 | if (rc) { |
| 282 | printk(KERN_ERR "%s: Error attempting to initialize " | 279 | printk(KERN_ERR "%s: Error attempting to initialize " |
| 283 | "the persistent file for the dentry with name " | 280 | "the lower file for the dentry with name " |
| 284 | "[%s]; rc = [%d]\n", __func__, | 281 | "[%s]; rc = [%d]\n", __func__, |
| 285 | ecryptfs_dentry->d_name.name, rc); | 282 | ecryptfs_dentry->d_name.name, rc); |
| 286 | goto out_free_kmem; | 283 | goto out_free_kmem; |
| 287 | } | 284 | } |
| 285 | put_lower = 1; | ||
| 288 | crypt_stat = &ecryptfs_inode_to_private( | 286 | crypt_stat = &ecryptfs_inode_to_private( |
| 289 | ecryptfs_dentry->d_inode)->crypt_stat; | 287 | ecryptfs_dentry->d_inode)->crypt_stat; |
| 290 | /* TODO: lock for crypt_stat comparison */ | 288 | /* TODO: lock for crypt_stat comparison */ |
| @@ -302,18 +300,7 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry, | |||
| 302 | } | 300 | } |
| 303 | crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR; | 301 | crypt_stat->flags |= ECRYPTFS_METADATA_IN_XATTR; |
| 304 | } | 302 | } |
| 305 | mount_crypt_stat = &ecryptfs_superblock_to_private( | 303 | ecryptfs_i_size_init(page_virt, ecryptfs_dentry->d_inode); |
| 306 | ecryptfs_dentry->d_sb)->mount_crypt_stat; | ||
| 307 | if (mount_crypt_stat->flags & ECRYPTFS_ENCRYPTED_VIEW_ENABLED) { | ||
| 308 | if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) | ||
| 309 | file_size = (crypt_stat->metadata_size | ||
| 310 | + i_size_read(lower_dentry->d_inode)); | ||
| 311 | else | ||
| 312 | file_size = i_size_read(lower_dentry->d_inode); | ||
| 313 | } else { | ||
| 314 | file_size = get_unaligned_be64(page_virt); | ||
| 315 | } | ||
| 316 | i_size_write(ecryptfs_dentry->d_inode, (loff_t)file_size); | ||
| 317 | out_free_kmem: | 304 | out_free_kmem: |
| 318 | kmem_cache_free(ecryptfs_header_cache_2, page_virt); | 305 | kmem_cache_free(ecryptfs_header_cache_2, page_virt); |
| 319 | goto out; | 306 | goto out; |
| @@ -322,6 +309,8 @@ out_put: | |||
| 322 | mntput(lower_mnt); | 309 | mntput(lower_mnt); |
| 323 | d_drop(ecryptfs_dentry); | 310 | d_drop(ecryptfs_dentry); |
| 324 | out: | 311 | out: |
| 312 | if (put_lower) | ||
| 313 | ecryptfs_put_lower_file(ecryptfs_dentry->d_inode); | ||
| 325 | return rc; | 314 | return rc; |
| 326 | } | 315 | } |
| 327 | 316 | ||
| @@ -538,8 +527,6 @@ static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry) | |||
| 538 | dget(lower_dentry); | 527 | dget(lower_dentry); |
| 539 | rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry); | 528 | rc = vfs_rmdir(lower_dir_dentry->d_inode, lower_dentry); |
| 540 | dput(lower_dentry); | 529 | dput(lower_dentry); |
| 541 | if (!rc) | ||
| 542 | d_delete(lower_dentry); | ||
| 543 | fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode); | 530 | fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode); |
| 544 | dir->i_nlink = lower_dir_dentry->d_inode->i_nlink; | 531 | dir->i_nlink = lower_dir_dentry->d_inode->i_nlink; |
| 545 | unlock_dir(lower_dir_dentry); | 532 | unlock_dir(lower_dir_dentry); |
| @@ -610,8 +597,8 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
| 610 | fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode); | 597 | fsstack_copy_attr_all(old_dir, lower_old_dir_dentry->d_inode); |
| 611 | out_lock: | 598 | out_lock: |
| 612 | unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry); | 599 | unlock_rename(lower_old_dir_dentry, lower_new_dir_dentry); |
| 613 | dput(lower_new_dentry->d_parent); | 600 | dput(lower_new_dir_dentry); |
| 614 | dput(lower_old_dentry->d_parent); | 601 | dput(lower_old_dir_dentry); |
| 615 | dput(lower_new_dentry); | 602 | dput(lower_new_dentry); |
| 616 | dput(lower_old_dentry); | 603 | dput(lower_old_dentry); |
| 617 | return rc; | 604 | return rc; |
| @@ -759,8 +746,11 @@ static int truncate_upper(struct dentry *dentry, struct iattr *ia, | |||
| 759 | 746 | ||
| 760 | if (unlikely((ia->ia_size == i_size))) { | 747 | if (unlikely((ia->ia_size == i_size))) { |
| 761 | lower_ia->ia_valid &= ~ATTR_SIZE; | 748 | lower_ia->ia_valid &= ~ATTR_SIZE; |
| 762 | goto out; | 749 | return 0; |
| 763 | } | 750 | } |
| 751 | rc = ecryptfs_get_lower_file(dentry); | ||
| 752 | if (rc) | ||
| 753 | return rc; | ||
| 764 | crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; | 754 | crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; |
| 765 | /* Switch on growing or shrinking file */ | 755 | /* Switch on growing or shrinking file */ |
| 766 | if (ia->ia_size > i_size) { | 756 | if (ia->ia_size > i_size) { |
| @@ -838,6 +828,7 @@ static int truncate_upper(struct dentry *dentry, struct iattr *ia, | |||
| 838 | lower_ia->ia_valid &= ~ATTR_SIZE; | 828 | lower_ia->ia_valid &= ~ATTR_SIZE; |
| 839 | } | 829 | } |
| 840 | out: | 830 | out: |
| 831 | ecryptfs_put_lower_file(inode); | ||
| 841 | return rc; | 832 | return rc; |
| 842 | } | 833 | } |
| 843 | 834 | ||
| @@ -913,7 +904,13 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia) | |||
| 913 | 904 | ||
| 914 | mount_crypt_stat = &ecryptfs_superblock_to_private( | 905 | mount_crypt_stat = &ecryptfs_superblock_to_private( |
| 915 | dentry->d_sb)->mount_crypt_stat; | 906 | dentry->d_sb)->mount_crypt_stat; |
| 907 | rc = ecryptfs_get_lower_file(dentry); | ||
| 908 | if (rc) { | ||
| 909 | mutex_unlock(&crypt_stat->cs_mutex); | ||
| 910 | goto out; | ||
| 911 | } | ||
| 916 | rc = ecryptfs_read_metadata(dentry); | 912 | rc = ecryptfs_read_metadata(dentry); |
| 913 | ecryptfs_put_lower_file(inode); | ||
| 917 | if (rc) { | 914 | if (rc) { |
| 918 | if (!(mount_crypt_stat->flags | 915 | if (!(mount_crypt_stat->flags |
| 919 | & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) { | 916 | & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) { |
| @@ -927,10 +924,17 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia) | |||
| 927 | goto out; | 924 | goto out; |
| 928 | } | 925 | } |
| 929 | rc = 0; | 926 | rc = 0; |
| 930 | crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); | 927 | crypt_stat->flags &= ~(ECRYPTFS_I_SIZE_INITIALIZED |
| 928 | | ECRYPTFS_ENCRYPTED); | ||
| 931 | } | 929 | } |
| 932 | } | 930 | } |
| 933 | mutex_unlock(&crypt_stat->cs_mutex); | 931 | mutex_unlock(&crypt_stat->cs_mutex); |
| 932 | if (S_ISREG(inode->i_mode)) { | ||
| 933 | rc = filemap_write_and_wait(inode->i_mapping); | ||
| 934 | if (rc) | ||
| 935 | goto out; | ||
| 936 | fsstack_copy_attr_all(inode, lower_inode); | ||
| 937 | } | ||
| 934 | memcpy(&lower_ia, ia, sizeof(lower_ia)); | 938 | memcpy(&lower_ia, ia, sizeof(lower_ia)); |
| 935 | if (ia->ia_valid & ATTR_FILE) | 939 | if (ia->ia_valid & ATTR_FILE) |
| 936 | lower_ia.ia_file = ecryptfs_file_to_lower(ia->ia_file); | 940 | lower_ia.ia_file = ecryptfs_file_to_lower(ia->ia_file); |
