Windows: FileNetworkPhysicalNameInfo implementation
authorPeter Scott <pscott@kerneldrivers.com>
Thu, 10 Nov 2011 16:06:53 +0000 (09:06 -0700)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Thu, 10 Nov 2011 18:16:57 +0000 (10:16 -0800)
Handle this File information query

Change-Id: Id16c22396cbb7e22b8958bc0438e58da048f4f70
Reviewed-on: http://gerrit.openafs.org/5830
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Tested-by: Jeffrey Altman <jaltman@secure-endpoints.com>

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

index cdd850f..87d21c8 100644 (file)
@@ -383,11 +383,22 @@ AFSQueryFileInfo( IN PDEVICE_OBJECT LibDeviceObject,
                 break;
             }
 
-        default:
+            case FileNetworkPhysicalNameInformation:
+            {
 
-                ntStatus = STATUS_INVALID_PARAMETER;
+                ntStatus = AFSQueryPhysicalNameInfo( Irp,
+                                                     pCcb->DirectoryCB,
+                                                     (FILE_NETWORK_PHYSICAL_NAME_INFORMATION *)pBuffer,
+                                                     &lLength);
 
                 break;
+            }
+
+            default:
+            {
+                ntStatus = STATUS_INVALID_PARAMETER;
+                break;
+            }
         }
 
 try_exit:
@@ -1604,6 +1615,105 @@ AFSQueryRemoteProtocolInfo( IN PIRP Irp,
 }
 
 NTSTATUS
+AFSQueryPhysicalNameInfo( IN PIRP Irp,
+                          IN AFSDirectoryCB *DirectoryCB,
+                          IN OUT PFILE_NETWORK_PHYSICAL_NAME_INFORMATION Buffer,
+                          IN OUT PLONG Length)
+{
+
+    NTSTATUS ntStatus = STATUS_SUCCESS;
+    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;
+
+    pCcb = (AFSCcb *)pIrpSp->FileObject->FsContext2;
+
+    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;
+        }
+        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
+            {
+
+                RtlCopyMemory( &Buffer->FileName[ cchCopied],
+                               pCcb->FullFileName.Buffer,
+                               ulCopyLength);
+
+                *Length -= ulCopyLength;
+            }
+        }
+    }
+    else
+    {
+
+        ntStatus = STATUS_BUFFER_TOO_SMALL;
+    }
+
+    return ntStatus;
+}
+
+NTSTATUS
 AFSSetBasicInfo( IN PIRP Irp,
                  IN AFSDirectoryCB *DirectoryCB)
 {
index c51ae08..e8c506d 100644 (file)
@@ -761,6 +761,12 @@ AFSQueryRemoteProtocolInfo( IN PIRP Irp,
                             IN OUT PLONG Length);
 
 NTSTATUS
+AFSQueryPhysicalNameInfo( IN PIRP Irp,
+                          IN AFSDirectoryCB *DirectoryCB,
+                          IN OUT PFILE_NETWORK_PHYSICAL_NAME_INFORMATION Buffer,
+                          IN OUT PLONG Length);
+
+NTSTATUS
 AFSSetFileInfo( IN PDEVICE_OBJECT DeviceObject,
                 IN PIRP Irp);