Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenfindscsi.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Storage Stack 00003 * LICENSE: DDK - see license.txt in the root dir 00004 * FILE: drivers/storage/cdrom/cdrom.c 00005 * PURPOSE: CDROM driver 00006 * PROGRAMMERS: Based on a source code sample from Microsoft NT4 DDK 00007 */ 00008 00009 #include "precomp.h" 00010 00011 //#define NDEBUG 00012 #include <debug.h> 00013 00014 NTSTATUS 00015 NTAPI 00016 FindScsiAdapter ( 00017 IN HANDLE KeyHandle, 00018 IN UNICODE_STRING ScsiUnicodeString[], 00019 OUT PUCHAR IntermediateController 00020 ); 00021 00022 #define INIT_OPEN_KEY(name, rootHandle, pNewHandle) \ 00023 InitializeObjectAttributes( \ 00024 &objectAttributes, \ 00025 (name), \ 00026 OBJ_CASE_INSENSITIVE, \ 00027 (rootHandle), \ 00028 NULL \ 00029 ); \ 00030 \ 00031 status = ZwOpenKey( \ 00032 (pNewHandle), \ 00033 KEY_READ | KEY_ENUMERATE_SUB_KEYS, \ 00034 &objectAttributes \ 00035 ); 00036 00037 00038 NTSTATUS 00039 NTAPI 00040 FindScsiAdapter ( 00041 IN HANDLE KeyHandle, 00042 IN UNICODE_STRING ScsiUnicodeString[], 00043 OUT UCHAR *IntermediateController 00044 ) 00045 00046 /*++ 00047 00048 Routine Description: 00049 00050 Recursive routine to walk registry tree under KeyHandle looking for 00051 location of ScsiAdapter and other valid controllers that the ScsiAdapter 00052 might hang off of. When ScsiAdapter is found, FindScsiAdapter 00053 returns an ARC name for the intervening controller(s) between the 00054 original key and ScsiAdapter. 00055 00056 Arguments: 00057 00058 KeyHandle -- Handle of open registry key (somewhere under 00059 \Registry\Machine\Hardware\Description\System) 00060 00061 ScsiUnicodeString -- NT name of SCSI device being sought in the registry 00062 00063 IntermediateController -- Null terminated buffer which this routine fills with 00064 ARC name for intervening controller(s). Null is returned 00065 if ScsiAdapter sits at the root or if it is not found. 00066 00067 Return Value: 00068 00069 STATUS_SUCCESS -- IntermediateController set to something like multi(1) 00070 00071 STATUS_OBJECT_PATH_NOT_FOUND -- all ok, but no ScsiAdapter 00072 (with correct scsi id & lun info) found; In this case 00073 IntermediateController is explicitly set to null. 00074 00075 Other status codes as returned by open\enumerate registry routines 00076 may also be returned. 00077 00078 --*/ 00079 00080 { 00081 #if 0 00082 NTSTATUS status; 00083 ULONG index; 00084 ULONG resultLength; 00085 UCHAR lowerController[64]; 00086 BOOLEAN validControllerNumber; 00087 UNICODE_STRING unicodeString[64]; 00088 OBJECT_ATTRIBUTES objectAttributes; 00089 00090 HANDLE controllerHandle; 00091 HANDLE controllerNumberHandle; 00092 ULONG controllerIndex; 00093 ULONG controllerNumberIndex; 00094 UCHAR keyBuffer[256]; // Allow for variable length name at end 00095 UCHAR numberKeyBuffer[64]; 00096 PKEY_BASIC_INFORMATION pControllerKeyInformation; 00097 PKEY_BASIC_INFORMATION pControllerNumberKeyInformation; 00098 00099 // TODO: Any PAGED_CODE stuff... 00100 00101 // 00102 // Walk enumerated subkeys, looking for valid controllers 00103 // 00104 00105 for (controllerIndex = 0; TRUE; controllerIndex++) { 00106 00107 // 00108 // Ensure pControllerKeyInformation->Name is null terminated 00109 // 00110 00111 RtlZeroMemory(keyBuffer, sizeof(keyBuffer)); 00112 00113 pControllerKeyInformation = (PKEY_BASIC_INFORMATION) keyBuffer; 00114 00115 status = ZwEnumerateKey( 00116 KeyHandle, 00117 controllerIndex, 00118 KeyBasicInformation, 00119 pControllerKeyInformation, 00120 sizeof(keyBuffer), 00121 &resultLength 00122 ); 00123 00124 if (!NT_SUCCESS(status)) { 00125 00126 if (status != STATUS_NO_MORE_ENTRIES) { 00127 DebugPrint ((2, "FindScsiAdapter: Error 0x%x enumerating key\n", status)); 00128 return(status); 00129 } 00130 00131 break; // return NOT_FOUND 00132 } 00133 00134 DebugPrint ((3, "FindScsiAdapter: Found Adapter=%S\n", pControllerKeyInformation->Name)); 00135 00136 if (!_wcsicmp(pControllerKeyInformation->Name, L"ScsiAdapter")) { 00137 00138 // 00139 // Found scsi, now verify that it's the same one we're trying to initialize. 00140 // 00141 00142 INIT_OPEN_KEY (ScsiUnicodeString, KeyHandle, &controllerHandle); 00143 00144 ZwClose(controllerHandle); 00145 00146 if (NT_SUCCESS(status)) { 00147 00148 // 00149 // Found correct scsi, now build ARC name of IntermediateController 00150 // (i.e. the intervening controllers, or everything above ScsiAdapter) 00151 // start with null, and build string one controller at a time as we 00152 // return up the recursively called routine. 00153 // 00154 00155 IntermediateController = "\0"; 00156 00157 return (STATUS_SUCCESS); 00158 } 00159 00160 // 00161 // Found ScsiAdapter, but wrong scsi id or Lun info doesn't match, 00162 // (ignore other ZwOpenKey errors &) keep looking... 00163 // 00164 00165 } 00166 00167 else if (!_wcsicmp(pControllerKeyInformation->Name, L"MultifunctionAdapter") || 00168 !_wcsicmp(pControllerKeyInformation->Name, L"EisaAdapter")) { 00169 00170 // 00171 // This is a valid controller that may have ScsiAdapter beneath it. 00172 // Open controller & walk controller's subkeys: 0, 1, 2, etc.... 00173 // 00174 00175 RtlInitUnicodeString (unicodeString, pControllerKeyInformation->Name); 00176 00177 INIT_OPEN_KEY (unicodeString, KeyHandle, &controllerHandle); 00178 00179 if (!NT_SUCCESS(status)) { 00180 DebugPrint ((2, "FindScsiAdapter: ZwOpenKey got status = %x \n", status)); 00181 ZwClose (controllerHandle); 00182 return (status); 00183 } 00184 00185 00186 00187 for (controllerNumberIndex = 0; TRUE; controllerNumberIndex++) { 00188 00189 RtlZeroMemory(numberKeyBuffer, sizeof(numberKeyBuffer)); 00190 00191 pControllerNumberKeyInformation = (PKEY_BASIC_INFORMATION) numberKeyBuffer; 00192 00193 status = ZwEnumerateKey( 00194 controllerHandle, 00195 controllerNumberIndex, 00196 KeyBasicInformation, 00197 pControllerNumberKeyInformation, 00198 sizeof(numberKeyBuffer), 00199 &resultLength 00200 ); 00201 00202 if (!NT_SUCCESS(status)) { 00203 00204 if (status != STATUS_NO_MORE_ENTRIES) { 00205 DebugPrint ((2, "FindScsiAdapter: Status %x enumerating key\n", status)); 00206 ZwClose(controllerHandle); 00207 return (status); 00208 } 00209 00210 ZwClose(controllerHandle); 00211 00212 break; // next controller 00213 } 00214 00215 DebugPrint ((3, "FindScsiAdapter: Found Adapter #=%S\n", pControllerNumberKeyInformation->Name)); 00216 00217 validControllerNumber = TRUE; 00218 00219 for (index = 0; index < pControllerNumberKeyInformation->NameLength / 2; index++) { 00220 00221 if (!isxdigit(pControllerNumberKeyInformation->Name[index])) { 00222 validControllerNumber = FALSE; 00223 break; 00224 } 00225 00226 } 00227 00228 if (validControllerNumber) { 00229 00230 // 00231 // Found valid controller and controller number: check children for scsi. 00232 // 00233 00234 RtlInitUnicodeString (unicodeString, pControllerNumberKeyInformation->Name); 00235 00236 INIT_OPEN_KEY (unicodeString, controllerHandle, &controllerNumberHandle); 00237 00238 if (!NT_SUCCESS(status)) { 00239 DebugPrint ((2, "FindScsiAdapter: Status %x opening controller number key\n", status)); 00240 ZwClose(controllerNumberHandle); 00241 ZwClose(controllerHandle); 00242 return (status); 00243 } 00244 00245 RtlZeroMemory(lowerController, sizeof(lowerController)); 00246 00247 status = FindScsiAdapter( 00248 controllerNumberHandle, 00249 ScsiUnicodeString, 00250 &lowerController[0] 00251 ); 00252 00253 ZwClose(controllerNumberHandle); 00254 00255 if (NT_SUCCESS(status)) { 00256 00257 // 00258 // SUCCESS! 00259 // 00260 // Scsi adapter DOES exist under this node, 00261 // prepend Arc Name for the current adapter to whatever was returned 00262 // by other calls to this routine. 00263 // 00264 00265 if (!_wcsicmp(pControllerKeyInformation->Name, L"MultifunctionAdapter")) { 00266 sprintf(IntermediateController, "multi(0)%s", lowerController); 00267 } else { 00268 sprintf(IntermediateController, "eisa(0)%s", lowerController); 00269 } 00270 00271 ZwClose(controllerHandle); 00272 00273 return(STATUS_SUCCESS); 00274 } 00275 00276 else if (status != STATUS_OBJECT_PATH_NOT_FOUND) { 00277 ZwClose(controllerHandle); 00278 return(status); 00279 } 00280 00281 // 00282 // Scsi not found under this controller number, check next one 00283 // 00284 00285 } // if validControllerNumber 00286 00287 } // for controllerNumberIndex 00288 00289 00290 00291 // 00292 // ScsiAdapter not found under this controller 00293 // 00294 00295 ZwClose(controllerHandle); 00296 00297 } // else if valid subkey (i.e., scsi, multi, eisa) 00298 00299 } // for controllerIndex 00300 00301 // 00302 // ScsiAdapter not found under key we were called with 00303 // 00304 00305 IntermediateController = "\0"; 00306 #endif 00307 return (STATUS_OBJECT_PATH_NOT_FOUND); 00308 } 00309 Generated on Sat May 26 2012 04:26:46 for ReactOS by
1.7.6.1
|