kernel32/tests/pipe: Enable compilation with long types.
[wine.git] / dlls / wnaspi32 / aspi.c
blobae2d24489f6935a6ef90acb148951af8b8df6319
1 /**************************************************************************
2 * ASPI routines
3 * Copyright (C) 2000 David Elliott <dfe@infinite-internet.net>
4 * Copyright (C) 2005 Vitaliy Margolen
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 /* These routines are to be called from either WNASPI32 or WINASPI */
23 /* FIXME:
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.
32 #include <stdio.h>
33 #include <stdarg.h>
34 #include <sys/types.h>
35 #include <string.h>
36 #include <stdlib.h>
38 #include "windef.h"
39 #include "winbase.h"
40 #include "winreg.h"
41 #include "winerror.h"
42 #include "winescsi.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(aspi);
48 static const WCHAR wDevicemapScsi[] = {'H','A','R','D','W','A','R','E','\\','D','E','V','I','C','E','M','A','P','\\','S','c','s','i',0};
50 /* Exported functions */
51 int ASPI_GetNumControllers(void)
53 HKEY hkeyScsi, hkeyPort;
54 DWORD i = 0, numPorts, num_ha = 0;
55 WCHAR wPortName[15];
57 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, wDevicemapScsi, 0,
58 KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &hkeyScsi) != ERROR_SUCCESS )
60 ERR("Could not open HKLM\\%s\n", debugstr_w(wDevicemapScsi));
61 return 0;
63 while (RegEnumKeyW(hkeyScsi, i++, wPortName, ARRAY_SIZE(wPortName)) == ERROR_SUCCESS)
65 if (RegOpenKeyExW(hkeyScsi, wPortName, 0, KEY_QUERY_VALUE, &hkeyPort) == ERROR_SUCCESS)
67 if (RegQueryInfoKeyW(hkeyPort, NULL, NULL, NULL, &numPorts, NULL, NULL,
68 NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
70 num_ha += numPorts;
72 RegCloseKey(hkeyPort);
76 RegCloseKey(hkeyScsi);
77 TRACE("Returning %ld host adapters\n", num_ha );
78 return num_ha;
81 /* SCSI_GetHCforController
82 * RETURNS
83 * HIWORD: Host Adapter
84 * LOWORD: Channel
86 DWORD ASPI_GetHCforController( int controller )
88 HKEY hkeyScsi, hkeyPort;
89 DWORD i = 0, numPorts;
90 int num_ha = controller + 1;
91 WCHAR wPortName[15];
92 WCHAR wBusName[15];
94 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, wDevicemapScsi, 0,
95 KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &hkeyScsi) != ERROR_SUCCESS )
97 ERR("Could not open HKLM\\%s\n", debugstr_w(wDevicemapScsi));
98 return 0xFFFFFFFF;
100 while (RegEnumKeyW(hkeyScsi, i++, wPortName, ARRAY_SIZE(wPortName)) == ERROR_SUCCESS)
102 if (RegOpenKeyExW(hkeyScsi, wPortName, 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS,
103 &hkeyPort) == ERROR_SUCCESS)
105 if (RegQueryInfoKeyW(hkeyPort, NULL, NULL, NULL, &numPorts, NULL, NULL,
106 NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
108 num_ha -= numPorts;
109 if (num_ha <= 0) break;
111 else
112 RegCloseKey(hkeyPort);
115 RegCloseKey(hkeyScsi);
117 if (num_ha > 0)
119 ERR("Invalid controller(%d)\n", controller);
120 return 0xFFFFFFFF;
123 if (RegEnumKeyW(hkeyPort, -num_ha, wBusName, ARRAY_SIZE(wBusName)) != ERROR_SUCCESS)
125 ERR("Failed to enumerate keys\n");
126 RegCloseKey(hkeyPort);
127 return 0xFFFFFFFF;
129 RegCloseKey(hkeyPort);
131 return (wcstol(&wPortName[9], NULL, 10) << 16) + wcstol(&wBusName[9], NULL, 10);