Loading...
1/*
2 * /proc interface for comedi
3 *
4 * COMEDI - Linux Control and Measurement Device Interface
5 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18/*
19 * This is some serious bloatware.
20 *
21 * Taken from Dave A.'s PCL-711 driver, 'cuz I thought it
22 * was cool.
23 */
24
25#include "comedidev.h"
26#include "comedi_internal.h"
27#include <linux/proc_fs.h>
28#include <linux/seq_file.h>
29
30static int comedi_read(struct seq_file *m, void *v)
31{
32 int i;
33 int devices_q = 0;
34 struct comedi_driver *driv;
35
36 seq_printf(m, "comedi version " COMEDI_RELEASE "\nformat string: %s\n",
37 "\"%2d: %-20s %-20s %4d\", i, driver_name, board_name, n_subdevices");
38
39 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
40 struct comedi_device *dev = comedi_dev_get_from_minor(i);
41
42 if (!dev)
43 continue;
44
45 down_read(&dev->attach_lock);
46 if (dev->attached) {
47 devices_q = 1;
48 seq_printf(m, "%2d: %-20s %-20s %4d\n",
49 i, dev->driver->driver_name,
50 dev->board_name, dev->n_subdevices);
51 }
52 up_read(&dev->attach_lock);
53 comedi_dev_put(dev);
54 }
55 if (!devices_q)
56 seq_puts(m, "no devices\n");
57
58 mutex_lock(&comedi_drivers_list_lock);
59 for (driv = comedi_drivers; driv; driv = driv->next) {
60 seq_printf(m, "%s:\n", driv->driver_name);
61 for (i = 0; i < driv->num_names; i++)
62 seq_printf(m, " %s\n",
63 *(char **)((char *)driv->board_name +
64 i * driv->offset));
65
66 if (!driv->num_names)
67 seq_printf(m, " %s\n", driv->driver_name);
68 }
69 mutex_unlock(&comedi_drivers_list_lock);
70
71 return 0;
72}
73
74/*
75 * seq_file wrappers for procfile show routines.
76 */
77static int comedi_proc_open(struct inode *inode, struct file *file)
78{
79 return single_open(file, comedi_read, NULL);
80}
81
82static const struct file_operations comedi_proc_fops = {
83 .open = comedi_proc_open,
84 .read = seq_read,
85 .llseek = seq_lseek,
86 .release = single_release,
87};
88
89void comedi_proc_init(void)
90{
91 proc_create("comedi", 0644, NULL, &comedi_proc_fops);
92}
93
94void comedi_proc_cleanup(void)
95{
96 remove_proc_entry("comedi", NULL);
97}
1/*
2 module/proc.c
3 /proc interface for comedi
4
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1998 David A. Schleef <ds@schleef.org>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
22*/
23
24/*
25 This is some serious bloatware.
26
27 Taken from Dave A.'s PCL-711 driver, 'cuz I thought it
28 was cool.
29*/
30
31#define __NO_VERSION__
32#include "comedidev.h"
33#include "comedi_fops.h"
34#include <linux/proc_fs.h>
35#include <linux/string.h>
36
37#ifdef CONFIG_PROC_FS
38static int comedi_read(char *buf, char **start, off_t offset, int len,
39 int *eof, void *data)
40{
41 int i;
42 int devices_q = 0;
43 int l = 0;
44 struct comedi_driver *driv;
45
46 l += sprintf(buf + l,
47 "comedi version " COMEDI_RELEASE "\n"
48 "format string: %s\n",
49 "\"%2d: %-20s %-20s %4d\", i, "
50 "driver_name, board_name, n_subdevices");
51
52 for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
53 struct comedi_device_file_info *dev_file_info =
54 comedi_get_device_file_info(i);
55 struct comedi_device *dev;
56
57 if (dev_file_info == NULL)
58 continue;
59 dev = dev_file_info->device;
60
61 if (dev->attached) {
62 devices_q = 1;
63 l += sprintf(buf + l, "%2d: %-20s %-20s %4d\n",
64 i,
65 dev->driver->driver_name,
66 dev->board_name, dev->n_subdevices);
67 }
68 }
69 if (!devices_q)
70 l += sprintf(buf + l, "no devices\n");
71
72 for (driv = comedi_drivers; driv; driv = driv->next) {
73 l += sprintf(buf + l, "%s:\n", driv->driver_name);
74 for (i = 0; i < driv->num_names; i++) {
75 l += sprintf(buf + l, " %s\n",
76 *(char **)((char *)driv->board_name +
77 i * driv->offset));
78 }
79 if (!driv->num_names)
80 l += sprintf(buf + l, " %s\n", driv->driver_name);
81 }
82
83 return l;
84}
85
86void comedi_proc_init(void)
87{
88 struct proc_dir_entry *comedi_proc;
89
90 comedi_proc = create_proc_entry("comedi", S_IFREG | S_IRUGO, NULL);
91 if (comedi_proc)
92 comedi_proc->read_proc = comedi_read;
93}
94
95void comedi_proc_cleanup(void)
96{
97 remove_proc_entry("comedi", NULL);
98}
99#endif