Commit 7e411172 authored by Alexander Viro's avatar Alexander Viro Committed by Christoph Hellwig

[PATCH] tty cleanups (3/12)

	/proc/tty/drivers converted to seq_file
parent 27e8099f
...@@ -12,13 +12,12 @@ ...@@ -12,13 +12,12 @@
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/stat.h> #include <linux/stat.h>
#include <linux/tty.h> #include <linux/tty.h>
#include <linux/seq_file.h>
#include <asm/bitops.h> #include <asm/bitops.h>
extern struct tty_ldisc ldiscs[]; extern struct tty_ldisc ldiscs[];
static int tty_drivers_read_proc(char *page, char **start, off_t off,
int count, int *eof, void *data);
static int tty_ldiscs_read_proc(char *page, char **start, off_t off, static int tty_ldiscs_read_proc(char *page, char **start, off_t off,
int count, int *eof, void *data); int count, int *eof, void *data);
...@@ -30,72 +29,95 @@ static struct proc_dir_entry *proc_tty_ldisc, *proc_tty_driver; ...@@ -30,72 +29,95 @@ static struct proc_dir_entry *proc_tty_ldisc, *proc_tty_driver;
/* /*
* This is the handler for /proc/tty/drivers * This is the handler for /proc/tty/drivers
*/ */
static int tty_drivers_read_proc(char *page, char **start, off_t off, static int show_tty_driver(struct seq_file *m, void *v)
int count, int *eof, void *data)
{ {
int len = 0; struct tty_driver *p = v;
off_t begin = 0;
struct tty_driver *p; seq_printf(m, "%-20s ", p->driver_name ? p->driver_name : "unknown");
char range[20], deftype[20]; seq_printf(m, "/dev/%-8s ", p->name);
char *type; if (p->num > 1) {
char range[20];
list_for_each_entry(p, &tty_drivers, tty_drivers) { sprintf(range, "%d-%d", p->minor_start,
if (p->num > 1) p->minor_start + p->num - 1);
sprintf(range, "%d-%d", p->minor_start, seq_printf(m, "%3d %7s ", p->major, range);
p->minor_start + p->num - 1); } else {
seq_printf(m, "%3d %7d ", p->major, p->minor_start);
}
switch (p->type) {
case TTY_DRIVER_TYPE_SYSTEM:
seq_printf(m, "system");
if (p->subtype == SYSTEM_TYPE_TTY)
seq_printf(m, ":/dev/tty");
else if (p->subtype == SYSTEM_TYPE_SYSCONS)
seq_printf(m, ":console");
else if (p->subtype == SYSTEM_TYPE_CONSOLE)
seq_printf(m, ":vtmaster");
break;
case TTY_DRIVER_TYPE_CONSOLE:
seq_printf(m, "console");
break;
case TTY_DRIVER_TYPE_SERIAL:
seq_printf(m, "serial");
if (p->subtype == 2)
seq_printf(m, ":callout");
break;
case TTY_DRIVER_TYPE_PTY:
if (p->subtype == PTY_TYPE_MASTER)
seq_printf(m, "pty:master");
else if (p->subtype == PTY_TYPE_SLAVE)
seq_printf(m, "pty:slave");
else else
sprintf(range, "%d", p->minor_start); seq_printf(m, "pty");
switch (p->type) { break;
case TTY_DRIVER_TYPE_SYSTEM: default:
if (p->subtype == SYSTEM_TYPE_TTY) seq_printf(m, "type:%d.%d", p->type, p->subtype);
type = "system:/dev/tty";
else if (p->subtype == SYSTEM_TYPE_SYSCONS)
type = "system:console";
else if (p->subtype == SYSTEM_TYPE_CONSOLE)
type = "system:vtmaster";
else
type = "system";
break;
case TTY_DRIVER_TYPE_CONSOLE:
type = "console";
break;
case TTY_DRIVER_TYPE_SERIAL:
if (p->subtype == 2)
type = "serial:callout";
else
type = "serial";
break;
case TTY_DRIVER_TYPE_PTY:
if (p->subtype == PTY_TYPE_MASTER)
type = "pty:master";
else if (p->subtype == PTY_TYPE_SLAVE)
type = "pty:slave";
else
type = "pty";
break;
default:
sprintf(deftype, "type:%d.%d", p->type, p->subtype);
type = deftype;
break;
}
len += sprintf(page+len, "%-20s /dev/%-8s %3d %7s %s\n",
p->driver_name ? p->driver_name : "unknown",
p->name, p->major, range, type);
if (len+begin > off+count)
break;
if (len+begin < off) {
begin += len;
len = 0;
}
} }
if (!p) seq_putc(m, '\n');
*eof = 1; return 0;
if (off >= len+begin) }
return 0;
*start = page + (off-begin); /* iterator */
return ((count < begin+len-off) ? count : begin+len-off); static void *t_start(struct seq_file *m, loff_t *pos)
{
struct list_head *p;
loff_t l = *pos;
list_for_each(p, &tty_drivers)
if (!l--)
return list_entry(p, struct tty_driver, tty_drivers);
return NULL;
}
static void *t_next(struct seq_file *m, void *v, loff_t *pos)
{
struct list_head *p = ((struct tty_driver *)v)->tty_drivers.next;
(*pos)++;
return p==&tty_drivers ? NULL :
list_entry(p, struct tty_driver, tty_drivers);
} }
static void t_stop(struct seq_file *m, void *v)
{
}
static struct seq_operations tty_drivers_op = {
.start = t_start,
.next = t_next,
.stop = t_stop,
.show = show_tty_driver
};
static int tty_drivers_open(struct inode *inode, struct file *file)
{
return seq_open(file, &tty_drivers_op);
}
static struct file_operations proc_tty_drivers_operations = {
.open = tty_drivers_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release,
};
/* /*
* This is the handler for /proc/tty/ldiscs * This is the handler for /proc/tty/ldiscs
*/ */
...@@ -170,11 +192,14 @@ void proc_tty_unregister_driver(struct tty_driver *driver) ...@@ -170,11 +192,14 @@ void proc_tty_unregister_driver(struct tty_driver *driver)
*/ */
void __init proc_tty_init(void) void __init proc_tty_init(void)
{ {
struct proc_dir_entry *entry;
if (!proc_mkdir("tty", 0)) if (!proc_mkdir("tty", 0))
return; return;
proc_tty_ldisc = proc_mkdir("tty/ldisc", 0); proc_tty_ldisc = proc_mkdir("tty/ldisc", 0);
proc_tty_driver = proc_mkdir("tty/driver", 0); proc_tty_driver = proc_mkdir("tty/driver", 0);
create_proc_read_entry("tty/ldiscs", 0, 0, tty_ldiscs_read_proc,NULL); create_proc_read_entry("tty/ldiscs", 0, 0, tty_ldiscs_read_proc,NULL);
create_proc_read_entry("tty/drivers", 0, 0, tty_drivers_read_proc,NULL); entry = create_proc_entry("tty/drivers", 0, NULL);
if (entry)
entry->proc_fops = &proc_tty_drivers_operations;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment