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.

64 lines
1.8 KiB

  1. #include "pch.h"
  2. NTSTATUS
  3. PptFdoClose(
  4. IN PDEVICE_OBJECT DeviceObject,
  5. IN PIRP Irp
  6. )
  7. {
  8. PFDO_EXTENSION fdx = DeviceObject->DeviceExtension;
  9. NTSTATUS status;
  10. PAGED_CODE();
  11. //
  12. // Verify that our device has not been SUPRISE_REMOVED. Generally
  13. // only parallel ports on hot-plug busses (e.g., PCMCIA) and
  14. // parallel ports in docking stations will be surprise removed.
  15. //
  16. if( fdx->PnpState & PPT_DEVICE_SURPRISE_REMOVED ) {
  17. //
  18. // Our device has been SURPRISE removed, but since this is only
  19. // a CLOSE, SUCCEED anyway.
  20. //
  21. status = P4CompleteRequest( Irp, STATUS_SUCCESS, 0 );
  22. goto target_exit;
  23. }
  24. //
  25. // Try to acquire RemoveLock to prevent the device object from going
  26. // away while we're using it.
  27. //
  28. status = PptAcquireRemoveLock(&fdx->RemoveLock, Irp);
  29. if( !NT_SUCCESS( status ) ) {
  30. // Our device has been removed, but since this is only a CLOSE, SUCCEED anyway.
  31. status = STATUS_SUCCESS;
  32. goto target_exit;
  33. }
  34. //
  35. // We have the RemoveLock
  36. //
  37. ExAcquireFastMutex(&fdx->OpenCloseMutex);
  38. if( fdx->OpenCloseRefCount > 0 ) {
  39. //
  40. // prevent rollover - strange as it may seem, it is perfectly
  41. // legal for us to receive more closes than creates - this
  42. // info came directly from Mr. PnP himself
  43. //
  44. if( ((LONG)InterlockedDecrement(&fdx->OpenCloseRefCount)) < 0 ) {
  45. // handle underflow
  46. InterlockedIncrement(&fdx->OpenCloseRefCount);
  47. }
  48. }
  49. ExReleaseFastMutex(&fdx->OpenCloseMutex);
  50. target_exit:
  51. DD((PCE)fdx,DDT,"PptFdoClose - OpenCloseRefCount after close = %d\n",fdx->OpenCloseRefCount);
  52. return P4CompleteRequestReleaseRemLock( Irp, STATUS_SUCCESS, 0, &fdx->RemoveLock );
  53. }