0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/kernel.h>
0012 #include <linux/slab.h>
0013 #include <linux/export.h>
0014 #include <linux/usb.h>
0015 #include <linux/fs.h>
0016 #include <linux/uaccess.h>
0017
0018 #include "usb_mon.h"
0019
0020 #define STAT_BUF_SIZE 80
0021
0022 struct snap {
0023 int slen;
0024 char str[STAT_BUF_SIZE];
0025 };
0026
0027 static int mon_stat_open(struct inode *inode, struct file *file)
0028 {
0029 struct mon_bus *mbus;
0030 struct snap *sp;
0031
0032 sp = kmalloc(sizeof(struct snap), GFP_KERNEL);
0033 if (sp == NULL)
0034 return -ENOMEM;
0035
0036 mbus = inode->i_private;
0037
0038 sp->slen = snprintf(sp->str, STAT_BUF_SIZE,
0039 "nreaders %d events %u text_lost %u\n",
0040 mbus->nreaders, mbus->cnt_events, mbus->cnt_text_lost);
0041
0042 file->private_data = sp;
0043 return 0;
0044 }
0045
0046 static ssize_t mon_stat_read(struct file *file, char __user *buf,
0047 size_t nbytes, loff_t *ppos)
0048 {
0049 struct snap *sp = file->private_data;
0050
0051 return simple_read_from_buffer(buf, nbytes, ppos, sp->str, sp->slen);
0052 }
0053
0054 static int mon_stat_release(struct inode *inode, struct file *file)
0055 {
0056 struct snap *sp = file->private_data;
0057 file->private_data = NULL;
0058 kfree(sp);
0059 return 0;
0060 }
0061
0062 const struct file_operations mon_fops_stat = {
0063 .owner = THIS_MODULE,
0064 .open = mon_stat_open,
0065 .llseek = no_llseek,
0066 .read = mon_stat_read,
0067
0068
0069
0070 .release = mon_stat_release,
0071 };