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.

70 lines
2.5 KiB

  1. #include "pch.h"
  2. NTSTATUS
  3. PptPdoCreateOpen(
  4. IN PDEVICE_OBJECT Pdo,
  5. IN PIRP Irp
  6. )
  7. {
  8. NTSTATUS status;
  9. PPDO_EXTENSION pdx = Pdo->DeviceExtension;
  10. // bail out if a delete is pending for this device object
  11. if(pdx->DeviceStateFlags & PPT_DEVICE_DELETE_PENDING) {
  12. return P4CompleteRequest( Irp, STATUS_DELETE_PENDING, 0 );
  13. }
  14. // bail out if device has been removed
  15. if(pdx->DeviceStateFlags & (PPT_DEVICE_REMOVED|PPT_DEVICE_SURPRISE_REMOVED) ) {
  16. return P4CompleteRequest( Irp, STATUS_DEVICE_REMOVED, 0 );
  17. }
  18. // bail out if caller is confused and thinks that we are a directory
  19. if( IoGetCurrentIrpStackLocation(Irp)->Parameters.Create.Options & FILE_DIRECTORY_FILE ) {
  20. return P4CompleteRequest( Irp, STATUS_NOT_A_DIRECTORY, 0 );
  21. }
  22. // this is an exclusive access device - fail IRP if we are already open
  23. ExAcquireFastMutex(&pdx->OpenCloseMutex);
  24. if( InterlockedIncrement( &pdx->OpenCloseRefCount ) != 1 ) {
  25. InterlockedDecrement( &pdx->OpenCloseRefCount );
  26. ExReleaseFastMutex( &pdx->OpenCloseMutex );
  27. return P4CompleteRequest( Irp, STATUS_ACCESS_DENIED, 0 );
  28. }
  29. ExReleaseFastMutex(&pdx->OpenCloseMutex);
  30. PptPdoGetPortInfoFromFdo( Pdo );
  31. //
  32. // Set the default ieee1284 modes
  33. //
  34. ParInitializeExtension1284Info( pdx );
  35. // used to pause worker thread when we enter a "Hold Requests" state due to PnP requests
  36. KeInitializeEvent( &pdx->PauseEvent, NotificationEvent, TRUE );
  37. // set to TRUE to tell worker thread to kill itself
  38. pdx->TimeToTerminateThread = FALSE;
  39. // we are an exclusive access device - we should not already have a worker thread
  40. PptAssert( !pdx->ThreadObjectPointer );
  41. // dispatch routines signal worker thread on this semaphore when there is work for worker thread to do
  42. KeInitializeSemaphore(&pdx->RequestSemaphore, 0, MAXLONG);
  43. // create worker thread to handle serialized requests at Passive Level IRQL
  44. status = ParCreateSystemThread( pdx );
  45. if( status != STATUS_SUCCESS ) {
  46. DD((PCE)pdx,DDW,"PptPdoCreateOpen - FAIL worker thread creation\n");
  47. ExAcquireFastMutex( &pdx->OpenCloseMutex );
  48. InterlockedDecrement( &pdx->OpenCloseRefCount );
  49. if( pdx->OpenCloseRefCount < 0 ) {
  50. pdx->OpenCloseRefCount = 0;
  51. }
  52. ExReleaseFastMutex( &pdx->OpenCloseMutex );
  53. } else {
  54. DD((PCE)pdx,DDT,"PptPdoCreateOpen - SUCCESS\n");
  55. }
  56. return P4CompleteRequest( Irp, status, 0 );
  57. }