inode.c (9e9fd65d1fa51d919d54d731be0e66492b5b6c5a) | inode.c (821f7494a77627fb1ab539591c57b22cdca702d6) |
---|---|
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> --- 129 unchanged lines hidden (view full) --- 138 139 if (IS_ERR(inode)) 140 return PTR_ERR(inode); 141 d_instantiate(dentry, inode); 142 143 return 0; 144} 145 | 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> --- 129 unchanged lines hidden (view full) --- 138 139 if (IS_ERR(inode)) 140 return PTR_ERR(inode); 141 d_instantiate(dentry, inode); 142 143 return 0; 144} 145 |
146static int ecryptfs_do_unlink(struct inode *dir, struct dentry *dentry, 147 struct inode *inode) 148{ 149 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); 150 struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir); 151 struct dentry *lower_dir_dentry; 152 int rc; 153 154 dget(lower_dentry); 155 lower_dir_dentry = lock_parent(lower_dentry); 156 rc = vfs_unlink(lower_dir_inode, lower_dentry); 157 if (rc) { 158 printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc); 159 goto out_unlock; 160 } 161 fsstack_copy_attr_times(dir, lower_dir_inode); 162 set_nlink(inode, ecryptfs_inode_to_lower(inode)->i_nlink); 163 inode->i_ctime = dir->i_ctime; 164 d_drop(dentry); 165out_unlock: 166 unlock_dir(lower_dir_dentry); 167 dput(lower_dentry); 168 return rc; 169} 170 |
|
146/** 147 * ecryptfs_do_create 148 * @directory_inode: inode of the new file's dentry's parent in ecryptfs 149 * @ecryptfs_dentry: New file's dentry in ecryptfs 150 * @mode: The mode of the new file 151 * @nd: nameidata of ecryptfs' parent's dentry & vfsmount 152 * 153 * Creates the underlying file and the eCryptfs inode which will link to --- 23 unchanged lines hidden (view full) --- 177 if (rc) { 178 printk(KERN_ERR "%s: Failure to create dentry in lower fs; " 179 "rc = [%d]\n", __func__, rc); 180 inode = ERR_PTR(rc); 181 goto out_lock; 182 } 183 inode = __ecryptfs_get_inode(lower_dentry->d_inode, 184 directory_inode->i_sb); | 171/** 172 * ecryptfs_do_create 173 * @directory_inode: inode of the new file's dentry's parent in ecryptfs 174 * @ecryptfs_dentry: New file's dentry in ecryptfs 175 * @mode: The mode of the new file 176 * @nd: nameidata of ecryptfs' parent's dentry & vfsmount 177 * 178 * Creates the underlying file and the eCryptfs inode which will link to --- 23 unchanged lines hidden (view full) --- 202 if (rc) { 203 printk(KERN_ERR "%s: Failure to create dentry in lower fs; " 204 "rc = [%d]\n", __func__, rc); 205 inode = ERR_PTR(rc); 206 goto out_lock; 207 } 208 inode = __ecryptfs_get_inode(lower_dentry->d_inode, 209 directory_inode->i_sb); |
185 if (IS_ERR(inode)) | 210 if (IS_ERR(inode)) { 211 vfs_unlink(lower_dir_dentry->d_inode, lower_dentry); |
186 goto out_lock; | 212 goto out_lock; |
213 } |
|
187 fsstack_copy_attr_times(directory_inode, lower_dir_dentry->d_inode); 188 fsstack_copy_inode_size(directory_inode, lower_dir_dentry->d_inode); 189out_lock: 190 unlock_dir(lower_dir_dentry); 191out: 192 return inode; 193} 194 195/** 196 * ecryptfs_initialize_file 197 * 198 * Cause the file to be changed from a basic empty file to an ecryptfs 199 * file with a header and first data page. 200 * 201 * Returns zero on success 202 */ | 214 fsstack_copy_attr_times(directory_inode, lower_dir_dentry->d_inode); 215 fsstack_copy_inode_size(directory_inode, lower_dir_dentry->d_inode); 216out_lock: 217 unlock_dir(lower_dir_dentry); 218out: 219 return inode; 220} 221 222/** 223 * ecryptfs_initialize_file 224 * 225 * Cause the file to be changed from a basic empty file to an ecryptfs 226 * file with a header and first data page. 227 * 228 * Returns zero on success 229 */ |
203static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry, 204 struct inode *ecryptfs_inode) | 230int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry, 231 struct inode *ecryptfs_inode) |
205{ 206 struct ecryptfs_crypt_stat *crypt_stat = 207 &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat; 208 int rc = 0; 209 210 if (S_ISDIR(ecryptfs_inode->i_mode)) { 211 ecryptfs_printk(KERN_DEBUG, "This is a directory\n"); 212 crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); --- 47 unchanged lines hidden (view full) --- 260 "lower filesystem\n"); 261 rc = PTR_ERR(ecryptfs_inode); 262 goto out; 263 } 264 /* At this point, a file exists on "disk"; we need to make sure 265 * that this on disk file is prepared to be an ecryptfs file */ 266 rc = ecryptfs_initialize_file(ecryptfs_dentry, ecryptfs_inode); 267 if (rc) { | 232{ 233 struct ecryptfs_crypt_stat *crypt_stat = 234 &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat; 235 int rc = 0; 236 237 if (S_ISDIR(ecryptfs_inode->i_mode)) { 238 ecryptfs_printk(KERN_DEBUG, "This is a directory\n"); 239 crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); --- 47 unchanged lines hidden (view full) --- 287 "lower filesystem\n"); 288 rc = PTR_ERR(ecryptfs_inode); 289 goto out; 290 } 291 /* At this point, a file exists on "disk"; we need to make sure 292 * that this on disk file is prepared to be an ecryptfs file */ 293 rc = ecryptfs_initialize_file(ecryptfs_dentry, ecryptfs_inode); 294 if (rc) { |
268 drop_nlink(ecryptfs_inode); | 295 ecryptfs_do_unlink(directory_inode, ecryptfs_dentry, 296 ecryptfs_inode); 297 make_bad_inode(ecryptfs_inode); |
269 unlock_new_inode(ecryptfs_inode); 270 iput(ecryptfs_inode); 271 goto out; 272 } 273 d_instantiate(ecryptfs_dentry, ecryptfs_inode); 274 unlock_new_inode(ecryptfs_inode); 275out: 276 return rc; --- 195 unchanged lines hidden (view full) --- 472 unlock_dir(lower_dir_dentry); 473 dput(lower_new_dentry); 474 dput(lower_old_dentry); 475 return rc; 476} 477 478static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry) 479{ | 298 unlock_new_inode(ecryptfs_inode); 299 iput(ecryptfs_inode); 300 goto out; 301 } 302 d_instantiate(ecryptfs_dentry, ecryptfs_inode); 303 unlock_new_inode(ecryptfs_inode); 304out: 305 return rc; --- 195 unchanged lines hidden (view full) --- 501 unlock_dir(lower_dir_dentry); 502 dput(lower_new_dentry); 503 dput(lower_old_dentry); 504 return rc; 505} 506 507static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry) 508{ |
480 int rc = 0; 481 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); 482 struct inode *lower_dir_inode = ecryptfs_inode_to_lower(dir); 483 struct dentry *lower_dir_dentry; 484 485 dget(lower_dentry); 486 lower_dir_dentry = lock_parent(lower_dentry); 487 rc = vfs_unlink(lower_dir_inode, lower_dentry); 488 if (rc) { 489 printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc); 490 goto out_unlock; 491 } 492 fsstack_copy_attr_times(dir, lower_dir_inode); 493 set_nlink(dentry->d_inode, 494 ecryptfs_inode_to_lower(dentry->d_inode)->i_nlink); 495 dentry->d_inode->i_ctime = dir->i_ctime; 496 d_drop(dentry); 497out_unlock: 498 unlock_dir(lower_dir_dentry); 499 dput(lower_dentry); 500 return rc; | 509 return ecryptfs_do_unlink(dir, dentry, dentry->d_inode); |
501} 502 503static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry, 504 const char *symname) 505{ 506 int rc; 507 struct dentry *lower_dentry; 508 struct dentry *lower_dir_dentry; --- 458 unchanged lines hidden (view full) --- 967 if (rc) 968 goto out; 969 if (ia->ia_valid & ATTR_SIZE) { 970 rc = ecryptfs_inode_newsize_ok(inode, ia->ia_size); 971 if (rc) 972 goto out; 973 } 974 | 510} 511 512static int ecryptfs_symlink(struct inode *dir, struct dentry *dentry, 513 const char *symname) 514{ 515 int rc; 516 struct dentry *lower_dentry; 517 struct dentry *lower_dir_dentry; --- 458 unchanged lines hidden (view full) --- 976 if (rc) 977 goto out; 978 if (ia->ia_valid & ATTR_SIZE) { 979 rc = ecryptfs_inode_newsize_ok(inode, ia->ia_size); 980 if (rc) 981 goto out; 982 } 983 |
975 if (S_ISREG(inode->i_mode)) { 976 rc = filemap_write_and_wait(inode->i_mapping); 977 if (rc) 978 goto out; 979 fsstack_copy_attr_all(inode, lower_inode); 980 } | |
981 memcpy(&lower_ia, ia, sizeof(lower_ia)); 982 if (ia->ia_valid & ATTR_FILE) 983 lower_ia.ia_file = ecryptfs_file_to_lower(ia->ia_file); 984 if (ia->ia_valid & ATTR_SIZE) { 985 rc = truncate_upper(dentry, ia, &lower_ia); 986 if (rc < 0) 987 goto out; 988 } --- 176 unchanged lines hidden --- | 984 memcpy(&lower_ia, ia, sizeof(lower_ia)); 985 if (ia->ia_valid & ATTR_FILE) 986 lower_ia.ia_file = ecryptfs_file_to_lower(ia->ia_file); 987 if (ia->ia_valid & ATTR_SIZE) { 988 rc = truncate_upper(dentry, ia, &lower_ia); 989 if (rc < 0) 990 goto out; 991 } --- 176 unchanged lines hidden --- |