Windows: Remove trailing slash on non-root directories
authorpete scott <pscott@kerneldrivers.com>
Wed, 24 Sep 2014 17:00:36 +0000 (11:00 -0600)
committerJeffrey Altman <jaltman@your-file-system.com>
Thu, 25 Sep 2014 12:30:24 +0000 (08:30 -0400)
For the FileNameInformation and FilePhysicalNameInformation queries
a trailing slash is required for the \\server\share\ path but is
not required for directories below the root.

Change-Id: Iabbe7daed4f60ad995c04c70dfb2992af095281e
Reviewed-on: http://gerrit.openafs.org/11489
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>

src/WINNT/afsrdr/kernel/lib/AFSGeneric.cpp
src/WINNT/afsrdr/kernel/lib/AFSNameSupport.cpp
src/WINNT/afsrdr/kernel/lib/Include/AFSCommon.h

index ffb96c4..f2ea340 100644 (file)
@@ -10002,3 +10002,29 @@ try_exit:
 
     return ntStatus;
 }
+
+BOOLEAN
+AFSIsShareName( IN UNICODE_STRING *FileName)
+{
+
+    BOOLEAN     bIsShareName = TRUE;
+    USHORT      usIndex = 1; // Skip the first \
+
+    //
+    // A share name will be of the form \Share so only a single \ at the beginning
+    //
+
+    while( usIndex < FileName->Length/sizeof( WCHAR))
+    {
+
+       if( FileName->Buffer[ usIndex] == L'\\')
+       {
+           bIsShareName = FALSE;
+           break;
+       }
+
+       usIndex++;
+    }
+
+    return bIsShareName;
+}
\ No newline at end of file
index 97cdb0c..6448ded 100644 (file)
@@ -5263,7 +5263,6 @@ AFSGetFullFileName( IN AFSFcb *Fcb,
     ULONG       ulCopyLength = 0;
     ULONG       cchCopied = 0;
     BOOLEAN     bAddTrailingSlash = FALSE;
-    BOOLEAN     bAddLeadingSlash = FALSE;
     USHORT      usFullNameLength = 0;
 
     __Enter
@@ -5273,15 +5272,11 @@ AFSGetFullFileName( IN AFSFcb *Fcb,
        // Add a trailing slash for anything which is of the form \server\share
        //
 
-       if( Ccb->FullFileName.Length == 0 ||
-           Ccb->FullFileName.Buffer[ 0] != L'\\')
-       {
-           bAddLeadingSlash = TRUE;
-       }
-
-       if( Fcb->ObjectInformation->FileType == AFS_FILE_TYPE_DIRECTORY &&
-           Ccb->FullFileName.Length > 0 &&
-           Ccb->FullFileName.Buffer[ (Ccb->FullFileName.Length/sizeof( WCHAR)) - 1] != L'\\')
+       if( ( Fcb->ObjectInformation->FileType == AFS_FILE_TYPE_DIRECTORY ||
+             Fcb->ObjectInformation->FileType == AFS_FILE_TYPE_MOUNTPOINT) &&
+           Ccb->FullFileName.Length > sizeof( WCHAR) &&
+           Ccb->FullFileName.Buffer[ (Ccb->FullFileName.Length/sizeof( WCHAR)) - 1] != L'\\' &&
+           AFSIsShareName( &Ccb->FullFileName))
        {
            bAddTrailingSlash = TRUE;
        }
@@ -5290,11 +5285,6 @@ AFSGetFullFileName( IN AFSFcb *Fcb,
                                    AFSServerName.Length +
                                    Ccb->FullFileName.Length;
 
-       if( bAddLeadingSlash)
-       {
-           usFullNameLength += sizeof( WCHAR);
-       }
-
        if( bAddTrailingSlash)
        {
            usFullNameLength += sizeof( WCHAR);
@@ -5334,17 +5324,6 @@ AFSGetFullFileName( IN AFSFcb *Fcb,
                *RemainingLength -= AFSServerName.Length;
                cchCopied += AFSServerName.Length/sizeof( WCHAR);
 
-               if ( ulCopyLength > 0 &&
-                    bAddLeadingSlash)
-               {
-
-                   FileName[ cchCopied] = L'\\';
-
-                   ulCopyLength -= sizeof( WCHAR);
-                   *RemainingLength -= sizeof( WCHAR);
-                   cchCopied++;
-               }
-
                if( ulCopyLength >= Ccb->FullFileName.Length)
                {
 
index 38de896..d81f288 100644 (file)
@@ -1451,6 +1451,9 @@ NTSTATUS
 AFSRetrieveTargetFileInfo( IN PUNICODE_STRING TargetName,
                           OUT AFSFileInfoCB *FileInfo);
 
+BOOLEAN
+AFSIsShareName( IN UNICODE_STRING *FileName);
+
 //
 // AFSNameArray.cpp Prototypes
 //