Commit in reactos/drivers/fs/vfat on MAIN
fcb.c+46-51.37 -> 1.38
create.c+27-161.68 -> 1.69
+73-21
2 modified files
- Fixed a bug, which prevents an opening of files, if the file name contains short path names.

reactos/drivers/fs/vfat
fcb.c 1.37 -> 1.38
diff -u -r1.37 -r1.38
--- fcb.c	28 Jan 2004 20:53:46 -0000	1.37
+++ fcb.c	3 Jul 2004 17:31:30 -0000	1.38
@@ -1,4 +1,4 @@
-/* $Id: fcb.c,v 1.37 2004/01/28 20:53:46 ekohl Exp $
+/* $Id: fcb.c,v 1.38 2004/07/03 17:31:30 hbirr Exp $
  *
  *
  * FILE:             drivers/fs/vfat/fcb.c
@@ -594,6 +594,7 @@
   UNICODE_STRING NameU;
   UNICODE_STRING RootNameU;
   PWCHAR curr, prev, last;
+  ULONG Length;
 
   DPRINT ("vfatGetFCBForFile (%x,%x,%x,%wZ)\n",
           pVCB,
@@ -626,6 +627,24 @@
       NameU.Buffer = pFileNameU->Buffer;
       NameU.MaximumLength = NameU.Length = (curr - pFileNameU->Buffer) * sizeof(WCHAR);
       FCB = vfatGrabFCBFromTable(pVCB, &NameU);
+      if (FCB)
+        {
+	  Length = (curr - pFileNameU->Buffer) * sizeof(WCHAR);
+          if (Length != FCB->PathNameU.Length)
+	    {
+	      if (pFileNameU->Length + FCB->PathNameU.Length - Length > pFileNameU->MaximumLength)
+	        {
+		  vfatReleaseFCB (pVCB, FCB);
+		  return STATUS_OBJECT_NAME_INVALID;
+		}
+	      memmove(pFileNameU->Buffer + FCB->PathNameU.Length / sizeof(WCHAR), 
+		      curr, pFileNameU->Length - Length);
+	      pFileNameU->Length += FCB->PathNameU.Length - Length;
+	      curr = pFileNameU->Buffer + FCB->PathNameU.Length / sizeof(WCHAR);
+              last = pFileNameU->Buffer + pFileNameU->Length / sizeof(WCHAR) - 1;
+	    }
+	  memcpy(pFileNameU->Buffer, FCB->PathNameU.Buffer, FCB->PathNameU.Length);
+	}
     }
   else
     {
@@ -637,8 +656,10 @@
       FCB = vfatOpenRootFCB(pVCB);
       curr = pFileNameU->Buffer;
     }
-  curr++;
+  
   parentFCB = NULL;
+  prev = curr;
+
   while (curr <= last)
     {
       if (parentFCB)
@@ -659,13 +680,34 @@
           return  STATUS_OBJECT_PATH_NOT_FOUND;
 	}
       parentFCB = FCB;
-      NameU.Buffer = pFileNameU->Buffer;
+      if (prev < curr)
+        {
+	  Length = (curr - prev) * sizeof(WCHAR);
+	  if (Length != parentFCB->LongNameU.Length)
+	    {
+	      if (pFileNameU->Length + parentFCB->LongNameU.Length - Length > pFileNameU->MaximumLength)
+	        {
+		  vfatReleaseFCB (pVCB, parentFCB);
+		  return STATUS_OBJECT_NAME_INVALID;
+		}
+	      memmove(prev + parentFCB->LongNameU.Length / sizeof(WCHAR), curr, 
+		      pFileNameU->Length - (curr - pFileNameU->Buffer) * sizeof(WCHAR));
+	      pFileNameU->Length += parentFCB->LongNameU.Length - Length;
+	      curr = prev + parentFCB->LongNameU.Length / sizeof(WCHAR);
+              last = pFileNameU->Buffer + pFileNameU->Length / sizeof(WCHAR) - 1;
+	    }
+	  memcpy(prev, parentFCB->LongNameU.Buffer, parentFCB->LongNameU.Length);
+	}
+      curr++;      
       prev = curr;
       while (*curr != L'\\' && curr <= last)
         {
 	  curr++;
 	}
-      NameU.MaximumLength = NameU.Length = (curr - NameU.Buffer) * sizeof(WCHAR);
+      NameU.Buffer = pFileNameU->Buffer;
+      NameU.Length = (curr - NameU.Buffer) * sizeof(WCHAR);
+      NameU.MaximumLength = pFileNameU->MaximumLength;
+      DPRINT("%wZ\n", &NameU);
       FCB = vfatGrabFCBFromTable(pVCB, &NameU);
       if (FCB == NULL)
         {
@@ -694,7 +736,6 @@
               return  status;
 	    }
 	}
-      curr++;
     }
 
   *pParentFCB = parentFCB;

reactos/drivers/fs/vfat
create.c 1.68 -> 1.69
diff -u -r1.68 -r1.69
--- create.c	23 Jun 2004 20:23:59 -0000	1.68
+++ create.c	3 Jul 2004 17:31:30 -0000	1.69
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: create.c,v 1.68 2004/06/23 20:23:59 hbirr Exp $
+/* $Id: create.c,v 1.69 2004/07/03 17:31:30 hbirr Exp $
  *
  * PROJECT:          ReactOS kernel
  * FILE:             drivers/fs/vfat/create.c
@@ -339,34 +339,35 @@
   PVFATFCB ParentFcb;
   PVFATFCB Fcb;
   NTSTATUS Status;
-  UNICODE_STRING NameU;
-  WCHAR Name[MAX_PATH];
   ULONG Size;
   ULONG MediaChangeCount;
 
 //  PDEVICE_OBJECT DeviceObject = DeviceExt->StorageDevice->Vpb->DeviceObject;
   
-  DPRINT ("VfatOpenFile(%08lx, %08lx, '%wZ')\n", DeviceExt, FileObject, FileNameU);
+  DPRINT ("VfatOpenFile(%08lx, %08lx, '%wZ')\n", DeviceExt, FileObject, &FileObject->FileName);
 
   if (FileObject->RelatedFileObject)
     {
       DPRINT ("Converting relative filename to absolute filename\n");
 
-      NameU.Buffer = Name;
-      NameU.Length = 0;
-      NameU.MaximumLength = sizeof(Name);
-
       Fcb = FileObject->RelatedFileObject->FsContext;
-      RtlCopyUnicodeString(&NameU, &Fcb->PathNameU);
+      RtlCopyUnicodeString(FileNameU, &Fcb->PathNameU);
       if (!vfatFCBIsRoot(Fcb))
         {
-	  NameU.Buffer[NameU.Length / sizeof(WCHAR)] = L'\\';
-	  NameU.Length += sizeof(WCHAR);
+	  RtlAppendUnicodeToString(FileNameU, L"\\");
 	}
-      RtlAppendUnicodeStringToString(&NameU, FileNameU);
-      NameU.Buffer[NameU.Length / sizeof(WCHAR)] = 0;
-      FileNameU = &NameU;
+      RtlAppendUnicodeStringToString(FileNameU, &FileObject->FileName);
+    }
+  else
+    {
+      RtlCopyUnicodeString(FileNameU, &FileObject->FileName);
+    }
+  if (FileNameU->Length > sizeof(WCHAR) &&
+      FileNameU->Buffer[FileNameU->Length / sizeof(WCHAR) - 1] == L'\\')
+    {
+      FileNameU->Length -= sizeof(WCHAR);
     }
+  FileNameU->Buffer[FileNameU->Length / sizeof(WCHAR)] = 0;
 
   DPRINT ("PathName to open: '%wZ'\n", FileNameU);
 
@@ -425,6 +426,10 @@
           return  Status;
 	}
     }
+  else
+    {
+      RtlCopyUnicodeString(FileNameU, &Fcb->PathNameU);
+    }
   if (Fcb->Flags & FCB_DELETE_PENDING)
     {
       vfatReleaseFCB (DeviceExt, Fcb);
@@ -492,6 +497,8 @@
   BOOLEAN PagingFileCreate = FALSE;
   LARGE_INTEGER AllocationSize;
   BOOLEAN Dots;
+  UNICODE_STRING NameU;
+  WCHAR NameW[MAX_PATH];
   
   /* Unpack the various parameters. */
   Stack = IoGetCurrentIrpStackLocation (Irp);
@@ -568,8 +575,12 @@
 	}
     }
 
+  NameU.Buffer = NameW;
+  NameU.Length = 0;
+  NameU.MaximumLength = sizeof(NameW);
+
   /* Try opening the file. */
-  Status = VfatOpenFile (DeviceExt, FileObject, &FileObject->FileName);
+  Status = VfatOpenFile (DeviceExt, FileObject, &NameU);
 
   /*
    * If the directory containing the file to open doesn't exist then
@@ -594,7 +605,7 @@
 	{
 	  ULONG Attributes;
 	  Attributes = Stack->Parameters.Create.FileAttributes;
-	  Status = VfatAddEntry (DeviceExt, &FileObject->FileName, FileObject, RequestedOptions, 
+	  Status = VfatAddEntry (DeviceExt, &NameU, FileObject, RequestedOptions, 
 				 (UCHAR)(Attributes & FILE_ATTRIBUTE_VALID_FLAGS));
 	  if (NT_SUCCESS (Status))
 	    {
CVSspam 0.2.8