Leaked source code of windows server 2003
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.

142 lines
3.9 KiB

  1. //==========================================================================;
  2. //
  3. // PinMedia.CPP
  4. // WDM MiniDrivers.
  5. // AIW Hardware platform.
  6. // Global shared in Mediums support functions inplementation
  7. // Copyright (c) 1996 - 1997 ATI Technologies Inc. All Rights Reserved.
  8. //
  9. //==========================================================================;
  10. extern "C"
  11. {
  12. #include "strmini.h"
  13. #include "ksmedia.h"
  14. #include "wdmdebug.h"
  15. }
  16. #include "wdmdrv.h"
  17. #include "pinmedia.h"
  18. /*^^*
  19. * GetDriverInstanceNumber()
  20. * Purpose : gets the instance number of the driver. I think it can be retrived from the
  21. * Registry path, where Instance is a part of the PCI device address
  22. *
  23. * Inputs : PDEVICE_OBJECT pDeviceObject : pointer to DeviceObject
  24. *
  25. * Outputs : ULONG Instance of the driver
  26. * Author : IKLEBANOV
  27. *^^*/
  28. ULONG GetDriverInstanceNumber( PDEVICE_OBJECT pDeviceObject)
  29. {
  30. return( 0);
  31. }
  32. /*^^*
  33. * ReadPinMediumFromRegistryFolder()
  34. * Purpose : Reads the pin GUID from the Registry if the default is overwritten
  35. * by user .INF file. Also construct medium from this GUID and two ULONG 0.
  36. *
  37. * Inputs : HANDLE hFolder : Registry folder handle
  38. * ULONG nPin : pin number to get Medium data of
  39. * PKSPIN_MEDIUM pMediumKSPin : pointer to return pin Medium data
  40. *
  41. * Outputs : BOOL, TRUE if Registry Medium data found for this pin and valid
  42. * Author : IKLEBANOV
  43. *^^*/
  44. BOOL ReadPinMediumFromRegistryFolder( HANDLE hFolder, ULONG nPin, PKSPIN_MEDIUM pPinMedium)
  45. {
  46. NTSTATUS ntStatus;
  47. UNICODE_STRING unicodeValueName, unicodeNumber, unicodeResult, unicodeGUID;
  48. ULONG ulBufLength;
  49. PKEY_VALUE_FULL_INFORMATION pRegistryFullInfo = NULL;
  50. GUID guidPin;
  51. WCHAR wchBuffer[PINMEDIA_REGISTRY_BUFFER_LENGTH];
  52. WCHAR wchResultBuffer[PINMEDIA_REGISTRY_BUFFER_LENGTH];
  53. ENSURE
  54. {
  55. if( hFolder == NULL)
  56. FAIL;
  57. unicodeNumber.Buffer = wchBuffer;
  58. unicodeNumber.MaximumLength = sizeof( wchBuffer);
  59. unicodeNumber.Length = 0;
  60. ntStatus = ::RtlIntegerToUnicodeString( nPin, 10, &unicodeNumber);
  61. if( !NT_SUCCESS( ntStatus))
  62. FAIL;
  63. ::RtlInitUnicodeString( &unicodeValueName, UNICODE_WDM_REG_PIN_NUMBER);
  64. unicodeResult.Buffer = wchResultBuffer;
  65. unicodeResult.MaximumLength = sizeof( wchResultBuffer);
  66. unicodeResult.Length = 0;
  67. ::RtlCopyUnicodeString( &unicodeResult,
  68. &unicodeValueName);
  69. ntStatus = ::RtlAppendUnicodeStringToString( &unicodeResult,
  70. &unicodeNumber);
  71. if( !NT_SUCCESS( ntStatus))
  72. FAIL;
  73. ulBufLength = 0;
  74. ntStatus = ::ZwQueryValueKey( hFolder,
  75. &unicodeResult,
  76. KeyValueFullInformation,
  77. pRegistryFullInfo,
  78. ulBufLength, &ulBufLength);
  79. //
  80. // This call is expected to fail. It's called only to retrieve the required
  81. // buffer length
  82. //
  83. if( !ulBufLength || ( ulBufLength >= sizeof( KEY_VALUE_FULL_INFORMATION) + 100))
  84. FAIL;
  85. pRegistryFullInfo = ( PKEY_VALUE_FULL_INFORMATION) \
  86. ::ExAllocatePool( PagedPool, ulBufLength);
  87. if( pRegistryFullInfo == NULL)
  88. FAIL;
  89. ntStatus = ::ZwQueryValueKey( hFolder,
  90. &unicodeResult,
  91. KeyValueFullInformation,
  92. pRegistryFullInfo,
  93. ulBufLength, &ulBufLength);
  94. if( !NT_SUCCESS( ntStatus))
  95. FAIL;
  96. if( !pRegistryFullInfo->DataLength || !pRegistryFullInfo->DataOffset)
  97. FAIL;
  98. ::RtlInitUnicodeString( &unicodeGUID,
  99. ( WCHAR*)((( PUCHAR)pRegistryFullInfo) + pRegistryFullInfo->DataOffset));
  100. ntStatus = ::RtlGUIDFromString( &unicodeGUID, &guidPin);
  101. if( !NT_SUCCESS( ntStatus))
  102. FAIL;
  103. ::RtlCopyMemory( &pPinMedium->Set,
  104. ( PUCHAR)&guidPin,
  105. sizeof( GUID));
  106. pPinMedium->Id = 0;
  107. pPinMedium->Flags = 0;
  108. ::ExFreePool( pRegistryFullInfo);
  109. return( TRUE);
  110. } END_ENSURE;
  111. if( pRegistryFullInfo != NULL)
  112. ::ExFreePool( pRegistryFullInfo);
  113. return( FALSE);
  114. }