[CDFS]
[reactos.git] / reactos / drivers / filesystems / cdfs / fcb.c
index 3f75b6e..4a361d9 100644 (file)
 
 /* FUNCTIONS ****************************************************************/
 
-static PWCHAR
-CdfsGetNextPathElement(PWCHAR FileName)
+static BOOLEAN
+CdfsGetNextPathElement(PCUNICODE_STRING CurrentElement, PUNICODE_STRING NextElement)
 {
-    if (*FileName == L'\0')
-    {
-        return(NULL);
-    }
+    *NextElement = *CurrentElement;
+
+    if (NextElement->Length == 0)
+        return FALSE;
 
-    while (*FileName != L'\0' && *FileName != L'\\')
+    while ((NextElement->Length) && (NextElement->Buffer[0] != L'\\'))
     {
-        FileName++;
+        NextElement->Buffer++;
+        NextElement->Length -= sizeof(WCHAR);
+        NextElement->MaximumLength -= sizeof(WCHAR);
     }
 
-    return(FileName);
-}
-
-
-static VOID
-CdfsWSubString(LPWSTR pTarget, LPCWSTR pSource, size_t pLength)
-{
-    wcsncpy (pTarget, pSource, pLength);
-    pTarget [pLength] = L'\0';
+    return TRUE;
 }
 
 
@@ -144,9 +138,9 @@ CdfsGrabFCB(PDEVICE_EXTENSION Vcb,
 {
     KIRQL  oldIrql;
 
-    DPRINT("grabbing FCB at %p: %S, refCount:%d\n",
+    DPRINT("grabbing FCB at %p: %wZ, refCount:%d\n",
         Fcb,
-        Fcb->PathName,
+        &Fcb->PathName,
         Fcb->RefCount);
 
     KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
@@ -214,7 +208,8 @@ CdfsGrabFCBFromTable(PDEVICE_EXTENSION Vcb,
     {
         Fcb = CONTAINING_RECORD(current_entry, FCB, FcbListEntry);
 
-        DPRINT("Comparing '%wZ' and '%wZ'\n", FileName, &Fcb->PathName);
+        // Disabled the DPRINT! Can't be called at DISPATCH_LEVEL!
+        //DPRINT("Comparing '%wZ' and '%wZ'\n", FileName, &Fcb->PathName);
         if (RtlCompareUnicodeString(FileName, &Fcb->PathName, TRUE) == 0)
         {
             Fcb->RefCount++;
@@ -607,11 +602,9 @@ CdfsGetFCBForFile(PDEVICE_EXTENSION Vcb,
                   PUNICODE_STRING FileName)
 {
     UNICODE_STRING PathName;
-    UNICODE_STRING ElementName;
+    UNICODE_STRING NextElement;
+    UNICODE_STRING CurrentElement;
     NTSTATUS Status;
-    WCHAR  pathName [MAX_PATH];
-    WCHAR  elementName [MAX_PATH];
-    PWCHAR  currentElement;
     PFCB  FCB;
     PFCB  parentFCB;
 
@@ -622,7 +615,8 @@ CdfsGetFCBForFile(PDEVICE_EXTENSION Vcb,
         FileName);
 
     /* Trivial case, open of the root directory on volume */
-    if (FileName->Buffer[0] == L'\0' || wcscmp(FileName->Buffer, L"\\") == 0)
+    if (FileName->Length == 0 ||
+            ((FileName->Buffer[0] == '\\') && (FileName->Length == sizeof(WCHAR))))
     {
         DPRINT("returning root FCB\n");
 
@@ -634,23 +628,28 @@ CdfsGetFCBForFile(PDEVICE_EXTENSION Vcb,
     }
     else
     {
-        currentElement = &FileName->Buffer[1];
-        wcscpy (pathName, L"\\");
+        /* Start with empty path */
+        PathName = *FileName;
+        PathName.Length = 0;
+        CurrentElement = *FileName;
+
         FCB = CdfsOpenRootFCB (Vcb);
     }
     parentFCB = NULL;
 
-    /* Parse filename and check each path element for existance and access */
-    while (CdfsGetNextPathElement(currentElement) != 0)
+    /* Parse filename and check each path element for existence and access */
+    while (CdfsGetNextPathElement(&CurrentElement, &NextElement))
     {
         /*  Skip blank directory levels */
-        if ((CdfsGetNextPathElement(currentElement) - currentElement) == 0)
+        if (CurrentElement.Buffer[0] == L'\\')
         {
-            currentElement++;
+            CurrentElement.Buffer++;
+            CurrentElement.Length -= sizeof(WCHAR);
+            CurrentElement.MaximumLength -= sizeof(WCHAR);
             continue;
         }
 
-        DPRINT("Parsing, currentElement:%S\n", currentElement);
+        DPRINT("Parsing, currentElement:%wZ\n", &CurrentElement);
         DPRINT("  parentFCB:%p FCB:%p\n", parentFCB, FCB);
 
         /* Descend to next directory level */
@@ -674,33 +673,26 @@ CdfsGetFCBForFile(PDEVICE_EXTENSION Vcb,
         }
         parentFCB = FCB;
 
-        /* Extract next directory level into dirName */
-        CdfsWSubString(pathName,
-            FileName->Buffer,
-            CdfsGetNextPathElement(currentElement) - FileName->Buffer);
-        DPRINT("  pathName:%S\n", pathName);
-
-        RtlInitUnicodeString(&PathName, pathName);
+        /* Extract next directory level */
+        PathName.Length = (NextElement.Buffer - FileName->Buffer) * sizeof(WCHAR);
+        DPRINT("  PathName:%wZ\n", &PathName);
 
         FCB = CdfsGrabFCBFromTable(Vcb, &PathName);
         if (FCB == NULL)
         {
-            CdfsWSubString(elementName,
-                currentElement,
-                CdfsGetNextPathElement(currentElement) - currentElement);
-            DPRINT("  elementName:%S\n", elementName);
+            UNICODE_STRING ChildElement = CurrentElement;
+            ChildElement.Length = (NextElement.Buffer - CurrentElement.Buffer) * sizeof(WCHAR);
 
-            RtlInitUnicodeString(&ElementName, elementName);
             Status = CdfsDirFindFile(Vcb,
                 parentFCB,
-                &ElementName,
+                &ChildElement,
                 &FCB);
             if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
             {
                 *pParentFCB = parentFCB;
                 *pFCB = NULL;
-                currentElement = CdfsGetNextPathElement(currentElement);
-                if (*currentElement == L'\0' || CdfsGetNextPathElement(currentElement + 1) == 0)
+
+                if (NextElement.Length == 0)
                 {
                     return(STATUS_OBJECT_NAME_NOT_FOUND);
                 }
@@ -718,7 +710,7 @@ CdfsGetFCBForFile(PDEVICE_EXTENSION Vcb,
                 return(Status);
             }
         }
-        currentElement = CdfsGetNextPathElement(currentElement);
+        CurrentElement = NextElement;
     }
 
     *pParentFCB = parentFCB;