lynnux
驱动牛犊
驱动牛犊
  • 注册日期2008-02-27
  • 最后登录2016-09-07
  • 粉丝0
  • 关注0
  • 积分4分
  • 威望32点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分0分
  • 社区居民
阅读:2840回复:1

NLGetFullPathName获取cmd.exe创建文件路径的问题

楼主#
更多 发布于:2010-06-05 11:17
我主要想在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;

    }
我心已绝
znsoft
管理员
管理员
  • 注册日期2001-03-23
  • 最后登录2023-10-25
  • 粉丝300
  • 关注6
  • 积分910分
  • 威望14796点
  • 贡献值7点
  • 好评度2410点
  • 原创分5分
  • 专家分100分
  • 社区居民
  • 最爱沙发
  • 社区明星
沙发#
发布于:2010-06-05 14:56
你跟一下啥原因嘛.既然可以跟,那就是有原因了.
http://www.zndev.com 免费源码交换网 ----------------------------- 软件创造价值,驱动提供力量! 淡泊以明志,宁静以致远。 ---------------------------------- 勤用搜索,多查资料,先搜再问。
游客

返回顶部