aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjorn Bringert <bringert@android.com>2011-12-20 19:49:52 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2011-12-21 16:40:24 -0500
commit5154b93b8eceb57bdab4e77030bf21ead15b42e4 (patch)
tree575ae6ca09d8b2b1f6827a7e9e3e4e9ada03b019
parent1d3f8f2da1c28709a3c494f3872b89c871906b2d (diff)
ashmem: Support lseek(2) in ashmem driver
Signed-off-by: Bjorn Bringert <bringert@android.com> [jstultz: tweaked commit subject] CC: Brian Swetland <swetland@google.com> CC: Colin Cross <ccross@android.com> CC: Arve Hjønnevåg <arve@android.com> CC: Dima Zavin <dima@android.com> CC: Robert Love <rlove@google.com> Signed-off-by: John Stultz <john.stultz@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/staging/android/ashmem.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c
index 40c3dc867bf9..777e2b257d4e 100644
--- a/drivers/staging/android/ashmem.c
+++ b/drivers/staging/android/ashmem.c
@@ -178,7 +178,7 @@ static int ashmem_open(struct inode *inode, struct file *file)
178 struct ashmem_area *asma; 178 struct ashmem_area *asma;
179 int ret; 179 int ret;
180 180
181 ret = nonseekable_open(inode, file); 181 ret = generic_file_open(inode, file);
182 if (unlikely(ret)) 182 if (unlikely(ret))
183 return ret; 183 return ret;
184 184
@@ -230,6 +230,42 @@ static ssize_t ashmem_read(struct file *file, char __user *buf,
230 } 230 }
231 231
232 ret = asma->file->f_op->read(asma->file, buf, len, pos); 232 ret = asma->file->f_op->read(asma->file, buf, len, pos);
233 if (ret < 0) {
234 goto out;
235 }
236
237 /** Update backing file pos, since f_ops->read() doesn't */
238 asma->file->f_pos = *pos;
239
240out:
241 mutex_unlock(&ashmem_mutex);
242 return ret;
243}
244
245static loff_t ashmem_llseek(struct file *file, loff_t offset, int origin)
246{
247 struct ashmem_area *asma = file->private_data;
248 int ret;
249
250 mutex_lock(&ashmem_mutex);
251
252 if (asma->size == 0) {
253 ret = -EINVAL;
254 goto out;
255 }
256
257 if (!asma->file) {
258 ret = -EBADF;
259 goto out;
260 }
261
262 ret = asma->file->f_op->llseek(asma->file, offset, origin);
263 if (ret < 0) {
264 goto out;
265 }
266
267 /** Copy f_pos from backing file, since f_ops->llseek() sets it */
268 file->f_pos = asma->file->f_pos;
233 269
234out: 270out:
235 mutex_unlock(&ashmem_mutex); 271 mutex_unlock(&ashmem_mutex);
@@ -648,6 +684,7 @@ static struct file_operations ashmem_fops = {
648 .open = ashmem_open, 684 .open = ashmem_open,
649 .release = ashmem_release, 685 .release = ashmem_release,
650 .read = ashmem_read, 686 .read = ashmem_read,
687 .llseek = ashmem_llseek,
651 .mmap = ashmem_mmap, 688 .mmap = ashmem_mmap,
652 .unlocked_ioctl = ashmem_ioctl, 689 .unlocked_ioctl = ashmem_ioctl,
653 .compat_ioctl = ashmem_ioctl, 690 .compat_ioctl = ashmem_ioctl,