This source file includes following definitions.
- generic_proc_info
- dispatch_scsi_info
- build_proc_dir_entries
- parseFree
- parseInit
- parseOpt
- proc_print_scsidevice
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 <linux/stat.h>
36 #include <linux/blk.h>
37 #include "scsi.h"
38 #include "hosts.h"
39
40 #ifndef TRUE
41 #define TRUE 1
42 #define FALSE 0
43 #endif
44
45 extern int scsi_proc_info(char *, char **, off_t, int, int, int);
46
47 struct scsi_dir {
48 struct proc_dir_entry entry;
49 char name[4];
50 };
51
52
53
54
55
56 int generic_proc_info(char *buffer, char **start, off_t offset,
57 int length, int inode, int inout)
58 {
59 int len, pos, begin;
60
61 if(inout == TRUE)
62 return(-ENOSYS);
63
64 begin = 0;
65 pos = len = sprintf(buffer,
66 "The driver does not yet support the proc-fs\n");
67 if(pos < offset) {
68 len = 0;
69 begin = pos;
70 }
71
72 *start = buffer + (offset - begin);
73 len -= (offset - begin);
74 if(len > length)
75 len = length;
76
77 return(len);
78 }
79
80
81
82
83 extern int dispatch_scsi_info(int ino, char *buffer, char **start,
84 off_t offset, int length, int func)
85 {
86 struct Scsi_Host *hpnt = scsi_hostlist;
87
88 if(ino == PROC_SCSI_SCSI) {
89
90
91
92
93 return(scsi_proc_info(buffer, start, offset, length, 0, func));
94 }
95
96 while(hpnt) {
97 if (ino == (hpnt->host_no + PROC_SCSI_FILE)) {
98 if(hpnt->hostt->proc_info == NULL)
99 return generic_proc_info(buffer, start, offset, length,
100 hpnt->host_no, func);
101 else
102 return(hpnt->hostt->proc_info(buffer, start, offset,
103 length, hpnt->host_no, func));
104 }
105 hpnt = hpnt->next;
106 }
107 return(-EBADF);
108 }
109
110 void build_proc_dir_entries(Scsi_Host_Template *tpnt)
111 {
112 struct Scsi_Host *hpnt;
113
114 struct scsi_dir *scsi_hba_dir;
115
116 proc_scsi_register(0, tpnt->proc_dir);
117
118 hpnt = scsi_hostlist;
119 while (hpnt) {
120 if (tpnt == hpnt->hostt) {
121 scsi_hba_dir = scsi_init_malloc(sizeof(struct scsi_dir), GFP_KERNEL);
122 if(scsi_hba_dir == NULL)
123 panic("Not enough memory to register SCSI HBA in /proc/scsi !\n");
124 memset(scsi_hba_dir, 0, sizeof(struct scsi_dir));
125 scsi_hba_dir->entry.low_ino = PROC_SCSI_FILE + hpnt->host_no;
126 scsi_hba_dir->entry.namelen = sprintf(scsi_hba_dir->name,"%d",
127 hpnt->host_no);
128 scsi_hba_dir->entry.name = scsi_hba_dir->name;
129 scsi_hba_dir->entry.mode = S_IFREG | S_IRUGO | S_IWUSR;
130 proc_scsi_register(tpnt->proc_dir, &scsi_hba_dir->entry);
131 }
132 hpnt = hpnt->next;
133 }
134 }
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158 typedef struct
159 {
160 char *buf,
161 *cmdList,
162 *bufPos,
163 **cmdPos,
164 cmdNum;
165 } parseHandle;
166
167
168 inline int parseFree (parseHandle *handle)
169 {
170 kfree (handle->cmdPos);
171 kfree (handle);
172
173 return(-1);
174 }
175
176
177 parseHandle *parseInit(char *buf, char *cmdList, int cmdNum)
178 {
179 char *ptr;
180 parseHandle *handle;
181
182 if (!buf || !cmdList)
183 return(NULL);
184 if ((handle = (parseHandle*) kmalloc(sizeof(parseHandle), 1)) == 0)
185 return(NULL);
186 if ((handle->cmdPos = (char**) kmalloc(sizeof(int), cmdNum)) == 0) {
187 kfree(handle);
188 return(NULL);
189 }
190
191 handle->buf = handle->bufPos = buf;
192 handle->cmdList = cmdList;
193 handle->cmdNum = cmdNum;
194
195 handle->cmdPos[cmdNum = 0] = cmdList;
196 for (ptr = cmdList; *ptr; ptr++) {
197 if(*ptr == ' ') {
198 *ptr++ = 0;
199 handle->cmdPos[++cmdNum] = ptr++;
200 }
201 }
202 return(handle);
203 }
204
205
206 int parseOpt(parseHandle *handle, char **param)
207 {
208 int cmdIndex = 0,
209 cmdLen = 0;
210 char *startPos;
211
212 if (!handle)
213 return(parseFree(handle));
214
215 for (; *(handle->bufPos) && *(handle->bufPos) == ' '; handle->bufPos++);
216 if (!*(handle->bufPos))
217 return(parseFree(handle));
218
219 startPos = handle->bufPos;
220 for (; handle->cmdPos[cmdIndex][cmdLen] && *(handle->bufPos); handle->bufPos++)
221 {
222 for (;;)
223 {
224 if (*(handle->bufPos) == handle->cmdPos[cmdIndex][cmdLen])
225 break;
226 else
227 if (memcmp(startPos, (char*)(handle->cmdPos[++cmdIndex]), cmdLen))
228 return(parseFree(handle));
229
230 if (cmdIndex >= handle->cmdNum)
231 return(parseFree(handle));
232 }
233
234 cmdLen++;
235 }
236
237
238
239 for (; *(handle->bufPos) && *(handle->bufPos) == ' '; handle->bufPos++);
240 *param = handle->bufPos;
241
242 for (; *(handle->bufPos) && *(handle->bufPos) != ' '; handle->bufPos++);
243 *(handle->bufPos++) = 0;
244
245 return(cmdIndex);
246 }
247
248 #define MAX_SCSI_DEVICE_CODE 10
249 const char *const scsi_dev_types[MAX_SCSI_DEVICE_CODE] =
250 {
251 "Direct-Access ",
252 "Sequential-Access",
253 "Printer ",
254 "Processor ",
255 "WORM ",
256 "CD-ROM ",
257 "Scanner ",
258 "Optical Device ",
259 "Medium Changer ",
260 "Communications "
261 };
262
263 void proc_print_scsidevice(Scsi_Device *scd, char *buffer, int *size, int len)
264 {
265 int x, y = *size;
266
267 y = sprintf(buffer + len,
268 "Host: scsi%d Channel: %02d Id: %02d Lun: %02d\n Vendor: ",
269 scd->host->host_no, scd->channel, scd->id, scd->lun);
270 for (x = 0; x < 8; x++) {
271 if (scd->vendor[x] >= 0x20)
272 y += sprintf(buffer + len + y, "%c", scd->vendor[x]);
273 else
274 y += sprintf(buffer + len + y," ");
275 }
276 y += sprintf(buffer + len + y, " Model: ");
277 for (x = 0; x < 16; x++) {
278 if (scd->model[x] >= 0x20)
279 y += sprintf(buffer + len + y, "%c", scd->model[x]);
280 else
281 y += sprintf(buffer + len + y, " ");
282 }
283 y += sprintf(buffer + len + y, " Rev: ");
284 for (x = 0; x < 4; x++) {
285 if (scd->rev[x] >= 0x20)
286 y += sprintf(buffer + len + y, "%c", scd->rev[x]);
287 else
288 y += sprintf(buffer + len + y, " ");
289 }
290 y += sprintf(buffer + len + y, "\n");
291
292 y += sprintf(buffer + len + y, " Type: %s ",
293 scd->type < MAX_SCSI_DEVICE_CODE ?
294 scsi_dev_types[(int)scd->type] : "Unknown " );
295 y += sprintf(buffer + len + y, " ANSI"
296 " SCSI revision: %02x", (scd->scsi_level < 3)?1:2);
297 if (scd->scsi_level == 2)
298 y += sprintf(buffer + len + y, " CCS\n");
299 else
300 y += sprintf(buffer + len + y, "\n");
301
302 *size = y;
303 return;
304 }
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323