| From 5154b93b8eceb57bdab4e77030bf21ead15b42e4 Mon Sep 17 00:00:00 2001 |
| From: Bjorn Bringert <bringert@android.com> |
| Date: Tue, 20 Dec 2011 16:49:52 -0800 |
| Subject: ashmem: Support lseek(2) in ashmem driver |
| MIME-Version: 1.0 |
| Content-Type: text/plain; charset=UTF-8 |
| Content-Transfer-Encoding: 8bit |
| Patch-mainline: HEAD |
| Git-commit: 5154b93b8eceb57bdab4e77030bf21ead15b42e4 |
| |
| 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> |
| |
| diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c |
| index 40c3dc8..777e2b2 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) |
| struct ashmem_area *asma; |
| int ret; |
| |
| - ret = nonseekable_open(inode, file); |
| + ret = generic_file_open(inode, file); |
| if (unlikely(ret)) |
| return ret; |
| |
| @@ -230,6 +230,42 @@ static ssize_t ashmem_read(struct file *file, char __user *buf, |
| } |
| |
| ret = asma->file->f_op->read(asma->file, buf, len, pos); |
| + if (ret < 0) { |
| + goto out; |
| + } |
| + |
| + /** Update backing file pos, since f_ops->read() doesn't */ |
| + asma->file->f_pos = *pos; |
| + |
| +out: |
| + mutex_unlock(&ashmem_mutex); |
| + return ret; |
| +} |
| + |
| +static loff_t ashmem_llseek(struct file *file, loff_t offset, int origin) |
| +{ |
| + struct ashmem_area *asma = file->private_data; |
| + int ret; |
| + |
| + mutex_lock(&ashmem_mutex); |
| + |
| + if (asma->size == 0) { |
| + ret = -EINVAL; |
| + goto out; |
| + } |
| + |
| + if (!asma->file) { |
| + ret = -EBADF; |
| + goto out; |
| + } |
| + |
| + ret = asma->file->f_op->llseek(asma->file, offset, origin); |
| + if (ret < 0) { |
| + goto out; |
| + } |
| + |
| + /** Copy f_pos from backing file, since f_ops->llseek() sets it */ |
| + file->f_pos = asma->file->f_pos; |
| |
| out: |
| mutex_unlock(&ashmem_mutex); |
| @@ -648,6 +684,7 @@ static struct file_operations ashmem_fops = { |
| .open = ashmem_open, |
| .release = ashmem_release, |
| .read = ashmem_read, |
| + .llseek = ashmem_llseek, |
| .mmap = ashmem_mmap, |
| .unlocked_ioctl = ashmem_ioctl, |
| .compat_ioctl = ashmem_ioctl, |