[ktap] [PATCH 3/4] ktap: add support for write() operation

  • From: Yann Droneaud <ydroneaud@xxxxxxxxxx>
  • To: ktap@xxxxxxxxxxxxx
  • Date: Mon, 4 Nov 2013 22:22:41 +0100

Instead of using ioctls, new driver should use read/write
operations when applicable.

Here, uploading opcodes seems to fit well with a write
operation.

Signed-off-by: Yann Droneaud <ydroneaud@xxxxxxxxxx>
---
 interpreter/ktap.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/interpreter/ktap.c b/interpreter/ktap.c
index 646d8a1..1cbcba1 100644
--- a/interpreter/ktap.c
+++ b/interpreter/ktap.c
@@ -137,6 +137,36 @@ static void print_version(void)
 {
 }
 
+static int ktapvm_open(struct inode *inode, struct file *filp)
+{
+       return nonseekable_open(inode, filp);
+}
+
+static int ktapvm_release(struct inode *inode, struct file *filp)
+{
+       return 0;
+}
+
+static ssize_t ktapvm_write(struct file *filp, const char __user *buf, size_t 
count, loff_t *pos)
+{
+       ktap_parm parm;
+
+       if (count < sizeo(ktap_parm))
+               return -EINVAL;
+
+       ret = copy_from_user(&parm, buf,
+                            sizeof(ktap_parm));
+       if (ret != 0)
+               return -EFAULT;
+
+       ret = ktap_main(file, &parm);
+
+       if (ret != 0)
+               return ret;
+
+       return size;
+}
+
 static long ktap_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        ktap_parm parm;
@@ -182,6 +212,10 @@ static long ktapvm_ioctl(struct file *file, unsigned int 
cmd, unsigned long arg)
 
 static const struct file_operations ktapvm_fops = {
        .owner  = THIS_MODULE,
+       .open                   = ktapvm_open,
+       .write                  = ktapvm_write,
+       .release                = ktapvm_release,
+       .llseek                 = no_llseek,
        .unlocked_ioctl         = ktapvm_ioctl,
 };
 
-- 
1.8.3.1


Other related posts: