Blame view

fs/proc/proc_tty.c 4.47 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  // SPDX-License-Identifier: GPL-2.0
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
  /*
   * proc_tty.c -- handles /proc/tty
   *
   * Copyright 1997, Theodore Ts'o
   */
7c0f6ba68   Linus Torvalds   Replace <asm/uacc...
7
  #include <linux/uaccess.h>
b640a89dd   Alexey Dobriyan   proc: convert /pr...
8
  #include <linux/module.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
9
10
11
12
13
14
15
16
  #include <linux/init.h>
  #include <linux/errno.h>
  #include <linux/time.h>
  #include <linux/proc_fs.h>
  #include <linux/stat.h>
  #include <linux/tty.h>
  #include <linux/seq_file.h>
  #include <linux/bitops.h>
c79dde629   nixiaoming   tty fix oops when...
17
  #include "internal.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
20
21
  /*
   * The /proc/tty directory inodes...
   */
849d20a12   Alexey Dobriyan   proc: remove proc...
22
  static struct proc_dir_entry *proc_tty_driver;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  
  /*
   * This is the handler for /proc/tty/drivers
   */
  static void show_tty_range(struct seq_file *m, struct tty_driver *p,
  	dev_t from, int num)
  {
  	seq_printf(m, "%-20s ", p->driver_name ? p->driver_name : "unknown");
  	seq_printf(m, "/dev/%-8s ", p->name);
  	if (p->num > 1) {
  		seq_printf(m, "%3d %d-%d ", MAJOR(from), MINOR(from),
  			MINOR(from) + num - 1);
  	} else {
  		seq_printf(m, "%3d %7d ", MAJOR(from), MINOR(from));
  	}
  	switch (p->type) {
  	case TTY_DRIVER_TYPE_SYSTEM:
9d6de12f7   Alexey Dobriyan   proc: use seq_put...
40
  		seq_puts(m, "system");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
  		if (p->subtype == SYSTEM_TYPE_TTY)
9d6de12f7   Alexey Dobriyan   proc: use seq_put...
42
  			seq_puts(m, ":/dev/tty");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
  		else if (p->subtype == SYSTEM_TYPE_SYSCONS)
9d6de12f7   Alexey Dobriyan   proc: use seq_put...
44
  			seq_puts(m, ":console");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
45
  		else if (p->subtype == SYSTEM_TYPE_CONSOLE)
9d6de12f7   Alexey Dobriyan   proc: use seq_put...
46
  			seq_puts(m, ":vtmaster");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
47
48
  		break;
  	case TTY_DRIVER_TYPE_CONSOLE:
9d6de12f7   Alexey Dobriyan   proc: use seq_put...
49
  		seq_puts(m, "console");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
51
  		break;
  	case TTY_DRIVER_TYPE_SERIAL:
9d6de12f7   Alexey Dobriyan   proc: use seq_put...
52
  		seq_puts(m, "serial");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
54
55
  		break;
  	case TTY_DRIVER_TYPE_PTY:
  		if (p->subtype == PTY_TYPE_MASTER)
9d6de12f7   Alexey Dobriyan   proc: use seq_put...
56
  			seq_puts(m, "pty:master");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57
  		else if (p->subtype == PTY_TYPE_SLAVE)
9d6de12f7   Alexey Dobriyan   proc: use seq_put...
58
  			seq_puts(m, "pty:slave");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
  		else
9d6de12f7   Alexey Dobriyan   proc: use seq_put...
60
  			seq_puts(m, "pty");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
62
63
64
65
66
67
68
69
70
  		break;
  	default:
  		seq_printf(m, "type:%d.%d", p->type, p->subtype);
  	}
  	seq_putc(m, '
  ');
  }
  
  static int show_tty_driver(struct seq_file *m, void *v)
  {
25216b003   Pavel Emelianov   Make /proc/tty/dr...
71
  	struct tty_driver *p = list_entry(v, struct tty_driver, tty_drivers);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
73
74
75
76
77
78
  	dev_t from = MKDEV(p->major, p->minor_start);
  	dev_t to = from + p->num;
  
  	if (&p->tty_drivers == tty_drivers.next) {
  		/* pseudo-drivers first */
  		seq_printf(m, "%-20s /dev/%-8s ", "/dev/tty", "tty");
  		seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 0);
9d6de12f7   Alexey Dobriyan   proc: use seq_put...
79
80
  		seq_puts(m, "system:/dev/tty
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81
82
  		seq_printf(m, "%-20s /dev/%-8s ", "/dev/console", "console");
  		seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 1);
9d6de12f7   Alexey Dobriyan   proc: use seq_put...
83
84
  		seq_puts(m, "system:console
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85
86
87
  #ifdef CONFIG_UNIX98_PTYS
  		seq_printf(m, "%-20s /dev/%-8s ", "/dev/ptmx", "ptmx");
  		seq_printf(m, "%3d %7d ", TTYAUX_MAJOR, 2);
9d6de12f7   Alexey Dobriyan   proc: use seq_put...
88
89
  		seq_puts(m, "system
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
91
92
93
  #endif
  #ifdef CONFIG_VT
  		seq_printf(m, "%-20s /dev/%-8s ", "/dev/vc/0", "vc/0");
  		seq_printf(m, "%3d %7d ", TTY_MAJOR, 0);
9d6de12f7   Alexey Dobriyan   proc: use seq_put...
94
95
  		seq_puts(m, "system:vtmaster
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  #endif
  	}
  
  	while (MAJOR(from) < MAJOR(to)) {
  		dev_t next = MKDEV(MAJOR(from)+1, 0);
  		show_tty_range(m, p, from, next - from);
  		from = next;
  	}
  	if (from != to)
  		show_tty_range(m, p, from, to - from);
  	return 0;
  }
  
  /* iterator */
  static void *t_start(struct seq_file *m, loff_t *pos)
  {
ca509f69d   Alexey Dobriyan   Protect tty drive...
112
  	mutex_lock(&tty_mutex);
25216b003   Pavel Emelianov   Make /proc/tty/dr...
113
  	return seq_list_start(&tty_drivers, *pos);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
114
115
116
117
  }
  
  static void *t_next(struct seq_file *m, void *v, loff_t *pos)
  {
25216b003   Pavel Emelianov   Make /proc/tty/dr...
118
  	return seq_list_next(v, &tty_drivers, pos);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119
120
121
122
  }
  
  static void t_stop(struct seq_file *m, void *v)
  {
ca509f69d   Alexey Dobriyan   Protect tty drive...
123
  	mutex_unlock(&tty_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
124
  }
03a44825b   Jan Engelhardt   procfs: constify ...
125
  static const struct seq_operations tty_drivers_op = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
126
127
128
129
130
  	.start	= t_start,
  	.next	= t_next,
  	.stop	= t_stop,
  	.show	= show_tty_driver
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131
132
133
134
135
136
137
138
  /*
   * This function is called by tty_register_driver() to handle
   * registering the driver's /proc handler into /proc/tty/driver/<foo>
   */
  void proc_tty_register_driver(struct tty_driver *driver)
  {
  	struct proc_dir_entry *ent;
  		
0f043a81e   Alexey Dobriyan   proc tty: remove ...
139
  	if (!driver->driver_name || driver->proc_entry ||
8a8dcabff   Christoph Hellwig   tty: replace ->pr...
140
  	    !driver->ops->proc_show)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
141
  		return;
8a8dcabff   Christoph Hellwig   tty: replace ->pr...
142
143
  	ent = proc_create_single_data(driver->driver_name, 0, proc_tty_driver,
  			       driver->ops->proc_show, driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
144
145
146
147
148
149
150
151
152
153
154
155
156
157
  	driver->proc_entry = ent;
  }
  
  /*
   * This function is called by tty_unregister_driver()
   */
  void proc_tty_unregister_driver(struct tty_driver *driver)
  {
  	struct proc_dir_entry *ent;
  
  	ent = driver->proc_entry;
  	if (!ent)
  		return;
  		
c79dde629   nixiaoming   tty fix oops when...
158
  	remove_proc_entry(ent->name, proc_tty_driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
159
160
161
162
163
164
165
166
167
  	
  	driver->proc_entry = NULL;
  }
  
  /*
   * Called by proc_root_init() to initialize the /proc/tty subtree
   */
  void __init proc_tty_init(void)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
168
169
  	if (!proc_mkdir("tty", NULL))
  		return;
849d20a12   Alexey Dobriyan   proc: remove proc...
170
  	proc_mkdir("tty/ldisc", NULL);	/* Preserved: it's userspace visible */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
171
172
173
174
175
176
  	/*
  	 * /proc/tty/driver/serial reveals the exact character counts for
  	 * serial links which is just too easy to abuse for inferring
  	 * password lengths and inter-keystroke timings during password
  	 * entry.
  	 */
b640a89dd   Alexey Dobriyan   proc: convert /pr...
177
  	proc_tty_driver = proc_mkdir_mode("tty/driver", S_IRUSR|S_IXUSR, NULL);
fddda2b7b   Christoph Hellwig   proc: introduce p...
178
179
  	proc_create_seq("tty/ldiscs", 0, NULL, &tty_ldiscs_seq_ops);
  	proc_create_seq("tty/drivers", 0, NULL, &tty_drivers_op);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
180
  }