Linux 2.6.17.7
[linux/fpc-iii.git] / drivers / usb / mon / mon_stat.c
blob6e4b165d070ad6cfac00ab11c30ad9d206d8a709
1 /*
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.
8 */
10 #include <linux/kernel.h>
11 #include <linux/usb.h>
12 #include <asm/uaccess.h>
14 #include "usb_mon.h"
16 #define STAT_BUF_SIZE 80
18 struct snap {
19 int slen;
20 char str[STAT_BUF_SIZE];
23 static int mon_stat_open(struct inode *inode, struct file *file)
25 struct mon_bus *mbus;
26 struct snap *sp;
28 if ((sp = kmalloc(sizeof(struct snap), GFP_KERNEL)) == NULL)
29 return -ENOMEM;
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;
38 return 0;
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;
45 loff_t pos = *ppos;
46 int cnt;
48 if (pos < 0 || pos >= sp->slen)
49 return 0;
50 if (nbytes == 0)
51 return 0;
52 if ((cnt = sp->slen - pos) > nbytes)
53 cnt = nbytes;
54 if (copy_to_user(buf, sp->str + pos, cnt))
55 return -EFAULT;
56 *ppos = pos + cnt;
57 return cnt;
60 static int mon_stat_release(struct inode *inode, struct file *file)
62 return 0;
65 struct file_operations mon_fops_stat = {
66 .owner = THIS_MODULE,
67 .open = mon_stat_open,
68 .llseek = no_llseek,
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,