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
This commit is contained in:
ben 2007-07-01 09:55:49 +00:00
parent 267d5afeab
commit 593371de82
2 changed files with 54 additions and 40 deletions

90
files.c
View File

@ -9,66 +9,78 @@
#include <linux/pagemap.h>
#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)
{
{
//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))
udata = (void __user *)buf;
if (!access_ok(VERIFY_READ, buf, len))
return -EFAULT;
udata = (void __user *)buf;
if (__get_user(data, udata))
return -EFAULT;
for (count = 0; (count + 4) <= len; count += 4, udata++) {
int ret;
/* 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, },
{},
};

View File

@ -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 */