File system drivers should forward the IRP_MJ_SHUTDOWN request to underlying storage drivers. Fixes bug #504.
Modified: trunk/reactos/drivers/fs/vfat/shutdown.c

Modified: trunk/reactos/drivers/fs/vfat/shutdown.c
--- trunk/reactos/drivers/fs/vfat/shutdown.c	2005-02-16 14:01:34 UTC (rev 13593)
+++ trunk/reactos/drivers/fs/vfat/shutdown.c	2005-02-16 15:27:30 UTC (rev 13594)
@@ -14,6 +14,34 @@
 
 /* FUNCTIONS ****************************************************************/
 
+NTSTATUS
+VfatDiskShutDown(PVCB Vcb)
+{
+   PIRP Irp;
+   KEVENT Event;
+   NTSTATUS Status;
+   IO_STATUS_BLOCK IoStatus;
+
+   KeInitializeEvent(&Event, NotificationEvent, FALSE);
+   Irp = IoBuildSynchronousFsdRequest(IRP_MJ_SHUTDOWN, Vcb->StorageDevice,
+                                      NULL, 0, NULL, &Event, &IoStatus);
+   if (Irp)
+   {
+      Status = IoCallDriver(Vcb->StorageDevice, Irp);
+      if (Status == STATUS_PENDING)
+      {
+         KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
+         Status = IoStatus.Status;
+      }
+   }
+   else
+   {
+      Status = IoStatus.Status;
+   }
+
+   return Status;
+}
+
 NTSTATUS STDCALL
 VfatShutdown(PDEVICE_OBJECT DeviceObject, PIRP Irp)
 {
@@ -37,15 +65,24 @@
 
 	 ExAcquireResourceExclusiveLite(&DeviceExt->DirResource, TRUE);
          Status = VfatFlushVolume(DeviceExt, DeviceExt->VolumeFcb);
-         ExReleaseResourceLite(&DeviceExt->DirResource);
-	 if (!NT_SUCCESS(Status))
-	 {
+         if (NT_SUCCESS(Status))
+         {
+            Status = VfatDiskShutDown(DeviceExt);
+            if (!NT_SUCCESS(Status))
+	       DPRINT1("VfatDiskShutDown failed, status = %x\n", Status);
+         }
+         else
+         {
 	    DPRINT1("VfatFlushVolume failed, status = %x\n", Status);
-	    Irp->IoStatus.Status = Status;
 	 }
+         ExReleaseResourceLite(&DeviceExt->DirResource);
+
          /* FIXME: Unmount the logical volume */
+
+         if (!NT_SUCCESS(Status))
+            Irp->IoStatus.Status = Status;
       }
-	 ExReleaseResourceLite(&VfatGlobalData->VolumeListLock);
+      ExReleaseResourceLite(&VfatGlobalData->VolumeListLock);
       
       /* FIXME: Free all global acquired resources */
 
@@ -53,13 +90,13 @@
    }
    else
    {
+      Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
       Status = STATUS_INVALID_DEVICE_REQUEST;
    }
 
-   Irp->IoStatus.Status = Status;
    Irp->IoStatus.Information = 0;
+   IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
-   IoCompleteRequest(Irp, IO_NO_INCREMENT);
    return(Status);
 }