[NPFS]
authorEric Kohl <eric.kohl@reactos.org>
Mon, 22 Nov 2010 23:08:11 +0000 (23:08 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Mon, 22 Nov 2010 23:08:11 +0000 (23:08 +0000)
Add an FCB that represents the file system (volume/device) and support absolute and relative open, cleanup and close.

svn path=/trunk/; revision=49713

reactos/drivers/filesystems/npfs/create.c
reactos/drivers/filesystems/npfs/npfs.c
reactos/drivers/filesystems/npfs/npfs.h

index dbcbaa1..dc70991 100644 (file)
@@ -105,6 +105,35 @@ NpfsSignalAndRemoveListeningServerInstance(PNPFS_FCB Fcb,
 }
 
 
+static VOID
+NpfsOpenFileSystem(PNPFS_FCB Fcb,
+                   PFILE_OBJECT FileObject,
+                   PIO_STATUS_BLOCK IoStatus)
+{
+    PNPFS_CCB Ccb;
+
+    DPRINT("NpfsOpenFileSystem()\n");
+
+    Ccb = ExAllocatePool(NonPagedPool, sizeof(NPFS_CCB));
+    if (Ccb == NULL)
+    {
+        IoStatus->Status = STATUS_NO_MEMORY;
+        return;
+    }
+
+    Ccb->Type = CCB_DEVICE;
+    Ccb->Fcb = Fcb;
+
+    FileObject->FsContext = Fcb;
+    FileObject->FsContext2 = Ccb;
+
+    IoStatus->Information = FILE_OPENED;
+    IoStatus->Status = STATUS_SUCCESS;
+
+    return;
+}
+
+
 static VOID
 NpfsOpenRootDirectory(PNPFS_FCB Fcb,
                       PFILE_OBJECT FileObject,
@@ -174,6 +203,24 @@ NpfsCreate(PDEVICE_OBJECT DeviceObject,
     }
 #endif
 
+    DPRINT("FileName->Length: %hu  RelatedFileObject: %p\n", FileName->Length, RelatedFileObject);
+
+    /* Open the file system */
+    if (FileName->Length == 0 &&
+        (RelatedFileObject == NULL || ((PNPFS_CCB)RelatedFileObject->FsContext2)->Type == CCB_DEVICE))
+    {
+        DPRINT("Open the file system\n");
+
+        NpfsOpenFileSystem(Vcb->DeviceFcb,
+                           FileObject,
+                           &Irp->IoStatus);
+
+        Status = Irp->IoStatus.Status;
+        IoCompleteRequest(Irp, IO_NO_INCREMENT);
+        return Status;
+    }
+
+    /* Open the root directory */
     if (FileName->Length == 2 && FileName->Buffer[0] == L'\\' && RelatedFileObject == NULL)
     {
         DPRINT("Open the root directory\n");
@@ -662,6 +709,15 @@ NpfsCleanup(PDEVICE_OBJECT DeviceObject,
         return STATUS_SUCCESS;
     }
 
+    if (Ccb->Type == CCB_DEVICE)
+    {
+        DPRINT("Cleanup the file system!\n");
+        Irp->IoStatus.Status = STATUS_SUCCESS;
+        Irp->IoStatus.Information = 0;
+        IoCompleteRequest(Irp, IO_NO_INCREMENT);
+        return STATUS_SUCCESS;
+    }
+
     if (Ccb->Type == CCB_DIRECTORY)
     {
         DPRINT("Cleanup the root directory!\n");
@@ -806,6 +862,20 @@ NpfsClose(PDEVICE_OBJECT DeviceObject,
         return STATUS_SUCCESS;
     }
 
+    if (Ccb->Type == CCB_DEVICE)
+    {
+        DPRINT("Closing the file system!\n");
+
+        ExFreePool(Ccb);
+        FileObject->FsContext = NULL;
+        FileObject->FsContext2 = NULL;
+
+        Irp->IoStatus.Status = STATUS_SUCCESS;
+        Irp->IoStatus.Information = 0;
+        IoCompleteRequest(Irp, IO_NO_INCREMENT);
+        return STATUS_SUCCESS;
+    }
+
     if (Ccb->Type == CCB_DIRECTORY)
     {
         DPRINT("Closing the root directory!\n");
index 825abe3..74fe99b 100644 (file)
@@ -85,12 +85,16 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
     Vcb->DefaultQuota = 8 * PAGE_SIZE;
     Vcb->MaxQuota = 64 * PAGE_SIZE;
 
+    /* Create the device FCB */
     Fcb = ExAllocatePool(NonPagedPool, sizeof(NPFS_FCB));
-    Fcb->Type = FCB_DIRECTORY;
+    Fcb->Type = FCB_DEVICE;
     Fcb->Vcb = Vcb;
+    Vcb->DeviceFcb = Fcb;
 
-
-
+    /* Create the root directory FCB */
+    Fcb = ExAllocatePool(NonPagedPool, sizeof(NPFS_FCB));
+    Fcb->Type = FCB_DIRECTORY;
+    Fcb->Vcb = Vcb;
     Vcb->RootFcb = Fcb;
 
     return STATUS_SUCCESS;
index cb37cb0..2e47e68 100644 (file)
@@ -28,6 +28,7 @@ typedef struct _NPFS_VCB
     ULONG MinQuota;
     ULONG DefaultQuota;
     ULONG MaxQuota;
+    struct _NPFS_FCB *DeviceFcb;
     struct _NPFS_FCB *RootFcb;
 } NPFS_VCB, *PNPFS_VCB;