@@ -307,105 +307,90 @@ ecryptfs_create(struct inode *directory_inode, struct dentry *ecryptfs_dentry,
307
307
return rc ;
308
308
}
309
309
310
+ static int ecryptfs_i_size_read (struct dentry * dentry , struct inode * inode )
311
+ {
312
+ struct ecryptfs_crypt_stat * crypt_stat ;
313
+ int rc ;
314
+
315
+ rc = ecryptfs_get_lower_file (dentry , inode );
316
+ if (rc ) {
317
+ printk (KERN_ERR "%s: Error attempting to initialize "
318
+ "the lower file for the dentry with name "
319
+ "[%s]; rc = [%d]\n" , __func__ ,
320
+ dentry -> d_name .name , rc );
321
+ return rc ;
322
+ }
323
+
324
+ crypt_stat = & ecryptfs_inode_to_private (inode )-> crypt_stat ;
325
+ /* TODO: lock for crypt_stat comparison */
326
+ if (!(crypt_stat -> flags & ECRYPTFS_POLICY_APPLIED ))
327
+ ecryptfs_set_default_sizes (crypt_stat );
328
+
329
+ rc = ecryptfs_read_and_validate_header_region (inode );
330
+ ecryptfs_put_lower_file (inode );
331
+ if (rc ) {
332
+ rc = ecryptfs_read_and_validate_xattr_region (dentry , inode );
333
+ if (!rc )
334
+ crypt_stat -> flags |= ECRYPTFS_METADATA_IN_XATTR ;
335
+ }
336
+
337
+ /* Must return 0 to allow non-eCryptfs files to be looked up, too */
338
+ return 0 ;
339
+ }
340
+
310
341
/**
311
342
* ecryptfs_lookup_interpose - Dentry interposition for a lookup
312
343
*/
313
- static int ecryptfs_lookup_interpose (struct dentry * ecryptfs_dentry ,
344
+ static int ecryptfs_lookup_interpose (struct dentry * dentry ,
314
345
struct dentry * lower_dentry ,
315
- struct inode * ecryptfs_dir_inode )
346
+ struct inode * dir_inode )
316
347
{
317
- struct dentry * lower_dir_dentry ;
348
+ struct inode * inode , * lower_inode = lower_dentry -> d_inode ;
349
+ struct ecryptfs_dentry_info * dentry_info ;
318
350
struct vfsmount * lower_mnt ;
319
- struct inode * inode , * lower_inode ;
320
- struct ecryptfs_crypt_stat * crypt_stat ;
321
- char * page_virt = NULL ;
322
- int put_lower = 0 , rc = 0 ;
323
-
324
- lower_dir_dentry = lower_dentry -> d_parent ;
325
- lower_mnt = mntget (ecryptfs_dentry_to_lower_mnt (
326
- ecryptfs_dentry -> d_parent ));
327
- lower_inode = lower_dentry -> d_inode ;
328
- fsstack_copy_attr_atime (ecryptfs_dir_inode , lower_dir_dentry -> d_inode );
351
+ int rc = 0 ;
352
+
353
+ lower_mnt = mntget (ecryptfs_dentry_to_lower_mnt (dentry -> d_parent ));
354
+ fsstack_copy_attr_atime (dir_inode , lower_dentry -> d_parent -> d_inode );
329
355
BUG_ON (!lower_dentry -> d_count );
330
- ecryptfs_set_dentry_private (ecryptfs_dentry ,
331
- kmem_cache_alloc (ecryptfs_dentry_info_cache ,
332
- GFP_KERNEL ));
333
- if (!ecryptfs_dentry_to_private (ecryptfs_dentry )) {
334
- rc = - ENOMEM ;
356
+
357
+ dentry_info = kmem_cache_alloc (ecryptfs_dentry_info_cache , GFP_KERNEL );
358
+ ecryptfs_set_dentry_private (dentry , dentry_info );
359
+ if (!dentry_info ) {
335
360
printk (KERN_ERR "%s: Out of memory whilst attempting "
336
361
"to allocate ecryptfs_dentry_info struct\n" ,
337
362
__func__ );
338
- goto out_put ;
363
+ dput (lower_dentry );
364
+ mntput (lower_mnt );
365
+ d_drop (dentry );
366
+ return - ENOMEM ;
339
367
}
340
- ecryptfs_set_dentry_lower (ecryptfs_dentry , lower_dentry );
341
- ecryptfs_set_dentry_lower_mnt (ecryptfs_dentry , lower_mnt );
368
+ ecryptfs_set_dentry_lower (dentry , lower_dentry );
369
+ ecryptfs_set_dentry_lower_mnt (dentry , lower_mnt );
370
+
342
371
if (!lower_dentry -> d_inode ) {
343
372
/* We want to add because we couldn't find in lower */
344
- d_add (ecryptfs_dentry , NULL );
345
- goto out ;
373
+ d_add (dentry , NULL );
374
+ return 0 ;
346
375
}
347
- inode = __ecryptfs_get_inode (lower_inode , ecryptfs_dir_inode -> i_sb );
376
+ inode = __ecryptfs_get_inode (lower_inode , dir_inode -> i_sb );
348
377
if (IS_ERR (inode )) {
349
- rc = PTR_ERR (inode );
350
- printk (KERN_ERR "%s: Error interposing; rc = [%d]\n" ,
351
- __func__ , rc );
352
- goto out ;
353
- }
354
- if (!S_ISREG (inode -> i_mode )) {
355
- if (inode -> i_state & I_NEW )
356
- unlock_new_inode (inode );
357
- d_add (ecryptfs_dentry , inode );
358
- goto out ;
359
- }
360
- /* Released in this function */
361
- page_virt = kmem_cache_zalloc (ecryptfs_header_cache_2 , GFP_USER );
362
- if (!page_virt ) {
363
- printk (KERN_ERR "%s: Cannot kmem_cache_zalloc() a page\n" ,
364
- __func__ );
365
- rc = - ENOMEM ;
366
- make_bad_inode (inode );
367
- goto out ;
368
- }
369
- rc = ecryptfs_get_lower_file (ecryptfs_dentry , inode );
370
- if (rc ) {
371
- printk (KERN_ERR "%s: Error attempting to initialize "
372
- "the lower file for the dentry with name "
373
- "[%s]; rc = [%d]\n" , __func__ ,
374
- ecryptfs_dentry -> d_name .name , rc );
375
- make_bad_inode (inode );
376
- goto out_free_kmem ;
378
+ printk (KERN_ERR "%s: Error interposing; rc = [%ld]\n" ,
379
+ __func__ , PTR_ERR (inode ));
380
+ return PTR_ERR (inode );
377
381
}
378
- put_lower = 1 ;
379
- crypt_stat = & ecryptfs_inode_to_private (inode )-> crypt_stat ;
380
- /* TODO: lock for crypt_stat comparison */
381
- if (!(crypt_stat -> flags & ECRYPTFS_POLICY_APPLIED ))
382
- ecryptfs_set_default_sizes (crypt_stat );
383
- rc = ecryptfs_read_and_validate_header_region (page_virt , inode );
384
- if (rc ) {
385
- memset (page_virt , 0 , PAGE_CACHE_SIZE );
386
- rc = ecryptfs_read_and_validate_xattr_region (page_virt ,
387
- inode );
382
+ if (S_ISREG (inode -> i_mode )) {
383
+ rc = ecryptfs_i_size_read (dentry , inode );
388
384
if (rc ) {
389
- rc = 0 ;
390
- goto unlock_inode ;
385
+ make_bad_inode ( inode ) ;
386
+ return rc ;
391
387
}
392
- crypt_stat -> flags |= ECRYPTFS_METADATA_IN_XATTR ;
393
388
}
394
- ecryptfs_i_size_init (page_virt , inode );
395
- unlock_inode :
389
+
396
390
if (inode -> i_state & I_NEW )
397
391
unlock_new_inode (inode );
398
- d_add (ecryptfs_dentry , inode );
399
- out_free_kmem :
400
- kmem_cache_free (ecryptfs_header_cache_2 , page_virt );
401
- goto out ;
402
- out_put :
403
- dput (lower_dentry );
404
- mntput (lower_mnt );
405
- d_drop (ecryptfs_dentry );
406
- out :
407
- if (put_lower )
408
- ecryptfs_put_lower_file (inode );
392
+ d_add (dentry , inode );
393
+
409
394
return rc ;
410
395
}
411
396
0 commit comments