[CDFS]
authorPierre Schweitzer <pierre@reactos.org>
Fri, 18 Apr 2014 21:40:02 +0000 (21:40 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Fri, 18 Apr 2014 21:40:02 +0000 (21:40 +0000)
Convert FCB pathname from simple buffer to unicode string.
Please carefully review if I missed something

svn path=/trunk/; revision=62779

reactos/drivers/filesystems/cdfs/cdfs.h
reactos/drivers/filesystems/cdfs/create.c
reactos/drivers/filesystems/cdfs/dirctl.c
reactos/drivers/filesystems/cdfs/fcb.c
reactos/drivers/filesystems/cdfs/finfo.c
reactos/drivers/filesystems/cdfs/fsctl.c

index 5a34413..78c9b57 100644 (file)
@@ -189,8 +189,9 @@ typedef struct _FCB
 
   UNICODE_STRING ShortNameU;
 
 
   UNICODE_STRING ShortNameU;
 
-  WCHAR *ObjectName;           /* point on filename (250 chars max) in PathName */
-  WCHAR PathName[MAX_PATH];    /* path+filename 260 max */
+  WCHAR *ObjectName;                   /* point on filename (250 chars max) in PathName */
+  UNICODE_STRING PathName;             /* path+filename 260 max */
+  WCHAR PathNameBuffer[MAX_PATH];      /* Buffer for PathName */
   WCHAR ShortNameBuffer[13];
 
   LIST_ENTRY FcbListEntry;
   WCHAR ShortNameBuffer[13];
 
   LIST_ENTRY FcbListEntry;
@@ -198,8 +199,8 @@ typedef struct _FCB
 
   ULONG DirIndex;
 
 
   ULONG DirIndex;
 
-  LARGE_INTEGER IndexNumber;   /* HighPart: Parent directory start sector */
-                               /* LowPart: Directory record offset in the parent directory file */
+  LARGE_INTEGER IndexNumber;           /* HighPart: Parent directory start sector */
+                                       /* LowPart: Directory record offset in the parent directory file */
 
   LONG RefCount;
   ULONG Flags;
 
   LONG RefCount;
   ULONG Flags;
index dcec4d1..eef173d 100644 (file)
@@ -56,7 +56,7 @@ CdfsMakeAbsoluteFilename(PFILE_OBJECT FileObject,
     }
 
     /* construct absolute path name */
     }
 
     /* construct absolute path name */
-    Length = (wcslen(Fcb->PathName) * sizeof(WCHAR)) +
+    Length = Fcb->PathName.Length +
         sizeof(WCHAR) +
         RelativeFileName->Length +
         sizeof(WCHAR);
         sizeof(WCHAR) +
         RelativeFileName->Length +
         sizeof(WCHAR);
@@ -69,8 +69,8 @@ CdfsMakeAbsoluteFilename(PFILE_OBJECT FileObject,
         return STATUS_INSUFFICIENT_RESOURCES;
     }
 
         return STATUS_INSUFFICIENT_RESOURCES;
     }
 
-    Status = RtlAppendUnicodeToString(AbsoluteFileName,
-        Fcb->PathName);
+    Status = RtlAppendUnicodeStringToString(AbsoluteFileName,
+        &Fcb->PathName);
     if (!NT_SUCCESS(Status))
     {
         RtlFreeUnicodeString(AbsoluteFileName);
     if (!NT_SUCCESS(Status))
     {
         RtlFreeUnicodeString(AbsoluteFileName);
index e8568e3..652ca11 100644 (file)
@@ -216,17 +216,20 @@ CdfsFindFile(PDEVICE_EXTENSION DeviceExt,
             /* it's root : complete essentials fields then return ok */
             RtlZeroMemory(Fcb, sizeof(FCB));
 
             /* 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->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;
 
             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;
         }
     }
             return STATUS_SUCCESS;
         }
     }
@@ -303,12 +306,13 @@ CdfsFindFile(PDEVICE_EXTENSION DeviceExt,
         if (FsRtlIsNameInExpression(&FileToFindUpcase, &LongName, TRUE, NULL) ||
             FsRtlIsNameInExpression(&FileToFindUpcase, &ShortName, TRUE, NULL))
         {
         if (FsRtlIsNameInExpression(&FileToFindUpcase, &LongName, TRUE, NULL) ||
             FsRtlIsNameInExpression(&FileToFindUpcase, &ShortName, TRUE, NULL))
         {
-            if (Parent->PathName[0])
+            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];
                 {
                     Fcb->ObjectName[0] = '\\';
                     Fcb->ObjectName = &Fcb->ObjectName[1];
@@ -316,16 +320,16 @@ CdfsFindFile(PDEVICE_EXTENSION DeviceExt,
             }
             else
             {
             }
             else
             {
-                Fcb->ObjectName=Fcb->PathName;
+                Fcb->ObjectName=Fcb->PathName.Buffer;
                 Fcb->ObjectName[0]='\\';
                 Fcb->ObjectName=&Fcb->ObjectName[1];
             }
 
                 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, min(wcslen(name) + 1,
 
             memcpy(&Fcb->Entry, Record, sizeof(DIR_RECORD));
             wcsncpy(Fcb->ObjectName, name, min(wcslen(name) + 1,
-                MAX_PATH - wcslen(Fcb->PathName) + wcslen(Fcb->ObjectName)));
+                MAX_PATH - (Fcb->PathName.Length / sizeof(WCHAR)) + wcslen(Fcb->ObjectName)));
 
             /* Copy short name */
             Fcb->ShortNameU.Length = ShortName.Length;
 
             /* Copy short name */
             Fcb->ShortNameU.Length = ShortName.Length;
@@ -338,8 +342,8 @@ CdfsFindFile(PDEVICE_EXTENSION DeviceExt,
             if (pOffset)
                 *pOffset = Offset;
 
             if (pOffset)
                 *pOffset = Offset;
 
-            DPRINT("FindFile: new Pathname %S, new Objectname %S, DirIndex %u\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);
 
             RtlFreeUnicodeString(&FileToFindUpcase);
             CcUnpinData(Context);
@@ -572,6 +576,8 @@ CdfsQueryDirectory(PDEVICE_OBJECT DeviceObject,
     DeviceExtension = DeviceObject->DeviceExtension;
     Stack = IoGetCurrentIrpStackLocation(Irp);
     FileObject = Stack->FileObject;
     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;
 
     Ccb = (PCCB)FileObject->FsContext2;
     Fcb = (PFCB)FileObject->FsContext;
@@ -646,7 +652,7 @@ CdfsQueryDirectory(PDEVICE_OBJECT DeviceObject,
     }
     DPRINT("Buffer = %p  tofind = %wZ\n", Buffer, &Ccb->DirectorySearchPattern);
 
     }
     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,
     while (Status == STATUS_SUCCESS && BufferLength > 0)
     {
         Status = CdfsFindFile(DeviceExtension,
@@ -746,7 +752,6 @@ CdfsQueryDirectory(PDEVICE_OBJECT DeviceObject,
 }
 
 
 }
 
 
-
 NTSTATUS NTAPI
 CdfsDirectoryControl(PDEVICE_OBJECT DeviceObject,
                      PIRP Irp)
 NTSTATUS NTAPI
 CdfsDirectoryControl(PDEVICE_OBJECT DeviceObject,
                      PIRP Irp)
index 6657008..1bd06c1 100644 (file)
@@ -73,17 +73,19 @@ CdfsCreateFCB(PCWSTR FileName)
     if(!Fcb) return NULL;
 
     RtlZeroMemory(Fcb, sizeof(FCB));
     if(!Fcb) return NULL;
 
     RtlZeroMemory(Fcb, sizeof(FCB));
+    Fcb->PathName.Buffer = Fcb->PathNameBuffer;
+    Fcb->PathName.MaximumLength = sizeof(Fcb->PathNameBuffer);
 
     if (FileName)
     {
 
     if (FileName)
     {
-        CdfsWSubString(Fcb->PathName, FileName, sizeof(Fcb->PathName) / sizeof(Fcb->PathName[0]) - 1);
-        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
         {
         }
         else
         {
-            Fcb->ObjectName = Fcb->PathName;
+            Fcb->ObjectName = Fcb->PathName.Buffer;
         }
     }
 
         }
     }
 
@@ -129,7 +131,7 @@ CdfsFCBIsDirectory(PFCB Fcb)
 BOOLEAN
 CdfsFCBIsRoot(PFCB Fcb)
 {
 BOOLEAN
 CdfsFCBIsRoot(PFCB Fcb)
 {
-    return(wcscmp(Fcb->PathName, L"\\") == 0);
+    return (Fcb->PathName.Length = sizeof(WCHAR) && Fcb->PathName.Buffer[0] == L'\\');
 }
 
 
 }
 
 
@@ -156,9 +158,9 @@ CdfsReleaseFCB(PDEVICE_EXTENSION Vcb,
 {
     KIRQL  oldIrql;
 
 {
     KIRQL  oldIrql;
 
-    DPRINT("releasing FCB at %p: %S, refCount:%d\n",
+    DPRINT("releasing FCB at %p: %wZ, refCount:%d\n",
         Fcb,
         Fcb,
-        Fcb->PathName,
+        &Fcb->PathName,
         Fcb->RefCount);
 
     KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
         Fcb->RefCount);
 
     KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
@@ -209,8 +211,8 @@ CdfsGrabFCBFromTable(PDEVICE_EXTENSION Vcb,
     {
         Fcb = CONTAINING_RECORD(current_entry, FCB, FcbListEntry);
 
     {
         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);
         {
             Fcb->RefCount++;
             KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
@@ -365,12 +367,12 @@ CdfsMakeFCBFromDirEntry(PVCB Vcb,
 
     /* Check if the full string would overflow the pathName buffer (the additional characters are for '\\' and '\0') */
     if ((LongName[0] != 0) &&
 
     /* Check if the full string would overflow the pathName buffer (the additional characters are for '\\' and '\0') */
     if ((LongName[0] != 0) &&
-        (wcslen(DirectoryFCB->PathName) + 1 + wcslen(LongName) + 1 > MAX_PATH))
+        ((DirectoryFCB->PathName.Length / sizeof(WCHAR)) + 1 + wcslen(LongName) + 1 > MAX_PATH))
     {
         return(STATUS_OBJECT_NAME_INVALID);
     }
 
     {
         return(STATUS_OBJECT_NAME_INVALID);
     }
 
-    wcscpy(pathName, DirectoryFCB->PathName);
+    wcscpy(pathName, DirectoryFCB->PathName.Buffer);
     if (!CdfsFCBIsRoot(DirectoryFCB))
     {
         wcscat(pathName, L"\\");
     if (!CdfsFCBIsRoot(DirectoryFCB))
     {
         wcscat(pathName, L"\\");
@@ -488,7 +490,7 @@ CdfsDirFindFile(PDEVICE_EXTENSION DeviceExt,
         DeviceExt,
         DirectoryFcb,
         FileToFind);
         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)
 
     /* default to '.' if no filename specified */
     if (FileToFind->Length == 0)
index 41304a8..a64d7cc 100644 (file)
@@ -164,7 +164,7 @@ CdfsGetNameInformation(PFILE_OBJECT FileObject,
         return STATUS_BUFFER_OVERFLOW;
 
     /* Calculate file name length in bytes */
         return STATUS_BUFFER_OVERFLOW;
 
     /* Calculate file name length in bytes */
-    NameLength = wcslen(Fcb->PathName) * sizeof(WCHAR);
+    NameLength = Fcb->PathName.Length;
     NameInfo->FileNameLength = NameLength;
 
     /* Calculate amount of bytes to copy not to overflow the buffer */
     NameInfo->FileNameLength = NameLength;
 
     /* Calculate amount of bytes to copy not to overflow the buffer */
@@ -172,7 +172,7 @@ CdfsGetNameInformation(PFILE_OBJECT FileObject,
         *BufferLength - FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]));
 
     /* Fill in the bytes */
         *BufferLength - FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]));
 
     /* Fill in the bytes */
-    RtlCopyMemory(NameInfo->FileName, Fcb->PathName, BytesToCopy);
+    RtlCopyMemory(NameInfo->FileName, Fcb->PathName.Buffer, BytesToCopy);
 
     /* Check if we could write more but are not able to */
     if (*BufferLength < NameLength + FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]))
 
     /* Check if we could write more but are not able to */
     if (*BufferLength < NameLength + FIELD_OFFSET(FILE_NAME_INFORMATION, FileName[0]))
@@ -268,7 +268,7 @@ CdfsGetAllInformation(PFILE_OBJECT FileObject,
     ASSERT(Info);
     ASSERT(Fcb);
 
     ASSERT(Info);
     ASSERT(Fcb);
 
-    NameLength = wcslen(Fcb->PathName) * sizeof(WCHAR);
+    NameLength = Fcb->PathName.Length;
     if (*BufferLength < sizeof(FILE_ALL_INFORMATION) + NameLength)
         return(STATUS_BUFFER_OVERFLOW);
 
     if (*BufferLength < sizeof(FILE_ALL_INFORMATION) + NameLength)
         return(STATUS_BUFFER_OVERFLOW);
 
@@ -321,7 +321,7 @@ CdfsGetAllInformation(PFILE_OBJECT FileObject,
     /* Name Information */
     Info->NameInformation.FileNameLength = NameLength;
     RtlCopyMemory(Info->NameInformation.FileName,
     /* Name Information */
     Info->NameInformation.FileNameLength = NameLength;
     RtlCopyMemory(Info->NameInformation.FileName,
-        Fcb->PathName,
+        Fcb->PathName.Buffer,
         NameLength + sizeof(WCHAR));
 
     *BufferLength -= (sizeof(FILE_ALL_INFORMATION) + NameLength + sizeof(WCHAR));
         NameLength + sizeof(WCHAR));
 
     *BufferLength -= (sizeof(FILE_ALL_INFORMATION) + NameLength + sizeof(WCHAR));
index 9b658c7..c4920b4 100644 (file)
@@ -513,7 +513,7 @@ CdfsVerifyVolume(PDEVICE_OBJECT DeviceObject,
         while (Entry != &DeviceExt->FcbListHead)
         {
             Fcb = (PFCB)CONTAINING_RECORD(Entry, FCB, FcbListEntry);
         while (Entry != &DeviceExt->FcbListHead)
         {
             Fcb = (PFCB)CONTAINING_RECORD(Entry, FCB, FcbListEntry);
-            DPRINT1("OpenFile %S  RefCount %ld\n", Fcb->PathName, Fcb->RefCount);
+            DPRINT1("OpenFile %wZ  RefCount %ld\n", &Fcb->PathName, Fcb->RefCount);
 
             Entry = Entry->Flink;
         }
 
             Entry = Entry->Flink;
         }