2 * Copyright (c) 2008, 2009, 2010, 2011 Kernel Drivers, LLC.
3 * Copyright (c) 2009, 2010, 2011 Your File System, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * - Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
14 * this list of conditions and the following disclaimer in the
16 * and/or other materials provided with the distribution.
17 * - Neither the names of Kernel Drivers, LLC and Your File System, Inc.
18 * nor the names of their contributors may be used to endorse or promote
19 * products derived from this software without specific prior written
20 * permission from Kernel Drivers, LLC and Your File System, Inc.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
26 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 // File: AFSCommSupport.cpp
39 #include "AFSCommon.h"
42 AFSEnumerateDirectory( IN GUID *AuthGroup,
43 IN AFSObjectInfoCB *ObjectInfoCB,
47 NTSTATUS ntStatus = STATUS_SUCCESS;
49 ULONG ulResultLen = 0;
50 AFSDirQueryCB *pDirQueryCB;
51 AFSDirEnumEntry *pCurrentDirEntry = NULL;
52 AFSDirectoryCB *pDirNode = NULL;
53 ULONG ulEntryLength = 0;
54 AFSDirEnumResp *pDirEnumResponse = NULL;
55 UNICODE_STRING uniDirName, uniTargetName;
56 ULONG ulRequestFlags = AFS_REQUEST_FLAG_SYNCHRONOUS;
58 UNICODE_STRING uniGUID;
64 uniGUID.MaximumLength = 0;
65 uniGUID.Buffer = NULL;
67 if( AuthGroup != NULL)
69 RtlStringFromGUID( *AuthGroup,
73 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
74 AFS_TRACE_LEVEL_VERBOSE,
75 "AFSEnumerateDirectory Enumerating FID %08lX-%08lX-%08lX-%08lX AuthGroup %wZ\n",
76 ObjectInfoCB->FileId.Cell,
77 ObjectInfoCB->FileId.Volume,
78 ObjectInfoCB->FileId.Vnode,
79 ObjectInfoCB->FileId.Unique,
82 if( AuthGroup != NULL)
84 RtlFreeUnicodeString( &uniGUID);
88 // Initialize the directory enumeration buffer for the directory
91 pBuffer = AFSExAllocatePoolWithTag( PagedPool,
92 AFS_DIR_ENUM_BUFFER_LEN,
98 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
101 RtlZeroMemory( pBuffer,
102 AFS_DIR_ENUM_BUFFER_LEN);
104 ulResultLen = AFS_DIR_ENUM_BUFFER_LEN;
107 // Use the payload buffer for information we will pass to the service
110 pDirQueryCB = (AFSDirQueryCB *)pBuffer;
112 pDirQueryCB->EnumHandle = 0;
117 ulRequestFlags |= AFS_REQUEST_FLAG_FAST_REQUEST;
121 // Loop on the information
128 // Go and retrieve the directory contents
131 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_DIR_ENUM,
135 &ObjectInfoCB->FileId,
137 sizeof( AFSDirQueryCB),
141 if( ntStatus != STATUS_SUCCESS ||
145 if( ntStatus == STATUS_NO_MORE_FILES ||
146 ntStatus == STATUS_NO_MORE_ENTRIES)
149 ntStatus = STATUS_SUCCESS;
154 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
155 AFS_TRACE_LEVEL_ERROR,
156 "AFSEnumerateDirectory Failed to enumerate directory Status %08lX\n",
163 pDirEnumResponse = (AFSDirEnumResp *)pBuffer;
165 pCurrentDirEntry = (AFSDirEnumEntry *)pDirEnumResponse->Entry;
168 // Remove the leading header from the processed length
171 ulResultLen -= FIELD_OFFSET( AFSDirEnumResp, Entry);
173 while( ulResultLen > 0)
176 uniDirName.Length = (USHORT)pCurrentDirEntry->FileNameLength;
178 uniDirName.MaximumLength = uniDirName.Length;
180 uniDirName.Buffer = (WCHAR *)((char *)pCurrentDirEntry + pCurrentDirEntry->FileNameOffset);
182 uniTargetName.Length = (USHORT)pCurrentDirEntry->TargetNameLength;
184 uniTargetName.MaximumLength = uniTargetName.Length;
186 uniTargetName.Buffer = (WCHAR *)((char *)pCurrentDirEntry + pCurrentDirEntry->TargetNameOffset);
189 // Be sure we don't have this entry in the case sensitive tree
192 ulCRC = AFSGenerateCRC( &uniDirName,
195 AFSLocateCaseSensitiveDirEntry( ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead,
199 if( pDirNode != NULL)
203 // Duplicate entry, skip it
206 ulEntryLength = QuadAlign( sizeof( AFSDirEnumEntry) +
208 uniTargetName.Length);
210 pCurrentDirEntry = (AFSDirEnumEntry *)((char *)pCurrentDirEntry + ulEntryLength);
212 if( ulResultLen >= ulEntryLength)
214 ulResultLen -= ulEntryLength;
224 pDirNode = AFSInitDirEntry( ObjectInfoCB,
228 (ULONG)InterlockedIncrement( &ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.ContentIndex));
230 if( pDirNode == NULL)
233 ntStatus = STATUS_INSUFFICIENT_RESOURCES;
239 // Set up the entry length
242 ulEntryLength = QuadAlign( sizeof( AFSDirEnumEntry) +
243 pCurrentDirEntry->FileNameLength +
244 pCurrentDirEntry->TargetNameLength);
247 // Init the short name if we have one
250 if( pCurrentDirEntry->ShortNameLength > 0)
253 UNICODE_STRING uniShortName;
255 pDirNode->NameInformation.ShortNameLength = pCurrentDirEntry->ShortNameLength;
257 RtlCopyMemory( pDirNode->NameInformation.ShortName,
258 pCurrentDirEntry->ShortName,
259 pDirNode->NameInformation.ShortNameLength);
262 // Generate the short name index
265 uniShortName.Length = pDirNode->NameInformation.ShortNameLength;
266 uniShortName.Buffer = pDirNode->NameInformation.ShortName;
268 pDirNode->Type.Data.ShortNameTreeEntry.HashIndex = AFSGenerateCRC( &uniShortName,
273 // Insert the node into the name tree
276 ASSERT( ExIsResourceAcquiredExclusiveLite( ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.TreeLock));
278 if( ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead == NULL)
281 ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead = pDirNode;
286 AFSInsertCaseSensitiveDirEntry( ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead,
290 if( ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.CaseInsensitiveTreeHead == NULL)
293 ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.CaseInsensitiveTreeHead = pDirNode;
295 SetFlag( pDirNode->Flags, AFS_DIR_ENTRY_CASE_INSENSTIVE_LIST_HEAD);
300 AFSInsertCaseInsensitiveDirEntry( ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.CaseInsensitiveTreeHead,
304 if( ObjectInfoCB->Specific.Directory.DirectoryNodeListHead == NULL)
307 ObjectInfoCB->Specific.Directory.DirectoryNodeListHead = pDirNode;
312 ObjectInfoCB->Specific.Directory.DirectoryNodeListTail->ListEntry.fLink = pDirNode;
314 pDirNode->ListEntry.bLink = ObjectInfoCB->Specific.Directory.DirectoryNodeListTail;
317 ObjectInfoCB->Specific.Directory.DirectoryNodeListTail = pDirNode;
319 SetFlag( pDirNode->Flags, AFS_DIR_ENTRY_INSERTED_ENUM_LIST);
321 InterlockedIncrement( &ObjectInfoCB->Specific.Directory.DirectoryNodeCount);
323 AFSDbgLogMsg( AFS_SUBSYSTEM_DIR_NODE_COUNT,
324 AFS_TRACE_LEVEL_VERBOSE,
325 "AFSEnumerateDirectory Adding entry %wZ Inc Count %d to parent FID %08lX-%08lX-%08lX-%08lX\n",
326 &pDirNode->NameInformation.FileName,
327 ObjectInfoCB->Specific.Directory.DirectoryNodeCount,
328 ObjectInfoCB->FileId.Cell,
329 ObjectInfoCB->FileId.Volume,
330 ObjectInfoCB->FileId.Vnode,
331 ObjectInfoCB->FileId.Unique);
333 if( pDirNode->Type.Data.ShortNameTreeEntry.HashIndex != 0)
337 // Insert the short name entry if we have a valid short name
340 if( ObjectInfoCB->Specific.Directory.ShortNameTree == NULL)
343 ObjectInfoCB->Specific.Directory.ShortNameTree = pDirNode;
348 AFSInsertShortNameDirEntry( ObjectInfoCB->Specific.Directory.ShortNameTree,
357 pCurrentDirEntry = (AFSDirEnumEntry *)((char *)pCurrentDirEntry + ulEntryLength);
359 if( ulResultLen >= ulEntryLength)
361 ulResultLen -= ulEntryLength;
369 ulResultLen = AFS_DIR_ENUM_BUFFER_LEN;
372 // Reset the information in the request buffer since it got trampled
376 pDirQueryCB->EnumHandle = pDirEnumResponse->EnumHandle;
378 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
379 AFS_TRACE_LEVEL_VERBOSE,
380 "AFSEnumerateDirectory EnumHandle %08lX\n",
381 pDirQueryCB->EnumHandle);
384 // If the enumeration handle is -1 then we are done
387 if( ((ULONG)-1) == pDirQueryCB->EnumHandle )
403 AFSExFreePool( pBuffer);
407 // If the processing failed then we should reset the directory content in the event
408 // it is re-enumerated
411 if( !NT_SUCCESS( ntStatus))
414 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
415 AFS_TRACE_LEVEL_ERROR,
416 "AFSEnumerateDirectory Resetting content for FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
417 ObjectInfoCB->FileId.Cell,
418 ObjectInfoCB->FileId.Volume,
419 ObjectInfoCB->FileId.Vnode,
420 ObjectInfoCB->FileId.Unique,
423 AFSResetDirectoryContent( ObjectInfoCB);
431 AFSEnumerateDirectoryNoResponse( IN GUID *AuthGroup,
432 IN AFSFileID *FileId)
435 NTSTATUS ntStatus = STATUS_SUCCESS;
436 AFSDirQueryCB stDirQueryCB;
437 ULONG ulRequestFlags = 0;
443 // Use the payload buffer for information we will pass to the service
446 stDirQueryCB.EnumHandle = 0;
448 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_DIR_ENUM,
453 (void *)&stDirQueryCB,
454 sizeof( AFSDirQueryCB),
458 if( ntStatus != STATUS_SUCCESS)
461 if( ntStatus == STATUS_NO_MORE_FILES ||
462 ntStatus == STATUS_NO_MORE_ENTRIES)
465 ntStatus = STATUS_SUCCESS;
470 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
471 AFS_TRACE_LEVEL_ERROR,
472 "AFSEnumerateDirectoryNoResponse Failed to enumerate directory Status %08lX\n",
482 AFSVerifyDirectoryContent( IN AFSObjectInfoCB *ObjectInfoCB,
486 NTSTATUS ntStatus = STATUS_SUCCESS;
487 void *pBuffer = NULL;
488 ULONG ulResultLen = 0;
489 AFSDirQueryCB *pDirQueryCB;
490 AFSDirEnumEntry *pCurrentDirEntry = NULL;
491 AFSDirectoryCB *pDirNode = NULL;
492 ULONG ulEntryLength = 0;
493 AFSDirEnumResp *pDirEnumResponse = NULL;
494 UNICODE_STRING uniDirName, uniTargetName;
495 ULONG ulRequestFlags = AFS_REQUEST_FLAG_SYNCHRONOUS | AFS_REQUEST_FLAG_FAST_REQUEST;
497 AFSObjectInfoCB *pObjectInfo = NULL;
498 ULONGLONG ullIndex = 0;
499 UNICODE_STRING uniGUID;
505 uniGUID.MaximumLength = 0;
506 uniGUID.Buffer = NULL;
508 if( AuthGroup != NULL)
510 RtlStringFromGUID( *AuthGroup,
514 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
515 AFS_TRACE_LEVEL_VERBOSE,
516 "AFSVerifyDirectoryContent Verifying content for FID %08lX-%08lX-%08lX-%08lX AuthGroup %wZ\n",
517 ObjectInfoCB->FileId.Cell,
518 ObjectInfoCB->FileId.Volume,
519 ObjectInfoCB->FileId.Vnode,
520 ObjectInfoCB->FileId.Unique,
523 if( AuthGroup != NULL)
525 RtlFreeUnicodeString( &uniGUID);
529 // Initialize the directory enumeration buffer for the directory
532 pBuffer = AFSExAllocatePoolWithTag( PagedPool,
533 AFS_DIR_ENUM_BUFFER_LEN,
539 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
542 RtlZeroMemory( pBuffer,
543 AFS_DIR_ENUM_BUFFER_LEN);
545 ulResultLen = AFS_DIR_ENUM_BUFFER_LEN;
548 // Use the payload buffer for information we will pass to the service
551 pDirQueryCB = (AFSDirQueryCB *)pBuffer;
553 pDirQueryCB->EnumHandle = 0;
556 // Loop on the information
563 // Go and retrieve the directory contents
566 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_DIR_ENUM,
570 &ObjectInfoCB->FileId,
572 sizeof( AFSDirQueryCB),
576 if( ntStatus != STATUS_SUCCESS ||
580 if( ntStatus == STATUS_NO_MORE_FILES ||
581 ntStatus == STATUS_NO_MORE_ENTRIES)
584 ntStatus = STATUS_SUCCESS;
589 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
590 AFS_TRACE_LEVEL_ERROR,
591 "AFSVerifyDirectoryContent Failed to enumerate directory Status %08lX\n",
598 pDirEnumResponse = (AFSDirEnumResp *)pBuffer;
600 pCurrentDirEntry = (AFSDirEnumEntry *)pDirEnumResponse->Entry;
603 // Remove the leading header from the processed length
606 ulResultLen -= FIELD_OFFSET( AFSDirEnumResp, Entry);
608 while( ulResultLen > 0)
611 uniDirName.Length = (USHORT)pCurrentDirEntry->FileNameLength;
613 uniDirName.MaximumLength = uniDirName.Length;
615 uniDirName.Buffer = (WCHAR *)((char *)pCurrentDirEntry + pCurrentDirEntry->FileNameOffset);
617 uniTargetName.Length = (USHORT)pCurrentDirEntry->TargetNameLength;
619 uniTargetName.MaximumLength = uniTargetName.Length;
621 uniTargetName.Buffer = (WCHAR *)((char *)pCurrentDirEntry + pCurrentDirEntry->TargetNameOffset);
624 // Does this entry already exist in the directory?
627 ulCRC = AFSGenerateCRC( &uniDirName,
630 ASSERT( ExIsResourceAcquiredExclusiveLite( ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.TreeLock));
632 AFSLocateCaseSensitiveDirEntry( ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead,
638 // Set up the entry length
641 ulEntryLength = QuadAlign( sizeof( AFSDirEnumEntry) +
642 pCurrentDirEntry->FileNameLength +
643 pCurrentDirEntry->TargetNameLength);
645 if( pDirNode != NULL)
649 // Check that the FIDs are the same
652 if( AFSIsEqualFID( &pCurrentDirEntry->FileId,
653 &pDirNode->ObjectInformation->FileId))
656 AFSAcquireShared( ObjectInfoCB->VolumeCB->ObjectInfoTree.TreeLock,
659 ullIndex = AFSCreateLowIndex( &pCurrentDirEntry->FileId);
661 ntStatus = AFSLocateHashEntry( ObjectInfoCB->VolumeCB->ObjectInfoTree.TreeHead,
663 (AFSBTreeEntry **)&pObjectInfo);
665 AFSReleaseResource( ObjectInfoCB->VolumeCB->ObjectInfoTree.TreeLock);
667 if( NT_SUCCESS( ntStatus) &&
672 // Indicate this is a valid entry
675 SetFlag( pDirNode->Flags, AFS_DIR_ENTRY_VALID);
677 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
678 AFS_TRACE_LEVEL_VERBOSE,
679 "AFSVerifyDirectoryContent Verified entry %wZ for parent FID %08lX-%08lX-%08lX-%08lX\n",
681 ObjectInfoCB->FileId.Cell,
682 ObjectInfoCB->FileId.Volume,
683 ObjectInfoCB->FileId.Vnode,
684 ObjectInfoCB->FileId.Unique);
688 // Update the metadata for the entry
691 if( pObjectInfo->DataVersion.QuadPart == 0 ||
692 pObjectInfo->DataVersion.QuadPart != pCurrentDirEntry->DataVersion.QuadPart)
695 AFSUpdateMetaData( pDirNode,
698 if( pObjectInfo->FileType == AFS_FILE_TYPE_DIRECTORY)
701 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
702 AFS_TRACE_LEVEL_VERBOSE,
703 "AFSVerifyDirectoryContent Setting VERIFY on entry %wZ for FID %08lX-%08lX-%08lX-%08lX\n",
705 ObjectInfoCB->FileId.Cell,
706 ObjectInfoCB->FileId.Volume,
707 ObjectInfoCB->FileId.Vnode,
708 ObjectInfoCB->FileId.Unique);
710 SetFlag( pObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY);
711 pObjectInfo->DataVersion.QuadPart = (ULONGLONG)-1;
712 pObjectInfo->Expiration.QuadPart = 0;
720 pCurrentDirEntry = (AFSDirEnumEntry *)((char *)pCurrentDirEntry + ulEntryLength);
722 if( ulResultLen >= ulEntryLength)
724 ulResultLen -= ulEntryLength;
735 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
736 AFS_TRACE_LEVEL_VERBOSE,
737 "AFSVerifyDirectoryContent Processing dir entry %wZ with different FID, same name in parent FID %08lX-%08lX-%08lX-%08lX\n",
738 &pDirNode->NameInformation.FileName,
739 ObjectInfoCB->FileId.Cell,
740 ObjectInfoCB->FileId.Volume,
741 ObjectInfoCB->FileId.Vnode,
742 ObjectInfoCB->FileId.Unique);
745 // Need to tear down this entry and rebuild it below
748 if( pDirNode->OpenReferenceCount == 0)
751 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
752 AFS_TRACE_LEVEL_VERBOSE,
753 "AFSVerifyDirectoryContent Deleting dir entry %wZ from parent FID %08lX-%08lX-%08lX-%08lX\n",
754 &pDirNode->NameInformation.FileName,
755 ObjectInfoCB->FileId.Cell,
756 ObjectInfoCB->FileId.Volume,
757 ObjectInfoCB->FileId.Vnode,
758 ObjectInfoCB->FileId.Unique);
760 AFSDeleteDirEntry( ObjectInfoCB,
766 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
767 AFS_TRACE_LEVEL_VERBOSE,
768 "AFSVerifyDirectoryContent Setting dir entry %p name %wZ DELETED in parent FID %08lX-%08lX-%08lX-%08lX\n",
770 &pDirNode->NameInformation.FileName,
771 ObjectInfoCB->FileId.Cell,
772 ObjectInfoCB->FileId.Volume,
773 ObjectInfoCB->FileId.Vnode,
774 ObjectInfoCB->FileId.Unique);
776 SetFlag( pDirNode->Flags, AFS_DIR_ENTRY_DELETED);
778 AFSRemoveNameEntry( ObjectInfoCB,
783 pDirNode = AFSInitDirEntry( ObjectInfoCB,
787 (ULONG)InterlockedIncrement( &ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.ContentIndex));
789 if( pDirNode == NULL)
792 ntStatus = STATUS_INSUFFICIENT_RESOURCES;
798 // Init the short name if we have one
801 if( pCurrentDirEntry->ShortNameLength > 0)
804 UNICODE_STRING uniShortName;
806 pDirNode->NameInformation.ShortNameLength = pCurrentDirEntry->ShortNameLength;
808 RtlCopyMemory( pDirNode->NameInformation.ShortName,
809 pCurrentDirEntry->ShortName,
810 pDirNode->NameInformation.ShortNameLength);
813 // Generate the short name index
816 uniShortName.Length = pDirNode->NameInformation.ShortNameLength;
817 uniShortName.Buffer = pDirNode->NameInformation.ShortName;
819 pDirNode->Type.Data.ShortNameTreeEntry.HashIndex = AFSGenerateCRC( &uniShortName,
824 // Insert the node into the name tree
827 ASSERT( ExIsResourceAcquiredExclusiveLite( ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.TreeLock));
829 if( ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead == NULL)
832 ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead = pDirNode;
837 AFSInsertCaseSensitiveDirEntry( ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead,
841 if( ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.CaseInsensitiveTreeHead == NULL)
844 ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.CaseInsensitiveTreeHead = pDirNode;
846 SetFlag( pDirNode->Flags, AFS_DIR_ENTRY_CASE_INSENSTIVE_LIST_HEAD);
851 AFSInsertCaseInsensitiveDirEntry( ObjectInfoCB->Specific.Directory.DirectoryNodeHdr.CaseInsensitiveTreeHead,
855 if( ObjectInfoCB->Specific.Directory.DirectoryNodeListHead == NULL)
858 ObjectInfoCB->Specific.Directory.DirectoryNodeListHead = pDirNode;
863 (ObjectInfoCB->Specific.Directory.DirectoryNodeListTail)->ListEntry.fLink = pDirNode;
865 pDirNode->ListEntry.bLink = ObjectInfoCB->Specific.Directory.DirectoryNodeListTail;
868 ObjectInfoCB->Specific.Directory.DirectoryNodeListTail = pDirNode;
870 SetFlag( pDirNode->Flags, AFS_DIR_ENTRY_INSERTED_ENUM_LIST);
872 InterlockedIncrement( &ObjectInfoCB->Specific.Directory.DirectoryNodeCount);
874 AFSDbgLogMsg( AFS_SUBSYSTEM_DIR_NODE_COUNT,
875 AFS_TRACE_LEVEL_VERBOSE,
876 "AFSVerifyDirectoryContent Adding entry %wZ Inc Count %d to parent FID %08lX-%08lX-%08lX-%08lX\n",
877 &pDirNode->NameInformation.FileName,
878 ObjectInfoCB->Specific.Directory.DirectoryNodeCount,
879 ObjectInfoCB->FileId.Cell,
880 ObjectInfoCB->FileId.Volume,
881 ObjectInfoCB->FileId.Vnode,
882 ObjectInfoCB->FileId.Unique);
884 if( pDirNode->Type.Data.ShortNameTreeEntry.HashIndex != 0)
888 // Insert the short name entry if we have a valid short name
891 if( ObjectInfoCB->Specific.Directory.ShortNameTree == NULL)
894 ObjectInfoCB->Specific.Directory.ShortNameTree = pDirNode;
899 AFSInsertShortNameDirEntry( ObjectInfoCB->Specific.Directory.ShortNameTree,
908 pCurrentDirEntry = (AFSDirEnumEntry *)((char *)pCurrentDirEntry + ulEntryLength);
910 if( ulResultLen >= ulEntryLength)
912 ulResultLen -= ulEntryLength;
920 ulResultLen = AFS_DIR_ENUM_BUFFER_LEN;
923 // Reset the information in the request buffer since it got trampled
927 pDirQueryCB->EnumHandle = pDirEnumResponse->EnumHandle;
930 // If the enumeration handle is -1 then we are done
933 if( ((ULONG)-1) == pDirQueryCB->EnumHandle )
949 AFSExFreePool( pBuffer);
957 AFSNotifyFileCreate( IN GUID *AuthGroup,
958 IN AFSObjectInfoCB *ParentObjectInfo,
959 IN PLARGE_INTEGER FileSize,
960 IN ULONG FileAttributes,
961 IN UNICODE_STRING *FileName,
962 OUT AFSDirectoryCB **DirNode)
965 NTSTATUS ntStatus = STATUS_SUCCESS;
966 AFSFileCreateCB stCreateCB;
967 AFSFileCreateResultCB *pResultCB = NULL;
968 ULONG ulResultLen = 0;
969 UNICODE_STRING uniTargetName;
970 AFSDirectoryCB *pDirNode = NULL;
972 LARGE_INTEGER liOldDataVersion;
978 // Init the control block for the request
981 RtlZeroMemory( &stCreateCB,
982 sizeof( AFSFileCreateCB));
984 stCreateCB.ParentId = ParentObjectInfo->FileId;
986 stCreateCB.AllocationSize = *FileSize;
988 stCreateCB.FileAttributes = FileAttributes;
990 stCreateCB.EaSize = 0;
992 liOldDataVersion = ParentObjectInfo->DataVersion;
995 // Allocate our return buffer
998 pResultCB = (AFSFileCreateResultCB *)AFSExAllocatePoolWithTag( PagedPool,
1000 AFS_GENERIC_MEMORY_1_TAG);
1002 if( pResultCB == NULL)
1005 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1008 RtlZeroMemory( pResultCB,
1011 ulResultLen = PAGE_SIZE;
1014 // Send the call to the service
1017 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_CREATE_FILE,
1018 AFS_REQUEST_FLAG_SYNCHRONOUS | AFS_REQUEST_FLAG_HOLD_FID,
1023 sizeof( AFSFileCreateCB),
1027 if( ntStatus != STATUS_SUCCESS)
1030 if( NT_SUCCESS( ntStatus))
1033 ntStatus = STATUS_DEVICE_NOT_READY;
1036 try_return( ntStatus);
1040 // We may have raced with an invalidation call and a subsequent re-enumeration of this parent
1041 // and though we created the node, it is already in our list. If this is the case then
1042 // look up the entry rather than create a new entry
1043 // The check is to ensure the DV has been modified
1046 if( liOldDataVersion.QuadPart != pResultCB->ParentDataVersion.QuadPart - 1 ||
1047 liOldDataVersion.QuadPart != ParentObjectInfo->DataVersion.QuadPart)
1050 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1051 AFS_TRACE_LEVEL_VERBOSE,
1052 "AFSNotifyFileCreate Raced with an invalidate call and a re-enumeration for entry %wZ\n",
1056 // We raced so go and lookup the directory entry in the parent
1059 ulCRC = AFSGenerateCRC( FileName,
1062 AFSAcquireShared( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock,
1065 AFSLocateCaseSensitiveDirEntry( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.CaseSensitiveTreeHead,
1069 AFSReleaseResource( ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.TreeLock);
1071 if( pDirNode != NULL)
1074 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1075 AFS_TRACE_LEVEL_VERBOSE,
1076 "AFSNotifyFileCreate Located dir entry for file %wZ\n",
1079 *DirNode = pDirNode;
1081 try_return( ntStatus = STATUS_REPARSE);
1085 // We are unsure of our current data so set the verify flag. It may already be set
1086 // but no big deal to reset it
1089 SetFlag( ParentObjectInfo->Flags, AFS_OBJECT_FLAGS_VERIFY);
1091 ParentObjectInfo->DataVersion.QuadPart = (ULONGLONG)-1;
1097 // Update the parent data version
1100 ParentObjectInfo->DataVersion = pResultCB->ParentDataVersion;
1103 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1104 AFS_TRACE_LEVEL_VERBOSE,
1105 "AFSNotifyFileCreate Creating new entry %wZ\n",
1109 // Initialize the directory entry
1112 uniTargetName.Length = (USHORT)pResultCB->DirEnum.TargetNameLength;
1114 uniTargetName.MaximumLength = uniTargetName.Length;
1116 uniTargetName.Buffer = (WCHAR *)((char *)&pResultCB->DirEnum + pResultCB->DirEnum.TargetNameOffset);
1118 pDirNode = AFSInitDirEntry( ParentObjectInfo,
1121 &pResultCB->DirEnum,
1122 (ULONG)InterlockedIncrement( &ParentObjectInfo->Specific.Directory.DirectoryNodeHdr.ContentIndex));
1124 if( pDirNode == NULL)
1127 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1131 // Init the short name if we have one
1134 if( pResultCB->DirEnum.ShortNameLength > 0)
1137 UNICODE_STRING uniShortName;
1139 pDirNode->NameInformation.ShortNameLength = pResultCB->DirEnum.ShortNameLength;
1141 RtlCopyMemory( pDirNode->NameInformation.ShortName,
1142 pResultCB->DirEnum.ShortName,
1143 pDirNode->NameInformation.ShortNameLength);
1146 // Generate the short name index
1149 uniShortName.Length = pDirNode->NameInformation.ShortNameLength;
1150 uniShortName.Buffer = pDirNode->NameInformation.ShortName;
1152 pDirNode->Type.Data.ShortNameTreeEntry.HashIndex = AFSGenerateCRC( &uniShortName,
1157 // Return the directory node
1160 *DirNode = pDirNode;
1164 if( pResultCB != NULL)
1167 AFSExFreePool( pResultCB);
1170 if( !NT_SUCCESS( ntStatus))
1180 AFSUpdateFileInformation( IN AFSFileID *ParentFid,
1181 IN AFSObjectInfoCB *ObjectInfo,
1185 NTSTATUS ntStatus = STATUS_SUCCESS;
1186 AFSDeviceExt *pDeviceExt = (AFSDeviceExt *)AFSRDRDeviceObject->DeviceExtension;
1187 AFSFileUpdateCB stUpdateCB;
1188 ULONG ulResultLen = 0;
1189 AFSFileUpdateResultCB *pUpdateResultCB = NULL;
1195 // Init the control block for the request
1198 RtlZeroMemory( &stUpdateCB,
1199 sizeof( AFSFileUpdateCB));
1201 stUpdateCB.AllocationSize = ObjectInfo->EndOfFile;
1203 stUpdateCB.FileAttributes = ObjectInfo->FileAttributes;
1205 stUpdateCB.EaSize = ObjectInfo->EaSize;
1207 stUpdateCB.ParentId = *ParentFid;
1209 stUpdateCB.LastAccessTime = ObjectInfo->LastAccessTime;
1211 stUpdateCB.CreateTime = ObjectInfo->CreationTime;
1213 stUpdateCB.ChangeTime = ObjectInfo->ChangeTime;
1215 stUpdateCB.LastWriteTime = ObjectInfo->LastWriteTime;
1217 pUpdateResultCB = (AFSFileUpdateResultCB *)AFSExAllocatePoolWithTag( PagedPool,
1219 AFS_UPDATE_RESULT_TAG);
1221 if( pUpdateResultCB == NULL)
1224 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1227 ulResultLen = PAGE_SIZE;
1229 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_UPDATE_FILE,
1230 AFS_REQUEST_FLAG_SYNCHRONOUS,
1233 &ObjectInfo->FileId,
1235 sizeof( AFSFileUpdateCB),
1239 if( ntStatus != STATUS_SUCCESS)
1242 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1243 AFS_TRACE_LEVEL_ERROR,
1244 "AFSUpdateFileInformation failed FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
1245 ObjectInfo->FileId.Cell,
1246 ObjectInfo->FileId.Volume,
1247 ObjectInfo->FileId.Vnode,
1248 ObjectInfo->FileId.Unique,
1251 try_return( ntStatus);
1255 // Update the data version
1258 ObjectInfo->DataVersion = pUpdateResultCB->DirEnum.DataVersion;
1262 if( pUpdateResultCB != NULL)
1265 AFSExFreePool( pUpdateResultCB);
1273 AFSNotifyDelete( IN AFSDirectoryCB *DirectoryCB,
1274 IN BOOLEAN CheckOnly)
1276 NTSTATUS ntStatus = STATUS_SUCCESS;
1277 ULONG ulResultLen = 0;
1278 AFSFileDeleteCB stDelete;
1279 AFSFileDeleteResultCB stDeleteResult;
1280 ULONG ulRequestFlags = AFS_REQUEST_FLAG_SYNCHRONOUS;
1281 GUID *pAuthGroup = NULL;
1286 stDelete.ParentId = DirectoryCB->ObjectInformation->ParentObjectInformation->FileId;
1288 stDelete.ProcessId = (ULONGLONG)PsGetCurrentProcessId();
1290 ulResultLen = sizeof( AFSFileDeleteResultCB);
1294 ulRequestFlags |= AFS_REQUEST_FLAG_CHECK_ONLY;
1297 if( DirectoryCB->ObjectInformation->Fcb != NULL)
1299 pAuthGroup = &DirectoryCB->ObjectInformation->Fcb->AuthGroup;
1302 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_DELETE_FILE,
1305 &DirectoryCB->NameInformation.FileName,
1306 &DirectoryCB->ObjectInformation->FileId,
1308 sizeof( AFSFileDeleteCB),
1312 if( ntStatus != STATUS_SUCCESS)
1315 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1316 AFS_TRACE_LEVEL_ERROR,
1317 "AFSNotifyDelete failed FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
1318 &DirectoryCB->ObjectInformation->FileId.Cell,
1319 &DirectoryCB->ObjectInformation->FileId.Volume,
1320 &DirectoryCB->ObjectInformation->FileId.Vnode,
1321 &DirectoryCB->ObjectInformation->FileId.Unique,
1324 try_return( ntStatus);
1331 // Update the parent data version
1334 if( DirectoryCB->ObjectInformation->ParentObjectInformation->DataVersion.QuadPart != stDeleteResult.ParentDataVersion.QuadPart)
1337 DirectoryCB->ObjectInformation->ParentObjectInformation->Flags |= AFS_OBJECT_FLAGS_VERIFY;
1339 DirectoryCB->ObjectInformation->ParentObjectInformation->DataVersion.QuadPart = (ULONGLONG)-1;
1352 AFSNotifyRename( IN AFSObjectInfoCB *ObjectInfo,
1353 IN AFSObjectInfoCB *ParentObjectInfo,
1354 IN AFSObjectInfoCB *TargetParentObjectInfo,
1355 IN AFSDirectoryCB *DirectoryCB,
1356 IN UNICODE_STRING *TargetName,
1357 OUT AFSFileID *UpdatedFID)
1360 NTSTATUS ntStatus = STATUS_SUCCESS;
1361 AFSFileRenameCB *pRenameCB = NULL;
1362 AFSFileRenameResultCB *pRenameResultCB = NULL;
1363 ULONG ulResultLen = 0;
1364 GUID *pAuthGroup = NULL;
1370 // Init the control block for the request
1373 pRenameCB = (AFSFileRenameCB *)AFSExAllocatePoolWithTag( PagedPool,
1375 AFS_RENAME_REQUEST_TAG);
1377 if( pRenameCB == NULL)
1380 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1383 RtlZeroMemory( pRenameCB,
1386 pRenameCB->SourceParentId = ParentObjectInfo->FileId;
1388 pRenameCB->TargetParentId = TargetParentObjectInfo->FileId;
1390 pRenameCB->TargetNameLength = TargetName->Length;
1392 RtlCopyMemory( pRenameCB->TargetName,
1394 TargetName->Length);
1396 if( ObjectInfo->Fcb != NULL)
1398 pAuthGroup = &ObjectInfo->Fcb->AuthGroup;
1402 // Use the same buffer for the result control block
1405 pRenameResultCB = (AFSFileRenameResultCB *)pRenameCB;
1407 ulResultLen = PAGE_SIZE;
1409 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_RENAME_FILE,
1410 AFS_REQUEST_FLAG_SYNCHRONOUS,
1412 &DirectoryCB->NameInformation.FileName,
1413 &ObjectInfo->FileId,
1415 sizeof( AFSFileRenameCB) + TargetName->Length,
1419 if( ntStatus != STATUS_SUCCESS)
1422 AFSDbgLogMsg( AFS_SUBSYSTEM_FILE_PROCESSING,
1423 AFS_TRACE_LEVEL_ERROR,
1424 "AFSNotifyRename failed FID %08lX-%08lX-%08lX-%08lX Status %08lX\n",
1425 ObjectInfo->FileId.Cell,
1426 ObjectInfo->FileId.Volume,
1427 ObjectInfo->FileId.Vnode,
1428 ObjectInfo->FileId.Unique,
1431 try_return( ntStatus);
1435 // Update the information from the returned data
1438 ParentObjectInfo->DataVersion = pRenameResultCB->SourceParentDataVersion;
1440 TargetParentObjectInfo->DataVersion = pRenameResultCB->TargetParentDataVersion;
1443 // Move over the short name
1446 DirectoryCB->NameInformation.ShortNameLength = pRenameResultCB->DirEnum.ShortNameLength;
1448 if( DirectoryCB->NameInformation.ShortNameLength > 0)
1451 RtlCopyMemory( DirectoryCB->NameInformation.ShortName,
1452 pRenameResultCB->DirEnum.ShortName,
1453 DirectoryCB->NameInformation.ShortNameLength);
1456 if( UpdatedFID != NULL)
1459 *UpdatedFID = pRenameResultCB->DirEnum.FileId;
1464 if( pRenameCB != NULL)
1467 AFSExFreePool( pRenameCB);
1475 AFSEvaluateTargetByID( IN AFSObjectInfoCB *ObjectInfo,
1477 IN BOOLEAN FastCall,
1478 OUT AFSDirEnumEntry **DirEnumEntry)
1481 NTSTATUS ntStatus = STATUS_SUCCESS;
1482 AFSEvalTargetCB stTargetID;
1483 ULONG ulResultBufferLength;
1484 AFSDirEnumEntry *pDirEnumCB = NULL;
1485 ULONG ulRequestFlags = AFS_REQUEST_FLAG_SYNCHRONOUS;
1490 RtlZeroMemory( &stTargetID,
1491 sizeof( AFSEvalTargetCB));
1493 if( ObjectInfo->ParentObjectInformation != NULL)
1496 stTargetID.ParentId = ObjectInfo->ParentObjectInformation->FileId;
1500 // Allocate our response buffer
1503 pDirEnumCB = (AFSDirEnumEntry *)AFSExAllocatePoolWithTag( PagedPool,
1505 AFS_GENERIC_MEMORY_2_TAG);
1507 if( pDirEnumCB == NULL)
1510 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1514 // Call to the service to evaluate the fid
1517 ulResultBufferLength = PAGE_SIZE;
1522 ulRequestFlags |= AFS_REQUEST_FLAG_FAST_REQUEST;
1525 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_EVAL_TARGET_BY_ID,
1529 &ObjectInfo->FileId,
1531 sizeof( AFSEvalTargetCB),
1533 &ulResultBufferLength);
1535 if( ntStatus != STATUS_SUCCESS)
1539 // If we received back a STATUS_INVALID_HANDLE then mark the parent as requiring
1543 if( ntStatus == STATUS_INVALID_HANDLE)
1546 if( ObjectInfo->ParentObjectInformation != NULL)
1549 SetFlag( ObjectInfo->ParentObjectInformation->Flags, AFS_OBJECT_FLAGS_VERIFY);
1553 try_return( ntStatus);
1557 // Pass back the dir enum entry
1560 if( DirEnumEntry != NULL)
1563 *DirEnumEntry = pDirEnumCB;
1568 AFSExFreePool( pDirEnumCB);
1573 if( !NT_SUCCESS( ntStatus))
1576 if( pDirEnumCB != NULL)
1579 AFSExFreePool( pDirEnumCB);
1582 *DirEnumEntry = NULL;
1590 AFSEvaluateTargetByName( IN GUID *AuthGroup,
1591 IN AFSFileID *ParentFileId,
1592 IN PUNICODE_STRING SourceName,
1593 OUT AFSDirEnumEntry **DirEnumEntry)
1596 NTSTATUS ntStatus = STATUS_SUCCESS;
1597 AFSEvalTargetCB stTargetID;
1598 ULONG ulResultBufferLength;
1599 AFSDirEnumEntry *pDirEnumCB = NULL;
1604 stTargetID.ParentId = *ParentFileId;
1607 // Allocate our response buffer
1610 pDirEnumCB = (AFSDirEnumEntry *)AFSExAllocatePoolWithTag( PagedPool,
1612 AFS_GENERIC_MEMORY_3_TAG);
1614 if( pDirEnumCB == NULL)
1617 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1621 // Call to the service to evaluate the fid
1624 ulResultBufferLength = PAGE_SIZE;
1626 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_EVAL_TARGET_BY_NAME,
1627 AFS_REQUEST_FLAG_SYNCHRONOUS,
1632 sizeof( AFSEvalTargetCB),
1634 &ulResultBufferLength);
1636 if( ntStatus != STATUS_SUCCESS)
1639 try_return( ntStatus);
1643 // Pass back the dir enum entry
1646 *DirEnumEntry = pDirEnumCB;
1650 if( !NT_SUCCESS( ntStatus))
1653 if( pDirEnumCB != NULL)
1656 AFSExFreePool( pDirEnumCB);
1659 *DirEnumEntry = NULL;
1667 AFSRetrieveVolumeInformation( IN GUID *AuthGroup,
1668 IN AFSFileID *FileID,
1669 OUT AFSVolumeInfoCB *VolumeInformation)
1672 NTSTATUS ntStatus = STATUS_SUCCESS;
1673 ULONG ulResultLen = 0;
1678 ulResultLen = sizeof( AFSVolumeInfoCB);
1680 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_GET_VOLUME_INFO,
1681 AFS_REQUEST_FLAG_SYNCHRONOUS,
1690 if( ntStatus != STATUS_SUCCESS)
1693 try_return( ntStatus);
1705 AFSNotifyPipeTransceive( IN AFSCcb *Ccb,
1706 IN ULONG InputLength,
1707 IN ULONG OutputLength,
1708 IN void *InputDataBuffer,
1709 OUT void *OutputDataBuffer,
1710 OUT ULONG *BytesReturned)
1713 NTSTATUS ntStatus = STATUS_SUCCESS;
1714 ULONG ulResultLen = 0;
1715 MDL *pInputMdl = NULL, *pOutputMdl = NULL;
1716 void *pInputSystemBuffer = NULL, *pOutputSystemBuffer = NULL;
1717 ULONG ulBufferLength = OutputLength;
1718 AFSPipeIORequestCB *pIoRequest = NULL;
1719 GUID *pAuthGroup = NULL;
1725 // Map the user buffer to a system address
1728 pInputSystemBuffer = AFSLockUserBuffer( InputDataBuffer,
1732 if( pInputSystemBuffer == NULL)
1735 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1738 pIoRequest = (AFSPipeIORequestCB *)AFSExAllocatePoolWithTag( PagedPool,
1739 sizeof( AFSPipeIORequestCB) +
1741 AFS_GENERIC_MEMORY_4_TAG);
1743 if( pIoRequest == NULL)
1746 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1749 RtlZeroMemory( pIoRequest,
1750 sizeof( AFSPipeIORequestCB) + InputLength);
1752 pIoRequest->RequestId = Ccb->RequestID;
1754 pIoRequest->RootId = Ccb->DirectoryCB->ObjectInformation->VolumeCB->ObjectInformation.FileId;
1756 pIoRequest->BufferLength = InputLength;
1758 RtlCopyMemory( (void *)((char *)pIoRequest + sizeof( AFSPipeIORequestCB)),
1762 pOutputSystemBuffer = AFSLockUserBuffer( OutputDataBuffer,
1766 if( pOutputSystemBuffer == NULL)
1769 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1772 if( Ccb->DirectoryCB->ObjectInformation->Fcb != NULL)
1774 pAuthGroup = &Ccb->DirectoryCB->ObjectInformation->Fcb->AuthGroup;
1778 // Send the call to the service
1781 ulResultLen = OutputLength;
1783 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_PIPE_TRANSCEIVE,
1784 AFS_REQUEST_FLAG_SYNCHRONOUS,
1786 &Ccb->DirectoryCB->NameInformation.FileName,
1789 sizeof( AFSPipeIORequestCB) + InputLength,
1790 pOutputSystemBuffer,
1793 if( ntStatus != STATUS_SUCCESS &&
1794 ntStatus != STATUS_BUFFER_OVERFLOW)
1797 if( NT_SUCCESS( ntStatus))
1800 ntStatus = STATUS_DEVICE_NOT_READY;
1803 try_return( ntStatus);
1807 // Return the bytes processed
1810 *BytesReturned = ulResultLen;
1814 if( pInputMdl != NULL)
1817 MmUnlockPages( pInputMdl);
1819 IoFreeMdl( pInputMdl);
1822 if( pOutputMdl != NULL)
1825 MmUnlockPages( pOutputMdl);
1827 IoFreeMdl( pOutputMdl);
1830 if( pIoRequest != NULL)
1833 AFSExFreePool( pIoRequest);
1841 AFSNotifySetPipeInfo( IN AFSCcb *Ccb,
1842 IN ULONG InformationClass,
1843 IN ULONG InputLength,
1844 IN void *DataBuffer)
1847 NTSTATUS ntStatus = STATUS_SUCCESS;
1848 AFSPipeInfoRequestCB *pInfoRequest = NULL;
1849 GUID *pAuthGroup = NULL;
1854 pInfoRequest = (AFSPipeInfoRequestCB *)AFSExAllocatePoolWithTag( PagedPool,
1855 sizeof( AFSPipeInfoRequestCB) +
1857 AFS_GENERIC_MEMORY_5_TAG);
1859 if( pInfoRequest == NULL)
1862 try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES);
1865 RtlZeroMemory( pInfoRequest,
1866 sizeof( AFSPipeInfoRequestCB) + InputLength);
1868 pInfoRequest->RequestId = Ccb->RequestID;
1870 pInfoRequest->RootId = Ccb->DirectoryCB->ObjectInformation->VolumeCB->ObjectInformation.FileId;
1872 pInfoRequest->BufferLength = InputLength;
1874 pInfoRequest->InformationClass = InformationClass;
1876 RtlCopyMemory( (void *)((char *)pInfoRequest + sizeof( AFSPipeInfoRequestCB)),
1880 if( Ccb->DirectoryCB->ObjectInformation->Fcb != NULL)
1882 pAuthGroup = &Ccb->DirectoryCB->ObjectInformation->Fcb->AuthGroup;
1886 // Send the call to the service
1889 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_PIPE_SET_INFO,
1890 AFS_REQUEST_FLAG_SYNCHRONOUS,
1892 &Ccb->DirectoryCB->NameInformation.FileName,
1895 sizeof( AFSPipeInfoRequestCB) + InputLength,
1899 if( ntStatus != STATUS_SUCCESS)
1902 if( NT_SUCCESS( ntStatus))
1905 ntStatus = STATUS_DEVICE_NOT_READY;
1908 try_return( ntStatus);
1913 if( pInfoRequest != NULL)
1916 AFSExFreePool( pInfoRequest);
1924 AFSNotifyQueryPipeInfo( IN AFSCcb *Ccb,
1925 IN ULONG InformationClass,
1926 IN ULONG OutputLength,
1927 IN void *DataBuffer,
1928 OUT ULONG *BytesReturned)
1931 NTSTATUS ntStatus = STATUS_SUCCESS;
1932 AFSPipeInfoRequestCB stInfoRequest;
1933 ULONG ulBytesProcessed = 0;
1934 GUID *pAuthGroup = NULL;
1939 RtlZeroMemory( &stInfoRequest,
1940 sizeof( AFSPipeInfoRequestCB));
1942 stInfoRequest.RequestId = Ccb->RequestID;
1944 stInfoRequest.RootId = Ccb->DirectoryCB->ObjectInformation->VolumeCB->ObjectInformation.FileId;
1946 stInfoRequest.BufferLength = OutputLength;
1948 stInfoRequest.InformationClass = InformationClass;
1950 ulBytesProcessed = OutputLength;
1952 if( Ccb->DirectoryCB->ObjectInformation->Fcb != NULL)
1954 pAuthGroup = &Ccb->DirectoryCB->ObjectInformation->Fcb->AuthGroup;
1958 // Send the call to the service
1961 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_PIPE_QUERY_INFO,
1962 AFS_REQUEST_FLAG_SYNCHRONOUS,
1964 &Ccb->DirectoryCB->NameInformation.FileName,
1967 sizeof( AFSPipeInfoRequestCB),
1971 if( ntStatus != STATUS_SUCCESS)
1974 if( NT_SUCCESS( ntStatus))
1977 ntStatus = STATUS_DEVICE_NOT_READY;
1980 try_return( ntStatus);
1983 *BytesReturned = ulBytesProcessed;
1994 AFSReleaseFid( IN AFSFileID *FileId)
1997 NTSTATUS ntStatus = STATUS_SUCCESS;
2002 ntStatus = AFSProcessRequest( AFS_REQUEST_TYPE_RELEASE_FID,
2017 AFSIsExtentRequestQueued( IN AFSFileID *FileID,
2018 IN LARGE_INTEGER *ExtentOffset,
2022 BOOLEAN bRequestQueued = FALSE;
2023 NTSTATUS ntStatus = STATUS_SUCCESS;
2024 AFSDeviceExt *pControlDevExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
2025 AFSCommSrvcCB *pCommSrvc = NULL;
2026 AFSPoolEntry *pPoolEntry = NULL;
2027 AFSRequestExtentsCB *pRequestExtents = NULL;
2033 pCommSrvc = &pControlDevExt->Specific.Control.CommServiceCB;
2035 AFSAcquireShared( &pCommSrvc->IrpPoolLock,
2038 pPoolEntry = pCommSrvc->RequestPoolHead;
2040 while( pPoolEntry != NULL)
2043 if( pPoolEntry->RequestType == AFS_REQUEST_TYPE_REQUEST_FILE_EXTENTS)
2046 if( AFSIsEqualFID( &pPoolEntry->FileId, FileID))
2049 pRequestExtents = (AFSRequestExtentsCB *)pPoolEntry->Data;
2051 if( pRequestExtents->ByteOffset.QuadPart == ExtentOffset->QuadPart &&
2052 pRequestExtents->Length == Length)
2055 bRequestQueued = TRUE;
2060 pPoolEntry = pPoolEntry->fLink;
2063 AFSReleaseResource( &pCommSrvc->IrpPoolLock);
2066 return bRequestQueued;