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>
 
  12 #include <asm/uaccess.h>
 
  16 #define STAT_BUF_SIZE  80
 
  20         char str[STAT_BUF_SIZE];
 
  23 static int mon_stat_open(struct inode *inode, struct file *file)
 
  28         if ((sp = kmalloc(sizeof(struct snap), GFP_KERNEL)) == NULL)
 
  31         mbus = inode->u.generic_ip;
 
  33         sp->slen = snprintf(sp->str, STAT_BUF_SIZE,
 
  34             "nreaders %d text_lost %u\n",
 
  35             mbus->nreaders, mbus->cnt_text_lost);
 
  37         file->private_data = sp;
 
  41 static ssize_t mon_stat_read(struct file *file, char __user *buf,
 
  42                                 size_t nbytes, loff_t *ppos)
 
  44         struct snap *sp = file->private_data;
 
  48         if (pos < 0 || pos >= sp->slen)
 
  52         if ((cnt = sp->slen - pos) > nbytes)
 
  54         if (copy_to_user(buf, sp->str + pos, cnt))
 
  60 static int mon_stat_release(struct inode *inode, struct file *file)
 
  65 struct file_operations mon_fops_stat = {
 
  67         .open =         mon_stat_open,
 
  69         .read =         mon_stat_read,
 
  70         /* .write =     mon_stat_write, */
 
  71         /* .poll =              mon_stat_poll, */
 
  72         /* .ioctl =     mon_stat_ioctl, */
 
  73         .release =      mon_stat_release,