1 // SPDX-License-Identifier: GPL-2.0
3 * The USB Monitor, inspired by Dave Harding's USBMon.
5 * This is the 's' or 'stat' reader which debugs usbmon itself.
6 * Note that this code blows through locks, so make sure that
7 * /dbg/usbmon/0s is well protected from non-root users.
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
13 #include <linux/export.h>
14 #include <linux/usb.h>
16 #include <linux/uaccess.h>
20 #define STAT_BUF_SIZE 80
24 char str[STAT_BUF_SIZE];
27 static int mon_stat_open(struct inode *inode, struct file *file)
32 sp = kmalloc(sizeof(struct snap), GFP_KERNEL);
36 mbus = inode->i_private;
38 sp->slen = snprintf(sp->str, STAT_BUF_SIZE,
39 "nreaders %d events %u text_lost %u\n",
40 mbus->nreaders, mbus->cnt_events, mbus->cnt_text_lost);
42 file->private_data = sp;
46 static ssize_t mon_stat_read(struct file *file, char __user *buf,
47 size_t nbytes, loff_t *ppos)
49 struct snap *sp = file->private_data;
51 return simple_read_from_buffer(buf, nbytes, ppos, sp->str, sp->slen);
54 static int mon_stat_release(struct inode *inode, struct file *file)
56 struct snap *sp = file->private_data;
57 file->private_data = NULL;
62 const struct file_operations mon_fops_stat = {
64 .open = mon_stat_open,
66 .read = mon_stat_read,
67 /* .write = mon_stat_write, */
68 /* .poll = mon_stat_poll, */
69 /* .unlocked_ioctl = mon_stat_ioctl, */
70 .release = mon_stat_release,