Windows: More specific error values
[openafs.git] / src / WINNT / afsrdr / kernel / lib / AFSNameSupport.cpp
index 7e16890..7ce548e 100644 (file)
@@ -154,7 +154,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                               pCurrentObject->FileId.Volume,
                               pCurrentObject->FileId.Vnode,
                               pCurrentObject->FileId.Unique,
-                              ntStatus);
+                              STATUS_FILE_DELETED);
 
                 try_return( ntStatus = STATUS_FILE_DELETED);
             }
@@ -171,7 +171,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                               pCurrentObject->FileId.Volume,
                               pCurrentObject->FileId.Vnode,
                               pCurrentObject->FileId.Unique,
-                              ntStatus);
+                              STATUS_DELETE_PENDING);
 
                 try_return( ntStatus = STATUS_DELETE_PENDING);
             }
@@ -361,7 +361,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                     if( pDirEntry->NameInformation.TargetName.Length == 0)
                     {
 
-                        ntStatus = STATUS_ACCESS_DENIED;
+                        ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
 
                         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                                       AFS_TRACE_LEVEL_ERROR,
@@ -663,13 +663,8 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                           pCurrentVolume,
                                           pCurrentVolume->VolumeReferenceCount);
 
-                            AFSReleaseResource( pCurrentVolume->VolumeLock);
-
                             pCurrentVolume = AFSGlobalRoot;
 
-                            AFSAcquireShared( pCurrentVolume->VolumeLock,
-                                              TRUE);
-
                             InterlockedIncrement( &pCurrentVolume->VolumeReferenceCount);
 
                             AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
@@ -826,8 +821,6 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                                   pCurrentVolume,
                                   pCurrentVolume->VolumeReferenceCount);
 
-                    AFSReleaseResource( pCurrentVolume->VolumeLock);
-
                     ntStatus = AFSBuildMountPointTarget( AuthGroup,
                                                          pDirEntry,
                                                          &pCurrentVolume);
@@ -852,13 +845,11 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
 
                         bReleaseCurrentVolume = FALSE;
 
-                        try_return( ntStatus = STATUS_ACCESS_DENIED);
+                        try_return( ntStatus);
                     }
 
                     ASSERT( pCurrentVolume->VolumeReferenceCount > 1);
 
-                    ASSERT( ExIsResourceAcquiredLite( pCurrentVolume->VolumeLock));
-
                     //
                     // Replace the current name for the mp with the volume root of the target
                     //
@@ -935,7 +926,8 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
 
                         ntStatus = AFSProcessDFSLink( pDirEntry,
                                                       FileObject,
-                                                      &uniRemainingPath);
+                                                      &uniRemainingPath,
+                                                      AuthGroup);
                     }
                     else
                     {
@@ -1565,7 +1557,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                               AFS_TRACE_LEVEL_ERROR,
-                              "AFSLocateNameEntry (FO: %08lX) Deleted parent %wZ FID %08lX-%08lX-%08lX-%08lX\n",
+                              "AFSLocateNameEntry (FO: %08lX) Deleted entry %wZ FID %08lX-%08lX-%08lX-%08lX\n",
                               FileObject,
                               &pDirEntry->NameInformation.FileName,
                               pCurrentObject->FileId.Cell,
@@ -1589,7 +1581,7 @@ AFSLocateNameEntry( IN GUID *AuthGroup,
                 if( InterlockedDecrement( &pDirEntry->OpenReferenceCount) == 0)
                 {
 
-                    AFSDbgLogMsg( AFS_SUBSYSTEM_CLEANUP_PROCESSING,
+                    AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING|AFS_SUBSYSTEM_CLEANUP_PROCESSING,
                                   AFS_TRACE_LEVEL_VERBOSE,
                                   "AFSLocateNameEntry Deleting dir entry %08lX (%08lX) for %wZ\n",
                                   pDirEntry,
@@ -1874,8 +1866,6 @@ try_exit:
 
                 ASSERT( pCurrentVolume->VolumeReferenceCount > 1);
 
-                ASSERT( ExIsResourceAcquiredLite( pCurrentVolume->VolumeLock));
-
                 InterlockedDecrement( &pCurrentVolume->VolumeReferenceCount);
 
                 AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
@@ -1883,8 +1873,6 @@ try_exit:
                               "AFSLocateNameEntry Decrement3 count on volume %08lX Cnt %d\n",
                               pCurrentVolume,
                               pCurrentVolume->VolumeReferenceCount);
-
-                AFSReleaseResource( pCurrentVolume->VolumeLock);
             }
 
             if( RootPathName->Buffer != uniFullPathName.Buffer)
@@ -2624,11 +2612,11 @@ AFSParseName( IN PIRP Irp,
             *FileName = pIrpSp->FileObject->FileName;
 
             //
-            // Grab the root node exclusive before returning
+            // Grab the root node while checking state
             //
 
-            AFSAcquireExcl( pVolumeCB->VolumeLock,
-                            TRUE);
+            AFSAcquireShared( pVolumeCB->VolumeLock,
+                              TRUE);
 
             if( BooleanFlagOn( pVolumeCB->ObjectInformation.Flags, AFS_OBJECT_FLAGS_OBJECT_INVALID) ||
                 BooleanFlagOn( pVolumeCB->Flags, AFS_VOLUME_FLAGS_OFFLINE))
@@ -2678,7 +2666,7 @@ AFSParseName( IN PIRP Irp,
                 }
             }
 
-            AFSConvertToShared( pVolumeCB->VolumeLock);
+            AFSReleaseResource( pVolumeCB->VolumeLock);
 
             if( BooleanFlagOn( pDirEntry->ObjectInformation->Flags, AFS_OBJECT_FLAGS_VERIFY))
             {
@@ -2710,8 +2698,6 @@ AFSParseName( IN PIRP Irp,
                                   pDirEntry->ObjectInformation->FileId.Unique,
                                   ntStatus);
 
-                    AFSReleaseResource( pVolumeCB->VolumeLock);
-
                     try_return( ntStatus);
                 }
             }
@@ -2739,8 +2725,6 @@ AFSParseName( IN PIRP Irp,
                               "AFSParseName (%08lX) Failed to allocate full name buffer\n",
                               Irp);
 
-                AFSReleaseResource( pVolumeCB->VolumeLock);
-
                 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
             }
 
@@ -2806,8 +2790,6 @@ AFSParseName( IN PIRP Irp,
 
                     AFSExFreePool( uniFullName.Buffer);
 
-                    AFSReleaseResource( pVolumeCB->VolumeLock);
-
                     try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
                 }
 
@@ -2835,8 +2817,6 @@ AFSParseName( IN PIRP Irp,
 
                     AFSExFreePool( uniFullName.Buffer);
 
-                    AFSReleaseResource( pVolumeCB->VolumeLock);
-
                     try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
                 }
 
@@ -2855,8 +2835,6 @@ AFSParseName( IN PIRP Irp,
 
                 AFSExFreePool( uniFullName.Buffer);
 
-                AFSReleaseResource( pVolumeCB->VolumeLock);
-
                 try_return( ntStatus);
             }
 
@@ -3035,8 +3013,8 @@ AFSParseName( IN PIRP Irp,
         // Be sure we are online and ready to go
         //
 
-        AFSAcquireExcl( AFSGlobalRoot->VolumeLock,
-                        TRUE);
+        AFSAcquireShared( AFSGlobalRoot->VolumeLock,
+                          TRUE);
 
         if( BooleanFlagOn( AFSGlobalRoot->ObjectInformation.Flags, AFS_OBJECT_FLAGS_OBJECT_INVALID) ||
             BooleanFlagOn( AFSGlobalRoot->Flags, AFS_VOLUME_FLAGS_OFFLINE))
@@ -3086,6 +3064,8 @@ AFSParseName( IN PIRP Irp,
             }
         }
 
+        AFSReleaseResource( AFSGlobalRoot->VolumeLock);
+
         if( !BooleanFlagOn( AFSGlobalRoot->ObjectInformation.Flags, AFS_OBJECT_FLAGS_DIRECTORY_ENUMERATED))
         {
 
@@ -3107,8 +3087,6 @@ AFSParseName( IN PIRP Irp,
                               Irp,
                               ntStatus);
 
-                AFSReleaseResource( AFSGlobalRoot->VolumeLock);
-
                 try_return( ntStatus);
             }
         }
@@ -3137,8 +3115,6 @@ AFSParseName( IN PIRP Irp,
                           NULL,
                           AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
 
-            AFSReleaseResource( AFSGlobalRoot->VolumeLock);
-
             *VolumeCB = NULL;
 
             FileName->Length = 0;
@@ -3205,8 +3181,6 @@ AFSParseName( IN PIRP Irp,
                               NULL,
                               AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
 
-                AFSReleaseResource( AFSGlobalRoot->VolumeLock);
-
                 *VolumeCB = NULL;
 
                 FileName->Length = 0;
@@ -3250,8 +3224,6 @@ AFSParseName( IN PIRP Irp,
                               NULL,
                               AFSGlobalRoot->DirectoryCB->OpenReferenceCount);
 
-                AFSReleaseResource( AFSGlobalRoot->VolumeLock);
-
                 ClearFlag( *ParseFlags, AFS_PARSE_FLAG_ROOT_ACCESS);
 
                 *VolumeCB = NULL;
@@ -3271,8 +3243,6 @@ AFSParseName( IN PIRP Irp,
                           Irp,
                           &uniComponentName);
 
-            AFSReleaseResource( AFSGlobalRoot->VolumeLock);
-
             //
             // Add in the full share name to pass back
             //
@@ -3381,7 +3351,6 @@ AFSParseName( IN PIRP Irp,
 
                     if( !NT_SUCCESS( ntStatus))
                     {
-                        AFSReleaseResource( AFSGlobalRoot->VolumeLock);
 
                         if ( bIsAllShare &&
                              uniRemainingPath.Length == 0 &&
@@ -3526,12 +3495,6 @@ AFSParseName( IN PIRP Irp,
         }
 
         //
-        // We only need the volume shared at this point
-        //
-
-        AFSConvertToShared( pVolumeCB->VolumeLock);
-
-        //
         // Init our name array
         //
 
@@ -3546,8 +3509,6 @@ AFSParseName( IN PIRP Irp,
                           "AFSParseName (%08lX) Failed to initialize name array\n",
                           Irp);
 
-            AFSReleaseResource( pVolumeCB->VolumeLock);
-
             try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
         }
 
@@ -3595,7 +3556,6 @@ try_exit:
 
         if( *VolumeCB != NULL)
         {
-
             ASSERT( (*VolumeCB)->VolumeReferenceCount > 1);
         }
 
@@ -3621,7 +3581,6 @@ AFSCheckCellName( IN GUID *AuthGroup,
 
     NTSTATUS ntStatus = STATUS_SUCCESS;
     UNICODE_STRING uniName;
-    AFSFileID stFileID;
     AFSDirEnumEntry *pDirEnumEntry = NULL;
     AFSDeviceExt *pDevExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
     AFSDirHdr *pDirHdr = &AFSGlobalRoot->ObjectInformation.Specific.Directory.DirectoryNodeHdr;
@@ -3684,10 +3643,8 @@ AFSCheckCellName( IN GUID *AuthGroup,
         // OK, ask the CM about this component name
         //
 
-        stFileID = AFSGlobalRoot->ObjectInformation.FileId;
-
         ntStatus = AFSEvaluateTargetByName( AuthGroup,
-                                            &stFileID,
+                                            &AFSGlobalRoot->ObjectInformation,
                                             CellName,
                                             &pDirEnumEntry);
 
@@ -3716,12 +3673,6 @@ AFSCheckCellName( IN GUID *AuthGroup,
         {
 
             //
-            // We have the global root on entry so drop it now
-            //
-
-            AFSReleaseResource( AFSGlobalRoot->VolumeLock);
-
-            //
             // Build the root volume entry
             //
 
@@ -3731,14 +3682,6 @@ AFSCheckCellName( IN GUID *AuthGroup,
 
             if( !NT_SUCCESS( ntStatus))
             {
-
-                //
-                // On failure this routine is expecting to hold the global root
-                //
-
-                AFSAcquireShared( AFSGlobalRoot->VolumeLock,
-                                  TRUE);
-
                 try_return( ntStatus);
             }
 
@@ -3972,7 +3915,7 @@ AFSBuildMountPointTarget( IN GUID *AuthGroup,
                               DirectoryCB->ObjectInformation->FileId.Vnode,
                               DirectoryCB->ObjectInformation->FileId.Unique);
 
-                try_return( ntStatus = STATUS_ACCESS_DENIED);
+                try_return( ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED);
             }
 
             AFSAcquireExcl( &DirectoryCB->NonPaged->Lock,
@@ -4115,8 +4058,6 @@ AFSBuildMountPointTarget( IN GUID *AuthGroup,
             AFSReleaseResource( &pVolumeCB->RootFcb->NPFcb->Resource);
         }
 
-        AFSConvertToShared( pVolumeCB->VolumeLock);
-
         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE_2,
                       "AFSBuildMountPointTarget Evaluated target of %wZ FID %08lX-%08lX-%08lX-%08lX as root volume\n",
@@ -4128,6 +4069,8 @@ AFSBuildMountPointTarget( IN GUID *AuthGroup,
 
         InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
+        AFSReleaseResource( pVolumeCB->VolumeLock);
+
         AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSBuildMountPointTarget Increment count on volume %08lX Cnt %d\n",
@@ -4272,8 +4215,6 @@ AFSBuildRootVolume( IN GUID *AuthGroup,
             AFSReleaseResource( &pVolumeCB->RootFcb->NPFcb->Resource);
         }
 
-        AFSConvertToShared( pVolumeCB->VolumeLock);
-
         AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
                       AFS_TRACE_LEVEL_VERBOSE_2,
                       "AFSBuildRootVolume Evaluated target of %wZ FID %08lX-%08lX-%08lX-%08lX as root volume\n",
@@ -4285,6 +4226,8 @@ AFSBuildRootVolume( IN GUID *AuthGroup,
 
         InterlockedIncrement( &pVolumeCB->VolumeReferenceCount);
 
+        AFSReleaseResource( pVolumeCB->VolumeLock);
+
         AFSDbgLogMsg( AFS_SUBSYSTEM_VOLUME_REF_COUNTING,
                       AFS_TRACE_LEVEL_VERBOSE,
                       "AFSBuildRootVolume Increment count on volume %08lX Cnt %d\n",
@@ -4304,14 +4247,14 @@ try_exit:
 NTSTATUS
 AFSProcessDFSLink( IN AFSDirectoryCB *DirEntry,
                    IN PFILE_OBJECT FileObject,
-                   IN UNICODE_STRING *RemainingPath)
+                   IN UNICODE_STRING *RemainingPath,
+                   IN GUID *AuthGroup)
 {
 
     NTSTATUS ntStatus = STATUS_INVALID_DEVICE_REQUEST;
     UNICODE_STRING uniReparseName;
     UNICODE_STRING uniMUPDeviceName;
     AFSDirEnumEntry *pDirEntry = NULL;
-    GUID *pAuthGroup = NULL;
 
     __Enter
     {
@@ -4333,13 +4276,8 @@ AFSProcessDFSLink( IN AFSDirectoryCB *DirEntry,
         if( DirEntry->NameInformation.TargetName.Length == 0)
         {
 
-            if( DirEntry->ObjectInformation->Fcb != NULL)
-            {
-                pAuthGroup = &DirEntry->ObjectInformation->Fcb->AuthGroup;
-            }
-
             ntStatus = AFSEvaluateTargetByID( DirEntry->ObjectInformation,
-                                              pAuthGroup,
+                                              AuthGroup,
                                               FALSE,
                                               &pDirEntry);
 
@@ -4360,7 +4298,7 @@ AFSProcessDFSLink( IN AFSDirectoryCB *DirEntry,
                 if( NT_SUCCESS( ntStatus))
                 {
 
-                    ntStatus = STATUS_ACCESS_DENIED;
+                    ntStatus = STATUS_REPARSE_POINT_NOT_RESOLVED;
                 }
 
                 try_return( ntStatus);