inode.c (dd55c89852481a0708c3fd4b48f3081f4280d9d3) inode.c (332ab16f830f59e7621ae8eb2c353dc135a316f6)
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-2007 International Business Machines Corp.
7 * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
8 * Michael C. Thompsion <mcthomps@us.ibm.com>

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

163 }
164 ecryptfs_printk(KERN_DEBUG, "Initializing crypto context\n");
165 rc = ecryptfs_new_file_context(ecryptfs_dentry);
166 if (rc) {
167 ecryptfs_printk(KERN_ERR, "Error creating new file "
168 "context; rc = [%d]\n", rc);
169 goto out;
170 }
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-2007 International Business Machines Corp.
7 * Author(s): Michael A. Halcrow <mahalcro@us.ibm.com>
8 * Michael C. Thompsion <mcthomps@us.ibm.com>

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

163 }
164 ecryptfs_printk(KERN_DEBUG, "Initializing crypto context\n");
165 rc = ecryptfs_new_file_context(ecryptfs_dentry);
166 if (rc) {
167 ecryptfs_printk(KERN_ERR, "Error creating new file "
168 "context; rc = [%d]\n", rc);
169 goto out;
170 }
171 rc = ecryptfs_init_persistent_file(ecryptfs_dentry);
171 rc = ecryptfs_get_lower_file(ecryptfs_dentry);
172 if (rc) {
173 printk(KERN_ERR "%s: Error attempting to initialize "
172 if (rc) {
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__,
176 ecryptfs_dentry->d_name.name, rc);
177 goto out;
178 }
179 rc = ecryptfs_write_metadata(ecryptfs_dentry);
175 "[%s]; rc = [%d]\n", __func__,
176 ecryptfs_dentry->d_name.name, rc);
177 goto out;
178 }
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;
183 }
182 ecryptfs_put_lower_file(ecryptfs_dentry->d_inode);
184out:
185 return rc;
186}
187
188/**
189 * ecryptfs_create
190 * @dir: The inode of the directory in which to create the file.
191 * @dentry: The eCryptfs dentry

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

225{
226 struct dentry *lower_dir_dentry;
227 struct vfsmount *lower_mnt;
228 struct inode *lower_inode;
229 struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
230 struct ecryptfs_crypt_stat *crypt_stat;
231 char *page_virt = NULL;
232 u64 file_size;
183out:
184 return rc;
185}
186
187/**
188 * ecryptfs_create
189 * @dir: The inode of the directory in which to create the file.
190 * @dentry: The eCryptfs dentry

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

224{
225 struct dentry *lower_dir_dentry;
226 struct vfsmount *lower_mnt;
227 struct inode *lower_inode;
228 struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
229 struct ecryptfs_crypt_stat *crypt_stat;
230 char *page_virt = NULL;
231 u64 file_size;
233 int rc = 0;
232 int put_lower = 0, rc = 0;
234
235 lower_dir_dentry = lower_dentry->d_parent;
236 lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(
237 ecryptfs_dentry->d_parent));
238 lower_inode = lower_dentry->d_inode;
239 fsstack_copy_attr_atime(ecryptfs_dir_inode, lower_dir_dentry->d_inode);
240 BUG_ON(!lower_dentry->d_count);
241 ecryptfs_set_dentry_private(ecryptfs_dentry,

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

272 /* Released in this function */
273 page_virt = kmem_cache_zalloc(ecryptfs_header_cache_2, GFP_USER);
274 if (!page_virt) {
275 printk(KERN_ERR "%s: Cannot kmem_cache_zalloc() a page\n",
276 __func__);
277 rc = -ENOMEM;
278 goto out;
279 }
233
234 lower_dir_dentry = lower_dentry->d_parent;
235 lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(
236 ecryptfs_dentry->d_parent));
237 lower_inode = lower_dentry->d_inode;
238 fsstack_copy_attr_atime(ecryptfs_dir_inode, lower_dir_dentry->d_inode);
239 BUG_ON(!lower_dentry->d_count);
240 ecryptfs_set_dentry_private(ecryptfs_dentry,

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

271 /* Released in this function */
272 page_virt = kmem_cache_zalloc(ecryptfs_header_cache_2, GFP_USER);
273 if (!page_virt) {
274 printk(KERN_ERR "%s: Cannot kmem_cache_zalloc() a page\n",
275 __func__);
276 rc = -ENOMEM;
277 goto out;
278 }
280 rc = ecryptfs_init_persistent_file(ecryptfs_dentry);
279 rc = ecryptfs_get_lower_file(ecryptfs_dentry);
281 if (rc) {
282 printk(KERN_ERR "%s: Error attempting to initialize "
280 if (rc) {
281 printk(KERN_ERR "%s: Error attempting to initialize "
283 "the persistent file for the dentry with name "
282 "the lower file for the dentry with name "
284 "[%s]; rc = [%d]\n", __func__,
285 ecryptfs_dentry->d_name.name, rc);
286 goto out_free_kmem;
287 }
283 "[%s]; rc = [%d]\n", __func__,
284 ecryptfs_dentry->d_name.name, rc);
285 goto out_free_kmem;
286 }
287 put_lower = 1;
288 crypt_stat = &ecryptfs_inode_to_private(
289 ecryptfs_dentry->d_inode)->crypt_stat;
290 /* TODO: lock for crypt_stat comparison */
291 if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED))
292 ecryptfs_set_default_sizes(crypt_stat);
293 rc = ecryptfs_read_and_validate_header_region(page_virt,
294 ecryptfs_dentry->d_inode);
295 if (rc) {

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

317out_free_kmem:
318 kmem_cache_free(ecryptfs_header_cache_2, page_virt);
319 goto out;
320out_put:
321 dput(lower_dentry);
322 mntput(lower_mnt);
323 d_drop(ecryptfs_dentry);
324out:
288 crypt_stat = &ecryptfs_inode_to_private(
289 ecryptfs_dentry->d_inode)->crypt_stat;
290 /* TODO: lock for crypt_stat comparison */
291 if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED))
292 ecryptfs_set_default_sizes(crypt_stat);
293 rc = ecryptfs_read_and_validate_header_region(page_virt,
294 ecryptfs_dentry->d_inode);
295 if (rc) {

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

317out_free_kmem:
318 kmem_cache_free(ecryptfs_header_cache_2, page_virt);
319 goto out;
320out_put:
321 dput(lower_dentry);
322 mntput(lower_mnt);
323 d_drop(ecryptfs_dentry);
324out:
325 if (put_lower)
326 ecryptfs_put_lower_file(ecryptfs_dentry->d_inode);
325 return rc;
326}
327
328/**
329 * ecryptfs_lookup
330 * @ecryptfs_dir_inode: The eCryptfs directory inode
331 * @ecryptfs_dentry: The eCryptfs dentry that we are looking up
332 * @ecryptfs_nd: nameidata; may be NULL

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

752 struct inode *inode = dentry->d_inode;
753 struct ecryptfs_crypt_stat *crypt_stat;
754 loff_t i_size = i_size_read(inode);
755 loff_t lower_size_before_truncate;
756 loff_t lower_size_after_truncate;
757
758 if (unlikely((ia->ia_size == i_size))) {
759 lower_ia->ia_valid &= ~ATTR_SIZE;
327 return rc;
328}
329
330/**
331 * ecryptfs_lookup
332 * @ecryptfs_dir_inode: The eCryptfs directory inode
333 * @ecryptfs_dentry: The eCryptfs dentry that we are looking up
334 * @ecryptfs_nd: nameidata; may be NULL

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

754 struct inode *inode = dentry->d_inode;
755 struct ecryptfs_crypt_stat *crypt_stat;
756 loff_t i_size = i_size_read(inode);
757 loff_t lower_size_before_truncate;
758 loff_t lower_size_after_truncate;
759
760 if (unlikely((ia->ia_size == i_size))) {
761 lower_ia->ia_valid &= ~ATTR_SIZE;
760 goto out;
762 return 0;
761 }
763 }
764 rc = ecryptfs_get_lower_file(dentry);
765 if (rc)
766 return rc;
762 crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat;
763 /* Switch on growing or shrinking file */
764 if (ia->ia_size > i_size) {
765 char zero[] = { 0x00 };
766
767 lower_ia->ia_valid &= ~ATTR_SIZE;
768 /* Write a single 0 at the last position of the file;
769 * this triggers code that will fill in 0's throughout

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

831 upper_size_to_lower_size(crypt_stat, ia->ia_size);
832 if (lower_size_after_truncate < lower_size_before_truncate) {
833 lower_ia->ia_size = lower_size_after_truncate;
834 lower_ia->ia_valid |= ATTR_SIZE;
835 } else
836 lower_ia->ia_valid &= ~ATTR_SIZE;
837 }
838out:
767 crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat;
768 /* Switch on growing or shrinking file */
769 if (ia->ia_size > i_size) {
770 char zero[] = { 0x00 };
771
772 lower_ia->ia_valid &= ~ATTR_SIZE;
773 /* Write a single 0 at the last position of the file;
774 * this triggers code that will fill in 0's throughout

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

836 upper_size_to_lower_size(crypt_stat, ia->ia_size);
837 if (lower_size_after_truncate < lower_size_before_truncate) {
838 lower_ia->ia_size = lower_size_after_truncate;
839 lower_ia->ia_valid |= ATTR_SIZE;
840 } else
841 lower_ia->ia_valid &= ~ATTR_SIZE;
842 }
843out:
844 ecryptfs_put_lower_file(inode);
839 return rc;
840}
841
842/**
843 * ecryptfs_truncate
844 * @dentry: The ecryptfs layer dentry
845 * @new_length: The length to expand the file to
846 *

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

906 crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
907 else if (S_ISREG(dentry->d_inode->i_mode)
908 && (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)
909 || !(crypt_stat->flags & ECRYPTFS_KEY_VALID))) {
910 struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
911
912 mount_crypt_stat = &ecryptfs_superblock_to_private(
913 dentry->d_sb)->mount_crypt_stat;
845 return rc;
846}
847
848/**
849 * ecryptfs_truncate
850 * @dentry: The ecryptfs layer dentry
851 * @new_length: The length to expand the file to
852 *

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

912 crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
913 else if (S_ISREG(dentry->d_inode->i_mode)
914 && (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)
915 || !(crypt_stat->flags & ECRYPTFS_KEY_VALID))) {
916 struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
917
918 mount_crypt_stat = &ecryptfs_superblock_to_private(
919 dentry->d_sb)->mount_crypt_stat;
920 rc = ecryptfs_get_lower_file(dentry);
921 if (rc) {
922 mutex_unlock(&crypt_stat->cs_mutex);
923 goto out;
924 }
914 rc = ecryptfs_read_metadata(dentry);
925 rc = ecryptfs_read_metadata(dentry);
926 ecryptfs_put_lower_file(inode);
915 if (rc) {
916 if (!(mount_crypt_stat->flags
917 & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) {
918 rc = -EIO;
919 printk(KERN_WARNING "Either the lower file "
920 "is not in a valid eCryptfs format, "
921 "or the key could not be retrieved. "
922 "Plaintext passthrough mode is not "

--- 206 unchanged lines hidden ---
927 if (rc) {
928 if (!(mount_crypt_stat->flags
929 & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) {
930 rc = -EIO;
931 printk(KERN_WARNING "Either the lower file "
932 "is not in a valid eCryptfs format, "
933 "or the key could not be retrieved. "
934 "Plaintext passthrough mode is not "

--- 206 unchanged lines hidden ---