Staging: vme: llseek support in user driver
authorArthur Benilov <arthur.benilov@iba-group.com>
Tue, 16 Feb 2010 14:40:30 +0000 (15:40 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 4 Mar 2010 00:43:01 +0000 (16:43 -0800)
Provide vme_user_llseek() implementation.

Signed-off-by: Arthur Benilov <arthur.benilov@iba-group.com>
Signed-off-by: Vincent Bossier <vincent.bossier@iba-group.com>
Acked-by: Martyn Welch <martyn.welch@ge.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/vme/devices/vme_user.c

index 48d46ca..ddecbe5 100644 (file)
@@ -400,8 +400,39 @@ static ssize_t vme_user_write(struct file *file, const char *buf, size_t count,
 
 static loff_t vme_user_llseek(struct file *file, loff_t off, int whence)
 {
-       printk(KERN_ERR "Llseek currently incomplete\n");
-       return -EINVAL;
+       loff_t absolute = -1;
+       unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
+       size_t image_size;
+
+       down(&image[minor].sem);
+       image_size = vme_get_size(image[minor].resource);
+
+       switch (whence) {
+       case SEEK_SET:
+               absolute = off;
+               break;
+       case SEEK_CUR:
+               absolute = file->f_pos + off;
+               break;
+       case SEEK_END:
+               absolute = image_size + off;
+               break;
+       default:
+               up(&image[minor].sem);
+               return -EINVAL;
+               break;
+       }
+
+       if ((absolute < 0) || (absolute >= image_size)) {
+               up(&image[minor].sem);
+               return -EINVAL;
+       }
+
+       file->f_pos = absolute;
+
+       up(&image[minor].sem);
+
+       return absolute;
 }
 
 /*