2 * The USB Monitor, inspired by Dave Harding's USBMon.
4 * This is the 's' or 'stat' reader which debugs usbmon itself.
5 * Note that this code blows through locks, so make sure that
6 * /dbg/usbmon/0s is well protected from non-root users.
10 #include <linux/kernel.h>
11 #include <linux/usb.h>
13 #include <asm/uaccess.h>
17 #define STAT_BUF_SIZE 80
21 char str[STAT_BUF_SIZE];
24 static int mon_stat_open(struct inode *inode, struct file *file)
29 if ((sp = kmalloc(sizeof(struct snap), GFP_KERNEL)) == NULL)
32 mbus = inode->i_private;
34 sp->slen = snprintf(sp->str, STAT_BUF_SIZE,
35 "nreaders %d events %u text_lost %u\n",
36 mbus->nreaders, mbus->cnt_events, mbus->cnt_text_lost);
38 file->private_data = sp;
42 static ssize_t mon_stat_read(struct file *file, char __user *buf,
43 size_t nbytes, loff_t *ppos)
45 struct snap *sp = file->private_data;
47 return simple_read_from_buffer(buf, nbytes, ppos, sp->str, sp->slen);
50 static int mon_stat_release(struct inode *inode, struct file *file)
52 struct snap *sp = file->private_data;
53 file->private_data = NULL;
58 const struct file_operations mon_fops_stat = {
60 .open = mon_stat_open,
62 .read = mon_stat_read,
63 /* .write = mon_stat_write, */
64 /* .poll = mon_stat_poll, */
65 /* .ioctl = mon_stat_ioctl, */
66 .release = mon_stat_release,