ANDROID: sdcardfs: add read_iter/write_iter opeations

Adapted from wrapfs
commit f398bf6a7377 ("Wrapfs: add read_iter/write_iter opeations")

Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
Signed-off-by: Mengyang Li <li.mengyang@stonybrook.edu>
Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 35766959
Change-Id: I2b3de59c9682fc705bf21df0de6df81e76fd2e40
This commit is contained in:
Daniel Rosenberg 2017-03-09 21:48:09 -08:00 committed by Amit Pundir
parent d73d4fde4c
commit 63cd557652

View file

@ -338,6 +338,52 @@ static loff_t sdcardfs_file_llseek(struct file *file, loff_t offset, int whence)
return err;
}
/*
* Sdcardfs read_iter, redirect modified iocb to lower read_iter
*/
ssize_t sdcardfs_read_iter(struct kiocb *iocb, struct iov_iter *iter)
{
int err;
struct file *file = iocb->ki_filp, *lower_file;
lower_file = sdcardfs_lower_file(file);
if (!lower_file->f_op->read_iter) {
err = -EINVAL;
goto out;
}
get_file(lower_file); /* prevent lower_file from being released */
iocb->ki_filp = lower_file;
err = lower_file->f_op->read_iter(iocb, iter);
/* ? wait IO finish to update atime as ecryptfs ? */
iocb->ki_filp = file;
fput(lower_file);
out:
return err;
}
/*
* Sdcardfs write_iter, redirect modified iocb to lower write_iter
*/
ssize_t sdcardfs_write_iter(struct kiocb *iocb, struct iov_iter *iter)
{
int err;
struct file *file = iocb->ki_filp, *lower_file;
lower_file = sdcardfs_lower_file(file);
if (!lower_file->f_op->write_iter) {
err = -EINVAL;
goto out;
}
get_file(lower_file); /* prevent lower_file from being released */
iocb->ki_filp = lower_file;
err = lower_file->f_op->write_iter(iocb, iter);
iocb->ki_filp = file;
fput(lower_file);
out:
return err;
}
const struct file_operations sdcardfs_main_fops = {
.llseek = generic_file_llseek,
@ -353,6 +399,8 @@ const struct file_operations sdcardfs_main_fops = {
.release = sdcardfs_file_release,
.fsync = sdcardfs_fsync,
.fasync = sdcardfs_fasync,
.read_iter = sdcardfs_read_iter,
.write_iter = sdcardfs_write_iter,
};
/* trimmed directory options */