aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ecryptfs/file.c')
-rw-r--r--fs/ecryptfs/file.c63
1 files changed, 33 insertions, 30 deletions
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c
index 622c95140802..4ec9eb00a241 100644
--- a/fs/ecryptfs/file.c
+++ b/fs/ecryptfs/file.c
@@ -31,7 +31,6 @@
31#include <linux/security.h> 31#include <linux/security.h>
32#include <linux/compat.h> 32#include <linux/compat.h>
33#include <linux/fs_stack.h> 33#include <linux/fs_stack.h>
34#include <linux/smp_lock.h>
35#include "ecryptfs_kernel.h" 34#include "ecryptfs_kernel.h"
36 35
37/** 36/**
@@ -48,7 +47,7 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb,
48 const struct iovec *iov, 47 const struct iovec *iov,
49 unsigned long nr_segs, loff_t pos) 48 unsigned long nr_segs, loff_t pos)
50{ 49{
51 int rc; 50 ssize_t rc;
52 struct dentry *lower_dentry; 51 struct dentry *lower_dentry;
53 struct vfsmount *lower_vfsmount; 52 struct vfsmount *lower_vfsmount;
54 struct file *file = iocb->ki_filp; 53 struct file *file = iocb->ki_filp;
@@ -192,22 +191,20 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
192 | ECRYPTFS_ENCRYPTED); 191 | ECRYPTFS_ENCRYPTED);
193 } 192 }
194 mutex_unlock(&crypt_stat->cs_mutex); 193 mutex_unlock(&crypt_stat->cs_mutex);
195 if (!ecryptfs_inode_to_private(inode)->lower_file) { 194 rc = ecryptfs_get_lower_file(ecryptfs_dentry, inode);
196 rc = ecryptfs_init_persistent_file(ecryptfs_dentry); 195 if (rc) {
197 if (rc) { 196 printk(KERN_ERR "%s: Error attempting to initialize "
198 printk(KERN_ERR "%s: Error attempting to initialize " 197 "the lower file for the dentry with name "
199 "the persistent file for the dentry with name " 198 "[%s]; rc = [%d]\n", __func__,
200 "[%s]; rc = [%d]\n", __func__, 199 ecryptfs_dentry->d_name.name, rc);
201 ecryptfs_dentry->d_name.name, rc); 200 goto out_free;
202 goto out_free;
203 }
204 } 201 }
205 if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_RDONLY) 202 if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_ACCMODE)
206 && !(file->f_flags & O_RDONLY)) { 203 == O_RDONLY && (file->f_flags & O_ACCMODE) != O_RDONLY) {
207 rc = -EPERM; 204 rc = -EPERM;
208 printk(KERN_WARNING "%s: Lower persistent file is RO; eCryptfs " 205 printk(KERN_WARNING "%s: Lower file is RO; eCryptfs "
209 "file must hence be opened RO\n", __func__); 206 "file must hence be opened RO\n", __func__);
210 goto out_free; 207 goto out_put;
211 } 208 }
212 ecryptfs_set_file_lower( 209 ecryptfs_set_file_lower(
213 file, ecryptfs_inode_to_private(inode)->lower_file); 210 file, ecryptfs_inode_to_private(inode)->lower_file);
@@ -235,19 +232,22 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
235 "Plaintext passthrough mode is not " 232 "Plaintext passthrough mode is not "
236 "enabled; returning -EIO\n"); 233 "enabled; returning -EIO\n");
237 mutex_unlock(&crypt_stat->cs_mutex); 234 mutex_unlock(&crypt_stat->cs_mutex);
238 goto out_free; 235 goto out_put;
239 } 236 }
240 rc = 0; 237 rc = 0;
241 crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED); 238 crypt_stat->flags &= ~(ECRYPTFS_I_SIZE_INITIALIZED
239 | ECRYPTFS_ENCRYPTED);
242 mutex_unlock(&crypt_stat->cs_mutex); 240 mutex_unlock(&crypt_stat->cs_mutex);
243 goto out; 241 goto out;
244 } 242 }
245 } 243 }
246 mutex_unlock(&crypt_stat->cs_mutex); 244 mutex_unlock(&crypt_stat->cs_mutex);
247 ecryptfs_printk(KERN_DEBUG, "inode w/ addr = [0x%p], i_ino = [0x%.16x] " 245 ecryptfs_printk(KERN_DEBUG, "inode w/ addr = [0x%p], i_ino = "
248 "size: [0x%.16x]\n", inode, inode->i_ino, 246 "[0x%.16lx] size: [0x%.16llx]\n", inode, inode->i_ino,
249 i_size_read(inode)); 247 (unsigned long long)i_size_read(inode));
250 goto out; 248 goto out;
249out_put:
250 ecryptfs_put_lower_file(inode);
251out_free: 251out_free:
252 kmem_cache_free(ecryptfs_file_info_cache, 252 kmem_cache_free(ecryptfs_file_info_cache,
253 ecryptfs_file_to_private(file)); 253 ecryptfs_file_to_private(file));
@@ -257,17 +257,13 @@ out:
257 257
258static int ecryptfs_flush(struct file *file, fl_owner_t td) 258static int ecryptfs_flush(struct file *file, fl_owner_t td)
259{ 259{
260 int rc = 0; 260 return file->f_mode & FMODE_WRITE
261 struct file *lower_file = NULL; 261 ? filemap_write_and_wait(file->f_mapping) : 0;
262
263 lower_file = ecryptfs_file_to_lower(file);
264 if (lower_file->f_op && lower_file->f_op->flush)
265 rc = lower_file->f_op->flush(lower_file, td);
266 return rc;
267} 262}
268 263
269static int ecryptfs_release(struct inode *inode, struct file *file) 264static int ecryptfs_release(struct inode *inode, struct file *file)
270{ 265{
266 ecryptfs_put_lower_file(inode);
271 kmem_cache_free(ecryptfs_file_info_cache, 267 kmem_cache_free(ecryptfs_file_info_cache,
272 ecryptfs_file_to_private(file)); 268 ecryptfs_file_to_private(file));
273 return 0; 269 return 0;
@@ -276,7 +272,14 @@ static int ecryptfs_release(struct inode *inode, struct file *file)
276static int 272static int
277ecryptfs_fsync(struct file *file, int datasync) 273ecryptfs_fsync(struct file *file, int datasync)
278{ 274{
279 return vfs_fsync(ecryptfs_file_to_lower(file), datasync); 275 int rc = 0;
276
277 rc = generic_file_fsync(file, datasync);
278 if (rc)
279 goto out;
280 rc = vfs_fsync(ecryptfs_file_to_lower(file), datasync);
281out:
282 return rc;
280} 283}
281 284
282static int ecryptfs_fasync(int fd, struct file *file, int flag) 285static int ecryptfs_fasync(int fd, struct file *file, int flag)
@@ -284,11 +287,9 @@ static int ecryptfs_fasync(int fd, struct file *file, int flag)
284 int rc = 0; 287 int rc = 0;
285 struct file *lower_file = NULL; 288 struct file *lower_file = NULL;
286 289
287 lock_kernel();
288 lower_file = ecryptfs_file_to_lower(file); 290 lower_file = ecryptfs_file_to_lower(file);
289 if (lower_file->f_op && lower_file->f_op->fasync) 291 if (lower_file->f_op && lower_file->f_op->fasync)
290 rc = lower_file->f_op->fasync(fd, lower_file, flag); 292 rc = lower_file->f_op->fasync(fd, lower_file, flag);
291 unlock_kernel();
292 return rc; 293 return rc;
293} 294}
294 295
@@ -322,6 +323,7 @@ ecryptfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
322 323
323const struct file_operations ecryptfs_dir_fops = { 324const struct file_operations ecryptfs_dir_fops = {
324 .readdir = ecryptfs_readdir, 325 .readdir = ecryptfs_readdir,
326 .read = generic_read_dir,
325 .unlocked_ioctl = ecryptfs_unlocked_ioctl, 327 .unlocked_ioctl = ecryptfs_unlocked_ioctl,
326#ifdef CONFIG_COMPAT 328#ifdef CONFIG_COMPAT
327 .compat_ioctl = ecryptfs_compat_ioctl, 329 .compat_ioctl = ecryptfs_compat_ioctl,
@@ -332,6 +334,7 @@ const struct file_operations ecryptfs_dir_fops = {
332 .fsync = ecryptfs_fsync, 334 .fsync = ecryptfs_fsync,
333 .fasync = ecryptfs_fasync, 335 .fasync = ecryptfs_fasync,
334 .splice_read = generic_file_splice_read, 336 .splice_read = generic_file_splice_read,
337 .llseek = default_llseek,
335}; 338};
336 339
337const struct file_operations ecryptfs_main_fops = { 340const struct file_operations ecryptfs_main_fops = {