[CDFS]
[reactos.git] / reactos / drivers / filesystems / cdfs / dirctl.c
index 0160c92..652ca11 100644 (file)
@@ -1,31 +1,30 @@
 /*
-*  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/dirctl.c
-* PURPOSE:          CDROM (ISO 9660) filesystem driver
-* PROGRAMMER:       Art Yerkes
-*                   Eric Kohl
-* 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/dirctl.c
+ * PURPOSE:          CDROM (ISO 9660) filesystem driver
+ * PROGRAMMER:       Art Yerkes
+ *                   Eric Kohl
+ * UPDATE HISTORY:
+ */
 
 /* INCLUDES *****************************************************************/
 
@@ -178,9 +177,9 @@ CdfsFindFile(PDEVICE_EXTENSION DeviceExt,
     PDIR_RECORD Record;
     LARGE_INTEGER StreamOffset, OffsetOfEntry;
 
-    DPRINT("FindFile(Parent %x, FileToFind '%wZ', DirIndex: %d)\n",
+    DPRINT("FindFile(Parent %p, FileToFind '%wZ', DirIndex: %u)\n",
         Parent, FileToFind, pDirIndex ? *pDirIndex : 0);
-    DPRINT("FindFile: old Pathname %x, old Objectname %x)\n",
+    DPRINT("FindFile: old Pathname %p, old Objectname %p)\n",
         Fcb->PathName, Fcb->ObjectName);
 
     IsRoot = FALSE;
@@ -217,17 +216,20 @@ CdfsFindFile(PDEVICE_EXTENSION DeviceExt,
             /* it's root : complete essentials fields then return ok */
             RtlZeroMemory(Fcb, sizeof(FCB));
 
-            Fcb->PathName[0] = '\\';
-            Fcb->ObjectName = &Fcb->PathName[1];
+            Fcb->PathNameBuffer[0] = '\\';
+            Fcb->ObjectName = &Fcb->PathNameBuffer[1];
             Fcb->Entry.ExtentLocationL = DeviceExt->CdInfo.RootStart;
             Fcb->Entry.DataLengthL = DeviceExt->CdInfo.RootSize;
             Fcb->Entry.FileFlags = 0x02; //FILE_ATTRIBUTE_DIRECTORY;
+            Fcb->PathName.Length = sizeof(WCHAR);
+            Fcb->PathName.MaximumLength = sizeof(Fcb->PathNameBuffer);
+            Fcb->PathName.Buffer = Fcb->PathNameBuffer;
 
             if (pDirIndex)
                 *pDirIndex = 0;
             if (pOffset)
                 *pOffset = 0;
-            DPRINT("CdfsFindFile: new Pathname %S, new Objectname %S)\n",Fcb->PathName, Fcb->ObjectName);
+            DPRINT("CdfsFindFile: new Pathname %wZ, new Objectname %S)\n",&Fcb->PathName, Fcb->ObjectName);
             return STATUS_SUCCESS;
         }
     }
@@ -237,7 +239,7 @@ CdfsFindFile(PDEVICE_EXTENSION DeviceExt,
         DirSize = Parent->Entry.DataLengthL;
     }
 
-    DPRINT("StreamOffset %I64u  DirSize %lu\n", StreamOffset.QuadPart, DirSize);
+    DPRINT("StreamOffset %I64d  DirSize %u\n", StreamOffset.QuadPart, DirSize);
 
     if (pDirIndex && (*pDirIndex))
         DirIndex = *pDirIndex;
@@ -304,12 +306,13 @@ CdfsFindFile(PDEVICE_EXTENSION DeviceExt,
         if (FsRtlIsNameInExpression(&FileToFindUpcase, &LongName, TRUE, NULL) ||
             FsRtlIsNameInExpression(&FileToFindUpcase, &ShortName, TRUE, NULL))
         {
-            if (Parent && Parent->PathName)
+            if (Parent->PathName.Buffer[0])
             {
-                len = wcslen(Parent->PathName);
-                memcpy(Fcb->PathName, Parent->PathName, len*sizeof(WCHAR));
-                Fcb->ObjectName=&Fcb->PathName[len];
-                if (len != 1 || Fcb->PathName[0] != '\\')
+                len = Parent->PathName.Length / sizeof(WCHAR);
+                memcpy(Fcb->PathName.Buffer, Parent->PathName.Buffer, Parent->PathName.Length);
+                Fcb->PathName.Length = Parent->PathName.Length;
+                Fcb->ObjectName=&Fcb->PathName.Buffer[len];
+                if (len != 1 || Fcb->PathName.Buffer[0] != '\\')
                 {
                     Fcb->ObjectName[0] = '\\';
                     Fcb->ObjectName = &Fcb->ObjectName[1];
@@ -317,15 +320,16 @@ CdfsFindFile(PDEVICE_EXTENSION DeviceExt,
             }
             else
             {
-                Fcb->ObjectName=Fcb->PathName;
+                Fcb->ObjectName=Fcb->PathName.Buffer;
                 Fcb->ObjectName[0]='\\';
                 Fcb->ObjectName=&Fcb->ObjectName[1];
             }
 
-            DPRINT("PathName '%S'  ObjectName '%S'\n", Fcb->PathName, Fcb->ObjectName);
+            DPRINT("PathName '%wZ'  ObjectName '%S'\n", &Fcb->PathName, Fcb->ObjectName);
 
             memcpy(&Fcb->Entry, Record, sizeof(DIR_RECORD));
-            wcsncpy(Fcb->ObjectName, name, MAX_PATH);
+            wcsncpy(Fcb->ObjectName, name, min(wcslen(name) + 1,
+                MAX_PATH - (Fcb->PathName.Length / sizeof(WCHAR)) + wcslen(Fcb->ObjectName)));
 
             /* Copy short name */
             Fcb->ShortNameU.Length = ShortName.Length;
@@ -338,8 +342,8 @@ CdfsFindFile(PDEVICE_EXTENSION DeviceExt,
             if (pOffset)
                 *pOffset = Offset;
 
-            DPRINT("FindFile: new Pathname %S, new Objectname %S, DirIndex %d\n",
-                Fcb->PathName, Fcb->ObjectName, DirIndex);
+            DPRINT("FindFile: new Pathname %wZ, new Objectname %S, DirIndex %u\n",
+                &Fcb->PathName, Fcb->ObjectName, DirIndex);
 
             RtlFreeUnicodeString(&FileToFindUpcase);
             CcUnpinData(Context);
@@ -375,6 +379,8 @@ CdfsGetNameInformation(PFCB Fcb,
 
     DPRINT("CdfsGetNameInformation() called\n");
 
+    UNREFERENCED_PARAMETER(DeviceExt);
+
     Length = wcslen(Fcb->ObjectName) * sizeof(WCHAR);
     if ((sizeof(FILE_NAMES_INFORMATION) + Length) > BufferLength)
         return(STATUS_BUFFER_OVERFLOW);
@@ -400,6 +406,8 @@ CdfsGetDirectoryInformation(PFCB Fcb,
 
     DPRINT("CdfsGetDirectoryInformation() called\n");
 
+    UNREFERENCED_PARAMETER(DeviceExt);
+
     Length = wcslen(Fcb->ObjectName) * sizeof(WCHAR);
     if ((sizeof (FILE_DIRECTORY_INFORMATION) + Length) > BufferLength)
         return(STATUS_BUFFER_OVERFLOW);
@@ -447,6 +455,8 @@ CdfsGetFullDirectoryInformation(PFCB Fcb,
 
     DPRINT("CdfsGetFullDirectoryInformation() called\n");
 
+    UNREFERENCED_PARAMETER(DeviceExt);
+
     Length = wcslen(Fcb->ObjectName) * sizeof(WCHAR);
     if ((sizeof (FILE_FULL_DIR_INFORMATION) + Length) > BufferLength)
         return(STATUS_BUFFER_OVERFLOW);
@@ -496,6 +506,8 @@ CdfsGetBothDirectoryInformation(PFCB Fcb,
 
     DPRINT("CdfsGetBothDirectoryInformation() called\n");
 
+    UNREFERENCED_PARAMETER(DeviceExt);
+
     Length = wcslen(Fcb->ObjectName) * sizeof(WCHAR);
     if ((sizeof (FILE_BOTH_DIR_INFORMATION) + Length) > BufferLength)
         return(STATUS_BUFFER_OVERFLOW);
@@ -533,7 +545,7 @@ CdfsGetBothDirectoryInformation(PFCB Fcb,
 
     /* Copy short name */
     ASSERT(Fcb->ShortNameU.Length / sizeof(WCHAR) <= 12);
-    Info->ShortNameLength = Fcb->ShortNameU.Length;
+    Info->ShortNameLength = (CCHAR)Fcb->ShortNameU.Length;
     RtlCopyMemory(Info->ShortName, Fcb->ShortNameU.Buffer, Fcb->ShortNameU.Length);
 
     return(STATUS_SUCCESS);
@@ -564,6 +576,8 @@ CdfsQueryDirectory(PDEVICE_OBJECT DeviceObject,
     DeviceExtension = DeviceObject->DeviceExtension;
     Stack = IoGetCurrentIrpStackLocation(Irp);
     FileObject = Stack->FileObject;
+    TempFcb.PathName.Buffer = TempFcb.PathNameBuffer;
+    TempFcb.PathName.MaximumLength = sizeof(TempFcb.PathNameBuffer);
 
     Ccb = (PCCB)FileObject->FsContext2;
     Fcb = (PFCB)FileObject->FsContext;
@@ -585,7 +599,15 @@ CdfsQueryDirectory(PDEVICE_OBJECT DeviceObject,
         Buffer = Irp->UserBuffer;
     }
 
-    if (SearchPattern != NULL)
+    /* Allocate search pattern in case:
+     * -> We don't have one already in context
+     * -> We have been given an input pattern
+     * -> The pattern length is not null
+     * -> The pattern buffer is not null
+     * Otherwise, we'll fall later and allocate a match all (*) pattern
+     */
+    if (SearchPattern != NULL &&
+        SearchPattern->Length != 0 && SearchPattern->Buffer != NULL)
     {
         if (Ccb->DirectorySearchPattern.Buffer == NULL)
         {
@@ -630,7 +652,7 @@ CdfsQueryDirectory(PDEVICE_OBJECT DeviceObject,
     }
     DPRINT("Buffer = %p  tofind = %wZ\n", Buffer, &Ccb->DirectorySearchPattern);
 
-    TempFcb.ObjectName = TempFcb.PathName;
+    TempFcb.ObjectName = TempFcb.PathName.Buffer;
     while (Status == STATUS_SUCCESS && BufferLength > 0)
     {
         Status = CdfsFindFile(DeviceExtension,
@@ -730,7 +752,6 @@ CdfsQueryDirectory(PDEVICE_OBJECT DeviceObject,
 }
 
 
-
 NTSTATUS NTAPI
 CdfsDirectoryControl(PDEVICE_OBJECT DeviceObject,
                      PIRP Irp)
@@ -756,7 +777,7 @@ CdfsDirectoryControl(PDEVICE_OBJECT DeviceObject,
         break;
 
     default:
-        DPRINT1("CDFS: MinorFunction %d\n", Stack->MinorFunction);
+        DPRINT1("CDFS: MinorFunction %u\n", Stack->MinorFunction);
         Status = STATUS_INVALID_DEVICE_REQUEST;
         break;
     }