Oh, now I see your point, sorry about the confusion.
In this case let me clarify my previous statement: the rule i’ve been using is that if during pre IRP_MJ_CREATE for FileObject the FileObject->RelatedFileObject field is not NULL then actual path of the file is made up from the name of FileObject->RelatedFileObject + FileObject->FileName, the difference being that the name of FileObject->RelatedFileObject is not guaranteed to be the same as FileObject->RelatedFileObject->FileName.
Since FileObject->RelatedFileObject is an opened FILE_OBJECT one should call FltGetFileNameInformation() to get its name. The reason it works to call FltGetFileNameInformation() is because the cases where FltGetFileNameInformation() doesn’t work don’t really apply here (we’re in preCreate so TopLevelIrp isn’t set; we’re clearly not in the paging path and the RelatedFileObject is opened because the caller has a handle to it - the RelatedFileObject is passed as a handle to IoCreateFile via OBJECT_ATTRIBUTES). So one shouldn’t blindly call RtlUnicodeStringCat() with RelatedFileObject->FilenName and FileObject->FileName.
Another thing to note is that, as far I remember, FileObject->RelatedFileObject is undefined during any other operation (except IRP_MJ_NETWORK_QUERY_OPEN which actually has an IRP_MJ_CREATE parameter so it falls under the same rules).
In general one should really leave it to FltGetFileNameInformation() to handle all these details, I certainly prefer using it.
Thanks,
Alex.
On May 23, 2013, at 7:43 AM, Peter Scott wrote:
>
> It is not guaranteed to be valid and should not be relied upon.
>
> Pete
>
> On 5/23/2013 8:31 AM, Sergey Pisarev wrote:
>> this is pre_create for file_object and not for
>> file_object->RelatedFileObject.
>>
>> why RelatedFileObject->FileName must be valid during pre-create of
>> file_object ?
>>
>> On Thu, May 23, 2013 at 6:14 PM, Alex Carp >> mailto:xxxxx> wrote:
>>
>> The OP mentioned he’s doing this at PreCreate(), so he should be
>> fine. Also, no reason to call the Unsafe version of the function,
>> FltGetFileNameInformation() should work just fine.
>>
>> Thanks,
>> Alex.
>>
>> On May 23, 2013, at 3:56 AM, Sergey Pisarev
>> > wrote:
>>
>>> you can’t use RelatedFileObject->FileName since this is not a
>>> create operation for RelatedFileObject
>>>
>>> use FltGetFileNameInformationUnsafe or store name in stream context
>>>
>>>
>>> On Thu, May 23, 2013 at 1:14 PM, >>> mailto:xxxxx> wrote:
>>>
>>> Thanks a million, it is the exact directory name stored in:
>>>
>>> FltObjects->FileObject->RelatedFileObject->FileName
>>>
>>> Now, it is working much effectively.
>>>
>>> —
>>> NTFSD is sponsored by OSR
>>>
>>> OSR is hiring!! Info at http://www.osr.com/careers
>>>
>>> For our schedule of debugging and file system seminars visit:
>>> http://www.osr.com/seminars
>>>
>>> To unsubscribe, visit the List Server section of OSR Online at
>>> http://www.osronline.com/page.cfm?name=ListServer
>>>
>>>
>>> — NTFSD is sponsored by OSR OSR is hiring!! Info at
>>> http://www.osr.com/careers For our schedule of debugging and file
>>> system seminars visit: http://www.osr.com/seminars To unsubscribe,
>>> visit the List Server section of OSR Online at
>>> http://www.osronline.com/page.cfm?name=ListServer
>>
>>
>> —
>> NTFSD is sponsored by OSR
>>
>> OSR is hiring!! Info at http://www.osr.com/careers
>>
>> For our schedule of debugging and file system seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>>
>> — NTFSD is sponsored by OSR OSR is hiring!! Info at
>> http://www.osr.com/careers For our schedule of debugging and file system
>> seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
>> List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>
> –
> Kernel Drivers
> Windows File System and Device Driver Consulting
> www.KernelDrivers.com
> 866.263.9295
>
> —
> NTFSD is sponsored by OSR
>
> OSR is hiring!! Info at http://www.osr.com/careers
>
> For our schedule of debugging and file system seminars visit: http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>