Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

186 lines
5.6 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. extern CHAR ReturnTextBuffer[1024];
  4. /*
  5. GetEisaSlotInformation - Get EISA information.
  6. The user must passed 3 arguments to the function.
  7. 1st argument - bus number
  8. 2nd argument - registry field name, i.e. "Configuration Data"
  9. 3rd argument - Compressed ID.
  10. 4th argument - Compressed ID Mask. (optional)
  11. The function will look through the bus's configuration data value
  12. and return a list of slot number which contains the hardware with the
  13. same compressed ID.
  14. */
  15. BOOL
  16. GetEisaSlotInformation(
  17. IN DWORD cArgs,
  18. IN LPSTR Args[],
  19. OUT LPSTR *TextOut
  20. )
  21. {
  22. PCM_FULL_RESOURCE_DESCRIPTOR pFullResourceDescriptor;
  23. PCM_PARTIAL_RESOURCE_DESCRIPTOR pPartialDescriptor;
  24. ULONG ulID;
  25. DWORD dwMask = 0xffffff;
  26. BOOL fFirst = TRUE;
  27. CHAR szNum[10];
  28. BOOL fOkay;
  29. HKEY hKey;
  30. DWORD cbData;
  31. DWORD ValueType;
  32. PVOID ValueData;
  33. LONG Status;
  34. char szKClass[ MAX_PATH ];
  35. DWORD cbKClass;
  36. DWORD KSubKeys;
  37. DWORD cbKMaxSubKeyLen;
  38. DWORD cbKMaxClassLen;
  39. DWORD KValues;
  40. DWORD cbKMaxValueNameLen;
  41. DWORD SizeSecurityDescriptor;
  42. FILETIME KLastWriteTime;
  43. USHORT Count = 0;
  44. UCHAR Function, Slot = 0;
  45. PCM_EISA_SLOT_INFORMATION SlotInformation;
  46. ULONG DataLength;
  47. PUCHAR DataPointer,EndingAddress, BinaryPointer = NULL;
  48. /*
  49. * Make sure we have 4 variables
  50. */
  51. if ( cArgs < 3 )
  52. {
  53. SetErrorText(IDS_ERROR_BADARGS);
  54. return( FALSE );
  55. }
  56. ulID = atol( Args[2] );
  57. if ( cArgs > 3 )
  58. {
  59. dwMask = atol( Args[3] );
  60. }
  61. lstrcpy( ReturnTextBuffer, "{" );
  62. hKey = (HKEY)LongToHandle(atol( &(Args[0][1]) ));
  63. cbKClass = MAX_PATH;
  64. /*
  65. ** Get the registry handle information
  66. */
  67. fOkay = !( Status = RegQueryInfoKey ( hKey,
  68. szKClass,
  69. &cbKClass,
  70. NULL,
  71. &KSubKeys,
  72. &cbKMaxSubKeyLen,
  73. &cbKMaxClassLen,
  74. &KValues,
  75. &cbKMaxValueNameLen,
  76. &cbData,
  77. &SizeSecurityDescriptor,
  78. &KLastWriteTime ) );
  79. if ( !fOkay ) {
  80. lstrcat( ReturnTextBuffer, "}" );
  81. *TextOut = ReturnTextBuffer;
  82. OutputDebugString("RegQueryInfoKey error.\n\r");
  83. return(FALSE);
  84. } else {
  85. //
  86. // Allocate the buffer and get the data
  87. //
  88. // add some space for the margin
  89. while ( (ValueData = (PVOID)SAlloc( (CB)( cbData+10 ))) == NULL ) {
  90. lstrcat( ReturnTextBuffer, "}" );
  91. *TextOut = ReturnTextBuffer;
  92. OutputDebugString("Malloc error.\n\r");
  93. return(FALSE);
  94. }
  95. if ( fOkay ) {
  96. fOkay = !( Status = RegQueryValueEx( hKey,
  97. Args[1],
  98. NULL,
  99. &ValueType,
  100. ValueData,
  101. &cbData ) );
  102. if ( !fOkay ) {
  103. SFree( ValueData );
  104. lstrcat( ReturnTextBuffer, "}" );
  105. *TextOut = ReturnTextBuffer;
  106. OutputDebugString("RegQueryValueEx error.\n\r");
  107. return(FALSE);
  108. }
  109. }
  110. }
  111. pFullResourceDescriptor = (PCM_FULL_RESOURCE_DESCRIPTOR) ValueData;
  112. if ( pFullResourceDescriptor->PartialResourceList.Count != 0 )
  113. {
  114. pPartialDescriptor = ( PCM_PARTIAL_RESOURCE_DESCRIPTOR ) &pFullResourceDescriptor->PartialResourceList.PartialDescriptors;
  115. DataPointer = (PUCHAR)pPartialDescriptor + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
  116. DataLength = pPartialDescriptor->u.DeviceSpecificData.DataSize;
  117. if ( DataLength != 0 )
  118. {
  119. /*
  120. ** Go through the data one by one to find the compressed ID
  121. */
  122. EndingAddress = DataPointer + DataLength;
  123. SlotInformation = (PCM_EISA_SLOT_INFORMATION)DataPointer;
  124. while ((ULONG_PTR)BinaryPointer < (ULONG_PTR)EndingAddress) {
  125. if (SlotInformation->ReturnCode != EISA_EMPTY_SLOT) {
  126. BinaryPointer = (PUCHAR)SlotInformation;
  127. if (( SlotInformation->CompressedId & dwMask ) == ulID ) {
  128. if (!fFirst) {
  129. lstrcat( ReturnTextBuffer,"," );
  130. }
  131. fFirst = FALSE;
  132. wsprintf( szNum, "\"%d\"", Slot );
  133. lstrcat( ReturnTextBuffer, szNum );
  134. OutputDebugString(ReturnTextBuffer);
  135. }
  136. BinaryPointer += sizeof(CM_EISA_SLOT_INFORMATION);
  137. Function = 0;
  138. while (SlotInformation->NumberFunctions > Function) {
  139. BinaryPointer += sizeof(CM_EISA_FUNCTION_INFORMATION);
  140. Function++;
  141. }
  142. } else {
  143. BinaryPointer += sizeof(CM_EISA_SLOT_INFORMATION);
  144. }
  145. Slot++;
  146. SlotInformation = (PCM_EISA_SLOT_INFORMATION)BinaryPointer;
  147. }
  148. }
  149. }
  150. lstrcat( ReturnTextBuffer, "}" );
  151. *TextOut = ReturnTextBuffer;
  152. SFree( ValueData );
  153. return TRUE;
  154. }