This source file includes following definitions.
- get_not_present_info
- proc_readscsi
- proc_writescsi
- proc_scsilseek
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #include <linux/errno.h>
24 #include <linux/sched.h>
25 #include <linux/proc_fs.h>
26 #include <linux/stat.h>
27 #include <linux/mm.h>
28
29 #include <asm/segment.h>
30
31
32 static int proc_readscsi(struct inode * inode, struct file * file,
33 char * buf, int count);
34 static int proc_writescsi(struct inode * inode, struct file * file,
35 const char * buf, int count);
36 static int proc_scsilseek(struct inode *, struct file *, off_t, int);
37
38 extern void build_proc_dir_hba_entries(uint);
39
40
41 int (* dispatch_scsi_info_ptr) (int ino, char *buffer, char **start,
42 off_t offset, int length, int inout) = 0;
43
44 static struct file_operations proc_scsi_operations = {
45 proc_scsilseek,
46 proc_readscsi,
47 proc_writescsi,
48 proc_readdir,
49 NULL,
50 NULL,
51 NULL,
52 NULL,
53 NULL,
54 NULL
55 };
56
57
58
59
60 struct inode_operations proc_scsi_inode_operations = {
61 &proc_scsi_operations,
62 NULL,
63 proc_lookup,
64 NULL,
65 NULL,
66 NULL,
67 NULL,
68 NULL,
69 NULL,
70 NULL,
71 NULL,
72 NULL,
73 NULL,
74 NULL,
75 NULL,
76 NULL,
77 NULL
78 };
79
80 int get_not_present_info(char *buffer, char **start, off_t offset, int length)
81 {
82 int len, pos, begin;
83
84 begin = 0;
85 pos = len = sprintf(buffer,
86 "No low-level scsi modules are currently present\n");
87 if(pos < offset) {
88 len = 0;
89 begin = pos;
90 }
91
92 *start = buffer + (offset - begin);
93 len -= (offset - begin);
94 if(len > length)
95 len = length;
96
97 return(len);
98 }
99
100 #define PROC_BLOCK_SIZE (3*1024)
101
102
103
104 static int proc_readscsi(struct inode * inode, struct file * file,
105 char * buf, int count)
106 {
107 int length;
108 int bytes = count;
109 int copied = 0;
110 int thistime;
111 char * page;
112 char * start;
113
114 if (count < -1)
115 return(-EINVAL);
116
117
118 if (!(page = (char *) __get_free_page(GFP_KERNEL)))
119 return(-ENOMEM);
120
121 while(bytes > 0 || count == -1) {
122 thistime = bytes;
123 if(bytes > PROC_BLOCK_SIZE || count == -1)
124 thistime = PROC_BLOCK_SIZE;
125
126 if(dispatch_scsi_info_ptr)
127 length = dispatch_scsi_info_ptr(inode->i_ino, page, &start,
128 file->f_pos, thistime, 0);
129 else
130 length = get_not_present_info(page, &start, file->f_pos, thistime);
131 if(length < 0) {
132 free_page((ulong) page);
133 return(length);
134 }
135
136
137
138
139
140
141 if (length <= 0)
142 break;
143
144
145
146
147 if (count != -1)
148 memcpy_tofs(buf + copied, start, length);
149 file->f_pos += length;
150 bytes -= length;
151 copied += length;
152
153 if(length < thistime)
154 break;
155
156 }
157
158 free_page((ulong) page);
159 return(copied);
160 }
161
162
163 static int proc_writescsi(struct inode * inode, struct file * file,
164 const char * buf, int count)
165 {
166 int ret = 0;
167 char * page;
168
169 if(count > PROC_BLOCK_SIZE) {
170 return(-EOVERFLOW);
171 }
172
173 if(dispatch_scsi_info_ptr != NULL) {
174 if (!(page = (char *) __get_free_page(GFP_KERNEL)))
175 return(-ENOMEM);
176 memcpy_fromfs(page, buf, count);
177 ret = dispatch_scsi_info_ptr(inode->i_ino, page, 0, 0, count, 1);
178 } else
179 return(-ENOPKG);
180
181 free_page((ulong) page);
182 return(ret);
183 }
184
185
186 static int proc_scsilseek(struct inode * inode, struct file * file,
187 off_t offset, int orig)
188 {
189 switch (orig) {
190 case 0:
191 file->f_pos = offset;
192 return(file->f_pos);
193 case 1:
194 file->f_pos += offset;
195 return(file->f_pos);
196 case 2:
197 if (offset)
198 return(-EINVAL);
199 proc_readscsi(inode, file, 0, -1);
200 return(file->f_pos);
201 default:
202 return(-EINVAL);
203 }
204 }
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223