diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/usb/mon/mon_stat.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/usb/mon/mon_stat.c')
-rw-r--r-- | drivers/usb/mon/mon_stat.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/drivers/usb/mon/mon_stat.c b/drivers/usb/mon/mon_stat.c new file mode 100644 index 000000000000..6e4b165d070a --- /dev/null +++ b/drivers/usb/mon/mon_stat.c | |||
@@ -0,0 +1,74 @@ | |||
1 | /* | ||
2 | * The USB Monitor, inspired by Dave Harding's USBMon. | ||
3 | * | ||
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. | ||
7 | * | ||
8 | */ | ||
9 | |||
10 | #include <linux/kernel.h> | ||
11 | #include <linux/usb.h> | ||
12 | #include <asm/uaccess.h> | ||
13 | |||
14 | #include "usb_mon.h" | ||
15 | |||
16 | #define STAT_BUF_SIZE 80 | ||
17 | |||
18 | struct snap { | ||
19 | int slen; | ||
20 | char str[STAT_BUF_SIZE]; | ||
21 | }; | ||
22 | |||
23 | static int mon_stat_open(struct inode *inode, struct file *file) | ||
24 | { | ||
25 | struct mon_bus *mbus; | ||
26 | struct snap *sp; | ||
27 | |||
28 | if ((sp = kmalloc(sizeof(struct snap), GFP_KERNEL)) == NULL) | ||
29 | return -ENOMEM; | ||
30 | |||
31 | mbus = inode->u.generic_ip; | ||
32 | |||
33 | sp->slen = snprintf(sp->str, STAT_BUF_SIZE, | ||
34 | "nreaders %d text_lost %u\n", | ||
35 | mbus->nreaders, mbus->cnt_text_lost); | ||
36 | |||
37 | file->private_data = sp; | ||
38 | return 0; | ||
39 | } | ||
40 | |||
41 | static ssize_t mon_stat_read(struct file *file, char __user *buf, | ||
42 | size_t nbytes, loff_t *ppos) | ||
43 | { | ||
44 | struct snap *sp = file->private_data; | ||
45 | loff_t pos = *ppos; | ||
46 | int cnt; | ||
47 | |||
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; | ||
58 | } | ||
59 | |||
60 | static int mon_stat_release(struct inode *inode, struct file *file) | ||
61 | { | ||
62 | return 0; | ||
63 | } | ||
64 | |||
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, | ||
74 | }; | ||