@@ -168,19 +168,18 @@ static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry)
168
168
"context; rc = [%d]\n" , rc );
169
169
goto out ;
170
170
}
171
- rc = ecryptfs_init_persistent_file (ecryptfs_dentry );
171
+ rc = ecryptfs_get_lower_file (ecryptfs_dentry );
172
172
if (rc ) {
173
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
175
"[%s]; rc = [%d]\n" , __func__ ,
176
176
ecryptfs_dentry -> d_name .name , rc );
177
177
goto out ;
178
178
}
179
179
rc = ecryptfs_write_metadata (ecryptfs_dentry );
180
- if (rc ) {
180
+ if (rc )
181
181
printk (KERN_ERR "Error writing headers; rc = [%d]\n" , rc );
182
- goto out ;
183
- }
182
+ ecryptfs_put_lower_file (ecryptfs_dentry -> d_inode );
184
183
out :
185
184
return rc ;
186
185
}
@@ -226,11 +225,9 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry,
226
225
struct dentry * lower_dir_dentry ;
227
226
struct vfsmount * lower_mnt ;
228
227
struct inode * lower_inode ;
229
- struct ecryptfs_mount_crypt_stat * mount_crypt_stat ;
230
228
struct ecryptfs_crypt_stat * crypt_stat ;
231
229
char * page_virt = NULL ;
232
- u64 file_size ;
233
- int rc = 0 ;
230
+ int put_lower = 0 , rc = 0 ;
234
231
235
232
lower_dir_dentry = lower_dentry -> d_parent ;
236
233
lower_mnt = mntget (ecryptfs_dentry_to_lower_mnt (
@@ -277,14 +274,15 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry,
277
274
rc = - ENOMEM ;
278
275
goto out ;
279
276
}
280
- rc = ecryptfs_init_persistent_file (ecryptfs_dentry );
277
+ rc = ecryptfs_get_lower_file (ecryptfs_dentry );
281
278
if (rc ) {
282
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
281
"[%s]; rc = [%d]\n" , __func__ ,
285
282
ecryptfs_dentry -> d_name .name , rc );
286
283
goto out_free_kmem ;
287
284
}
285
+ put_lower = 1 ;
288
286
crypt_stat = & ecryptfs_inode_to_private (
289
287
ecryptfs_dentry -> d_inode )-> crypt_stat ;
290
288
/* TODO: lock for crypt_stat comparison */
@@ -302,18 +300,7 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry,
302
300
}
303
301
crypt_stat -> flags |= ECRYPTFS_METADATA_IN_XATTR ;
304
302
}
305
- mount_crypt_stat = & ecryptfs_superblock_to_private (
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 );
303
+ ecryptfs_i_size_init (page_virt , ecryptfs_dentry -> d_inode );
317
304
out_free_kmem :
318
305
kmem_cache_free (ecryptfs_header_cache_2 , page_virt );
319
306
goto out ;
@@ -322,6 +309,8 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry,
322
309
mntput (lower_mnt );
323
310
d_drop (ecryptfs_dentry );
324
311
out :
312
+ if (put_lower )
313
+ ecryptfs_put_lower_file (ecryptfs_dentry -> d_inode );
325
314
return rc ;
326
315
}
327
316
@@ -538,8 +527,6 @@ static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry)
538
527
dget (lower_dentry );
539
528
rc = vfs_rmdir (lower_dir_dentry -> d_inode , lower_dentry );
540
529
dput (lower_dentry );
541
- if (!rc )
542
- d_delete (lower_dentry );
543
530
fsstack_copy_attr_times (dir , lower_dir_dentry -> d_inode );
544
531
dir -> i_nlink = lower_dir_dentry -> d_inode -> i_nlink ;
545
532
unlock_dir (lower_dir_dentry );
@@ -610,8 +597,8 @@ ecryptfs_rename(struct inode *old_dir, struct dentry *old_dentry,
610
597
fsstack_copy_attr_all (old_dir , lower_old_dir_dentry -> d_inode );
611
598
out_lock :
612
599
unlock_rename (lower_old_dir_dentry , lower_new_dir_dentry );
613
- dput (lower_new_dentry -> d_parent );
614
- dput (lower_old_dentry -> d_parent );
600
+ dput (lower_new_dir_dentry );
601
+ dput (lower_old_dir_dentry );
615
602
dput (lower_new_dentry );
616
603
dput (lower_old_dentry );
617
604
return rc ;
@@ -759,8 +746,11 @@ static int truncate_upper(struct dentry *dentry, struct iattr *ia,
759
746
760
747
if (unlikely ((ia -> ia_size == i_size ))) {
761
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
754
crypt_stat = & ecryptfs_inode_to_private (dentry -> d_inode )-> crypt_stat ;
765
755
/* Switch on growing or shrinking file */
766
756
if (ia -> ia_size > i_size ) {
@@ -838,6 +828,7 @@ static int truncate_upper(struct dentry *dentry, struct iattr *ia,
838
828
lower_ia -> ia_valid &= ~ATTR_SIZE ;
839
829
}
840
830
out :
831
+ ecryptfs_put_lower_file (inode );
841
832
return rc ;
842
833
}
843
834
@@ -913,7 +904,13 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)
913
904
914
905
mount_crypt_stat = & ecryptfs_superblock_to_private (
915
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
912
rc = ecryptfs_read_metadata (dentry );
913
+ ecryptfs_put_lower_file (inode );
917
914
if (rc ) {
918
915
if (!(mount_crypt_stat -> flags
919
916
& ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED )) {
@@ -927,10 +924,17 @@ static int ecryptfs_setattr(struct dentry *dentry, struct iattr *ia)
927
924
goto out ;
928
925
}
929
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
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
938
memcpy (& lower_ia , ia , sizeof (lower_ia ));
935
939
if (ia -> ia_valid & ATTR_FILE )
936
940
lower_ia .ia_file = ecryptfs_file_to_lower (ia -> ia_file );
0 commit comments