Commit 3d304176 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by Linus Torvalds

proc tty: switch ircomm to ->proc_fops

Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 6fd69d3c
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/seq_file.h>
#include <linux/termios.h> #include <linux/termios.h>
#include <linux/tty.h> #include <linux/tty.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
...@@ -72,8 +73,7 @@ static int ircomm_tty_control_indication(void *instance, void *sap, ...@@ -72,8 +73,7 @@ static int ircomm_tty_control_indication(void *instance, void *sap,
static void ircomm_tty_flow_indication(void *instance, void *sap, static void ircomm_tty_flow_indication(void *instance, void *sap,
LOCAL_FLOW cmd); LOCAL_FLOW cmd);
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
static int ircomm_tty_read_proc(char *buf, char **start, off_t offset, int len, static const struct file_operations ircomm_tty_proc_fops;
int *eof, void *unused);
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
static struct tty_driver *driver; static struct tty_driver *driver;
...@@ -98,7 +98,7 @@ static const struct tty_operations ops = { ...@@ -98,7 +98,7 @@ static const struct tty_operations ops = {
.hangup = ircomm_tty_hangup, .hangup = ircomm_tty_hangup,
.wait_until_sent = ircomm_tty_wait_until_sent, .wait_until_sent = ircomm_tty_wait_until_sent,
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
.read_proc = ircomm_tty_read_proc, .proc_fops = &ircomm_tty_proc_fops,
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
}; };
...@@ -1245,150 +1245,170 @@ static void ircomm_tty_flow_indication(void *instance, void *sap, ...@@ -1245,150 +1245,170 @@ static void ircomm_tty_flow_indication(void *instance, void *sap,
} }
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
static int ircomm_tty_line_info(struct ircomm_tty_cb *self, char *buf) static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
{ {
int ret=0; char sep;
ret += sprintf(buf+ret, "State: %s\n", ircomm_tty_state[self->state]); seq_printf(m, "State: %s\n", ircomm_tty_state[self->state]);
ret += sprintf(buf+ret, "Service type: "); seq_puts(m, "Service type: ");
if (self->service_type & IRCOMM_9_WIRE) if (self->service_type & IRCOMM_9_WIRE)
ret += sprintf(buf+ret, "9_WIRE"); seq_puts(m, "9_WIRE");
else if (self->service_type & IRCOMM_3_WIRE) else if (self->service_type & IRCOMM_3_WIRE)
ret += sprintf(buf+ret, "3_WIRE"); seq_puts(m, "3_WIRE");
else if (self->service_type & IRCOMM_3_WIRE_RAW) else if (self->service_type & IRCOMM_3_WIRE_RAW)
ret += sprintf(buf+ret, "3_WIRE_RAW"); seq_puts(m, "3_WIRE_RAW");
else else
ret += sprintf(buf+ret, "No common service type!\n"); seq_puts(m, "No common service type!\n");
ret += sprintf(buf+ret, "\n"); seq_putc(m, '\n');
ret += sprintf(buf+ret, "Port name: %s\n", self->settings.port_name); seq_printf(m, "Port name: %s\n", self->settings.port_name);
ret += sprintf(buf+ret, "DTE status: "); seq_printf(m, "DTE status:");
if (self->settings.dte & IRCOMM_RTS) sep = ' ';
ret += sprintf(buf+ret, "RTS|"); if (self->settings.dte & IRCOMM_RTS) {
if (self->settings.dte & IRCOMM_DTR) seq_printf(m, "%cRTS", sep);
ret += sprintf(buf+ret, "DTR|"); sep = '|';
if (self->settings.dte) }
ret--; /* remove the last | */ if (self->settings.dte & IRCOMM_DTR) {
ret += sprintf(buf+ret, "\n"); seq_printf(m, "%cDTR", sep);
sep = '|';
ret += sprintf(buf+ret, "DCE status: "); }
if (self->settings.dce & IRCOMM_CTS) seq_putc(m, '\n');
ret += sprintf(buf+ret, "CTS|");
if (self->settings.dce & IRCOMM_DSR) seq_puts(m, "DCE status:");
ret += sprintf(buf+ret, "DSR|"); sep = ' ';
if (self->settings.dce & IRCOMM_CD) if (self->settings.dce & IRCOMM_CTS) {
ret += sprintf(buf+ret, "CD|"); seq_printf(m, "%cCTS", sep);
if (self->settings.dce & IRCOMM_RI) sep = '|';
ret += sprintf(buf+ret, "RI|"); }
if (self->settings.dce) if (self->settings.dce & IRCOMM_DSR) {
ret--; /* remove the last | */ seq_printf(m, "%cDSR", sep);
ret += sprintf(buf+ret, "\n"); sep = '|';
}
ret += sprintf(buf+ret, "Configuration: "); if (self->settings.dce & IRCOMM_CD) {
seq_printf(m, "%cCD", sep);
sep = '|';
}
if (self->settings.dce & IRCOMM_RI) {
seq_printf(m, "%cRI", sep);
sep = '|';
}
seq_putc(m, '\n');
seq_puts(m, "Configuration: ");
if (!self->settings.null_modem) if (!self->settings.null_modem)
ret += sprintf(buf+ret, "DTE <-> DCE\n"); seq_puts(m, "DTE <-> DCE\n");
else else
ret += sprintf(buf+ret, seq_puts(m, "DTE <-> DTE (null modem emulation)\n");
"DTE <-> DTE (null modem emulation)\n");
seq_printf(m, "Data rate: %d\n", self->settings.data_rate);
ret += sprintf(buf+ret, "Data rate: %d\n", self->settings.data_rate);
seq_puts(m, "Flow control:");
ret += sprintf(buf+ret, "Flow control: "); sep = ' ';
if (self->settings.flow_control & IRCOMM_XON_XOFF_IN) if (self->settings.flow_control & IRCOMM_XON_XOFF_IN) {
ret += sprintf(buf+ret, "XON_XOFF_IN|"); seq_printf(m, "%cXON_XOFF_IN", sep);
if (self->settings.flow_control & IRCOMM_XON_XOFF_OUT) sep = '|';
ret += sprintf(buf+ret, "XON_XOFF_OUT|"); }
if (self->settings.flow_control & IRCOMM_RTS_CTS_IN) if (self->settings.flow_control & IRCOMM_XON_XOFF_OUT) {
ret += sprintf(buf+ret, "RTS_CTS_IN|"); seq_printf(m, "%cXON_XOFF_OUT", sep);
if (self->settings.flow_control & IRCOMM_RTS_CTS_OUT) sep = '|';
ret += sprintf(buf+ret, "RTS_CTS_OUT|"); }
if (self->settings.flow_control & IRCOMM_DSR_DTR_IN) if (self->settings.flow_control & IRCOMM_RTS_CTS_IN) {
ret += sprintf(buf+ret, "DSR_DTR_IN|"); seq_printf(m, "%cRTS_CTS_IN", sep);
if (self->settings.flow_control & IRCOMM_DSR_DTR_OUT) sep = '|';
ret += sprintf(buf+ret, "DSR_DTR_OUT|"); }
if (self->settings.flow_control & IRCOMM_ENQ_ACK_IN) if (self->settings.flow_control & IRCOMM_RTS_CTS_OUT) {
ret += sprintf(buf+ret, "ENQ_ACK_IN|"); seq_printf(m, "%cRTS_CTS_OUT", sep);
if (self->settings.flow_control & IRCOMM_ENQ_ACK_OUT) sep = '|';
ret += sprintf(buf+ret, "ENQ_ACK_OUT|"); }
if (self->settings.flow_control) if (self->settings.flow_control & IRCOMM_DSR_DTR_IN) {
ret--; /* remove the last | */ seq_printf(m, "%cDSR_DTR_IN", sep);
ret += sprintf(buf+ret, "\n"); sep = '|';
}
ret += sprintf(buf+ret, "Flags: "); if (self->settings.flow_control & IRCOMM_DSR_DTR_OUT) {
if (self->flags & ASYNC_CTS_FLOW) seq_printf(m, "%cDSR_DTR_OUT", sep);
ret += sprintf(buf+ret, "ASYNC_CTS_FLOW|"); sep = '|';
if (self->flags & ASYNC_CHECK_CD) }
ret += sprintf(buf+ret, "ASYNC_CHECK_CD|"); if (self->settings.flow_control & IRCOMM_ENQ_ACK_IN) {
if (self->flags & ASYNC_INITIALIZED) seq_printf(m, "%cENQ_ACK_IN", sep);
ret += sprintf(buf+ret, "ASYNC_INITIALIZED|"); sep = '|';
if (self->flags & ASYNC_LOW_LATENCY) }
ret += sprintf(buf+ret, "ASYNC_LOW_LATENCY|"); if (self->settings.flow_control & IRCOMM_ENQ_ACK_OUT) {
if (self->flags & ASYNC_CLOSING) seq_printf(m, "%cENQ_ACK_OUT", sep);
ret += sprintf(buf+ret, "ASYNC_CLOSING|"); sep = '|';
if (self->flags & ASYNC_NORMAL_ACTIVE) }
ret += sprintf(buf+ret, "ASYNC_NORMAL_ACTIVE|"); seq_putc(m, '\n');
if (self->flags)
ret--; /* remove the last | */ seq_puts(m, "Flags:");
ret += sprintf(buf+ret, "\n"); sep = ' ';
if (self->flags & ASYNC_CTS_FLOW) {
ret += sprintf(buf+ret, "Role: %s\n", self->client ? seq_printf(m, "%cASYNC_CTS_FLOW", sep);
"client" : "server"); sep = '|';
ret += sprintf(buf+ret, "Open count: %d\n", self->open_count); }
ret += sprintf(buf+ret, "Max data size: %d\n", self->max_data_size); if (self->flags & ASYNC_CHECK_CD) {
ret += sprintf(buf+ret, "Max header size: %d\n", self->max_header_size); seq_printf(m, "%cASYNC_CHECK_CD", sep);
sep = '|';
}
if (self->flags & ASYNC_INITIALIZED) {
seq_printf(m, "%cASYNC_INITIALIZED", sep);
sep = '|';
}
if (self->flags & ASYNC_LOW_LATENCY) {
seq_printf(m, "%cASYNC_LOW_LATENCY", sep);
sep = '|';
}
if (self->flags & ASYNC_CLOSING) {
seq_printf(m, "%cASYNC_CLOSING", sep);
sep = '|';
}
if (self->flags & ASYNC_NORMAL_ACTIVE) {
seq_printf(m, "%cASYNC_NORMAL_ACTIVE", sep);
sep = '|';
}
seq_putc(m, '\n');
seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
seq_printf(m, "Open count: %d\n", self->open_count);
seq_printf(m, "Max data size: %d\n", self->max_data_size);
seq_printf(m, "Max header size: %d\n", self->max_header_size);
if (self->tty) if (self->tty)
ret += sprintf(buf+ret, "Hardware: %s\n", seq_printf(m, "Hardware: %s\n",
self->tty->hw_stopped ? "Stopped" : "Running"); self->tty->hw_stopped ? "Stopped" : "Running");
ret += sprintf(buf+ret, "\n");
return ret;
} }
static int ircomm_tty_proc_show(struct seq_file *m, void *v)
/*
* Function ircomm_tty_read_proc (buf, start, offset, len, eof, unused)
*
*
*
*/
static int ircomm_tty_read_proc(char *buf, char **start, off_t offset, int len,
int *eof, void *unused)
{ {
struct ircomm_tty_cb *self; struct ircomm_tty_cb *self;
int count = 0, l;
off_t begin = 0;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&ircomm_tty->hb_spinlock, flags); spin_lock_irqsave(&ircomm_tty->hb_spinlock, flags);
self = (struct ircomm_tty_cb *) hashbin_get_first(ircomm_tty); self = (struct ircomm_tty_cb *) hashbin_get_first(ircomm_tty);
while ((self != NULL) && (count < 4000)) { while (self != NULL) {
if (self->magic != IRCOMM_TTY_MAGIC) if (self->magic != IRCOMM_TTY_MAGIC)
break; break;
l = ircomm_tty_line_info(self, buf + count); ircomm_tty_line_info(self, m);
count += l;
if (count+begin > offset+len)
goto done;
if (count+begin < offset) {
begin += count;
count = 0;
}
self = (struct ircomm_tty_cb *) hashbin_get_next(ircomm_tty); self = (struct ircomm_tty_cb *) hashbin_get_next(ircomm_tty);
} }
*eof = 1;
done:
spin_unlock_irqrestore(&ircomm_tty->hb_spinlock, flags); spin_unlock_irqrestore(&ircomm_tty->hb_spinlock, flags);
if (offset >= count+begin)
return 0; return 0;
*start = buf + (offset-begin);
return ((len < begin+count-offset) ? len : begin+count-offset);
} }
static int ircomm_tty_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, ircomm_tty_proc_show, NULL);
}
static const struct file_operations ircomm_tty_proc_fops = {
.owner = THIS_MODULE,
.open = ircomm_tty_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>"); MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
......
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