阅读:2840回复:1
NLGetFullPathName获取cmd.exe创建文件路径的问题
我主要想在IRP_MJ_CREATE完成之前得到全路径,用NLGetFullPathName这个函数可以,但是用cmd.exe创建文件或目录的时候,NLGetFullPathName返回STATUS_UNSUCCESSFUL,跟了下是RelatedFileObject不为空的情况,实际上它取到了文件路径,但是要返回STATUS_UNSUCCESSFUL,求解释~~~
下面是NLGetFullPathName处理含RelatedFileObjec的部分代码,最后它说: // // Continue on to the end of the routine and return // STATUS_UNSUCCESSFUL since we are not able to return a "usable" // file name (caller cannot use the file name we return in other // calls because it is not "valid"). // returnValue = STATUS_UNSUCCESSFUL; 什么意思啊? // // CASE 3: We are opening a file that has a RelatedFileObject. // else if (FlagOn( LookupFlags, NLFL_IN_CREATE ) && (NULL != FileObject->RelatedFileObject)) { // // Must be a relative open. We cannot use ObQueryNameString to get // the name of the RelatedFileObject because it may result in // deadlock. // PNAME_CONTROL relativeName; ULONG returnLength; status = NLAllocateNameControl( &relativeName, LookasideList ); if (!NT_SUCCESS( status )) { goto NoResources; } status = NLPQueryFileSystemForFileName( FileObject->RelatedFileObject, NLExtHeader->AttachedToDeviceObject, relativeName ); if (NT_SUCCESS( status )) { // // We were able to get the relative FileoBject's name. // Build up the file name in the following format: // [volumeName]\[relativeFileObjectName]\[FileObjectName] // The VolumeName is already in FileNameControl if we've got one. // status = NLCheckAndGrowNameControl( FileNameControl, FileNameControl->Name.Length + relativeName->Name.Length ); if (!NT_SUCCESS( status )) { goto NoResources; } RtlAppendUnicodeStringToString( &FileNameControl->Name, &relativeName->Name ); } else { // // The query for the relative FileObject name was // unsuccessful. Build up the file name in the following format: // [volumeName]\...\[FileObjectName] // The volumeName is already in FileNameControl if we've got one. # define RFOPlaceholder L"...\\" status = NLCheckAndGrowNameControl( FileNameControl, FileNameControl->Name.Length + sizeof( RFOPlaceholder ) ); if (!NT_SUCCESS( status )) { goto NoResources; } RtlAppendUnicodeToString( &FileNameControl->Name, RFOPlaceholder ); cacheName = FALSE; } // // If there is not a slash and the end of the related file object // string and there is not a slash at the front of the file object // string, then add one. // if (((FileNameControl->Name.Length < sizeof(WCHAR) || (FileNameControl->Name.Buffer[(FileNameControl->Name.Length/sizeof(WCHAR))-1] != L'\\'))) && ((FileObject->FileName.Length < sizeof(WCHAR)) || (FileObject->FileName.Buffer[0] != L'\\'))) { status = NLCheckAndGrowNameControl( FileNameControl, FileNameControl->Name.Length + sizeof(WCHAR) ); if (!NT_SUCCESS( status )) { goto NoResources; } RtlAppendUnicodeToString( &FileNameControl->Name, L"\\" ); } NLFreeNameControl( relativeName, LookasideList ); // // At this time, copy over the FileObject->FileName to FileNameControl. // status = NLCheckAndGrowNameControl( FileNameControl, FileNameControl->Name.Length + FileObject->FileName.Length ); if (!NT_SUCCESS( status )) { goto NoResources; } RtlAppendUnicodeStringToString( &FileNameControl->Name, &FileObject->FileName ); // // Continue on to the end of the routine and return // STATUS_UNSUCCESSFUL since we are not able to return a "usable" // file name (caller cannot use the file name we return in other // calls because it is not "valid"). // returnValue = STATUS_UNSUCCESSFUL; } |
|
|
沙发#
发布于:2010-06-05 14:56
你跟一下啥原因嘛.既然可以跟,那就是有原因了.
|
|
|