Windows: Add Cell to FS Volume Information Label
authorJeffrey Altman <jaltman@your-file-system.com>
Thu, 14 Feb 2013 02:53:46 +0000 (21:53 -0500)
committerJeffrey Altman <jaltman@your-file-system.com>
Thu, 14 Feb 2013 14:46:58 +0000 (06:46 -0800)
Add the Cell name to the VolumeLabel field of the
FILE_FS_VOLUME_INFORMATION structure.  This permits "cell#volume" to be
displayed by cmd.exe's DIR command and other applications that call the
GetVolumeInformation() or GetVolumeInformationByHandle() Win32 APIs.

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

src/WINNT/afsrdr/kernel/lib/AFSVolumeInfo.cpp

index 2f1ae40..6e57fdb 100644 (file)
@@ -287,7 +287,7 @@ AFSQueryFsVolumeInfo( IN AFSVolumeInfoCB *VolumeInfo,
 {
 
     NTSTATUS ntStatus = STATUS_BUFFER_TOO_SMALL;
-    ULONG ulCopyLength;
+    ULONG ulLabelLength;
 
     RtlZeroMemory( Buffer,
                    *Length);
@@ -295,18 +295,17 @@ AFSQueryFsVolumeInfo( IN AFSVolumeInfoCB *VolumeInfo,
     if( *Length >= (ULONG)sizeof( FILE_FS_VOLUME_INFORMATION))
     {
 
-        if( *Length >= (ULONG)(FIELD_OFFSET( FILE_FS_VOLUME_INFORMATION, VolumeLabel) + (LONG)VolumeInfo->VolumeLabelLength))
-        {
+        ulLabelLength = VolumeInfo->VolumeLabelLength +
+            VolumeInfo->CellLength + sizeof( WCHAR);
 
-            ulCopyLength = (LONG)VolumeInfo->VolumeLabelLength;
+        if( *Length >= (ULONG)(FIELD_OFFSET( FILE_FS_VOLUME_INFORMATION, VolumeLabel) + ulLabelLength))
+        {
 
             ntStatus = STATUS_SUCCESS;
         }
         else
         {
 
-            ulCopyLength = *Length - FIELD_OFFSET( FILE_FS_VOLUME_INFORMATION, VolumeLabel);
-
             ntStatus = STATUS_BUFFER_OVERFLOW;
         }
 
@@ -314,20 +313,37 @@ AFSQueryFsVolumeInfo( IN AFSVolumeInfoCB *VolumeInfo,
 
         Buffer->VolumeSerialNumber = VolumeInfo->VolumeID;
 
-        Buffer->VolumeLabelLength = VolumeInfo->VolumeLabelLength;
+        Buffer->VolumeLabelLength = ulLabelLength;
 
         Buffer->SupportsObjects = FALSE;
 
         *Length -= FIELD_OFFSET( FILE_FS_VOLUME_INFORMATION, VolumeLabel);
 
-        if( ulCopyLength > 0)
+        if( *Length > 0)
         {
 
             RtlCopyMemory( Buffer->VolumeLabel,
-                           VolumeInfo->VolumeLabel,
-                           ulCopyLength);
+                           VolumeInfo->Cell,
+                           min( *Length, VolumeInfo->CellLength));
+
+            *Length -= min( *Length, VolumeInfo->CellLength);
+
+            if ( *Length >= sizeof( WCHAR))
+            {
 
-            *Length -= ulCopyLength;
+                Buffer->VolumeLabel[ VolumeInfo->CellLength / sizeof( WCHAR)] = L'#';
+
+                *Length -= sizeof( WCHAR);
+
+                if ( *Length > 0) {
+
+                    RtlCopyMemory( &Buffer->VolumeLabel[ (VolumeInfo->CellLength + sizeof( WCHAR)) / sizeof( WCHAR)],
+                                   VolumeInfo->VolumeLabel,
+                                   min( *Length, VolumeInfo->VolumeLabelLength));
+
+                    *Length -= min( *Length, VolumeInfo->VolumeLabelLength);
+                }
+            }
         }
     }