Windows: FilePhysicalNameInfo query AFS prefix
authorpete scott <pscott@kerneldrivers.com>
Wed, 24 Sep 2014 16:49:06 +0000 (10:49 -0600)
committerJeffrey Altman <jaltman@your-file-system.com>
Thu, 25 Sep 2014 12:29:58 +0000 (08:29 -0400)
In response to the FilePhysicalNameInformation query the AFS redirector
failed to include the server name in the response.  Since the constructed
name is the same as the FileNameInformation query create a helper function
AFSGetFullFileName() to populate the file name into the provided buffer
and use it to satisfy both queries.

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

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

index 2eb6c73..48fb3fd 100644 (file)
@@ -1121,14 +1121,9 @@ AFSQueryNameInfo( IN PIRP Irp,
 
     UNREFERENCED_PARAMETER(DirectoryCB);
     NTSTATUS ntStatus = STATUS_INFO_LENGTH_MISMATCH;
-    ULONG ulCopyLength = 0;
-    ULONG cchCopied = 0;
     AFSFcb *pFcb = NULL;
     AFSCcb *pCcb = NULL;
     IO_STACK_LOCATION *pIrpSp = IoGetCurrentIrpStackLocation( Irp);
-    BOOLEAN bAddLeadingSlash = FALSE;
-    BOOLEAN bAddTrailingSlash = FALSE;
-    USHORT usFullNameLength = 0;
 
     pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
 
@@ -1137,116 +1132,16 @@ AFSQueryNameInfo( IN PIRP Irp,
     if( *Length >= FIELD_OFFSET( FILE_NAME_INFORMATION, FileName))
     {
 
-        RtlZeroMemory( Buffer,
-                       *Length);
-
-        if( pCcb->FullFileName.Length == 0 ||
-            pCcb->FullFileName.Buffer[ 0] != L'\\')
-        {
-            bAddLeadingSlash = TRUE;
-        }
-
-        if( pFcb->ObjectInformation->FileType == AFS_FILE_TYPE_DIRECTORY &&
-            pCcb->FullFileName.Length > 0 &&
-            pCcb->FullFileName.Buffer[ (pCcb->FullFileName.Length/sizeof( WCHAR)) - 1] != L'\\')
-        {
-            bAddTrailingSlash = TRUE;
-        }
-
-        usFullNameLength = sizeof( WCHAR) +
-                                    AFSServerName.Length +
-                                    pCcb->FullFileName.Length;
-
-        if( bAddLeadingSlash)
-        {
-            usFullNameLength += sizeof( WCHAR);
-        }
-
-        if( bAddTrailingSlash)
-        {
-            usFullNameLength += sizeof( WCHAR);
-        }
-
-        if( *Length >= (LONG)(FIELD_OFFSET( FILE_NAME_INFORMATION, FileName) + (LONG)usFullNameLength))
-        {
-
-            ulCopyLength = (LONG)usFullNameLength;
-
-           ntStatus = STATUS_SUCCESS;
-        }
-        else
-        {
-
-            ulCopyLength = *Length - FIELD_OFFSET( FILE_NAME_INFORMATION, FileName);
-
-            ntStatus = STATUS_BUFFER_OVERFLOW;
-        }
-
-        Buffer->FileNameLength = (ULONG)usFullNameLength;
-
-        *Length -= FIELD_OFFSET( FILE_NAME_INFORMATION, FileName);
-
-        if( ulCopyLength > 0)
-        {
-
-            Buffer->FileName[ 0] = L'\\';
-            ulCopyLength -= sizeof( WCHAR);
-
-            *Length -= sizeof( WCHAR);
-            cchCopied += 1;
-
-            if( ulCopyLength >= AFSServerName.Length)
-            {
-
-                RtlCopyMemory( &Buffer->FileName[ 1],
-                               AFSServerName.Buffer,
-                               AFSServerName.Length);
-
-                ulCopyLength -= AFSServerName.Length;
-                *Length -= AFSServerName.Length;
-                cchCopied += AFSServerName.Length/sizeof( WCHAR);
-
-                if ( ulCopyLength > 0 &&
-                     bAddLeadingSlash)
-                {
-
-                    Buffer->FileName[ cchCopied] = L'\\';
-
-                    ulCopyLength -= sizeof( WCHAR);
-                    *Length -= sizeof( WCHAR);
-                    cchCopied++;
-                }
-
-                if( ulCopyLength >= pCcb->FullFileName.Length)
-                {
-
-                    RtlCopyMemory( &Buffer->FileName[ cchCopied],
-                                   pCcb->FullFileName.Buffer,
-                                   pCcb->FullFileName.Length);
-
-                    ulCopyLength -= pCcb->FullFileName.Length;
-                    *Length -= pCcb->FullFileName.Length;
-                    cchCopied += pCcb->FullFileName.Length/sizeof( WCHAR);
-
-                    if( ulCopyLength > 0 &&
-                        bAddTrailingSlash)
-                    {
-                        Buffer->FileName[ cchCopied] = L'\\';
-
-                        *Length -= sizeof( WCHAR);
-                    }
-                }
-                else
-                {
+       RtlZeroMemory( Buffer,
+                      *Length);
 
-                    RtlCopyMemory( &Buffer->FileName[ cchCopied],
-                                   pCcb->FullFileName.Buffer,
-                                   ulCopyLength);
+       *Length -= FIELD_OFFSET( FILE_NAME_INFORMATION, FileName);
 
-                    *Length -= ulCopyLength;
-                }
-            }
-        }
+       ntStatus = AFSGetFullFileName( pFcb,
+                                      pCcb,
+                                      &Buffer->FileNameLength,
+                                      Buffer->FileName,
+                                      Length);
     }
 
     return ntStatus;
@@ -1709,13 +1604,9 @@ AFSQueryPhysicalNameInfo( IN PIRP Irp,
 
     UNREFERENCED_PARAMETER(DirectoryCB);
     NTSTATUS ntStatus = STATUS_INFO_LENGTH_MISMATCH;
-    ULONG ulCopyLength = 0;
-    ULONG cchCopied = 0;
     AFSFcb *pFcb = NULL;
     AFSCcb *pCcb = NULL;
     IO_STACK_LOCATION *pIrpSp = IoGetCurrentIrpStackLocation( Irp);
-    BOOLEAN bAddLeadingSlash = FALSE;
-    USHORT usFullNameLength = 0;
 
     pFcb = (AFSFcb *)pIrpSp->FileObject->FsContext;
 
@@ -1724,74 +1615,16 @@ AFSQueryPhysicalNameInfo( IN PIRP Irp,
     if( *Length >= FIELD_OFFSET( FILE_NETWORK_PHYSICAL_NAME_INFORMATION, FileName))
     {
 
-        RtlZeroMemory( Buffer,
-                       *Length);
-
-        if( pCcb->FullFileName.Length == 0 ||
-            pCcb->FullFileName.Buffer[ 0] != L'\\')
-        {
-            bAddLeadingSlash = TRUE;
-        }
-
-        usFullNameLength = pCcb->FullFileName.Length;
-
-        if( bAddLeadingSlash)
-        {
-            usFullNameLength += sizeof( WCHAR);
-        }
-
-        if( *Length >= (LONG)(FIELD_OFFSET( FILE_NETWORK_PHYSICAL_NAME_INFORMATION, FileName) + (LONG)usFullNameLength))
-        {
-            ulCopyLength = (LONG)usFullNameLength;
-
-           ntStatus = STATUS_SUCCESS;
-        }
-        else
-        {
-
-            ulCopyLength = *Length - FIELD_OFFSET( FILE_NETWORK_PHYSICAL_NAME_INFORMATION, FileName);
-
-            ntStatus = STATUS_BUFFER_OVERFLOW;
-        }
-
-        Buffer->FileNameLength = (ULONG)usFullNameLength;
-
-        *Length -= FIELD_OFFSET( FILE_NETWORK_PHYSICAL_NAME_INFORMATION, FileName);
-
-        if( ulCopyLength > 0)
-        {
-
-            if( bAddLeadingSlash)
-            {
-
-                Buffer->FileName[ cchCopied] = L'\\';
-
-                ulCopyLength -= sizeof( WCHAR);
-                *Length -= sizeof( WCHAR);
-                cchCopied++;
-            }
-
-            if( ulCopyLength >= pCcb->FullFileName.Length)
-            {
-
-                RtlCopyMemory( &Buffer->FileName[ cchCopied],
-                               pCcb->FullFileName.Buffer,
-                               pCcb->FullFileName.Length);
-
-                ulCopyLength -= pCcb->FullFileName.Length;
-                *Length -= pCcb->FullFileName.Length;
-                cchCopied += pCcb->FullFileName.Length/sizeof( WCHAR);
-            }
-            else
-            {
+       RtlZeroMemory( Buffer,
+                      *Length);
 
-                RtlCopyMemory( &Buffer->FileName[ cchCopied],
-                               pCcb->FullFileName.Buffer,
-                               ulCopyLength);
+       *Length -= FIELD_OFFSET( FILE_NETWORK_PHYSICAL_NAME_INFORMATION, FileName);
 
-                *Length -= ulCopyLength;
-            }
-        }
+       ntStatus = AFSGetFullFileName( pFcb,
+                                      pCcb,
+                                      &Buffer->FileNameLength,
+                                      Buffer->FileName,
+                                      Length);
     }
 
     return ntStatus;
index 7a70e1a..97cdb0c 100644 (file)
@@ -5250,3 +5250,132 @@ try_exit:
 
     return ntStatus;
 }
+
+NTSTATUS
+AFSGetFullFileName( IN AFSFcb *Fcb,
+                   IN AFSCcb *Ccb,
+                   OUT ULONG *FileNameLength,
+                   OUT WCHAR *FileName,
+                   IN OUT LONG *RemainingLength)
+{
+
+    NTSTATUS    ntStatus = STATUS_SUCCESS;
+    ULONG       ulCopyLength = 0;
+    ULONG       cchCopied = 0;
+    BOOLEAN     bAddTrailingSlash = FALSE;
+    BOOLEAN     bAddLeadingSlash = FALSE;
+    USHORT      usFullNameLength = 0;
+
+    __Enter
+    {
+
+       //
+       // 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'\\')
+       {
+           bAddTrailingSlash = TRUE;
+       }
+
+       usFullNameLength = sizeof( WCHAR) +
+                                   AFSServerName.Length +
+                                   Ccb->FullFileName.Length;
+
+       if( bAddLeadingSlash)
+       {
+           usFullNameLength += sizeof( WCHAR);
+       }
+
+       if( bAddTrailingSlash)
+       {
+           usFullNameLength += sizeof( WCHAR);
+       }
+
+       if( *RemainingLength >= (LONG)usFullNameLength)
+       {
+           ulCopyLength = (LONG)usFullNameLength;
+       }
+       else
+       {
+
+           ulCopyLength = *RemainingLength;
+
+           ntStatus = STATUS_BUFFER_OVERFLOW;
+       }
+
+       *FileNameLength = (ULONG)usFullNameLength;
+
+       if( ulCopyLength > 0)
+       {
+
+           FileName[ 0] = L'\\';
+           ulCopyLength -= sizeof( WCHAR);
+
+           *RemainingLength -= sizeof( WCHAR);
+           cchCopied += 1;
+
+           if( ulCopyLength >= AFSServerName.Length)
+           {
+
+               RtlCopyMemory( &FileName[ 1],
+                              AFSServerName.Buffer,
+                              AFSServerName.Length);
+
+               ulCopyLength -= AFSServerName.Length;
+               *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)
+               {
+
+                   RtlCopyMemory( &FileName[ cchCopied],
+                                  Ccb->FullFileName.Buffer,
+                                  Ccb->FullFileName.Length);
+
+                   ulCopyLength -= Ccb->FullFileName.Length;
+                   *RemainingLength -= Ccb->FullFileName.Length;
+                   cchCopied += Ccb->FullFileName.Length/sizeof( WCHAR);
+
+                   if( ulCopyLength > 0 &&
+                       bAddTrailingSlash)
+                   {
+                       FileName[ cchCopied] = L'\\';
+
+                       *RemainingLength -= sizeof( WCHAR);
+                   }
+               }
+               else
+               {
+
+                   RtlCopyMemory( &FileName[ cchCopied],
+                                  Ccb->FullFileName.Buffer,
+                                  ulCopyLength);
+
+                   *RemainingLength -= ulCopyLength;
+               }
+           }
+       }
+    }
+
+    return ntStatus;
+}
index 55735e2..38de896 100644 (file)
@@ -637,6 +637,13 @@ AFSProcessDFSLink( IN AFSDirectoryCB *DirEntry,
                    IN GUID *AuthGroup,
                   OUT PUNICODE_STRING TargetName);
 
+NTSTATUS
+AFSGetFullFileName( IN AFSFcb *Fcb,
+                   IN AFSCcb *Ccb,
+                   OUT ULONG *FileNameLength,
+                   OUT WCHAR *FileName,
+                   IN OUT LONG *RemainingLength);
+
 //
 // AFSNetworkProviderSupport.cpp
 //