diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-23 02:59:04 (GMT) |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-10-23 02:59:04 (GMT) |
commit | 73ecf3a6e3f0206bf56a0fefe3b3eda042fb7034 (patch) | |
tree | 866f0ebb2b148479e93b5ac955097b1cc94ceb4e /fs/proc/proc_tty.c | |
parent | b9da0571050c09863e59f94d0b8594a290d61b88 (diff) | |
parent | cd3ecad19aea8debae9a48b53de2ec7a571f24e9 (diff) | |
download | linux-73ecf3a6e3f0206bf56a0fefe3b3eda042fb7034.tar.xz |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty-2.6: (49 commits)
serial8250: ratelimit "too much work" error
serial: bfin_sport_uart: speed up sport RX sample rate to be 3% faster
serial: abstraction for 8250 legacy ports
serial/imx: check that the buffer is non-empty before sending it out
serial: mfd: add more baud rates support
jsm: Remove the uart port on errors
Alchemy: Add UART PM methods.
8250: allow platforms to override PM hook.
altera_uart: Don't use plain integer as NULL pointer
altera_uart: Fix missing prototype for registering an early console
altera_uart: Fixup type usage of port flags
altera_uart: Make it possible to use Altera UART and 8250 ports together
altera_uart: Add support for different address strides
altera_uart: Add support for getting mapbase and IRQ from resources
altera_uart: Add support for polling mode (IRQ-less)
serial: Factor out uart_poll_timeout() from 8250 driver
serial: mark the 8250 driver as maintained
serial: 8250: Don't delay after transmitter is ready.
tty: MAINTAINERS: add drivers/serial/jsm/ as maintained driver
vcs: invoke the vt update callback when /dev/vcs* is written to
...
Diffstat (limited to 'fs/proc/proc_tty.c')
-rw-r--r-- | fs/proc/proc_tty.c | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/fs/proc/proc_tty.c b/fs/proc/proc_tty.c index 83adcc8..dc44f94 100644 --- a/fs/proc/proc_tty.c +++ b/fs/proc/proc_tty.c @@ -12,7 +12,10 @@ #include <linux/proc_fs.h> #include <linux/stat.h> #include <linux/tty.h> +#include <linux/tty_driver.h> +#include <linux/console.h> #include <linux/seq_file.h> +#include <linux/fdtable.h> #include <linux/bitops.h> /* @@ -137,6 +140,160 @@ static const struct file_operations proc_tty_drivers_operations = { }; /* + * The device ID of file descriptor 0 of the current reading + * task if a character device... + */ +static dev_t current_dev; + +/* + * This is the handler for /proc/tty/consoles + */ +static int show_console_dev(struct seq_file *m, void *v) +{ + const struct tty_driver *driver; + struct console *con; + int index, len; + char flags[10]; + dev_t dev; + + if (v == SEQ_START_TOKEN) + return 0; + con = (struct console *)v; + if (!con) + return 0; + driver = con->device(con, &index); + if (!driver) + return 0; + dev = MKDEV(driver->major, driver->minor_start) + index; + + index = 0; + if (con->flags & CON_ENABLED) + flags[index++] = 'E'; + if (con->flags & CON_CONSDEV) + flags[index++] = 'C'; + if (con->flags & CON_BOOT) + flags[index++] = 'B'; + if (con->flags & CON_PRINTBUFFER) + flags[index++] = 'p'; + if (con->flags & CON_BRL) + flags[index++] = 'b'; + if (con->flags & CON_ANYTIME) + flags[index++] = 'a'; + if (current_dev == dev) + flags[index++] = '*'; + flags[index] = 0; + + seq_printf(m, "%s%d%n", con->name, con->index, &len); + len = 21 - len; + if (len < 1) + len = 1; + seq_printf(m, "%*c", len, ' '); + seq_printf(m, "%c%c%c (%s)%n", con->read ? 'R' : '-', + con->write ? 'W' : '-', con->unblank ? 'U' : '-', + flags, &len); + len = 13 - len; + if (len < 1) + len = 1; + seq_printf(m, "%*c%4d:%d\n", len, ' ', MAJOR(dev), MINOR(dev)); + + return 0; +} + +/* iterator for consoles */ +static void *c_start(struct seq_file *m, loff_t *pos) +{ + struct console *con; + loff_t off = 0; + + if (*pos == 0) + return SEQ_START_TOKEN; + + acquire_console_sem(); + for (con = console_drivers; con; con = con->next) { + if (!con->device) + continue; + if (++off == *pos) + break; + } + release_console_sem(); + + return con; +} + +static void *c_next(struct seq_file *m, void *v, loff_t *pos) +{ + struct console *con; + + acquire_console_sem(); + if (v == SEQ_START_TOKEN) + con = console_drivers; + else + con = ((struct console *)v)->next; + for (; con; con = con->next) { + if (!con->device) + continue; + ++*pos; + break; + } + release_console_sem(); + + return con; +} + +static void c_stop(struct seq_file *m, void *v) +{ +} + +static const struct seq_operations tty_consoles_op = { + .start = c_start, + .next = c_next, + .stop = c_stop, + .show = show_console_dev +}; + +/* + * Used for open /proc/tty/consoles. Before this detect + * the device ID of file descriptor 0 of the current + * reading task if a character device... + */ +static int tty_consoles_open(struct inode *inode, struct file *file) +{ + struct files_struct *curfiles; + + current_dev = 0; + curfiles = get_files_struct(current); + if (curfiles) { + const struct file *curfp; + spin_lock(&curfiles->file_lock); + curfp = fcheck_files(curfiles, 0); + if (curfp && curfp->private_data) { + const struct inode *inode; + dget(curfp->f_dentry); + inode = curfp->f_dentry->d_inode; + if (S_ISCHR(inode->i_mode)) { + struct tty_struct *tty; + tty = (struct tty_struct *)curfp->private_data; + if (tty && tty->magic == TTY_MAGIC) { + tty = tty_pair_get_tty(tty); + current_dev = tty_devnum(tty); + } + } + dput(curfp->f_dentry); + } + spin_unlock(&curfiles->file_lock); + put_files_struct(curfiles); + } + return seq_open(file, &tty_consoles_op); +} + +static const struct file_operations proc_tty_consoles_operations = { + .open = tty_consoles_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; + +/* * This function is called by tty_register_driver() to handle * registering the driver's /proc handler into /proc/tty/driver/<foo> */ @@ -186,4 +343,5 @@ void __init proc_tty_init(void) proc_tty_driver = proc_mkdir_mode("tty/driver", S_IRUSR|S_IXUSR, NULL); proc_create("tty/ldiscs", 0, NULL, &tty_ldiscs_proc_fops); proc_create("tty/drivers", 0, NULL, &proc_tty_drivers_operations); + proc_create("tty/consoles", 0, NULL, &proc_tty_consoles_operations); } |