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