Better implementation of GetCalendarInfo{A,W}, not perfect.
[wine] / dlls / winaspi / aspi.c
1 /**************************************************************************
2  * ASPI routines
3  * Copyright (C) 2000 David Elliott <dfe@infinite-internet.net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 /* These routines are to be called from either WNASPI32 or WINASPI */
21
22 /* FIXME:
23  * - Registry format is stupid for now.. fix that later
24  * - No way to override automatic /proc detection, maybe provide an
25  *   HKEY_LOCAL_MACHINE\Software\Wine\Wine\Scsi regkey
26  * - Somewhat debating an #ifdef linux... technically all this code will
27  *   run on another UNIX.. it will fail nicely.
28  * - Please add support for mapping multiple channels on host adapters to
29  *   aspi controllers, e-mail me if you need help.
30  */
31
32 /*
33 Registry format is currently:
34 HKEY_DYN_DATA
35         WineScsi
36                 (default)=number of host adapters
37                 hHHcCCtTTdDD=linux device name
38 */
39 #include <stdio.h>
40 #include <sys/types.h>
41 #include <sys/ioctl.h>
42 #include <fcntl.h>
43 #include <dirent.h>
44 #include <unistd.h>
45 #include <errno.h>
46 #include <string.h>
47
48 #include "wine/debug.h"
49 #include "winreg.h"
50 #include "winerror.h"
51 #include "winescsi.h"
52
53 WINE_DEFAULT_DEBUG_CHANNEL(aspi);
54
55 /* Internal function prototypes */
56 static void
57 SCSI_GetProcinfo();
58
59 #ifdef linux
60 static void
61 SCSI_MapHCtoController();
62 #endif
63
64 static void set_last_error(void)
65 {
66     int save_errno = errno; /* errno gets overwritten by printf */
67     switch (errno)
68     {
69     case EAGAIN:
70         SetLastError( ERROR_SHARING_VIOLATION );
71         break;
72     case EBADF:
73         SetLastError( ERROR_INVALID_HANDLE );
74         break;
75     case ENOSPC:
76         SetLastError( ERROR_HANDLE_DISK_FULL );
77         break;
78     case EACCES:
79     case EPERM:
80     case EROFS:
81         SetLastError( ERROR_ACCESS_DENIED );
82         break;
83     case EBUSY:
84         SetLastError( ERROR_LOCK_VIOLATION );
85         break;
86     case ENOENT:
87         SetLastError( ERROR_FILE_NOT_FOUND );
88         break;
89     case EISDIR:
90         SetLastError( ERROR_CANNOT_MAKE );
91         break;
92     case ENFILE:
93     case EMFILE:
94         SetLastError( ERROR_NO_MORE_FILES );
95         break;
96     case EEXIST:
97         SetLastError( ERROR_FILE_EXISTS );
98         break;
99     case EINVAL:
100     case ESPIPE:
101         SetLastError( ERROR_SEEK );
102         break;
103     case ENOTEMPTY:
104         SetLastError( ERROR_DIR_NOT_EMPTY );
105         break;
106     case ENOEXEC:
107         SetLastError( ERROR_BAD_FORMAT );
108         break;
109     default:
110         WARN( "unknown file error: %s\n", strerror(save_errno) );
111         SetLastError( ERROR_GEN_FAILURE );
112         break;
113     }
114     errno = save_errno;
115 }
116
117 /* Exported functions */
118 void
119 SCSI_Init()
120 {
121         /* For now we just call SCSI_GetProcinfo */
122         SCSI_GetProcinfo();
123 #ifdef linux
124         SCSI_MapHCtoController();
125 #endif
126 }
127
128 int
129 ASPI_GetNumControllers()
130 {
131         HKEY hkeyScsi;
132         HKEY hkeyControllerMap;
133         DWORD error;
134         DWORD type = REG_DWORD;
135         DWORD num_ha = 0;
136         DWORD cbData = sizeof(num_ha);
137
138         if( RegOpenKeyExA(HKEY_DYN_DATA, KEYNAME_SCSI, 0, KEY_ALL_ACCESS, &hkeyScsi ) != ERROR_SUCCESS )
139         {
140                 ERR("Could not open HKEY_DYN_DATA\\%s\n",KEYNAME_SCSI);
141                 return 0;
142         }
143
144         if( (error=RegOpenKeyExA(hkeyScsi, KEYNAME_SCSI_CONTROLLERMAP, 0, KEY_ALL_ACCESS, &hkeyControllerMap )) != ERROR_SUCCESS )
145         {
146                 ERR("Could not open HKEY_DYN_DATA\\%s\\%s\n", KEYNAME_SCSI, KEYNAME_SCSI_CONTROLLERMAP);
147                 RegCloseKey(hkeyScsi);
148                 SetLastError(error);
149                 return 0;
150         }
151         if( RegQueryValueExA(hkeyControllerMap, NULL, NULL, &type, (LPBYTE)&num_ha, &cbData ) != ERROR_SUCCESS )
152         {
153                 ERR("Could not query value HKEY_DYN_DATA\\%s\n",KEYNAME_SCSI);
154                 num_ha=0;
155         }
156         RegCloseKey(hkeyControllerMap);
157         RegCloseKey(hkeyScsi);
158         TRACE("Returning %ld host adapters\n", num_ha );
159         return num_ha;
160 }
161
162 BOOL
163 SCSI_GetDeviceName( int h, int c, int t, int d, LPSTR devstr, LPDWORD lpcbData )
164 {
165
166         char idstr[20];
167         HKEY hkeyScsi;
168         DWORD type;
169
170         if( RegOpenKeyExA(HKEY_DYN_DATA, KEYNAME_SCSI, 0, KEY_ALL_ACCESS, &hkeyScsi ) != ERROR_SUCCESS )
171         {
172                 ERR("Could not open HKEY_DYN_DATA\\%s\n",KEYNAME_SCSI);
173                 return FALSE;
174         }
175
176
177         sprintf(idstr, "h%02dc%02dt%02dd%02d", h, c, t, d);
178
179         if( RegQueryValueExA(hkeyScsi, idstr, NULL, &type, devstr, lpcbData) != ERROR_SUCCESS )
180         {
181                 WARN("Could not query value HKEY_DYN_DATA\\%s\\%s\n",KEYNAME_SCSI, idstr);
182                 RegCloseKey(hkeyScsi);
183                 return FALSE;
184         }
185         RegCloseKey(hkeyScsi);
186
187         TRACE("scsi %s: Device name: %s\n",idstr,devstr);
188         return TRUE;
189 }
190
191 /* SCSI_GetHCforController
192  * RETURNS
193  *      HIWORD: Host Adapter
194  *      LOWORD: Channel
195  */
196 DWORD
197 ASPI_GetHCforController( int controller )
198 {
199         DWORD hc = 0xFFFFFFFF;
200         char cstr[20];
201         DWORD error;
202         HKEY hkeyScsi;
203         HKEY hkeyControllerMap;
204         DWORD type = REG_DWORD;
205         DWORD cbData = sizeof(DWORD);
206         DWORD disposition;
207 #if 0
208         FIXME("Please fix to map each channel of each host adapter to the proper ASPI controller number!\n");
209         hc = (controller << 16);
210         return hc;
211 #endif
212         if( (error=RegCreateKeyExA(HKEY_DYN_DATA, KEYNAME_SCSI, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkeyScsi, &disposition )) != ERROR_SUCCESS )
213         {
214                 ERR("Could not open HKEY_DYN_DATA\\%s\n",KEYNAME_SCSI);
215                 SetLastError(error);
216                 return hc;
217         }
218         if( disposition != REG_OPENED_EXISTING_KEY )
219         {
220                 WARN("Created HKEY_DYN_DATA\\%s\n",KEYNAME_SCSI);
221         }
222         if( (error=RegCreateKeyExA(hkeyScsi, KEYNAME_SCSI_CONTROLLERMAP, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkeyControllerMap, &disposition )) != ERROR_SUCCESS )
223         {
224                 ERR("Could not open HKEY_DYN_DATA\\%s\\%s\n", KEYNAME_SCSI, KEYNAME_SCSI_CONTROLLERMAP);
225                 RegCloseKey(hkeyScsi);
226                 SetLastError(error);
227                 return hc;
228         }
229         if( disposition != REG_OPENED_EXISTING_KEY )
230         {
231                 WARN("Created HKEY_DYN_DATA\\%s\\%s\n",KEYNAME_SCSI, KEYNAME_SCSI_CONTROLLERMAP);
232         }
233
234         sprintf(cstr, "c%02d", controller);
235         if( (error=RegQueryValueExA( hkeyControllerMap, cstr, 0, &type, (LPBYTE)&hc, &cbData)) != ERROR_SUCCESS )
236         {
237                 ERR("Could not open HKEY_DYN_DATA\\%s\\%s\\%s, error=%lx\n", KEYNAME_SCSI, KEYNAME_SCSI_CONTROLLERMAP, cstr, error );
238                 SetLastError( error );
239         }
240         RegCloseKey(hkeyControllerMap);
241         RegCloseKey(hkeyScsi);
242         return hc;
243
244 };
245
246 int
247 SCSI_OpenDevice( int h, int c, int t, int d )
248 {
249         char devstr[20];
250         DWORD cbData = 20;
251         int fd = -1;
252         char dainbread_linux_hack = 1;
253
254         if(!SCSI_GetDeviceName( h, c, t, d, devstr, &cbData ))
255         {
256                 WARN("Could not get device name for h%02dc%02dt%02dd%02d\n", h, c, t, d);
257                 return -1;
258         }
259
260 linux_hack:
261         TRACE("Opening device %s mode O_RDWR\n",devstr);
262         fd = open(devstr, O_RDWR);
263
264         if( fd < 0 )
265         {
266                 int len = strlen(devstr);
267                 set_last_error(); /* SetLastError() to errno */
268                 TRACE("Open failed (%s)\n", strerror(errno));
269
270                 /* in case of "/dev/sgX", convert from sga to sg0
271                  * and the other way around.
272                  * FIXME: remove it if the distributions
273                  * finally manage to agree on something.
274                  * The best would probably be a complete
275                  * rewrite of the Linux SCSI layer
276                  * to use CAM + devfs :-) */
277                 if ( (dainbread_linux_hack) &&
278                      (len >= 3) &&
279                      (devstr[len-3] == 's') && (devstr[len-2] == 'g') )
280                 {
281                         char *p = &devstr[len-1];
282                         *p = (*p >= 'a') ? *p - 'a' + '0' : *p - '0' + 'a';
283                         dainbread_linux_hack = 0;
284                         TRACE("Retry with \"equivalent\" Linux device '%s'\n", devstr);
285                         goto linux_hack;
286                 }
287         }
288         return fd;
289 }
290
291 #ifdef linux
292 /* SCSI_Fix_CMD_LEN
293  *      Checks to make sure the CMD_LEN is correct
294  */
295 void
296 SCSI_Fix_CMD_LEN(int fd, int cmd, int len)
297 {
298         int index=(cmd>>5)&7;
299
300         if (len!=scsi_command_size[index])
301         {
302                 TRACE("CDBLen for command %d claims to be %d, expected %d\n",
303                                 cmd, len, scsi_command_size[index]);
304                 ioctl(fd,SG_NEXT_CMD_LEN,&len);
305         }
306 }
307
308 int
309 SCSI_LinuxSetTimeout( int fd, int timeout )
310 {
311         int retval;
312         TRACE("Setting timeout to %d jiffies\n", timeout);
313         retval=ioctl(fd,SG_SET_TIMEOUT,&timeout);
314         if(retval)
315         {
316                 WARN("Could not set timeout ! (%s)\n", strerror(errno));
317         }
318         return retval;
319         
320 }
321
322 /* This function takes care of the write/read to the linux sg device.
323  * It returns TRUE or FALSE and uses set_last_error() to convert
324  * UNIX errno to Windows GetLastError().  The reason for that is that
325  * several programs will check that error and we might as well set
326  * it here.  We also return the value of the read call in
327  * lpcbBytesReturned.
328  */
329 BOOL /* NOTE: This function SHOULD BLOCK */
330 SCSI_LinuxDeviceIo( int fd,
331                 struct sg_header * lpInBuffer, DWORD cbInBuffer,
332                 struct sg_header * lpOutBuffer, DWORD cbOutBuffer,
333                 LPDWORD lpcbBytesReturned )
334 {
335         DWORD dwBytes;
336         DWORD save_error;
337
338         TRACE("Writing to Linux sg device\n");
339         dwBytes = write( fd, lpInBuffer, cbInBuffer );
340         if( dwBytes != cbInBuffer )
341         {
342                 set_last_error();
343                 save_error = GetLastError();
344                 WARN("Not enough bytes written to scsi device. bytes=%ld .. %ld\n", cbInBuffer, dwBytes );
345                 /* FIXME: set_last_error() never sets error to ERROR_NOT_ENOUGH_MEMORY... */
346                 if( save_error == ERROR_NOT_ENOUGH_MEMORY )
347                         MESSAGE("Your Linux kernel was not able to handle the amount of data sent to the scsi device. Try recompiling with a larger SG_BIG_BUFF value (kernel 2.0.x sg.h)");
348                 WARN("error= %ld\n", save_error );
349                 *lpcbBytesReturned = 0;
350                 return FALSE;
351         }
352         
353         TRACE("Reading reply from Linux sg device\n");
354         *lpcbBytesReturned = read( fd, lpOutBuffer, cbOutBuffer );
355         if( *lpcbBytesReturned != cbOutBuffer )
356         {
357                 set_last_error();
358                 save_error = GetLastError();
359                 WARN("Not enough bytes read from scsi device. bytes=%ld .. %ld\n", cbOutBuffer, *lpcbBytesReturned);
360                 WARN("error= %ld\n", save_error );
361                 return FALSE;
362         }
363         return TRUE;
364 }
365
366 /* Internal functions */
367 struct LinuxProcScsiDevice
368 {
369         int host;
370         int channel;
371         int target;
372         int lun;
373         char vendor[9];
374         char model[17];
375         char rev[5];
376         char type[33];
377         int ansirev;
378 };
379
380 /*
381  * we need to declare white spaces explicitly via %*1[ ],
382  * as there are very dainbread CD-ROM devices out there
383  * which have their manufacturer name blanked out via spaces,
384  * which confuses fscanf's parsing (skips all blank spaces)
385  */
386 static int
387 SCSI_getprocentry( FILE * procfile, struct LinuxProcScsiDevice * dev )
388 {
389         int result;
390         result = fscanf( procfile,
391                 "Host:%*1[ ]scsi%d%*1[ ]Channel:%*1[ ]%d%*1[ ]Id:%*1[ ]%d%*1[ ]Lun:%*1[ ]%d\n",
392                 &dev->host,
393                 &dev->channel,
394                 &dev->target,
395                 &dev->lun );
396         if( result == EOF )
397         {
398                 /* "end of entries" return, so no TRACE() here */
399                 return EOF;
400         }
401         if( result != 4 )
402         {
403                 ERR("bus id line scan count error\n");
404                 return 0;
405         }
406         result = fscanf( procfile,
407                 "  Vendor:%*1[ ]%8c%*1[ ]Model:%*1[ ]%16c%*1[ ]Rev:%*1[ ]%4c\n",
408                 dev->vendor,
409                 dev->model,
410                 dev->rev );
411         if( result != 3 )
412         {
413                 ERR("model line scan count error\n");
414                 return 0;
415         }
416
417         result = fscanf( procfile,
418                 "  Type:%*3[ ]%32c%*1[ ]ANSI%*1[ ]SCSI%*1[ ]revision:%*1[ ]%d\n",
419                 dev->type,
420                 &dev->ansirev );
421         if( result != 2 )
422         {
423                 ERR("SCSI type line scan count error\n");
424                 return 0;
425         }
426         /* Since we fscanf with %XXc instead of %s.. put a NULL at end */
427         dev->vendor[8] = 0;
428         dev->model[16] = 0;
429         dev->rev[4] = 0;
430         dev->type[32] = 0;
431
432         return 1;
433 }
434
435 static void
436 SCSI_printprocentry( const struct LinuxProcScsiDevice * dev )
437 {
438         TRACE( "Host: scsi%d Channel: %02d Id: %02d Lun: %02d\n",
439                 dev->host,
440                 dev->channel,
441                 dev->target,
442                 dev->lun );
443         TRACE( "  Vendor: %s Model: %s Rev: %s\n",
444                 dev->vendor,
445                 dev->model,
446                 dev->rev );
447         TRACE( "  Type:   %s ANSI SCSI revision: %02d\n",
448                 dev->type,
449                 dev->ansirev );
450 }
451
452 static BOOL
453 SCSI_PutRegControllerMap( HKEY hkeyControllerMap, int num_controller, int ha, int chan)
454 {
455         DWORD error;
456         char cstr[20];
457         DWORD hc;
458         hc = (ha << 16) + chan;
459         sprintf(cstr, "c%02d", num_controller);
460         if( (error=RegSetValueExA( hkeyControllerMap, cstr, 0, REG_DWORD, (LPBYTE)&hc, sizeof(DWORD))) != ERROR_SUCCESS )
461         {
462                 ERR("Could not create HKEY_DYN_DATA\\%s\\%s\\%s\n", KEYNAME_SCSI, KEYNAME_SCSI_CONTROLLERMAP, cstr );
463         }
464         return error;
465 }
466
467 static void
468 SCSI_MapHCtoController()
469 {
470         HKEY hkeyScsi;
471         HKEY hkeyControllerMap;
472         DWORD disposition;
473
474         char idstr[20];
475         DWORD cbIdStr;
476         int i = 0;
477         DWORD type = 0;
478         DWORD error;
479
480         DWORD num_controller = 0;
481         int last_ha = -1;
482         int last_chan = -1;
483
484         int ha = 0;
485         int chan = 0;
486
487         if( RegCreateKeyExA(HKEY_DYN_DATA, KEYNAME_SCSI, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkeyScsi, &disposition ) != ERROR_SUCCESS )
488         {
489                 ERR("Could not open HKEY_DYN_DATA\\%s\n",KEYNAME_SCSI);
490                 return;
491         }
492         if( disposition != REG_OPENED_EXISTING_KEY )
493         {
494                 WARN("Created HKEY_DYN_DATA\\%s\n",KEYNAME_SCSI);
495         }
496         if( RegCreateKeyExA(hkeyScsi, KEYNAME_SCSI_CONTROLLERMAP, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkeyControllerMap, &disposition ) != ERROR_SUCCESS )
497         {
498                 ERR("Could not create HKEY_DYN_DATA\\%s\\%s\n", KEYNAME_SCSI, KEYNAME_SCSI_CONTROLLERMAP);
499                 RegCloseKey(hkeyScsi);
500                 return;
501         }
502         
503         for( i=0; cbIdStr = sizeof(idstr), (error=RegEnumValueA( hkeyScsi, i, idstr, &cbIdStr, NULL, &type, NULL, NULL )) == ERROR_SUCCESS; i++ )
504         {
505                 if(idstr[0] == '\0') continue; /* skip the default value */
506
507                 if(sscanf(idstr, "h%02dc%02dt%*02dd%*02d", &ha, &chan) != 2) {
508                         ERR("incorrect reg. value %s\n", debugstr_a(idstr));
509                         continue;
510                 }
511
512                 if( last_ha < ha )
513                 {       /* Next HA */
514                         last_ha = ha;
515                         last_chan = chan;
516                         SCSI_PutRegControllerMap( hkeyControllerMap, num_controller, ha, chan);
517                         num_controller++;
518                 }
519                 else if( last_ha > ha )
520                 {
521                         FIXME("Expected registry to be sorted\n");
522                 }
523                 /* last_ha == ha */
524                 else if( last_chan < chan )
525                 {
526                         last_chan = chan;
527                         SCSI_PutRegControllerMap( hkeyControllerMap, num_controller, ha, chan);
528                         num_controller++;
529                 }
530                 else if( last_chan > chan )
531                 {
532                         FIXME("Expected registry to be sorted\n");
533                 }
534                 /* else last_ha == ha && last_chan == chan so do nothing */
535         }
536         /* Set (default) value to number of controllers */
537         if( RegSetValueExA(hkeyControllerMap, NULL, 0, REG_DWORD, (LPBYTE)&num_controller, sizeof(DWORD) ) != ERROR_SUCCESS )
538         {
539                 ERR("Could not set value HKEY_DYN_DATA\\%s\\%s\n",KEYNAME_SCSI, KEYNAME_SCSI_CONTROLLERMAP);
540         }
541         RegCloseKey(hkeyControllerMap);
542         RegCloseKey(hkeyScsi);
543         return;
544 }
545 #endif
546
547 int SCSI_Linux_CheckDevices(void)
548 {
549     DIR *devdir;
550     struct dirent *dent = NULL;
551
552     devdir = opendir("/dev");
553     for (dent=readdir(devdir);dent;dent=readdir(devdir))
554     {
555         if (!(strncmp(dent->d_name, "sg", 2)))
556             break;
557     }
558     closedir(devdir);
559
560     if (dent == NULL)
561     {
562         TRACE("WARNING: You don't have any /dev/sgX generic scsi devices ! \"man MAKEDEV\" !\n");
563         return 0;
564     }
565     return 1;
566 }
567
568 static void
569 SCSI_GetProcinfo()
570 /* I'll admit, this function is somewhat of a mess... it was originally
571  * designed to make some sort of linked list then I realized that
572  * HKEY_DYN_DATA would be a lot less messy
573  */
574 {
575 #ifdef linux
576         static const char procname[] = "/proc/scsi/scsi";
577         FILE * procfile = NULL;
578
579         char read_line[40], read1[10] = "\0", read2[10] = "\0";
580         int result = 0;
581
582         struct LinuxProcScsiDevice dev;
583
584         char idstr[20];
585         char devstr[20];
586
587         int devnum=0;
588         int num_ha = 0;
589
590         HKEY hkeyScsi;
591         DWORD disposition;
592
593         /* Check whether user has generic scsi devices at all */
594         if (!(SCSI_Linux_CheckDevices()))
595             return;
596         
597         procfile = fopen( procname, "r" );
598         if( !procfile )
599         {
600                 ERR("Could not open %s\n", procname);
601                 return;
602         }
603
604         fgets(read_line, 40, procfile);
605         sscanf( read_line, "Attached %9s %9s", read1, read2);
606
607         if(strcmp(read1, "devices:"))
608         {
609                 ERR("Incorrect %s format\n", procname);
610                 return;
611         }
612
613         if(!(strcmp(read2, "none")))
614         {
615                 ERR("No devices found in %s. Make sure you loaded your SCSI driver or set up ide-scsi emulation for your IDE device if this app needs it !\n", procname);
616                 return;
617         }
618
619         if( RegCreateKeyExA(HKEY_DYN_DATA, KEYNAME_SCSI, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkeyScsi, &disposition ) != ERROR_SUCCESS )
620         {
621                 ERR("Could not create HKEY_DYN_DATA\\%s\n",KEYNAME_SCSI);
622                 return;
623         }
624
625         /* Read info for one device */
626         while( (result = SCSI_getprocentry(procfile, &dev)) > 0 )
627         {
628                 /* Add to registry */
629
630                 sprintf(idstr, "h%02dc%02dt%02dd%02d", dev.host, dev.channel, dev.target, dev.lun);
631                 sprintf(devstr, "/dev/sg%c", 'a'+devnum);
632                 if( RegSetValueExA(hkeyScsi, idstr, 0, REG_SZ, devstr, strlen(devstr)+1 ) != ERROR_SUCCESS )
633                 {
634                         ERR("Could not set value HKEY_DYN_DATA\\%s\\%s\n",KEYNAME_SCSI, idstr);
635                 }
636
637                 /* Debug output */
638                 SCSI_printprocentry( &dev );
639
640                 /* FIXME: We *REALLY* need number of controllers.. not ha */
641                 /* num of hostadapters is highest ha + 1 */
642                 if( dev.host >= num_ha )
643                         num_ha = dev.host+1;
644                 devnum++;
645         } /* while(1) */
646         if( result != EOF )
647         {
648                 ERR("Sorry, incorrect %s format\n", procname);
649         }
650         fclose( procfile );
651         if( RegSetValueExA(hkeyScsi, NULL, 0, REG_DWORD, (LPBYTE)&num_ha, sizeof(num_ha) ) != ERROR_SUCCESS )
652         {
653                 ERR("Could not set value HKEY_DYN_DATA\\%s\n",KEYNAME_SCSI);
654         }
655         RegCloseKey(hkeyScsi);
656         return;
657 #endif
658 }