This source file includes following definitions.
- get_hba_index
- generic_proc_info
- dispatch_scsi_info
- count_templates
- build_proc_dir_hba_entries
- build_proc_dir_entries
- parseFree
- parseInit
- parseOpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 #ifdef MODULE
17
18
19
20
21 #define _SCSI_SYMS_VER_
22 #include <linux/autoconf.h>
23 #include <linux/module.h>
24 #include <linux/version.h>
25 #else
26 #define MOD_INC_USE_COUNT
27 #define MOD_DEC_USE_COUNT
28 #endif
29
30 #include <linux/string.h>
31 #include <linux/mm.h>
32 #include <linux/malloc.h>
33 #include <linux/proc_fs.h>
34 #include <linux/errno.h>
35 #include "../block/blk.h"
36 #include "scsi.h"
37 #include "hosts.h"
38
39 #ifndef TRUE
40 #define TRUE 1
41 #define FALSE 0
42 #endif
43
44 extern struct proc_dir_entry scsi_dir[];
45 extern struct proc_dir_entry scsi_hba_dir[];
46 extern int scsi_proc_info(char *, char **, off_t, int, int, int);
47
48
49 int get_hba_index(int ino)
50 {
51 Scsi_Host_Template *tpnt = scsi_hosts;
52 struct Scsi_Host *hpnt = scsi_hostlist;
53 uint x = 0;
54
55
56
57
58
59
60
61 while (tpnt) {
62 if (ino == tpnt->low_ino)
63 return(x);
64 x += 3;
65 while (hpnt) {
66 if(hpnt->hostt == tpnt)
67 x++;
68 hpnt = hpnt->next;
69 }
70 tpnt = tpnt->next;
71 }
72 return(0);
73 }
74
75
76
77
78 int generic_proc_info(char *buffer, char **start, off_t offset,
79 int length, int inode, int inout)
80 {
81 int len, pos, begin;
82
83 if(inout == TRUE)
84 return(-ENOSYS);
85
86 begin = 0;
87 pos = len = sprintf(buffer,
88 "The driver does not yet support the proc-fs\n");
89 if(pos < offset) {
90 len = 0;
91 begin = pos;
92 }
93
94 *start = buffer + (offset - begin);
95 len -= (offset - begin);
96 if(len > length)
97 len = length;
98
99 return(len);
100 }
101
102
103
104
105 extern int dispatch_scsi_info(int ino, char *buffer, char **start,
106 off_t offset, int length, int func)
107 {
108 int retval;
109 struct Scsi_Host *hpnt = scsi_hostlist;
110
111 if(func != 2) {
112 if(ino == PROC_SCSI_SCSI) {
113
114
115
116
117 return(scsi_proc_info(buffer, start, offset, length, 0, func));
118 }
119
120 while(hpnt) {
121 if (ino == (hpnt->host_no + PROC_SCSI_FILE)) {
122 if(hpnt->hostt->proc_info == NULL)
123 return generic_proc_info(buffer, start, offset, length,
124 hpnt->host_no, func);
125 else
126 return(hpnt->hostt->proc_info(buffer, start, offset,
127 length, hpnt->host_no, func));
128 }
129 hpnt = hpnt->next;
130 }
131 return(-EBADF);
132 } else
133 return(get_hba_index(ino));
134 }
135
136 inline uint count_templates(void)
137 {
138 Scsi_Host_Template *tpnt = scsi_hosts;
139 uint x = 0;
140
141 while (tpnt) {
142 tpnt = tpnt->next;
143 x++;
144 }
145 return (x);
146 }
147
148 void build_proc_dir_hba_entries(void)
149 {
150 Scsi_Host_Template *tpnt = scsi_hosts;
151 struct Scsi_Host *hpnt;
152 uint x, y;
153
154
155
156
157
158 static char names[PROC_SCSI_LAST - PROC_SCSI_FILE][4];
159
160 x = y = 0;
161
162 while (tpnt) {
163 scsi_hba_dir[x].low_ino = tpnt->low_ino;
164 scsi_hba_dir[x].namelen = 1;
165 scsi_hba_dir[x++].name = ".";
166 scsi_hba_dir[x].low_ino = PROC_SCSI;
167 scsi_hba_dir[x].namelen = 2;
168 scsi_hba_dir[x++].name = "..";
169
170 hpnt = scsi_hostlist;
171 while (hpnt) {
172 if (tpnt == hpnt->hostt) {
173 scsi_hba_dir[x].low_ino = PROC_SCSI_FILE + hpnt->host_no;
174 scsi_hba_dir[x].namelen = sprintf(names[y],"%d",hpnt->host_no);
175 scsi_hba_dir[x].name = names[y];
176 y++;
177 x++;
178 }
179 hpnt = hpnt->next;
180 }
181
182 scsi_hba_dir[x].low_ino = 0;
183 scsi_hba_dir[x].namelen = 0;
184 scsi_hba_dir[x++].name = NULL;
185 tpnt = tpnt->next;
186 }
187 }
188
189 void build_proc_dir_entries(void)
190 {
191 Scsi_Host_Template *tpnt = scsi_hosts;
192
193 uint newnum;
194 uint x;
195
196 newnum = count_templates();
197
198 scsi_dir[0].low_ino = PROC_SCSI;
199 scsi_dir[0].namelen = 1;
200 scsi_dir[0].name = ".";
201 scsi_dir[1].low_ino = PROC_ROOT_INO;
202 scsi_dir[1].namelen = 2;
203 scsi_dir[1].name = "..";
204 scsi_dir[2].low_ino = PROC_SCSI_SCSI;
205 scsi_dir[2].namelen = 4;
206 scsi_dir[2].name = "scsi";
207
208 for(x = 3; x < newnum + 3; x++, tpnt = tpnt->next) {
209 scsi_dir[x].low_ino = tpnt->low_ino;
210 scsi_dir[x].namelen = strlen(tpnt->procname);
211 scsi_dir[x].name = tpnt->procname;
212 }
213
214 scsi_dir[x].low_ino = 0;
215 scsi_dir[x].namelen = 0;
216 scsi_dir[x].name = NULL;
217
218 build_proc_dir_hba_entries();
219 }
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244 typedef struct
245 {
246 char *buf,
247 *cmdList,
248 *bufPos,
249 **cmdPos,
250 cmdNum;
251 } parseHandle;
252
253
254 inline int parseFree (parseHandle *handle)
255 {
256 kfree (handle->cmdPos);
257 kfree (handle);
258
259 return(-1);
260 }
261
262
263 parseHandle *parseInit(char *buf, char *cmdList, int cmdNum)
264 {
265 char *ptr;
266 parseHandle *handle;
267
268 if (!buf || !cmdList)
269 return(NULL);
270 if ((handle = (parseHandle*) kmalloc(sizeof(parseHandle), 1)) == 0)
271 return(NULL);
272 if ((handle->cmdPos = (char**) kmalloc(sizeof(int), cmdNum)) == 0) {
273 kfree(handle);
274 return(NULL);
275 }
276
277 handle->buf = handle->bufPos = buf;
278 handle->cmdList = cmdList;
279 handle->cmdNum = cmdNum;
280
281 handle->cmdPos[cmdNum = 0] = cmdList;
282 for (ptr = cmdList; *ptr; ptr++) {
283 if(*ptr == ' ') {
284 *ptr++ = 0;
285 handle->cmdPos[++cmdNum] = ptr++;
286 }
287 }
288 return(handle);
289 }
290
291
292 int parseOpt(parseHandle *handle, char **param)
293 {
294 int cmdIndex = 0,
295 cmdLen = 0;
296 char *startPos;
297
298 if (!handle)
299 return(parseFree(handle));
300
301 for (; *(handle->bufPos) && *(handle->bufPos) == ' '; handle->bufPos++);
302 if (!*(handle->bufPos))
303 return(parseFree(handle));
304
305 startPos = handle->bufPos;
306 for (; handle->cmdPos[cmdIndex][cmdLen] && *(handle->bufPos); handle->bufPos++)
307 {
308 for (;;)
309 {
310 if (*(handle->bufPos) == handle->cmdPos[cmdIndex][cmdLen])
311 break;
312 else
313 if (memcmp(startPos, (char*)(handle->cmdPos[++cmdIndex]), cmdLen))
314 return(parseFree(handle));
315
316 if (cmdIndex >= handle->cmdNum)
317 return(parseFree(handle));
318 }
319
320 cmdLen++;
321 }
322
323
324
325 for (; *(handle->bufPos) && *(handle->bufPos) == ' '; handle->bufPos++);
326 *param = handle->bufPos;
327
328 for (; *(handle->bufPos) && *(handle->bufPos) != ' '; handle->bufPos++);
329 *(handle->bufPos++) = 0;
330
331 return(cmdIndex);
332 }
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352