[NTOSKRNL]
authorPierre Schweitzer <pierre@reactos.org>
Wed, 7 Jul 2010 20:27:04 +0000 (20:27 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Wed, 7 Jul 2010 20:27:04 +0000 (20:27 +0000)
Implement volume mount notification in RawFS

svn path=/trunk/; revision=47965

reactos/ntoskrnl/io/iomgr/rawfs.c

index 7030b3c..36252d5 100755 (executable)
@@ -312,6 +312,7 @@ RawMountVolume(IN PIO_STACK_LOCATION IoStackLocation)
     NTSTATUS Status;
     PDEVICE_OBJECT DeviceObject;
     PVOLUME_DEVICE_OBJECT Volume;
+    PFILE_OBJECT FileObject = NULL;
     PAGED_CODE();
 
     /* Remember our owner */
@@ -349,6 +350,36 @@ RawMountVolume(IN PIO_STACK_LOCATION IoStackLocation)
     Volume->DeviceObject.SectorSize = DeviceObject->SectorSize;
     Volume->DeviceObject.Flags |= DO_DIRECT_IO;
     Volume->DeviceObject.Flags &= ~DO_DEVICE_INITIALIZING;
+
+    /* Try to get associated FO (for notification) */
+    _SEH2_TRY
+    {
+        FileObject = IoCreateStreamFileObjectLite(NULL,
+                                                  &(Volume->DeviceObject));
+    }
+    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+    {
+        /* Get the exception code */
+        Status = _SEH2_GetExceptionCode();
+    }
+    _SEH2_END;
+
+    /* If failed, delete devive */
+    if (!NT_SUCCESS(Status))
+    {
+        IoDeleteDevice((PDEVICE_OBJECT)Volume);
+        return Status;
+    }
+
+    /* Increment OpenCount by two to avoid dismount when RawClose() will be called on ObDereferenceObject() */
+    Volume->Vcb.OpenCount += 2;
+    /* Notify for sucessful mount */
+    FsRtlNotifyVolumeEvent(FileObject, FSRTL_VOLUME_MOUNT);
+    /* Decrease refcount to 0 to make FileObject being released */
+    ObDereferenceObject(FileObject);
+    /* It's not open anymore, go back to 0 */
+    Volume->Vcb.OpenCount -= 2;
+
     return Status;
 }