branch update for HEAD-2003091401
[reactos.git] / ntoskrnl / io / fs.c
index 223f159..7d8472a 100644 (file)
@@ -35,7 +35,6 @@ typedef struct _FS_CHANGE_NOTIFY_ENTRY
   PFSDNOTIFICATIONPROC FSDNotificationProc;
 } FS_CHANGE_NOTIFY_ENTRY, *PFS_CHANGE_NOTIFY_ENTRY;
 
-
 /* GLOBALS ******************************************************************/
 
 static ERESOURCE FileSystemListLock;
@@ -61,6 +60,9 @@ IopNotifyFileSystemChange(PDEVICE_OBJECT DeviceObject,
 
 #ifndef LIBCAPTIVE
 
+/*
+ * @implemented
+ */
 NTSTATUS STDCALL
 NtFsControlFile (
        IN      HANDLE                  DeviceHandle,
@@ -79,7 +81,7 @@ NtFsControlFile (
    PFILE_OBJECT FileObject;
    PDEVICE_OBJECT DeviceObject;
    PIRP Irp;
-   PIO_STACK_LOCATION StackPtr;
+   PEXTENDED_IO_STACK_LOCATION StackPtr;
    PKEVENT ptrEvent;
    IO_STATUS_BLOCK IoSB;
 
@@ -136,10 +138,13 @@ NtFsControlFile (
                                       ptrEvent,
                                       &IoSB);
    
+   //trigger FileObject/Event dereferencing
+   Irp->Tail.Overlay.OriginalFileObject = FileObject;
+   
    Irp->Overlay.AsynchronousParameters.UserApcRoutine = ApcRoutine;
    Irp->Overlay.AsynchronousParameters.UserApcContext = ApcContext;
 
-   StackPtr = IoGetNextIrpStackLocation(Irp);
+   StackPtr = (PEXTENDED_IO_STACK_LOCATION) IoGetNextIrpStackLocation(Irp);
    StackPtr->FileObject = FileObject;
    StackPtr->DeviceObject = DeviceObject;
    StackPtr->Parameters.FileSystemControl.InputBufferLength = InputBufferSize;
@@ -394,8 +399,19 @@ IoMountVolume(IN PDEVICE_OBJECT DeviceObject,
          current_entry = current_entry->Flink;
          continue;
        }
-      Status = IopMountFileSystem(current->DeviceObject,
-                                 DeviceObject);
+      /* If we are not allowed to mount this volume as a raw filesystem volume
+         then don't try this */
+#ifndef LIBCAPTIVE
+      if (!AllowRawMount && RawFsIsRawFileSystemDeviceObject(current->DeviceObject))
+        {
+          Status = STATUS_UNRECOGNIZED_VOLUME;
+        }
+      else
+#endif /* LIBCAPTIVE */
+        {
+          Status = IopMountFileSystem(current->DeviceObject,
+                                 DeviceObject);
+        }
       switch (Status)
        {
          case STATUS_FS_DRIVER_REQUIRED:
@@ -445,6 +461,8 @@ IoMountVolume(IN PDEVICE_OBJECT DeviceObject,
  *
  * RETURN VALUE
  *     Status
+ *
+ * @implemented
  */
 NTSTATUS STDCALL
 IoVerifyVolume(IN PDEVICE_OBJECT DeviceObject,
@@ -455,6 +473,7 @@ IoVerifyVolume(IN PDEVICE_OBJECT DeviceObject,
   KEVENT Event;
   PIRP Irp;
   NTSTATUS Status;
+  PDEVICE_OBJECT DevObject;
 
   DPRINT("IoVerifyVolume(DeviceObject %x  AllowRawMount %x)\n",
         DeviceObject, AllowRawMount);
@@ -472,12 +491,13 @@ IoVerifyVolume(IN PDEVICE_OBJECT DeviceObject,
   if (DeviceObject->Vpb->Flags & VPB_MOUNTED)
     {
       /* Issue verify request to the FSD */
+      DevObject = DeviceObject->Vpb->DeviceObject;
 
       KeInitializeEvent(&Event,
                        NotificationEvent,
                        FALSE);
 
-      Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
+      Irp = IoAllocateIrp(DevObject->StackSize, TRUE);
       if (Irp==NULL)
        {
          return(STATUS_INSUFFICIENT_RESOURCES);
@@ -492,14 +512,14 @@ IoVerifyVolume(IN PDEVICE_OBJECT DeviceObject,
       StackPtr->MinorFunction = IRP_MN_VERIFY_VOLUME;
       StackPtr->Flags = 0;
       StackPtr->Control = 0;
-      StackPtr->DeviceObject = DeviceObject;
+      StackPtr->DeviceObject = DevObject;
       StackPtr->FileObject = NULL;
       StackPtr->CompletionRoutine = NULL;
 
       StackPtr->Parameters.VerifyVolume.Vpb = DeviceObject->Vpb;
       StackPtr->Parameters.VerifyVolume.DeviceObject = DeviceObject;
 
-      Status = IoCallDriver(DeviceObject,
+      Status = IoCallDriver(DevObject,
                            Irp);
       if (Status==STATUS_PENDING)
        {
@@ -537,6 +557,9 @@ IoVerifyVolume(IN PDEVICE_OBJECT DeviceObject,
 }
 
 
+/*
+ * @implemented
+ */
 PDEVICE_OBJECT STDCALL
 IoGetDeviceToVerify(IN PETHREAD Thread)
 /*
@@ -548,6 +571,9 @@ IoGetDeviceToVerify(IN PETHREAD Thread)
 }
 
 
+/*
+ * @implemented
+ */
 VOID STDCALL
 IoSetDeviceToVerify(IN PETHREAD Thread,
                    IN PDEVICE_OBJECT DeviceObject)
@@ -557,6 +583,9 @@ IoSetDeviceToVerify(IN PETHREAD Thread,
 
 #endif /* LIBCAPTIVE */
 
+/*
+ * @implemented
+ */
 VOID STDCALL
 IoSetHardErrorOrVerifyDevice(IN PIRP Irp,
                             IN PDEVICE_OBJECT DeviceObject)
@@ -565,6 +594,9 @@ IoSetHardErrorOrVerifyDevice(IN PIRP Irp,
 }
 
 
+/*
+ * @implemented
+ */
 VOID STDCALL
 IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
 {
@@ -580,7 +612,12 @@ IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
   Fs->DeviceObject = DeviceObject;
   ExAcquireResourceExclusiveLite(&FileSystemListLock, TRUE);
 
-  InsertTailList(&FileSystemListHead,
+  /* The RAW filesystem device objects must be last in the list so the
+     raw filesystem driver is the last filesystem driver asked to mount
+     a volume. It is always the first filesystem driver registered so
+     we use InsertHeadList() here as opposed to the other alternative
+     InsertTailList(). */
+  InsertHeadList(&FileSystemListHead,
                 &Fs->Entry);
 
   ExReleaseResourceLite(&FileSystemListLock);
@@ -592,6 +629,9 @@ IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
 }
 
 
+/*
+ * @implemented
+ */
 VOID STDCALL
 IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
 {
@@ -638,6 +678,8 @@ IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
  *
  * NOTE
  *     From Bo Branten's ntifs.h v13.
+ *
+ * @implemented
  */
 PDEVICE_OBJECT STDCALL
 IoGetBaseFileSystemDeviceObject(IN PFILE_OBJECT FileObject)
@@ -702,6 +744,9 @@ IopNotifyFileSystemChange(PDEVICE_OBJECT DeviceObject,
 }
 
 
+/*
+ * @implemented
+ */
 NTSTATUS STDCALL
 IoRegisterFsRegistrationChange(IN PDRIVER_OBJECT DriverObject,
                               IN PFSDNOTIFICATIONPROC FSDNotificationProc)
@@ -725,6 +770,9 @@ IoRegisterFsRegistrationChange(IN PDRIVER_OBJECT DriverObject,
 }
 
 
+/*
+ * @implemented
+ */
 VOID STDCALL
 IoUnregisterFsRegistrationChange(IN PDRIVER_OBJECT DriverObject,
                                 IN PFSDNOTIFICATIONPROC FSDNotificationProc)