72 lines
1.4 KiB
C
72 lines
1.4 KiB
C
|
#include <linux/fs.h>
|
||
|
#include <linux/module.h>
|
||
|
#include <linux/version.h>
|
||
|
#include <linux/init.h>
|
||
|
#include <linux/fs.h>
|
||
|
#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;
|
||
|
|
||
|
return 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, __user *udata;
|
||
|
ssize_t count;
|
||
|
|
||
|
if (len < 4)
|
||
|
return -EINVAL;
|
||
|
|
||
|
if (!access_ok(VERIFY_WRITE, buf, len))
|
||
|
return -EFAULT;
|
||
|
|
||
|
udata = (void __user *)buf;
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
static const struct file_operations fpgafs_stat_fops = {
|
||
|
.open = fpgafs_pipe_open,
|
||
|
.read = fpgafs_stat_read,
|
||
|
};
|
||
|
|
||
|
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, },
|
||
|
#endif
|
||
|
{ "stat", &fpgafs_stat_fops, 0444, },
|
||
|
{},
|
||
|
};
|