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.

141 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1989-1998 Microsoft Corporation
  3. Module Name:
  4. PnP.c
  5. Abstract:
  6. The PnP package provides a method for file systems to
  7. notify applications and services that a volume is being
  8. locked or unlocked, so handles to it can be closed and
  9. reopened.
  10. This module exports routines which help file systems
  11. do this notification.
  12. Author:
  13. Keith Kaplan [KeithKa] 01-Apr-1998
  14. Revision History:
  15. --*/
  16. #include "FsRtlP.h"
  17. #ifndef FAR
  18. #define FAR
  19. #endif
  20. #include <IoEvent.h>
  21. #ifdef ALLOC_PRAGMA
  22. #pragma alloc_text(PAGE, FsRtlNotifyVolumeEvent)
  23. #endif
  24. NTKERNELAPI
  25. NTSTATUS
  26. FsRtlNotifyVolumeEvent (
  27. IN PFILE_OBJECT FileObject,
  28. IN ULONG EventCode
  29. )
  30. /*++
  31. Routine Description:
  32. This routine notifies any registered applications that a
  33. volume is being locked, unlocked, etc.
  34. Arguments:
  35. FileeObject - Supplies a file object for the volume being
  36. locked.
  37. EventCode - Which event is occuring -- e.g. FSRTL_VOLUME_LOCK
  38. Return Value:
  39. Status of the notification.
  40. --*/
  41. {
  42. NTSTATUS Status = STATUS_SUCCESS;
  43. TARGET_DEVICE_CUSTOM_NOTIFICATION Event;
  44. PDEVICE_OBJECT Pdo;
  45. //
  46. // Retrieve the device object associated with this file object.
  47. //
  48. Status = IoGetRelatedTargetDevice( FileObject, &Pdo );
  49. if (NT_SUCCESS( Status )) {
  50. ASSERT(Pdo != NULL);
  51. Event.Version = 1;
  52. Event.FileObject = NULL;
  53. Event.NameBufferOffset = -1;
  54. Event.Size = (USHORT)FIELD_OFFSET( TARGET_DEVICE_CUSTOM_NOTIFICATION, CustomDataBuffer );
  55. switch (EventCode) {
  56. case FSRTL_VOLUME_DISMOUNT:
  57. RtlCopyMemory( &Event.Event, &GUID_IO_VOLUME_DISMOUNT, sizeof( GUID ));
  58. break;
  59. case FSRTL_VOLUME_DISMOUNT_FAILED:
  60. RtlCopyMemory( &Event.Event, &GUID_IO_VOLUME_DISMOUNT_FAILED, sizeof( GUID ));
  61. break;
  62. case FSRTL_VOLUME_LOCK:
  63. RtlCopyMemory( &Event.Event, &GUID_IO_VOLUME_LOCK, sizeof( GUID ));
  64. break;
  65. case FSRTL_VOLUME_LOCK_FAILED:
  66. RtlCopyMemory( &Event.Event, &GUID_IO_VOLUME_LOCK_FAILED, sizeof( GUID ));
  67. break;
  68. case FSRTL_VOLUME_MOUNT:
  69. //
  70. // Mount notification is asynchronous to avoid deadlocks when someone
  71. // unwittingly causes a mount in the course of handling some other
  72. // PnP notification, e.g. MountMgr's device arrival code.
  73. //
  74. RtlCopyMemory( &Event.Event, &GUID_IO_VOLUME_MOUNT, sizeof( GUID ));
  75. IoReportTargetDeviceChangeAsynchronous( Pdo, &Event, NULL, NULL );
  76. ObDereferenceObject( Pdo );
  77. return STATUS_SUCCESS;
  78. break;
  79. case FSRTL_VOLUME_UNLOCK:
  80. RtlCopyMemory( &Event.Event, &GUID_IO_VOLUME_UNLOCK, sizeof( GUID ));
  81. break;
  82. default:
  83. ObDereferenceObject( Pdo );
  84. return STATUS_INVALID_PARAMETER;
  85. }
  86. IoReportTargetDeviceChange( Pdo, &Event );
  87. ObDereferenceObject( Pdo );
  88. }
  89. return Status;
  90. }