[fastfat_new]
authorAleksey Bragin <aleksey@reactos.org>
Sat, 17 Oct 2009 10:57:48 +0000 (10:57 +0000)
committerAleksey Bragin <aleksey@reactos.org>
Sat, 17 Oct 2009 10:57:48 +0000 (10:57 +0000)
- Search FCBs with unicode name too, besides of OEM.
- Create an infrastructure for opening existing FCB/DCBs.

svn path=/trunk/; revision=43527

reactos/drivers/filesystems/fastfat_new/create.c
reactos/drivers/filesystems/fastfat_new/dir.c
reactos/drivers/filesystems/fastfat_new/fastfat.h
reactos/drivers/filesystems/fastfat_new/fcb.c

index 61cb5bf..a92494b 100644 (file)
@@ -353,10 +353,11 @@ FatiCreate(IN PFAT_IRP_CONTEXT IrpContext,
     IO_STATUS_BLOCK Iosb;
     PIO_STACK_LOCATION IrpSp;
     BOOLEAN EndBackslash = FALSE, OpenedAsDos;
-    UNICODE_STRING RemainingPart, FirstName, NextName;
+    UNICODE_STRING RemainingPart, FirstName, NextName, FileNameUpcased;
     OEM_STRING AnsiFirstName;
     FF_ERROR FfError;
     TYPE_OF_OPEN TypeOfOpen;
+    BOOLEAN OplockPostIrp = FALSE;
 
     Iosb.Status = STATUS_SUCCESS;
 
@@ -684,10 +685,22 @@ FatiCreate(IN PFAT_IRP_CONTEXT IrpContext,
                                          &OpenedAsDos);
                 }
 
-                /* Check if we found anything */
+                /* If nothing found - try with unicode */
                 if (!NextFcb && Fcb->Dcb.SplayLinksUnicode)
                 {
-                    ASSERT(FALSE);
+                    FileNameUpcased.Buffer = FsRtlAllocatePool(PagedPool, FirstName.Length);
+                    FileNameUpcased.Length = 0;
+                    FileNameUpcased.MaximumLength = FirstName.Length;
+
+                    /* Downcase and then upcase to normalize it */
+                    Status = RtlDowncaseUnicodeString(&FileNameUpcased, &FirstName, FALSE);
+                    Status = RtlUpcaseUnicodeString(&FileNameUpcased, &FileNameUpcased, FALSE);
+
+                    /* Try to find FCB again using unicode name */
+                    NextFcb = FatFindFcb(IrpContext,
+                                         &Fcb->Dcb.SplayLinksUnicode,
+                                        (PSTRING)&FileNameUpcased,
+                                         &OpenedAsDos);
                 }
 
                 /* Move to the next FCB */
@@ -729,8 +742,116 @@ FatiCreate(IN PFAT_IRP_CONTEXT IrpContext,
         /* We have a valid FCB now */
         if (!RemainingPart.Length)
         {
-            DPRINT1("It's possible to open an existing FCB\n");
-            ASSERT(FALSE);
+            /* Check for target dir open */
+            if (OpenTargetDirectory)
+            {
+                DPRINT1("Opening target dir is missing\n");
+                ASSERT(FALSE);
+            }
+
+            /* Check this FCB's type */
+            if (FatNodeType(Fcb) == FAT_NTC_ROOT_DCB ||
+                FatNodeType(Fcb) == FAT_NTC_DCB)
+            {
+                /* Open a directory */
+                if (NonDirectoryFile)
+                {
+                    /* Forbidden */
+                    Iosb.Status = STATUS_FILE_IS_A_DIRECTORY;
+                    ASSERT(FALSE);
+                    return Iosb.Status;
+                }
+
+                /* Open existing DCB */
+                Iosb = FatiOpenExistingDcb(IrpContext,
+                                           FileObject,
+                                           Vcb,
+                                           Fcb,
+                                           DesiredAccess,
+                                           ShareAccess,
+                                           CreateDisposition,
+                                           NoEaKnowledge,
+                                           DeleteOnClose);
+
+                /* Save information */
+                Irp->IoStatus.Information = Iosb.Information;
+
+                /* Unlock VCB */
+                FatReleaseVcb(IrpContext, Vcb);
+
+                /* Complete the request */
+                FatCompleteRequest(IrpContext, Irp, Iosb.Status);
+
+                return Iosb.Status;
+            }
+            else if (FatNodeType(Fcb) == FAT_NTC_FCB)
+            {
+                /* Open a file */
+                if (OpenDirectory)
+                {
+                    /* Forbidden */
+                    Iosb.Status = STATUS_NOT_A_DIRECTORY;
+                    ASSERT(FALSE);
+                    return Iosb.Status;
+                }
+
+                /* Check for trailing backslash */
+                if (EndBackslash)
+                {
+                    /* Forbidden */
+                    Iosb.Status = STATUS_OBJECT_NAME_INVALID;
+                    ASSERT(FALSE);
+                    return Iosb.Status;
+                }
+
+                Iosb = FatiOpenExistingFcb(IrpContext,
+                                           FileObject,
+                                           Vcb,
+                                           Fcb,
+                                           DesiredAccess,
+                                           ShareAccess,
+                                           AllocationSize,
+                                           EaBuffer,
+                                           EaLength,
+                                           FileAttributes,
+                                           CreateDisposition,
+                                           NoEaKnowledge,
+                                           DeleteOnClose,
+                                           OpenedAsDos,
+                                           &OplockPostIrp);
+
+                /* Check if it's pending */
+                if (Iosb.Status != STATUS_PENDING)
+                {
+                    /* In case of success set cache supported flag */
+                    if (NT_SUCCESS(Iosb.Status) && !NoIntermediateBuffering)
+                    {
+                        SetFlag(FileObject->Flags, FO_CACHE_SUPPORTED);
+                    }
+
+                    /* Save information */
+                    Irp->IoStatus.Information = Iosb.Information;
+
+                    /* Unlock VCB */
+                    FatReleaseVcb(IrpContext, Vcb);
+
+                    /* Complete the request */
+                    FatCompleteRequest(IrpContext, Irp, Iosb.Status);
+
+                    return Iosb.Status;
+                }
+                else
+                {
+                    /* Queue this IRP */
+                    UNIMPLEMENTED;
+                    ASSERT(FALSE);
+                }
+            }
+            else
+            {
+                /* Unexpected FCB type */
+                KeBugCheckEx(/*FAT_FILE_SYSTEM*/0x23, __LINE__, (ULONG_PTR)Fcb, 0, 0);
+            }
         }
 
         /* During parsing we encountered a part which has no attached FCB/DCB.
index 2dd3584..1bb7826 100644 (file)
@@ -173,4 +173,24 @@ FatCreateDcb(IN PFAT_IRP_CONTEXT IrpContext,
     return Fcb;
 }
 
+IO_STATUS_BLOCK
+NTAPI
+FatiOpenExistingDcb(IN PFAT_IRP_CONTEXT IrpContext,
+                    IN PFILE_OBJECT FileObject,
+                    IN PVCB Vcb,
+                    IN PFCB Dcb,
+                    IN PACCESS_MASK DesiredAccess,
+                    IN USHORT ShareAccess,
+                    IN ULONG CreateDisposition,
+                    IN BOOLEAN NoEaKnowledge,
+                    IN BOOLEAN DeleteOnClose)
+{
+    IO_STATUS_BLOCK Iosb = {{0}};
+
+    Iosb.Status = STATUS_NOT_IMPLEMENTED;
+    UNIMPLEMENTED;
+
+    return Iosb;
+}
+
 /* EOF */
index 9fec7c0..6f79db7 100644 (file)
@@ -87,6 +87,17 @@ FatCreateDcb(IN PFAT_IRP_CONTEXT IrpContext,
              IN PFCB ParentDcb,
              IN FF_FILE *FileHandle);
 
+IO_STATUS_BLOCK NTAPI
+FatiOpenExistingDcb(IN PFAT_IRP_CONTEXT IrpContext,
+                    IN PFILE_OBJECT FileObject,
+                    IN PVCB Vcb,
+                    IN PFCB Dcb,
+                    IN PACCESS_MASK DesiredAccess,
+                    IN USHORT ShareAccess,
+                    IN ULONG CreateDisposition,
+                    IN BOOLEAN NoEaKnowledge,
+                    IN BOOLEAN DeleteOnClose);
+
 /*  --------------------------------------------------------  create.c  */
 
 NTSTATUS NTAPI
@@ -296,6 +307,23 @@ FatCreateFcb(
     IN PFCB ParentDcb,
     IN FF_FILE *FileHandle);
 
+IO_STATUS_BLOCK NTAPI
+FatiOpenExistingFcb(IN PFAT_IRP_CONTEXT IrpContext,
+                    IN PFILE_OBJECT FileObject,
+                    IN PVCB Vcb,
+                    IN PFCB Fcb,
+                    IN PACCESS_MASK DesiredAccess,
+                    IN USHORT ShareAccess,
+                    IN ULONG AllocationSize,
+                    IN PFILE_FULL_EA_INFORMATION EaBuffer,
+                    IN ULONG EaLength,
+                    IN UCHAR FileAttributes,
+                    IN ULONG CreateDisposition,
+                    IN BOOLEAN NoEaKnowledge,
+                    IN BOOLEAN DeleteOnClose,
+                    IN BOOLEAN OpenedAsDos,
+                    OUT PBOOLEAN OplockPostIrp);
+
 PFCB NTAPI
 FatFindFcb(PFAT_IRP_CONTEXT IrpContext,
            PRTL_SPLAY_LINKS *RootNode,
index 5092366..b9fe0d8 100644 (file)
@@ -172,6 +172,32 @@ FatCreateCcb()
     return Ccb;
 }
 
+IO_STATUS_BLOCK
+NTAPI
+FatiOpenExistingFcb(IN PFAT_IRP_CONTEXT IrpContext,
+                    IN PFILE_OBJECT FileObject,
+                    IN PVCB Vcb,
+                    IN PFCB Fcb,
+                    IN PACCESS_MASK DesiredAccess,
+                    IN USHORT ShareAccess,
+                    IN ULONG AllocationSize,
+                    IN PFILE_FULL_EA_INFORMATION EaBuffer,
+                    IN ULONG EaLength,
+                    IN UCHAR FileAttributes,
+                    IN ULONG CreateDisposition,
+                    IN BOOLEAN NoEaKnowledge,
+                    IN BOOLEAN DeleteOnClose,
+                    IN BOOLEAN OpenedAsDos,
+                    OUT PBOOLEAN OplockPostIrp)
+{
+    IO_STATUS_BLOCK Iosb = {{0}};
+
+    Iosb.Status = STATUS_NOT_IMPLEMENTED;
+    UNIMPLEMENTED;
+
+    return Iosb;
+}
+
 VOID
 NTAPI
 FatGetFcbUnicodeName(IN PFAT_IRP_CONTEXT IrpContext,