Don't try to create a file, if no parent fcb was found.
[reactos.git] / reactos / drivers / fs / vfat / create.c
index c8548f9..b0b8323 100644 (file)
@@ -439,10 +439,9 @@ VfatCreateFile ( PDEVICE_OBJECT DeviceObject, PIRP Irp )
        ULONG RequestedDisposition, RequestedOptions;
        PVFATCCB pCcb;
        PVFATFCB pFcb = NULL;
-       PVFATFCB ParentFcb;
+       PVFATFCB ParentFcb = NULL;
        PWCHAR c, last;
        BOOLEAN PagingFileCreate = FALSE;
-       LARGE_INTEGER AllocationSize;
        BOOLEAN Dots;
        UNICODE_STRING FileNameU;
         UNICODE_STRING PathNameU;
@@ -533,11 +532,6 @@ VfatCreateFile ( PDEVICE_OBJECT DeviceObject, PIRP Irp )
         }
         if (PathNameU.Length > sizeof(WCHAR) && PathNameU.Buffer[PathNameU.Length/sizeof(WCHAR)-1] == L'\\')
         {
-            if (!(RequestedOptions & FILE_DIRECTORY_FILE))
-            {
-                /* FIXME: Is this the right error message? */
-                return(STATUS_OBJECT_NAME_INVALID);
-            }
             PathNameU.Length -= sizeof(WCHAR);
         }
 
@@ -549,8 +543,8 @@ VfatCreateFile ( PDEVICE_OBJECT DeviceObject, PIRP Irp )
         * fail immediately
         */
        if (Status == STATUS_OBJECT_PATH_NOT_FOUND ||
-               Status == STATUS_INVALID_PARAMETER ||
-               Status == STATUS_DELETE_PENDING)
+            Status == STATUS_INVALID_PARAMETER ||
+           Status == STATUS_DELETE_PENDING)
        {
                if (ParentFcb)
                {
@@ -558,6 +552,11 @@ VfatCreateFile ( PDEVICE_OBJECT DeviceObject, PIRP Irp )
                }
                return(Status);
        }
+        if (!NT_SUCCESS(Status) && ParentFcb == NULL)
+        {
+                DPRINT1("VfatOpenFile faild for '%wZ', status %x\n", &PathNameU, Status);
+                return Status;
+        }
 
        /*
         * If the file open failed then create the required file
@@ -565,9 +564,9 @@ VfatCreateFile ( PDEVICE_OBJECT DeviceObject, PIRP Irp )
        if (!NT_SUCCESS (Status))
        {
                if (RequestedDisposition == FILE_CREATE ||
-                       RequestedDisposition == FILE_OPEN_IF ||
-                       RequestedDisposition == FILE_OVERWRITE_IF ||
-                       RequestedDisposition == FILE_SUPERSEDE)
+                   RequestedDisposition == FILE_OPEN_IF ||
+                   RequestedDisposition == FILE_OVERWRITE_IF ||
+                   RequestedDisposition == FILE_SUPERSEDE)
                {
                        ULONG Attributes;
                        Attributes = Stack->Parameters.Create.FileAttributes;
@@ -586,7 +585,6 @@ VfatCreateFile ( PDEVICE_OBJECT DeviceObject, PIRP Irp )
                                }
 
                                Irp->IoStatus.Information = FILE_CREATED;
-
                                VfatSetAllocationSizeInformation(FileObject,
                                        pFcb,
                                        DeviceExt,
@@ -607,7 +605,10 @@ VfatCreateFile ( PDEVICE_OBJECT DeviceObject, PIRP Irp )
                }
                else
                {
-                       vfatReleaseFCB (DeviceExt, ParentFcb);
+                       if (ParentFcb)
+                       {
+                               vfatReleaseFCB (DeviceExt, ParentFcb);
+                       }
                        return(Status);
                }
        }
@@ -691,13 +692,15 @@ VfatCreateFile ( PDEVICE_OBJECT DeviceObject, PIRP Irp )
 
 
                if (RequestedDisposition == FILE_OVERWRITE ||
-                       RequestedDisposition == FILE_OVERWRITE_IF)
+                   RequestedDisposition == FILE_OVERWRITE_IF ||
+                   RequestedDisposition == FILE_SUPERSEDE)
                {
-                       AllocationSize.QuadPart = 0;
+                        ExAcquireResourceExclusiveLite(&(pFcb->MainResource), TRUE);
                        Status = VfatSetAllocationSizeInformation (FileObject,
-                               pFcb,
-                               DeviceExt,
-                               &AllocationSize);
+                                                                  pFcb,
+                                                                  DeviceExt,
+                                                                  &Irp->Overlay.AllocationSize);
+                        ExReleaseResourceLite(&(pFcb->MainResource));
                        if (!NT_SUCCESS (Status))
                        {
                                VfatCloseFile (DeviceExt, FileObject);
@@ -705,15 +708,12 @@ VfatCreateFile ( PDEVICE_OBJECT DeviceObject, PIRP Irp )
                        }
                }
 
-
-               /* Supersede the file */
                if (RequestedDisposition == FILE_SUPERSEDE)
                {
-                       AllocationSize.QuadPart = 0;
-                       VfatSetAllocationSizeInformation(FileObject, pFcb, DeviceExt, &AllocationSize);
                        Irp->IoStatus.Information = FILE_SUPERSEDED;
                }
-               else if (RequestedDisposition == FILE_OVERWRITE || RequestedDisposition == FILE_OVERWRITE_IF)
+               else if (RequestedDisposition == FILE_OVERWRITE || 
+                        RequestedDisposition == FILE_OVERWRITE_IF)
                {
                        Irp->IoStatus.Information = FILE_OVERWRITTEN;
                }