1 /**************************************************************************
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 */
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.
34 #include <sys/types.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;
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
));
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
)
72 RegCloseKey(hkeyPort
);
76 RegCloseKey(hkeyScsi
);
77 TRACE("Returning %ld host adapters\n", num_ha
);
81 /* SCSI_GetHCforController
83 * HIWORD: Host Adapter
86 DWORD
ASPI_GetHCforController( int controller
)
88 HKEY hkeyScsi
, hkeyPort
;
89 DWORD i
= 0, numPorts
;
90 int num_ha
= controller
+ 1;
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
));
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
)
109 if (num_ha
<= 0) break;
112 RegCloseKey(hkeyPort
);
115 RegCloseKey(hkeyScsi
);
119 ERR("Invalid controller(%d)\n", controller
);
123 if (RegEnumKeyW(hkeyPort
, -num_ha
, wBusName
, ARRAY_SIZE(wBusName
)) != ERROR_SUCCESS
)
125 ERR("Failed to enumerate keys\n");
126 RegCloseKey(hkeyPort
);
129 RegCloseKey(hkeyPort
);
131 return (wcstol(&wPortName
[9], NULL
, 10) << 16) + wcstol(&wBusName
[9], NULL
, 10);