inode.c (513b046c96cc2fbce730a3474f6f7ff0c4fdd05c) inode.c (7ff1d74f5670329ac4b5959a675f8698ba95be20)
1/**
2 * eCryptfs: Linux filesystem encryption layer
3 *
4 * Copyright (C) 1997-2004 Erez Zadok
5 * Copyright (C) 2001-2004 Stony Brook University
6 * Copyright (C) 2004-2006 International Business Machines Corp.
7 * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
8 * Michael C. Thompsion <mcthomps@us.ibm.com>

--- 217 unchanged lines hidden (view full) ---

226 * Returns zero on success
227 */
228static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry)
229{
230 int rc = 0;
231 int lower_flags;
232 struct ecryptfs_crypt_stat *crypt_stat;
233 struct dentry *lower_dentry;
1/**
2 * eCryptfs: Linux filesystem encryption layer
3 *
4 * Copyright (C) 1997-2004 Erez Zadok
5 * Copyright (C) 2001-2004 Stony Brook University
6 * Copyright (C) 2004-2006 International Business Machines Corp.
7 * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
8 * Michael C. Thompsion <mcthomps@us.ibm.com>

--- 217 unchanged lines hidden (view full) ---

226 * Returns zero on success
227 */
228static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry)
229{
230 int rc = 0;
231 int lower_flags;
232 struct ecryptfs_crypt_stat *crypt_stat;
233 struct dentry *lower_dentry;
234 struct dentry *tlower_dentry = NULL;
235 struct file *lower_file;
236 struct inode *inode, *lower_inode;
237 struct vfsmount *lower_mnt;
238
239 lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
240 ecryptfs_printk(KERN_DEBUG, "lower_dentry->d_name.name = [%s]\n",
241 lower_dentry->d_name.name);
242 inode = ecryptfs_dentry->d_inode;
243 crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
234 struct file *lower_file;
235 struct inode *inode, *lower_inode;
236 struct vfsmount *lower_mnt;
237
238 lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry);
239 ecryptfs_printk(KERN_DEBUG, "lower_dentry->d_name.name = [%s]\n",
240 lower_dentry->d_name.name);
241 inode = ecryptfs_dentry->d_inode;
242 crypt_stat = &ecryptfs_inode_to_private(inode)->crypt_stat;
244 tlower_dentry = dget(lower_dentry);
245 if (!tlower_dentry) {
246 rc = -ENOMEM;
247 ecryptfs_printk(KERN_ERR, "Error dget'ing lower_dentry\n");
248 goto out;
249 }
250 lower_flags = ((O_CREAT | O_WRONLY | O_TRUNC) & O_ACCMODE) | O_RDWR;
251#if BITS_PER_LONG != 32
252 lower_flags |= O_LARGEFILE;
253#endif
254 lower_mnt = ecryptfs_dentry_to_lower_mnt(ecryptfs_dentry);
243 lower_flags = ((O_CREAT | O_WRONLY | O_TRUNC) & O_ACCMODE) | O_RDWR;
244#if BITS_PER_LONG != 32
245 lower_flags |= O_LARGEFILE;
246#endif
247 lower_mnt = ecryptfs_dentry_to_lower_mnt(ecryptfs_dentry);
255 mntget(lower_mnt);
256 /* Corresponding fput() at end of this function */
248 /* Corresponding fput() at end of this function */
257 lower_file = dentry_open(tlower_dentry, lower_mnt, lower_flags);
258 if (IS_ERR(lower_file)) {
259 rc = PTR_ERR(lower_file);
249 if ((rc = ecryptfs_open_lower_file(&lower_file, lower_dentry, lower_mnt,
250 lower_flags))) {
260 ecryptfs_printk(KERN_ERR,
261 "Error opening dentry; rc = [%i]\n", rc);
262 goto out;
263 }
251 ecryptfs_printk(KERN_ERR,
252 "Error opening dentry; rc = [%i]\n", rc);
253 goto out;
254 }
264 /* fput(lower_file) should handle the puts if we do this */
265 lower_file->f_dentry = tlower_dentry;
266 lower_file->f_vfsmnt = lower_mnt;
267 lower_inode = tlower_dentry->d_inode;
255 lower_inode = lower_dentry->d_inode;
268 if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) {
269 ecryptfs_printk(KERN_DEBUG, "This is a directory\n");
270 ECRYPTFS_CLEAR_FLAG(crypt_stat->flags, ECRYPTFS_ENCRYPTED);
271 goto out_fput;
272 }
273 ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_NEW_FILE);
274 ecryptfs_printk(KERN_DEBUG, "Initializing crypto context\n");
275 rc = ecryptfs_new_file_context(ecryptfs_dentry);

--- 4 unchanged lines hidden (view full) ---

280 }
281 rc = ecryptfs_write_headers(ecryptfs_dentry, lower_file);
282 if (rc) {
283 ecryptfs_printk(KERN_DEBUG, "Error writing headers\n");
284 goto out_fput;
285 }
286 rc = grow_file(ecryptfs_dentry, lower_file, inode, lower_inode);
287out_fput:
256 if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) {
257 ecryptfs_printk(KERN_DEBUG, "This is a directory\n");
258 ECRYPTFS_CLEAR_FLAG(crypt_stat->flags, ECRYPTFS_ENCRYPTED);
259 goto out_fput;
260 }
261 ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_NEW_FILE);
262 ecryptfs_printk(KERN_DEBUG, "Initializing crypto context\n");
263 rc = ecryptfs_new_file_context(ecryptfs_dentry);

--- 4 unchanged lines hidden (view full) ---

268 }
269 rc = ecryptfs_write_headers(ecryptfs_dentry, lower_file);
270 if (rc) {
271 ecryptfs_printk(KERN_DEBUG, "Error writing headers\n");
272 goto out_fput;
273 }
274 rc = grow_file(ecryptfs_dentry, lower_file, inode, lower_inode);
275out_fput:
288 fput(lower_file);
276 if ((rc = ecryptfs_close_lower_file(lower_file)))
277 printk(KERN_ERR "Error closing lower_file\n");
289out:
290 return rc;
291}
292
293/**
294 * ecryptfs_create
295 * @dir: The inode of the directory in which to create the file.
296 * @dentry: The eCryptfs dentry

--- 530 unchanged lines hidden (view full) ---

827 kmem_cache_alloc(ecryptfs_file_info_cache,
828 SLAB_KERNEL));
829 if (unlikely(!ecryptfs_file_to_private(&fake_ecryptfs_file))) {
830 rc = -ENOMEM;
831 goto out;
832 }
833 lower_dentry = ecryptfs_dentry_to_lower(dentry);
834 /* This dget & mntget is released through fput at out_fput: */
278out:
279 return rc;
280}
281
282/**
283 * ecryptfs_create
284 * @dir: The inode of the directory in which to create the file.
285 * @dentry: The eCryptfs dentry

--- 530 unchanged lines hidden (view full) ---

816 kmem_cache_alloc(ecryptfs_file_info_cache,
817 SLAB_KERNEL));
818 if (unlikely(!ecryptfs_file_to_private(&fake_ecryptfs_file))) {
819 rc = -ENOMEM;
820 goto out;
821 }
822 lower_dentry = ecryptfs_dentry_to_lower(dentry);
823 /* This dget & mntget is released through fput at out_fput: */
835 dget(lower_dentry);
836 lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
824 lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
837 mntget(lower_mnt);
838 lower_file = dentry_open(lower_dentry, lower_mnt, O_RDWR);
839 if (unlikely(IS_ERR(lower_file))) {
840 rc = PTR_ERR(lower_file);
825 if ((rc = ecryptfs_open_lower_file(&lower_file, lower_dentry, lower_mnt,
826 O_RDWR))) {
827 ecryptfs_printk(KERN_ERR,
828 "Error opening dentry; rc = [%i]\n", rc);
841 goto out_free;
842 }
843 ecryptfs_set_file_lower(&fake_ecryptfs_file, lower_file);
844 /* Switch on growing or shrinking file */
845 if (new_length > i_size) {
846 rc = ecryptfs_fill_zeros(&fake_ecryptfs_file, new_length);
847 if (rc) {
848 ecryptfs_printk(KERN_ERR,

--- 25 unchanged lines hidden (view full) ---

874 vmtruncate(lower_dentry->d_inode,
875 lower_size_after_truncate);
876 }
877 /* Update the access times */
878 lower_dentry->d_inode->i_mtime = lower_dentry->d_inode->i_ctime
879 = CURRENT_TIME;
880 mark_inode_dirty_sync(inode);
881out_fput:
829 goto out_free;
830 }
831 ecryptfs_set_file_lower(&fake_ecryptfs_file, lower_file);
832 /* Switch on growing or shrinking file */
833 if (new_length > i_size) {
834 rc = ecryptfs_fill_zeros(&fake_ecryptfs_file, new_length);
835 if (rc) {
836 ecryptfs_printk(KERN_ERR,

--- 25 unchanged lines hidden (view full) ---

862 vmtruncate(lower_dentry->d_inode,
863 lower_size_after_truncate);
864 }
865 /* Update the access times */
866 lower_dentry->d_inode->i_mtime = lower_dentry->d_inode->i_ctime
867 = CURRENT_TIME;
868 mark_inode_dirty_sync(inode);
869out_fput:
882 fput(lower_file);
870 if ((rc = ecryptfs_close_lower_file(lower_file)))
871 printk(KERN_ERR "Error closing lower_file\n");
883out_free:
884 if (ecryptfs_file_to_private(&fake_ecryptfs_file))
885 kmem_cache_free(ecryptfs_file_info_cache,
886 ecryptfs_file_to_private(&fake_ecryptfs_file));
887out:
888 return rc;
889}
890

--- 189 unchanged lines hidden ---
872out_free:
873 if (ecryptfs_file_to_private(&fake_ecryptfs_file))
874 kmem_cache_free(ecryptfs_file_info_cache,
875 ecryptfs_file_to_private(&fake_ecryptfs_file));
876out:
877 return rc;
878}
879

--- 189 unchanged lines hidden ---