file.c (b32e3dc7860d00124fa432dba09667e647cb9bcc) | file.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 <mhalcrow@us.ibm.com> 8 * Michael C. Thompson <mcthomps@us.ibm.com> --- 177 unchanged lines hidden (view full) --- 186 mutex_lock(&crypt_stat->cs_mutex); 187 if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) { 188 ecryptfs_printk(KERN_DEBUG, "Setting flags for stat...\n"); 189 /* Policy code enabled in future release */ 190 crypt_stat->flags |= (ECRYPTFS_POLICY_APPLIED 191 | ECRYPTFS_ENCRYPTED); 192 } 193 mutex_unlock(&crypt_stat->cs_mutex); | 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 <mhalcrow@us.ibm.com> 8 * Michael C. Thompson <mcthomps@us.ibm.com> --- 177 unchanged lines hidden (view full) --- 186 mutex_lock(&crypt_stat->cs_mutex); 187 if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) { 188 ecryptfs_printk(KERN_DEBUG, "Setting flags for stat...\n"); 189 /* Policy code enabled in future release */ 190 crypt_stat->flags |= (ECRYPTFS_POLICY_APPLIED 191 | ECRYPTFS_ENCRYPTED); 192 } 193 mutex_unlock(&crypt_stat->cs_mutex); |
194 rc = ecryptfs_init_persistent_file(ecryptfs_dentry); | 194 rc = ecryptfs_get_lower_file(ecryptfs_dentry); |
195 if (rc) { 196 printk(KERN_ERR "%s: Error attempting to initialize " | 195 if (rc) { 196 printk(KERN_ERR "%s: Error attempting to initialize " |
197 "the persistent file for the dentry with name " | 197 "the lower file for the dentry with name " |
198 "[%s]; rc = [%d]\n", __func__, 199 ecryptfs_dentry->d_name.name, rc); 200 goto out_free; 201 } 202 if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_ACCMODE) 203 == O_RDONLY && (file->f_flags & O_ACCMODE) != O_RDONLY) { 204 rc = -EPERM; | 198 "[%s]; rc = [%d]\n", __func__, 199 ecryptfs_dentry->d_name.name, rc); 200 goto out_free; 201 } 202 if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_ACCMODE) 203 == O_RDONLY && (file->f_flags & O_ACCMODE) != O_RDONLY) { 204 rc = -EPERM; |
205 printk(KERN_WARNING "%s: Lower persistent file is RO; eCryptfs " | 205 printk(KERN_WARNING "%s: Lower file is RO; eCryptfs " |
206 "file must hence be opened RO\n", __func__); | 206 "file must hence be opened RO\n", __func__); |
207 goto out_free; | 207 goto out_put; |
208 } 209 ecryptfs_set_file_lower( 210 file, ecryptfs_inode_to_private(inode)->lower_file); 211 if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { 212 ecryptfs_printk(KERN_DEBUG, "This is a directory\n"); 213 mutex_lock(&crypt_stat->cs_mutex); 214 crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); 215 mutex_unlock(&crypt_stat->cs_mutex); --- 11 unchanged lines hidden (view full) --- 227 & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) { 228 rc = -EIO; 229 printk(KERN_WARNING "Either the lower file " 230 "is not in a valid eCryptfs format, " 231 "or the key could not be retrieved. " 232 "Plaintext passthrough mode is not " 233 "enabled; returning -EIO\n"); 234 mutex_unlock(&crypt_stat->cs_mutex); | 208 } 209 ecryptfs_set_file_lower( 210 file, ecryptfs_inode_to_private(inode)->lower_file); 211 if (S_ISDIR(ecryptfs_dentry->d_inode->i_mode)) { 212 ecryptfs_printk(KERN_DEBUG, "This is a directory\n"); 213 mutex_lock(&crypt_stat->cs_mutex); 214 crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); 215 mutex_unlock(&crypt_stat->cs_mutex); --- 11 unchanged lines hidden (view full) --- 227 & ECRYPTFS_PLAINTEXT_PASSTHROUGH_ENABLED)) { 228 rc = -EIO; 229 printk(KERN_WARNING "Either the lower file " 230 "is not in a valid eCryptfs format, " 231 "or the key could not be retrieved. " 232 "Plaintext passthrough mode is not " 233 "enabled; returning -EIO\n"); 234 mutex_unlock(&crypt_stat->cs_mutex); |
235 goto out_free; | 235 goto out_put; |
236 } 237 rc = 0; 238 crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); 239 mutex_unlock(&crypt_stat->cs_mutex); 240 goto out; 241 } 242 } 243 mutex_unlock(&crypt_stat->cs_mutex); 244 ecryptfs_printk(KERN_DEBUG, "inode w/ addr = [0x%p], i_ino = " 245 "[0x%.16lx] size: [0x%.16llx]\n", inode, inode->i_ino, 246 (unsigned long long)i_size_read(inode)); 247 goto out; | 236 } 237 rc = 0; 238 crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); 239 mutex_unlock(&crypt_stat->cs_mutex); 240 goto out; 241 } 242 } 243 mutex_unlock(&crypt_stat->cs_mutex); 244 ecryptfs_printk(KERN_DEBUG, "inode w/ addr = [0x%p], i_ino = " 245 "[0x%.16lx] size: [0x%.16llx]\n", inode, inode->i_ino, 246 (unsigned long long)i_size_read(inode)); 247 goto out; |
248out_put: 249 ecryptfs_put_lower_file(inode); |
|
248out_free: 249 kmem_cache_free(ecryptfs_file_info_cache, 250 ecryptfs_file_to_private(file)); 251out: 252 return rc; 253} 254 255static int ecryptfs_flush(struct file *file, fl_owner_t td) 256{ | 250out_free: 251 kmem_cache_free(ecryptfs_file_info_cache, 252 ecryptfs_file_to_private(file)); 253out: 254 return rc; 255} 256 257static int ecryptfs_flush(struct file *file, fl_owner_t td) 258{ |
257 int rc = 0; 258 struct file *lower_file = NULL; 259 260 lower_file = ecryptfs_file_to_lower(file); 261 if (lower_file->f_op && lower_file->f_op->flush) 262 rc = lower_file->f_op->flush(lower_file, td); 263 return rc; | 259 return file->f_mode & FMODE_WRITE 260 ? filemap_write_and_wait(file->f_mapping) : 0; |
264} 265 266static int ecryptfs_release(struct inode *inode, struct file *file) 267{ | 261} 262 263static int ecryptfs_release(struct inode *inode, struct file *file) 264{ |
265 ecryptfs_put_lower_file(inode); |
|
268 kmem_cache_free(ecryptfs_file_info_cache, 269 ecryptfs_file_to_private(file)); 270 return 0; 271} 272 273static int 274ecryptfs_fsync(struct file *file, int datasync) 275{ --- 84 unchanged lines hidden --- | 266 kmem_cache_free(ecryptfs_file_info_cache, 267 ecryptfs_file_to_private(file)); 268 return 0; 269} 270 271static int 272ecryptfs_fsync(struct file *file, int datasync) 273{ --- 84 unchanged lines hidden --- |