file.c (513b046c96cc2fbce730a3474f6f7ff0c4fdd05c) | file.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 <mhalcrow@us.ibm.com> 8 * Michael C. Thompson <mcthomps@us.ibm.com> --- 184 unchanged lines hidden (view full) --- 193 file->f_pos = lower_file->f_pos; 194 if (rc >= 0) 195 ecryptfs_copy_attr_atime(inode, lower_file->f_dentry->d_inode); 196 return rc; 197} 198 199struct kmem_cache *ecryptfs_file_info_cache; 200 | 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 <mhalcrow@us.ibm.com> 8 * Michael C. Thompson <mcthomps@us.ibm.com> --- 184 unchanged lines hidden (view full) --- 193 file->f_pos = lower_file->f_pos; 194 if (rc >= 0) 195 ecryptfs_copy_attr_atime(inode, lower_file->f_dentry->d_inode); 196 return rc; 197} 198 199struct kmem_cache *ecryptfs_file_info_cache; 200 |
201int ecryptfs_open_lower_file(struct file **lower_file, 202 struct dentry *lower_dentry, 203 struct vfsmount *lower_mnt, int flags) 204{ 205 int rc = 0; 206 207 dget(lower_dentry); 208 mntget(lower_mnt); 209 *lower_file = dentry_open(lower_dentry, lower_mnt, flags); 210 if (IS_ERR(*lower_file)) { 211 printk(KERN_ERR "Error opening lower file for lower_dentry " 212 "[0x%p], lower_mnt [0x%p], and flags [0x%x]\n", 213 lower_dentry, lower_mnt, flags); 214 rc = PTR_ERR(*lower_file); 215 *lower_file = NULL; 216 goto out; 217 } 218out: 219 return rc; 220} 221 222int ecryptfs_close_lower_file(struct file *lower_file) 223{ 224 fput(lower_file); 225 return 0; 226} 227 |
|
201/** 202 * ecryptfs_open 203 * @inode: inode speciying file to open 204 * @file: Structure to return filled in 205 * 206 * Opens the file specified by inode. 207 * 208 * Returns zero on success; non-zero otherwise --- 30 unchanged lines hidden (view full) --- 239 mutex_lock(&crypt_stat->cs_mutex); 240 if (!ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_POLICY_APPLIED)) { 241 ecryptfs_printk(KERN_DEBUG, "Setting flags for stat...\n"); 242 /* Policy code enabled in future release */ 243 ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_POLICY_APPLIED); 244 ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_ENCRYPTED); 245 } 246 mutex_unlock(&crypt_stat->cs_mutex); | 228/** 229 * ecryptfs_open 230 * @inode: inode speciying file to open 231 * @file: Structure to return filled in 232 * 233 * Opens the file specified by inode. 234 * 235 * Returns zero on success; non-zero otherwise --- 30 unchanged lines hidden (view full) --- 266 mutex_lock(&crypt_stat->cs_mutex); 267 if (!ECRYPTFS_CHECK_FLAG(crypt_stat->flags, ECRYPTFS_POLICY_APPLIED)) { 268 ecryptfs_printk(KERN_DEBUG, "Setting flags for stat...\n"); 269 /* Policy code enabled in future release */ 270 ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_POLICY_APPLIED); 271 ECRYPTFS_SET_FLAG(crypt_stat->flags, ECRYPTFS_ENCRYPTED); 272 } 273 mutex_unlock(&crypt_stat->cs_mutex); |
247 /* This mntget & dget is undone via fput when the file is released */ 248 dget(lower_dentry); | |
249 lower_flags = file->f_flags; 250 if ((lower_flags & O_ACCMODE) == O_WRONLY) 251 lower_flags = (lower_flags & O_ACCMODE) | O_RDWR; 252 if (file->f_flags & O_APPEND) 253 lower_flags &= ~O_APPEND; 254 lower_mnt = ecryptfs_dentry_to_lower_mnt(ecryptfs_dentry); | 274 lower_flags = file->f_flags; 275 if ((lower_flags & O_ACCMODE) == O_WRONLY) 276 lower_flags = (lower_flags & O_ACCMODE) | O_RDWR; 277 if (file->f_flags & O_APPEND) 278 lower_flags &= ~O_APPEND; 279 lower_mnt = ecryptfs_dentry_to_lower_mnt(ecryptfs_dentry); |
255 mntget(lower_mnt); | |
256 /* Corresponding fput() in ecryptfs_release() */ | 280 /* Corresponding fput() in ecryptfs_release() */ |
257 lower_file = dentry_open(lower_dentry, lower_mnt, lower_flags); 258 if (IS_ERR(lower_file)) { 259 rc = PTR_ERR(lower_file); | 281 if ((rc = ecryptfs_open_lower_file(&lower_file, lower_dentry, lower_mnt, 282 lower_flags))) { |
260 ecryptfs_printk(KERN_ERR, "Error opening lower file\n"); 261 goto out_puts; 262 } 263 ecryptfs_set_file_lower(file, lower_file); 264 /* Isn't this check the same as the one in lookup? */ 265 lower_inode = lower_dentry->d_inode; 266 if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { 267 ecryptfs_printk(KERN_DEBUG, "This is a directory\n"); --- 68 unchanged lines hidden (view full) --- 336 return rc; 337} 338 339static int ecryptfs_release(struct inode *inode, struct file *file) 340{ 341 struct file *lower_file = ecryptfs_file_to_lower(file); 342 struct ecryptfs_file_info *file_info = ecryptfs_file_to_private(file); 343 struct inode *lower_inode = ecryptfs_inode_to_lower(inode); | 283 ecryptfs_printk(KERN_ERR, "Error opening lower file\n"); 284 goto out_puts; 285 } 286 ecryptfs_set_file_lower(file, lower_file); 287 /* Isn't this check the same as the one in lookup? */ 288 lower_inode = lower_dentry->d_inode; 289 if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { 290 ecryptfs_printk(KERN_DEBUG, "This is a directory\n"); --- 68 unchanged lines hidden (view full) --- 359 return rc; 360} 361 362static int ecryptfs_release(struct inode *inode, struct file *file) 363{ 364 struct file *lower_file = ecryptfs_file_to_lower(file); 365 struct ecryptfs_file_info *file_info = ecryptfs_file_to_private(file); 366 struct inode *lower_inode = ecryptfs_inode_to_lower(inode); |
367 int rc; |
|
344 | 368 |
345 fput(lower_file); | 369 if ((rc = ecryptfs_close_lower_file(lower_file))) { 370 printk(KERN_ERR "Error closing lower_file\n"); 371 goto out; 372 } |
346 inode->i_blocks = lower_inode->i_blocks; 347 kmem_cache_free(ecryptfs_file_info_cache, file_info); | 373 inode->i_blocks = lower_inode->i_blocks; 374 kmem_cache_free(ecryptfs_file_info_cache, file_info); |
348 return 0; | 375out: 376 return rc; |
349} 350 351static int 352ecryptfs_fsync(struct file *file, struct dentry *dentry, int datasync) 353{ 354 struct file *lower_file = ecryptfs_file_to_lower(file); 355 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); 356 struct inode *lower_inode = lower_dentry->d_inode; --- 84 unchanged lines hidden --- | 377} 378 379static int 380ecryptfs_fsync(struct file *file, struct dentry *dentry, int datasync) 381{ 382 struct file *lower_file = ecryptfs_file_to_lower(file); 383 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); 384 struct inode *lower_inode = lower_dentry->d_inode; --- 84 unchanged lines hidden --- |