started moving tags to a private internal header
[reactos.git] / reactos / ntoskrnl / io / rawfs.c
index df32d1e..6881de8 100755 (executable)
@@ -1,20 +1,16 @@
-/* $Id: rawfs.c,v 1.2 2003/05/15 13:34:37 ekohl Exp $
+/* $Id$
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/io/rawfs.c
  * PURPOSE:         Raw filesystem driver
- * PROGRAMMER:      Casper S. Hornstrup (chorns@users.sourceforge.net)
- * UPDATE HISTORY:
- *                  Created 13/04/2003
+ *
+ * PROGRAMMERS:     Casper S. Hornstrup (chorns@users.sourceforge.net)
  */
 
 /* INCLUDES *****************************************************************/
 
-#include <ddk/ntddk.h>
-#include <ddk/ntifs.h>
-#include <reactos/bugcodes.h>
-
+#include <ntoskrnl.h>
 #define NDEBUG
 #include <internal/debug.h>
 
@@ -65,7 +61,7 @@ typedef struct _RAWFS_IRP_CONTEXT
 typedef struct _RAWFS_FCB
 {
   /* Start FCB header required by ReactOS/Windows NT */
-  REACTOS_COMMON_FCB_HEADER RFCB;
+  FSRTL_COMMON_FCB_HEADER RFCB;
   SECTION_OBJECT_POINTERS SectionObjectPointers;
   ERESOURCE MainResource;
   ERESOURCE PagingIoResource;
@@ -94,8 +90,6 @@ typedef struct _RAWFS_CCB
 
 /* GLOBALS ******************************************************************/
 
-#define TAG_IRP TAG('R', 'I', 'R', 'P')
-
 static PDRIVER_OBJECT RawFsDriverObject;
 static PDEVICE_OBJECT DiskDeviceObject;
 static PDEVICE_OBJECT CdromDeviceObject;
@@ -196,8 +190,8 @@ RawFsWriteDisk(IN PDEVICE_OBJECT pDeviceObject,
     pDeviceObject,
     Buffer,
     WriteLength,
-    WriteOffset, 
-    &Event, 
+    WriteOffset,
+    &Event,
     &IoStatus);
   if (!Irp)
     {
@@ -231,7 +225,7 @@ RawFsBlockDeviceIoControl(IN PDEVICE_OBJECT DeviceObject,
   IN ULONG CtlCode,
   IN PVOID InputBuffer,
   IN ULONG InputBufferSize,
-  IN OUT PVOID OutputBuffer, 
+  IN OUT PVOID OutputBuffer,
   IN OUT PULONG pOutputBufferSize)
 {
        ULONG OutputBufferSize = 0;
@@ -241,9 +235,9 @@ RawFsBlockDeviceIoControl(IN PDEVICE_OBJECT DeviceObject,
        NTSTATUS Status;
 
        DPRINT("RawFsBlockDeviceIoControl(DeviceObject %x, CtlCode %x, "
-    "InputBuffer %x, InputBufferSize %x, OutputBuffer %x, " 
-    "POutputBufferSize %x (%x)\n", DeviceObject, CtlCode, 
-    InputBuffer, InputBufferSize, OutputBuffer, pOutputBufferSize, 
+    "InputBuffer %x, InputBufferSize %x, OutputBuffer %x, "
+    "POutputBufferSize %x (%x)\n", DeviceObject, CtlCode,
+    InputBuffer, InputBufferSize, OutputBuffer, pOutputBufferSize,
     pOutputBufferSize ? *pOutputBufferSize : 0);
 
        if (pOutputBufferSize)
@@ -254,14 +248,14 @@ RawFsBlockDeviceIoControl(IN PDEVICE_OBJECT DeviceObject,
        KeInitializeEvent(&Event, NotificationEvent, FALSE);
 
        DPRINT("Building device I/O control request ...\n");
-       Irp = IoBuildDeviceIoControlRequest(CtlCode, 
-    DeviceObject, 
-    InputBuffer, 
-    InputBufferSize, 
+       Irp = IoBuildDeviceIoControlRequest(CtlCode,
+    DeviceObject,
+    InputBuffer,
+    InputBufferSize,
     OutputBuffer,
-    OutputBufferSize, 
-    FALSE, 
-    &Event, 
+    OutputBufferSize,
+    FALSE,
+    &Event,
     &IoStatus);
        if (Irp == NULL)
        {
@@ -297,14 +291,14 @@ RawFsNewFCB(IN PRAWFS_GLOBAL_DATA pGlobalData)
   memset(Fcb, 0, sizeof(RAWFS_FCB));
   ExInitializeResourceLite(&Fcb->PagingIoResource);
   ExInitializeResourceLite(&Fcb->MainResource);
-//  FsRtlInitializeFileLock(&Fcb->FileLock, NULL, NULL); 
+//  FsRtlInitializeFileLock(&Fcb->FileLock, NULL, NULL);
   return Fcb;
 }
 
 static VOID
 RawFsDestroyFCB(IN PRAWFS_GLOBAL_DATA pGlobalData, IN PRAWFS_FCB pFcb)
 {
-  //FsRtlUninitializeFileLock(&pFcb->FileLock); 
+  //FsRtlUninitializeFileLock(&pFcb->FileLock);
   ExDeleteResourceLite(&pFcb->PagingIoResource);
   ExDeleteResourceLite(&pFcb->MainResource);
   ExFreeToNPagedLookasideList(&pGlobalData->FcbLookasideList, pFcb);
@@ -335,8 +329,8 @@ RawFsAllocateIrpContext(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
   DPRINT("RawFsAllocateIrpContext(DeviceObject %x, Irp %x)\n", DeviceObject, Irp);
 
-  assert(DeviceObject);
-  assert(Irp);
+  ASSERT(DeviceObject);
+  ASSERT(Irp);
 
   GlobalData = (PRAWFS_GLOBAL_DATA) DeviceObject->DeviceExtension;
   IrpContext = ExAllocateFromNPagedLookasideList(&IrpContextLookasideList);
@@ -347,7 +341,7 @@ RawFsAllocateIrpContext(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
       IrpContext->DeviceObject = DeviceObject;
       IrpContext->DeviceExt = DeviceObject->DeviceExtension;
       IrpContext->Stack = IoGetCurrentIrpStackLocation(Irp);
-      assert(IrpContext->Stack);
+      ASSERT(IrpContext->Stack);
       MajorFunction = IrpContext->MajorFunction = IrpContext->Stack->MajorFunction;
       IrpContext->MinorFunction = IrpContext->Stack->MinorFunction;
       IrpContext->FileObject = IrpContext->Stack->FileObject;
@@ -372,7 +366,7 @@ RawFsFreeIrpContext(IN PRAWFS_IRP_CONTEXT IrpContext)
 {
   DPRINT("RawFsFreeIrpContext(IrpContext %x)\n", IrpContext);
 
-  assert(IrpContext);
+  ASSERT(IrpContext);
 
   ExFreeToNPagedLookasideList(&IrpContextLookasideList, IrpContext);
 }
@@ -382,10 +376,11 @@ STDCALL RawFsDoRequest(PVOID IrpContext)
 {
   ULONG Count;
 
+  Count = InterlockedDecrement(&RawFsQueueCount);
+
   DPRINT("RawFsDoRequest(IrpContext %x), MajorFunction %x, %d\n",
     IrpContext, ((PRAWFS_IRP_CONTEXT) IrpContext)->MajorFunction, Count);
 
-  Count = InterlockedDecrement(&RawFsQueueCount);
   RawFsDispatchRequest((PRAWFS_IRP_CONTEXT) IrpContext);
 }
 
@@ -394,13 +389,13 @@ RawFsQueueRequest(PRAWFS_IRP_CONTEXT IrpContext)
 {
   ULONG Count;
 
-  DPRINT("RawFsQueueRequest (IrpContext %x), %d\n", IrpContext, Count);
-
-  assert(IrpContext != NULL);
-  assert(IrpContext->Irp != NULL);
+  ASSERT(IrpContext != NULL);
+  ASSERT(IrpContext->Irp != NULL);
 
   Count = InterlockedIncrement(&RawFsQueueCount);
 
+  DPRINT("RawFsQueueRequest (IrpContext %x), %d\n", IrpContext, Count);
+
   IrpContext->Flags |= IRPCONTEXT_CANWAIT;
   IoMarkIrpPending (IrpContext->Irp);
   ExInitializeWorkItem (&IrpContext->WorkQueueItem, RawFsDoRequest, IrpContext);
@@ -412,7 +407,7 @@ static NTSTATUS
 RawFsClose(IN PRAWFS_IRP_CONTEXT IrpContext)
 {
   DPRINT("RawFsClose(IrpContext %x)\n", IrpContext);
-  UNIMPLEMENTED
+  UNIMPLEMENTED;
   return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -435,7 +430,7 @@ RawFsCreateFile(IN PRAWFS_IRP_CONTEXT IrpContext)
   FileObject = IoSp->FileObject;
   DeviceExt = IrpContext->DeviceObject->DeviceExtension;
 
-  if (FileObject->FileName.Length == 0 && 
+  if (FileObject->FileName.Length == 0 &&
       FileObject->RelatedFileObject == NULL)
     {
       /* This a open operation for the volume itself */
@@ -456,8 +451,7 @@ RawFsCreateFile(IN PRAWFS_IRP_CONTEXT IrpContext)
          return (STATUS_INSUFFICIENT_RESOURCES);
        }
 
-      FileObject->Flags |= FO_FCB_IS_VALID;
-      FileObject->SectionObjectPointers = &pFcb->SectionObjectPointers;
+      FileObject->SectionObjectPointer = &pFcb->SectionObjectPointers;
       FileObject->FsContext = pFcb;
       FileObject->FsContext2 = pCcb;
       pFcb->RefCount++;
@@ -477,8 +471,8 @@ RawFsCreate(IN PRAWFS_IRP_CONTEXT IrpContext)
 
   DPRINT("RawFsCreate(IrpContext %x)\n", IrpContext);
 
-  assert(IrpContext);
-  
+  ASSERT(IrpContext);
+
   if (RawFsIsRawFileSystemDeviceObject(IrpContext->DeviceObject))
     {
       /* DeviceObject represents FileSystem instead of logical volume */
@@ -500,8 +494,8 @@ RawFsCreate(IN PRAWFS_IRP_CONTEXT IrpContext)
   Status = RawFsCreateFile(IrpContext);
 
   IrpContext->Irp->IoStatus.Status = Status;
-  IoCompleteRequest(IrpContext->Irp, 
-    NT_SUCCESS(Status) ? IO_DISK_INCREMENT : IO_NO_INCREMENT);
+  IoCompleteRequest(IrpContext->Irp,
+    (CCHAR)(NT_SUCCESS(Status) ? IO_DISK_INCREMENT : IO_NO_INCREMENT));
   RawFsFreeIrpContext(IrpContext);
 
   return Status;
@@ -511,7 +505,7 @@ static NTSTATUS
 RawFsRead(IN PRAWFS_IRP_CONTEXT IrpContext)
 {
   DPRINT("RawFsRead(IrpContext %x)\n", IrpContext);
-  UNIMPLEMENTED
+  UNIMPLEMENTED;
   return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -519,14 +513,14 @@ static NTSTATUS
 RawFsWrite(IN PRAWFS_IRP_CONTEXT IrpContext)
 {
   DPRINT("RawFsWrite(IrpContext %x)\n", IrpContext);
-  UNIMPLEMENTED
+  UNIMPLEMENTED;
   return STATUS_NOT_IMPLEMENTED;
 }
 
 static NTSTATUS
 RawFsMount(IN PRAWFS_IRP_CONTEXT IrpContext)
 {
-  PRAWFS_GLOBAL_DATA GlobalData;
+  PRAWFS_GLOBAL_DATA GlobalData = NULL;
   PDEVICE_OBJECT DeviceObject = NULL;
   PRAWFS_DEVICE_EXTENSION DeviceExt = NULL;
   PRAWFS_FCB VolumeFcb = NULL;
@@ -539,7 +533,7 @@ RawFsMount(IN PRAWFS_IRP_CONTEXT IrpContext)
 
   DPRINT("RawFsMount(IrpContext %x)\n", IrpContext);
 
-  assert(IrpContext);
+  ASSERT(IrpContext);
 
   if (!RawFsIsRawFileSystemDeviceObject(IrpContext->DeviceObject))
     {
@@ -565,7 +559,7 @@ RawFsMount(IN PRAWFS_IRP_CONTEXT IrpContext)
   DeviceObject->Flags |= DO_DIRECT_IO;
   DeviceExt = (PVOID) DeviceObject->DeviceExtension;
   RtlZeroMemory(DeviceExt, sizeof(RAWFS_DEVICE_EXTENSION));
-  
+
   /* Use same vpb as device disk */
   DeviceObject->Vpb = IrpContext->Stack->Parameters.MountVolume.DeviceObject->Vpb;
   DeviceExt->StorageDevice = IrpContext->Stack->Parameters.MountVolume.DeviceObject;
@@ -574,7 +568,7 @@ RawFsMount(IN PRAWFS_IRP_CONTEXT IrpContext)
   DeviceExt->StorageDevice->Vpb->Flags |= VPB_MOUNTED;
   DeviceObject->StackSize = DeviceExt->StorageDevice->StackSize + 1;
   DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
-  
+
   KeInitializeSpinLock(&DeviceExt->FcbListLock);
   InitializeListHead(&DeviceExt->FcbListHead);
 
@@ -640,9 +634,11 @@ RawFsMount(IN PRAWFS_IRP_CONTEXT IrpContext)
   VolumeFcb->RFCB.AllocationSize.QuadPart = VolumeFcb->RFCB.FileSize.QuadPart;
   DeviceExt->VolumeFcb = VolumeFcb;
 
+  KeEnterCriticalRegion();
   ExAcquireResourceExclusiveLite(&GlobalData->VolumeListLock, TRUE);
   InsertHeadList(&GlobalData->VolumeListHead, &DeviceExt->VolumeListEntry);
   ExReleaseResourceLite(&GlobalData->VolumeListLock);
+  KeLeaveCriticalRegion();
 
   /* No serial number */
   DeviceObject->Vpb->SerialNumber = 0;
@@ -674,8 +670,8 @@ RawFsFileSystemControl(IN PRAWFS_IRP_CONTEXT IrpContext)
   NTSTATUS Status;
 
   DPRINT("RawFsFileSystemControl(IrpContext %x)\n", IrpContext);
-  
-  assert (IrpContext);
+
+  ASSERT(IrpContext);
 
   switch (IrpContext->MinorFunction)
     {
@@ -712,7 +708,7 @@ static NTSTATUS
 RawFsQueryInformation(IN PRAWFS_IRP_CONTEXT IrpContext)
 {
   DPRINT("RawFsQueryInformation(IrpContext %x)\n", IrpContext);
-  UNIMPLEMENTED
+  UNIMPLEMENTED;
   return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -720,7 +716,7 @@ static NTSTATUS
 RawFsSetInformation(IN PRAWFS_IRP_CONTEXT IrpContext)
 {
   DPRINT("RawFsSetInformation(IrpContext %x)\n", IrpContext);
-  UNIMPLEMENTED
+  UNIMPLEMENTED;
   return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -728,7 +724,7 @@ static NTSTATUS
 RawFsDirectoryControl(IN PRAWFS_IRP_CONTEXT IrpContext)
 {
   DPRINT("RawFsDirectoryControl(IrpContext %x)\n", IrpContext);
-  UNIMPLEMENTED
+  UNIMPLEMENTED;
   return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -736,7 +732,7 @@ static NTSTATUS
 RawFsQueryVolumeInformation(IN PRAWFS_IRP_CONTEXT IrpContext)
 {
   DPRINT("RawFsQueryVolumeInformation(IrpContext %x)\n", IrpContext);
-  UNIMPLEMENTED
+  UNIMPLEMENTED;
   return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -744,7 +740,7 @@ static NTSTATUS
 RawFsSetVolumeInformation(IN PRAWFS_IRP_CONTEXT IrpContext)
 {
   DPRINT("RawFsSetVolumeInformation(IrpContext %x)\n", IrpContext);
-  UNIMPLEMENTED
+  UNIMPLEMENTED;
   return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -752,7 +748,7 @@ static NTSTATUS
 RawFsLockControl(IN PRAWFS_IRP_CONTEXT IrpContext)
 {
   DPRINT("RawFsLockControl(IrpContext %x)\n", IrpContext);
-  UNIMPLEMENTED
+  UNIMPLEMENTED;
   return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -760,7 +756,7 @@ static NTSTATUS
 RawFsCleanup(IN PRAWFS_IRP_CONTEXT IrpContext)
 {
   DPRINT("RawFsCleanup(IrpContext %x)\n", IrpContext);
-  UNIMPLEMENTED
+  UNIMPLEMENTED;
   return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -768,7 +764,7 @@ static NTSTATUS
 RawFsFlush(IN PRAWFS_IRP_CONTEXT IrpContext)
 {
   DPRINT("RawFsFlush(IrpContext %x)\n", IrpContext);
-  UNIMPLEMENTED
+  UNIMPLEMENTED;
   return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -791,7 +787,7 @@ RawFsDispatchRequest(IN PRAWFS_IRP_CONTEXT IrpContext)
   DPRINT("RawFsDispatchRequest(IrpContext %x), MajorFunction %x\n",
     IrpContext, IrpContext->MajorFunction);
 
-  assert (IrpContext);
+  ASSERT(IrpContext);
 
   switch (IrpContext->MajorFunction)
     {
@@ -839,8 +835,8 @@ RawFsBuildRequest(IN PDEVICE_OBJECT DeviceObject,
 
   DPRINT("RawFsBuildRequest(DeviceObject %x, Irp %x)\n", DeviceObject, Irp);
 
-  assert(DeviceObject);
-  assert(Irp);
+  ASSERT(DeviceObject);
+  ASSERT(Irp);
 
   IrpContext = RawFsAllocateIrpContext(DeviceObject, Irp);
   if (IrpContext == NULL)
@@ -887,7 +883,7 @@ RawFsDriverEntry(IN PDRIVER_OBJECT DriverObject,
   if (!NT_SUCCESS(Status))
     {
       CPRINT("IoCreateDevice() failed with status 0x%.08x\n", Status);
-      KeBugCheck(PHASE1_INITIALIZATION_FAILED);
+      KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
       return(Status);
     }
   DeviceData = DiskDeviceObject->DeviceExtension;
@@ -907,7 +903,7 @@ RawFsDriverEntry(IN PDRIVER_OBJECT DriverObject,
   if (!NT_SUCCESS(Status))
     {
       CPRINT("IoCreateDevice() failed with status 0x%.08x\n", Status);
-      KeBugCheck(PHASE1_INITIALIZATION_FAILED);
+      KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
       return(Status);
     }
   DeviceData = CdromDeviceObject->DeviceExtension;
@@ -926,8 +922,7 @@ RawFsDriverEntry(IN PDRIVER_OBJECT DriverObject,
     &TapeDeviceObject);
   if (!NT_SUCCESS(Status))
     {
-      CPRINT("IoCreateDevice() failed with status 0x%.08x\n", Status);
-      KeBugCheck(PHASE1_INITIALIZATION_FAILED);
+      KEBUGCHECKEX(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
       return(Status);
     }
   DeviceData = TapeDeviceObject->DeviceExtension;