1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39#include <linux/module.h>
40#include <linux/proc_fs.h>
41#include <linux/tty.h>
42#include <linux/sched.h>
43#include <linux/seq_file.h>
44
45#include "dgrp_common.h"
46
47
48static int dgrp_ports_open(struct inode *, struct file *);
49
50const struct file_operations dgrp_ports_ops = {
51 .owner = THIS_MODULE,
52 .open = dgrp_ports_open,
53 .read = seq_read,
54 .llseek = seq_lseek,
55 .release = seq_release
56};
57
58static void *dgrp_ports_seq_start(struct seq_file *seq, loff_t *pos)
59{
60 if (*pos == 0)
61 seq_puts(seq, "#num tty_open pr_open tot_wait MSTAT IFLAG OFLAG CFLAG BPS DIGIFLAGS\n");
62
63 return pos;
64}
65
66static void *dgrp_ports_seq_next(struct seq_file *seq, void *v, loff_t *pos)
67{
68 struct nd_struct *nd = seq->private;
69
70 if (*pos >= nd->nd_chan_count)
71 return NULL;
72
73 *pos += 1;
74
75 return pos;
76}
77
78static void dgrp_ports_seq_stop(struct seq_file *seq, void *v)
79{
80}
81
82static int dgrp_ports_seq_show(struct seq_file *seq, void *v)
83{
84 loff_t *pos = v;
85 struct nd_struct *nd;
86 struct ch_struct *ch;
87 struct un_struct *tun, *pun;
88 unsigned int totcnt;
89
90 nd = seq->private;
91 if (!nd)
92 return 0;
93
94 if (*pos >= nd->nd_chan_count)
95 return 0;
96
97 ch = &nd->nd_chan[*pos];
98 tun = &ch->ch_tun;
99 pun = &ch->ch_pun;
100
101
102
103
104
105
106 totcnt = tun->un_open_count +
107 pun->un_open_count +
108 ch->ch_wait_count[0] +
109 ch->ch_wait_count[1] +
110 ch->ch_wait_count[2];
111
112 seq_printf(seq, "%02d %02d %02d %02d 0x%04X 0x%04X 0x%04X 0x%04X %-6d 0x%04X\n",
113 (int) *pos,
114 tun->un_open_count,
115 pun->un_open_count,
116 ch->ch_wait_count[0] +
117 ch->ch_wait_count[1] +
118 ch->ch_wait_count[2],
119 (totcnt ? ch->ch_s_mlast : 0),
120 ch->ch_s_iflag,
121 ch->ch_s_oflag,
122 ch->ch_s_cflag,
123 (ch->ch_s_brate ? (1843200 / ch->ch_s_brate) : 0),
124 ch->ch_digi.digi_flags);
125
126 return 0;
127}
128
129static const struct seq_operations ports_seq_ops = {
130 .start = dgrp_ports_seq_start,
131 .next = dgrp_ports_seq_next,
132 .stop = dgrp_ports_seq_stop,
133 .show = dgrp_ports_seq_show,
134};
135
136
137
138
139
140
141
142
143
144static int dgrp_ports_open(struct inode *inode, struct file *file)
145{
146 struct seq_file *seq;
147 int rtn;
148
149 rtn = seq_open(file, &ports_seq_ops);
150 if (!rtn) {
151 seq = file->private_data;
152 seq->private = PDE_DATA(inode);
153 }
154
155 return rtn;
156}
157