From 593371de824fe9150a73b3b6299c0a3f66ed43cd Mon Sep 17 00:00:00 2001 From: ben Date: Sun, 1 Jul 2007 09:55:49 +0000 Subject: [PATCH] add basic write/read commands for file cmd and stat git-svn-id: svn+ssh://en.codiert.org/home/staff/ben/dev/misc.svn/projects/fpgafs@343 766a2236-cff9-0310-b0c0-a81a5f92509a --- files.c | 92 ++++++++++++++++++++++++++++++++------------------------ fpgafs.h | 2 ++ 2 files changed, 54 insertions(+), 40 deletions(-) diff --git a/files.c b/files.c index c36d35d..beaa651 100644 --- a/files.c +++ b/files.c @@ -9,66 +9,78 @@ #include #include "fpgafs.h" -/* generic open function for all pipe-like files */ -static int fpgafs_pipe_open(struct inode *inode, struct file *file) -{ - struct fpgafs_inode_info *i = FPGAFS_I(inode); - file->private_data = i->i_ctx; +static unsigned int stat; - return nonseekable_open(inode, file); +static int do_cmd(u32 cmd, u32 data) +{ + switch(cmd) { + case BLA: + stat = data; + break; + default: + return -EFAULT; + } + return 0; +} + +/* generic open function for all pipe-like files */ +static int fpgafs_open(struct inode *inode, struct file *file) +{ + //struct fpgafs_inode_info *i = FPGAFS_I(inode); + //file->private_data = i->i_ctx; + + return 0; // nonseekable_open(inode, file); } static ssize_t fpgafs_stat_read(struct file *file, char __user *buf, - size_t len, loff_t *pos) -{ + size_t len, loff_t *pos) + { //struct fpga_context *ctx = file->private_data; + u32 data; + data=stat; + + if (copy_to_user(buf, &data, sizeof(data))) + return -EFAULT; + + return 4; +} + +static const struct file_operations fpgafs_stat_fops = { + .open = fpgafs_open, + .read = fpgafs_stat_read, +}; + +static ssize_t fpgafs_cmd_write(struct file *file, const char __user *buf, + size_t len, loff_t *pos) +{ u32 data, __user *udata; - ssize_t count; if (len < 4) return -EINVAL; - if (!access_ok(VERIFY_WRITE, buf, len)) - return -EFAULT; - udata = (void __user *)buf; + if (!access_ok(VERIFY_READ, buf, len)) + return -EFAULT; - for (count = 0; (count + 4) <= len; count += 4, udata++) { - int ret; + if (__get_user(data, udata)) + return -EFAULT; - /* operation to read the status ... */ - data=0x42; - ret = 0; - if (ret == 0) - break; - - ret = __put_user(data, udata); - - if (ret) { - if (!count) - count = -EFAULT; - break; - } - } - - if (!count) - count = -EAGAIN; - - return count; + do_cmd(BLA,data); + return 4; } -static const struct file_operations fpgafs_stat_fops = { - .open = fpgafs_pipe_open, - .read = fpgafs_stat_read, +static const struct file_operations fpgafs_cmd_fops = { + .open = fpgafs_open, + .write = fpgafs_cmd_write, }; struct tree_descr fpgafs_dir_contents[] = { #if 0 - { "cmd", &fpgafs_cmd_fops, 0222, }, - { "din", &spufs_mbox_fops, 0222, }, - { "dout", &spufs_ibox_fops, 0444, }, - { "load", &spufs_wbox_fops, 0666, }, + { "din", &fpgafs_din_fops, 0222, }, + { "dout", &fpgafs_dout_fops, 0444, }, + { "load", &fpgafs_load_fops, 0666, }, #endif + { "cmd", &fpgafs_cmd_fops, 0222, }, { "stat", &fpgafs_stat_fops, 0444, }, {}, }; diff --git a/fpgafs.h b/fpgafs.h index ee15ad2..20d1480 100644 --- a/fpgafs.h +++ b/fpgafs.h @@ -26,4 +26,6 @@ extern struct tree_descr fpgafs_dir_contents[]; #define FPGAFS_I(inode) \ container_of(inode, struct fpgafs_inode_info, vfs_inode) +#define BLA 0 + #endif /* FPGAFS_H */