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/slab.h>
12 #include <linux/export.h>
13 #include <linux/usb.h>
15 #include <linux/uaccess.h>
19 #define STAT_BUF_SIZE 80
23 char str
[STAT_BUF_SIZE
];
26 static int mon_stat_open(struct inode
*inode
, struct file
*file
)
31 sp
= kmalloc(sizeof(struct snap
), GFP_KERNEL
);
35 mbus
= inode
->i_private
;
37 sp
->slen
= snprintf(sp
->str
, STAT_BUF_SIZE
,
38 "nreaders %d events %u text_lost %u\n",
39 mbus
->nreaders
, mbus
->cnt_events
, mbus
->cnt_text_lost
);
41 file
->private_data
= sp
;
45 static ssize_t
mon_stat_read(struct file
*file
, char __user
*buf
,
46 size_t nbytes
, loff_t
*ppos
)
48 struct snap
*sp
= file
->private_data
;
50 return simple_read_from_buffer(buf
, nbytes
, ppos
, sp
->str
, sp
->slen
);
53 static int mon_stat_release(struct inode
*inode
, struct file
*file
)
55 struct snap
*sp
= file
->private_data
;
56 file
->private_data
= NULL
;
61 const struct file_operations mon_fops_stat
= {
63 .open
= mon_stat_open
,
65 .read
= mon_stat_read
,
66 /* .write = mon_stat_write, */
67 /* .poll = mon_stat_poll, */
68 /* .unlocked_ioctl = mon_stat_ioctl, */
69 .release
= mon_stat_release
,