35 #include <linux/module.h>
36 #include <linux/tty.h>
37 #include <linux/sched.h>
40 #include <linux/ctype.h>
50 static int dgrp_add_id(
long id);
51 static int dgrp_remove_nd(
struct nd_struct *nd);
58 static int dgrp_gen_proc_open(
struct inode *,
struct file *);
59 static int dgrp_gen_proc_close(
struct inode *,
struct file *);
60 static int parse_write_config(
char *);
65 .open = dgrp_gen_proc_open,
66 .release = dgrp_gen_proc_close,
93 .open = config_proc_open,
97 .write = config_proc_write
102 .open = info_proc_open,
110 .open = nodeinfo_proc_open,
121 .proc_file_ops = &config_proc_file_ops,
127 .proc_file_ops = &info_proc_file_ops,
133 .proc_file_ops = &nodeinfo_proc_file_ops,
139 .child = dgrp_net_table
145 .child = dgrp_mon_table
151 .child = dgrp_ports_table
157 .child = dgrp_dpa_table
184 unregister_proc_table(dgrp_table, dgrp_proc_dir_entry);
185 net_entry_pointer =
NULL;
186 mon_entry_pointer =
NULL;
187 dpa_entry_pointer =
NULL;
188 ports_entry_pointer =
NULL;
190 if (dgrp_proc_dir_entry) {
192 dgrp_proc_dir_entry->
parent);
193 dgrp_proc_dir_entry =
NULL;
203 dgrp_proc_dir_entry = proc_create(
"dgrp",
S_IFDIR,
NULL,
204 &dgrp_proc_file_ops);
205 register_proc_table(dgrp_table, dgrp_proc_dir_entry);
235 for (; table->
id; table++) {
243 pr_warn(
"dgrp: Can't register %s\n",
257 if (dgrp_proc_match(len, table->
name, de))
267 de->
data = (
void *) table;
278 register_proc_table(table->
child, de);
281 net_entry_pointer = de;
284 mon_entry_pointer = de;
287 dpa_entry_pointer = de;
290 ports_entry_pointer = de;
307 if ((table == dgrp_net_table) && (tmp->
nd_net_de)) {
312 if ((table == dgrp_mon_table) && (tmp->
nd_mon_de))
315 if ((table == dgrp_dpa_table) && (tmp->
nd_dpa_de))
318 if ((table == dgrp_ports_table) && (tmp->
nd_ports_de))
322 for (; table->
id; table++) {
329 pr_alert(
"dgrp: malformed sysctl tree on free\n");
332 unregister_proc_table(table->
child, de);
341 pr_alert(
"proc entry %s in use, not removing\n",
358 if (!de || !de->
data) {
382 static int dgrp_gen_proc_close(
struct inode *inode,
struct file *file)
388 if (!de || !de->
data)
406 static void *config_proc_start(
struct seq_file *
m, loff_t *
pos)
411 static void *config_proc_next(
struct seq_file *
p,
void *
v, loff_t *
pos)
416 static void config_proc_stop(
struct seq_file *
m,
void *
v)
420 static int config_proc_show(
struct seq_file *
m,
void *
v)
426 seq_puts(m,
"#-----------------------------------------------------------------------------\n");
428 seq_puts(m,
"# ID Major State Ports\n");
434 ID_TO_CHAR(nd->
nd_ID, tmp_id);
436 seq_printf(m,
" %-2.2s %-5ld %-10.10s %-5d\n",
446 .start = config_proc_start,
447 .next = config_proc_next,
448 .stop = config_proc_stop,
449 .show = config_proc_show
452 static int config_proc_open(
struct inode *inode,
struct file *file)
454 return seq_open(file, &proc_config_ops);
463 static ssize_t config_proc_write(
struct file *file,
const char __user *
buffer,
473 inbuf = sp =
vzalloc(count + 1);
489 retval = parse_write_config(sp);
510 static inline char *skip_past_ws(
const char *
str)
512 while ((*str) && !
isspace(*str))
518 static int parse_id(
char **
c,
char *cID)
522 if (
isalnum(tmp) || (tmp ==
'_'))
529 if (
isalnum(tmp) || (tmp ==
'_')) {
538 static int parse_add_config(
char *
buf)
547 retval = parse_id(&c, cID);
551 ID = CHAR_TO_ID(cID);
555 return dgrp_add_id(ID);
558 static int parse_del_config(
char *buf)
569 retval = parse_id(&c, cID);
573 ID = CHAR_TO_ID(cID);
577 retval = kstrtol(c, 10, &major);
581 nd = nd_struct_get(major);
588 return dgrp_remove_nd(nd);
591 static int parse_chg_config(
char *buf)
607 static int parse_write_config(
char *buf)
613 retval = parse_add_config(buf);
616 retval = parse_del_config(buf);
619 retval = parse_chg_config(buf);
628 static int info_proc_show(
struct seq_file *m,
void *v)
631 seq_puts(m,
"register_with_sysfs: 1\n");
640 static int info_proc_open(
struct inode *inode,
struct file *file)
646 static void *nodeinfo_start(
struct seq_file *m, loff_t *pos)
651 static void *nodeinfo_next(
struct seq_file *
p,
void *v, loff_t *pos)
656 static void nodeinfo_stop(
struct seq_file *m,
void *v)
660 static int nodeinfo_show(
struct seq_file *m,
void *v)
668 seq_puts(m,
"#-----------------------------------------------------------------------------\n");
670 seq_puts(m,
"# ID State Version ID Version Description\n");
676 ID_TO_CHAR(nd->
nd_ID, tmp_id);
683 seq_printf(m,
" %-2.2s %-10.10s %-7.7s %-3d %-7.7s %-35.35s\n",
702 .start = nodeinfo_start,
703 .next = nodeinfo_next,
704 .stop = nodeinfo_stop,
705 .show = nodeinfo_show
708 static int nodeinfo_proc_open(
struct inode *inode,
struct file *file)
710 return seq_open(file, &nodeinfo_ops);
717 static int dgrp_add_id(
long id)
745 ret = nd_struct_add(nd);
752 register_dgrp_device(nd, ports_entry_pointer,
763 static int dgrp_remove_nd(
struct nd_struct *nd)
787 ret = nd_struct_del(nd);
795 static void register_dgrp_device(
struct nd_struct *node,
802 ID_TO_CHAR(node->
nd_ID, buf);
808 de->
data = (
void *) node;
822 pr_alert(
"%s - proc entry %s in use. Not removing.\n",