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