[CDFS]
[reactos.git] / reactos / drivers / filesystems / cdfs / fcb.c
index 12bee1d..1bd06c1 100644 (file)
@@ -1,30 +1,29 @@
 /*
-*  ReactOS kernel
-*  Copyright (C) 2002, 2004 ReactOS Team
-*
-*  This program is free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  This program is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  You should have received a copy of the GNU General Public License along
-*  with this program; if not, write to the Free Software Foundation, Inc.,
-*  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-/* $Id$
-*
-* COPYRIGHT:        See COPYING in the top level directory
-* PROJECT:          ReactOS kernel
-* FILE:             services/fs/cdfs/fcb.c
-* PURPOSE:          CDROM (ISO 9660) filesystem driver
-* PROGRAMMER:       Art Yerkes
-* UPDATE HISTORY:
-*/
+ *  ReactOS kernel
+ *  Copyright (C) 2002, 2004 ReactOS Team
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+/*
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS kernel
+ * FILE:             services/fs/cdfs/fcb.c
+ * PURPOSE:          CDROM (ISO 9660) filesystem driver
+ * PROGRAMMER:       Art Yerkes
+ * UPDATE HISTORY:
+ */
 
 /* INCLUDES *****************************************************************/
 
@@ -58,7 +57,7 @@ CdfsGetNextPathElement(PWCHAR FileName)
 
 
 static VOID
-CdfsWSubString(PWCHAR pTarget, const PWCHAR pSource, size_t pLength)
+CdfsWSubString(LPWSTR pTarget, LPCWSTR pSource, size_t pLength)
 {
     wcsncpy (pTarget, pSource, pLength);
     pTarget [pLength] = L'\0';
@@ -74,17 +73,19 @@ CdfsCreateFCB(PCWSTR FileName)
     if(!Fcb) return NULL;
 
     RtlZeroMemory(Fcb, sizeof(FCB));
+    Fcb->PathName.Buffer = Fcb->PathNameBuffer;
+    Fcb->PathName.MaximumLength = sizeof(Fcb->PathNameBuffer);
 
     if (FileName)
     {
-        wcscpy(Fcb->PathName, FileName);
-        if (wcsrchr(Fcb->PathName, '\\') != 0)
+        RtlAppendUnicodeToString(&Fcb->PathName, FileName);
+        if (wcsrchr(Fcb->PathName.Buffer, '\\') != 0)
         {
-            Fcb->ObjectName = wcsrchr(Fcb->PathName, '\\');
+            Fcb->ObjectName = wcsrchr(Fcb->PathName.Buffer, '\\');
         }
         else
         {
-            Fcb->ObjectName = Fcb->PathName;
+            Fcb->ObjectName = Fcb->PathName.Buffer;
         }
     }
 
@@ -130,7 +131,7 @@ CdfsFCBIsDirectory(PFCB Fcb)
 BOOLEAN
 CdfsFCBIsRoot(PFCB Fcb)
 {
-    return(wcscmp(Fcb->PathName, L"\\") == 0);
+    return (Fcb->PathName.Length = sizeof(WCHAR) && Fcb->PathName.Buffer[0] == L'\\');
 }
 
 
@@ -140,7 +141,7 @@ CdfsGrabFCB(PDEVICE_EXTENSION Vcb,
 {
     KIRQL  oldIrql;
 
-    DPRINT("grabbing FCB at %x: %S, refCount:%d\n",
+    DPRINT("grabbing FCB at %p: %S, refCount:%d\n",
         Fcb,
         Fcb->PathName,
         Fcb->RefCount);
@@ -157,9 +158,9 @@ CdfsReleaseFCB(PDEVICE_EXTENSION Vcb,
 {
     KIRQL  oldIrql;
 
-    DPRINT("releasing FCB at %x: %S, refCount:%d\n",
+    DPRINT("releasing FCB at %p: %wZ, refCount:%d\n",
         Fcb,
-        Fcb->PathName,
+        &Fcb->PathName,
         Fcb->RefCount);
 
     KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
@@ -210,8 +211,8 @@ CdfsGrabFCBFromTable(PDEVICE_EXTENSION Vcb,
     {
         Fcb = CONTAINING_RECORD(current_entry, FCB, FcbListEntry);
 
-        DPRINT("Comparing '%wZ' and '%S'\n", FileName, Fcb->PathName);
-        if (_wcsicmp(FileName->Buffer, Fcb->PathName) == 0)
+        DPRINT("Comparing '%wZ' and '%wZ'\n", FileName, &Fcb->PathName);
+        if (RtlCompareUnicodeString(FileName, &Fcb->PathName, TRUE) == 0)
         {
             Fcb->RefCount++;
             KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
@@ -364,13 +365,14 @@ CdfsMakeFCBFromDirEntry(PVCB Vcb,
     PFCB rcFCB;
     ULONG Size;
 
-    if (LongName [0] != 0 && wcslen (DirectoryFCB->PathName) +
-        sizeof(WCHAR) + wcslen (LongName) > MAX_PATH)
+    /* Check if the full string would overflow the pathName buffer (the additional characters are for '\\' and '\0') */
+    if ((LongName[0] != 0) &&
+        ((DirectoryFCB->PathName.Length / sizeof(WCHAR)) + 1 + wcslen(LongName) + 1 > MAX_PATH))
     {
         return(STATUS_OBJECT_NAME_INVALID);
     }
 
-    wcscpy(pathName, DirectoryFCB->PathName);
+    wcscpy(pathName, DirectoryFCB->PathName.Buffer);
     if (!CdfsFCBIsRoot(DirectoryFCB))
     {
         wcscat(pathName, L"\\");
@@ -412,7 +414,7 @@ CdfsMakeFCBFromDirEntry(PVCB Vcb,
     CdfsAddFCBToTable(Vcb, rcFCB);
     *fileFCB = rcFCB;
 
-    DPRINT("%S %d %I64d\n", LongName, Size, rcFCB->RFCB.AllocationSize.QuadPart);
+    DPRINT("%S %u %I64d\n", LongName, Size, rcFCB->RFCB.AllocationSize.QuadPart);
 
     return(STATUS_SUCCESS);
 }
@@ -451,7 +453,7 @@ CdfsAttachFCBToFileObject(PDEVICE_EXTENSION Vcb,
         Fcb->Flags |= FCB_CACHE_INITIALIZED;
     }
 
-    DPRINT("file open: fcb:%x file size: %d\n", Fcb, Fcb->Entry.DataLengthL);
+    DPRINT("file open: fcb:%p file size: %u\n", Fcb, Fcb->Entry.DataLengthL);
 
     return(STATUS_SUCCESS);
 }
@@ -488,7 +490,7 @@ CdfsDirFindFile(PDEVICE_EXTENSION DeviceExt,
         DeviceExt,
         DirectoryFcb,
         FileToFind);
-    DPRINT("Dir Path:%S\n", DirectoryFcb->PathName);
+    DPRINT("Dir Path:%wZ\n", &DirectoryFcb->PathName);
 
     /* default to '.' if no filename specified */
     if (FileToFind->Length == 0)
@@ -617,7 +619,7 @@ CdfsGetFCBForFile(PDEVICE_EXTENSION Vcb,
     PFCB  FCB;
     PFCB  parentFCB;
 
-    DPRINT("CdfsGetFCBForFile(%x, %x, %x, '%wZ')\n",
+    DPRINT("CdfsGetFCBForFile(%p, %p, %p, '%wZ')\n",
         Vcb,
         pParentFCB,
         pFCB,
@@ -653,7 +655,7 @@ CdfsGetFCBForFile(PDEVICE_EXTENSION Vcb,
         }
 
         DPRINT("Parsing, currentElement:%S\n", currentElement);
-        DPRINT("  parentFCB:%x FCB:%x\n", parentFCB, FCB);
+        DPRINT("  parentFCB:%p FCB:%p\n", parentFCB, FCB);
 
         /* Descend to next directory level */
         if (parentFCB)