Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[deliverable/linux.git] / drivers / usb / mon / mon_stat.c
CommitLineData
1da177e4
LT
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>
5a0e3ad6 11#include <linux/slab.h>
f940fcd8 12#include <linux/export.h>
1da177e4 13#include <linux/usb.h>
518386c7 14#include <linux/fs.h>
1da177e4
LT
15#include <asm/uaccess.h>
16
17#include "usb_mon.h"
18
19#define STAT_BUF_SIZE 80
20
21struct snap {
22 int slen;
23 char str[STAT_BUF_SIZE];
24};
25
26static int mon_stat_open(struct inode *inode, struct file *file)
27{
28 struct mon_bus *mbus;
29 struct snap *sp;
30
31 if ((sp = kmalloc(sizeof(struct snap), GFP_KERNEL)) == NULL)
32 return -ENOMEM;
33
8e18e294 34 mbus = inode->i_private;
1da177e4
LT
35
36 sp->slen = snprintf(sp->str, STAT_BUF_SIZE,
5b1c674d
PZ
37 "nreaders %d events %u text_lost %u\n",
38 mbus->nreaders, mbus->cnt_events, mbus->cnt_text_lost);
1da177e4
LT
39
40 file->private_data = sp;
41 return 0;
42}
43
44static ssize_t mon_stat_read(struct file *file, char __user *buf,
45 size_t nbytes, loff_t *ppos)
46{
47 struct snap *sp = file->private_data;
1da177e4 48
518386c7 49 return simple_read_from_buffer(buf, nbytes, ppos, sp->str, sp->slen);
1da177e4
LT
50}
51
52static int mon_stat_release(struct inode *inode, struct file *file)
53{
d4062fcb
ML
54 struct snap *sp = file->private_data;
55 file->private_data = NULL;
56 kfree(sp);
1da177e4
LT
57 return 0;
58}
59
066202dd 60const struct file_operations mon_fops_stat = {
1da177e4
LT
61 .owner = THIS_MODULE,
62 .open = mon_stat_open,
63 .llseek = no_llseek,
64 .read = mon_stat_read,
65 /* .write = mon_stat_write, */
66 /* .poll = mon_stat_poll, */
55929332 67 /* .unlocked_ioctl = mon_stat_ioctl, */
1da177e4
LT
68 .release = mon_stat_release,
69};
This page took 0.689175 seconds and 5 git commands to generate.