Best Method to get FullPathName

Hi all,

Which is best method to get full Path Name ? and Which will work always success ?

Constructing the FullPath using FileObjects or Querying the FileSystem for FullPath ?

Regards,
Satish K.S


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Why don’t you use the best of both worlds ?

First try to query the file system for the name, but if this doesn’t
success use the Fileobject (only in the IRP_MJ_CREATE path) to construct
the full file path.

Be aware that Windows NT and Windows 2000 use special “semantics” for
network names.

Bartjan.

At 01:55 PM 4/27/2001 +0530, you wrote:

Which is best method to get full Path Name ? and Which will work always
success ?

Constructing the FullPath using FileObjects or Querying the FileSystem for
FullPath ?

Regards,
Satish K.S


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

I dont why File system will fail to give full path. Any reason behind ?

Regards,
Satish K.S

----- Original Message -----
From: Bartjan Wattel
To: File Systems Developers
Sent: Friday, April 27, 2001 2:07 PM
Subject: [ntfsd] Re: Best Method to get FullPathName

Why don’t you use the best of both worlds ?

First try to query the file system for the name, but if this doesn’t success use the Fileobject (only in the IRP_MJ_CREATE path) to construct the full file path.

Be aware that Windows NT and Windows 2000 use special “semantics” for network names.

Bartjan.


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

I dont why File system will fail to give full path. Any reason behind ?

Regards,
Satish K.S

----- Original Message -----
From: Bartjan Wattel
To: File Systems Developers
Sent: Friday, April 27, 2001 2:07 PM
Subject: [ntfsd] Re: Best Method to get FullPathName

Why don’t you use the best of both worlds ?

First try to query the file system for the name, but if this doesn’t success use the Fileobject (only in the IRP_MJ_CREATE path) to construct the full file path.

Be aware that Windows NT and Windows 2000 use special “semantics” for network names.

Bartjan.


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Try querying the OS for the file name in the IRP_MJ_CREATE path where the
FileObject isn’t really opened yet by the OS… That won’t succeed.

At 06:27 PM 4/27/2001 +0530, you wrote:

I dont why File system will fail to give full path. Any reason behind ?


Bartjan.


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

I will Query the file name After success of Open/Create by Setting I/O Completion routine like SFilter sample. Does this always works ?

Regards,
Satish K.S
----- Original Message -----
From: Bartjan Wattel
To: File Systems Developers
Sent: Friday, April 27, 2001 7:12 PM
Subject: [ntfsd] Re: Best Method to get FullPathName

Try querying the OS for the file name in the IRP_MJ_CREATE path where the FileObject isn’t really opened yet by the OS… That won’t succeed.

At 06:27 PM 4/27/2001 +0530, you wrote:

I dont why File system will fail to give full path. Any reason behind ?


Bartjan. —
You are currently subscribed to ntfsd as: xxxxx@aalayance.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

It should. In that case you can’t even determine the filename from the
FileObject->FileName.Buffer because theoretically this buffer can be
destroyed at the time you are in your completion routine.

There is also an undocumented function ObQueryNameString. I don’t know if
it exist in NT, but it does exist in Win2000 and WinXP. You might consider
using that one.

Maybe there is some info on this API in the archives, I’s not sure.

Bartjan.

At 07:22 PM 4/27/01 +0530, you wrote:

I will Query the file name After success of Open/Create by Setting I/O
Completion routine like SFilter sample. Does this always works ?


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

The file system will fail to give the full path if you are processing an Irp in the create path. You cant ask the file system the name for of a file if it hasn’t even seen the file object yet.

Carl Woodward

---- Original Message -----
From: Satish
To: File Systems Developers
Sent: Friday, April 27, 2001 1:54 PM
Subject: [ntfsd] Re: Best Method to get FullPathName

I dont why File system will fail to give full path. Any reason behind ?

Regards,
Satish K.S

----- Original Message -----
From: Bartjan Wattel
To: File Systems Developers
Sent: Friday, April 27, 2001 2:07 PM
Subject: [ntfsd] Re: Best Method to get FullPathName

Why don’t you use the best of both worlds ?

First try to query the file system for the name, but if this doesn’t success use the Fileobject (only in the IRP_MJ_CREATE path) to construct the full file path.

Be aware that Windows NT and Windows 2000 use special “semantics” for network names.

Bartjan.


You are currently subscribed to ntfsd as: xxxxx@btinternet.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

>There is also an undocumented function ObQueryNameString. I don’t know if
it exist in NT,

but it does exist in Win2000 and WinXP. You might consider using that one.

It exists in NT4 too.

Max


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Here is how I do it:

// SciRtlGetFilename
// - Caller is responsible for freeing the name buffer.
NTSTATUS SciRtlGetFilename
(
PFILE_OBJECT FileObject,
PWCHAR *Filename,
PULONG Length
)
{
NTSTATUS ntStatus;
ULONG length = sizeof (FILE_NAME_INFORMATION) +
(sizeof (WCHAR) * (MAXIMUM_FILENAME_LENGTH -1));
ULONG lengthNeeded;
*Length = 0;
*Filename = ExAllocatePool(NonPagedPool, length);
if (*Filename != NULL)
{
PFILE_NAME_INFORMATION nameInformation =
(PFILE_NAME_INFORMATION)*Filename;
ntStatus = IoQueryFileInformation
(
FileObject,
FileNameInformation,
length,
nameInformation,
&lengthNeeded
);
if (NT_SUCCESS(ntStatus))
{
*Length = nameInformation->FileNameLength;
RtlMoveMemory
(
*Filename,
nameInformation->FileName,
nameInformation->FileNameLength
);
}
else
{
ExFreePool(*Filename);
*Filename = NULL;
}
}
else
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
return ntStatus;
}

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Maxim S. Shatskih
Sent: Sunday, April 29, 2001 6:48 AM
To: File Systems Developers
Subject: [ntfsd] Re: Best Method to get FullPathName

>There is also an undocumented function ObQueryNameString. I don’t know if
it exist in NT,
>but it does exist in Win2000 and WinXP. You might consider using
that one.

It exists in NT4 too.

Max


You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Jamey,

In most cases this mechanism will work. However, if the file is “opened by
ID” and the caller does not have traverse privilege, this call will fail
when made to the NTFS file system. There is essentially no way to guarantee
that you can extract the name of an arbitrary file, unfortunately. Yes,
this technique works MOST of the time, but anyone using this routine needs
to be prepared for it to fail (this code works if there is a failure, but
callers must also be able to handle this problem as well!)

Regards,

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: Jamey Kirby [mailto:xxxxx@storagecraft.com]
Sent: Sunday, April 29, 2001 1:36 PM
To: File Systems Developers
Subject: [ntfsd] Re: Best Method to get FullPathName

Here is how I do it:

// SciRtlGetFilename
// - Caller is responsible for freeing the name buffer.
NTSTATUS SciRtlGetFilename
(
PFILE_OBJECT FileObject,
PWCHAR *Filename,
PULONG Length
)
{
NTSTATUS ntStatus;
ULONG length = sizeof (FILE_NAME_INFORMATION) +
(sizeof (WCHAR) * (MAXIMUM_FILENAME_LENGTH -1));
ULONG lengthNeeded;
*Length = 0;
*Filename = ExAllocatePool(NonPagedPool, length);
if (*Filename != NULL)
{
PFILE_NAME_INFORMATION nameInformation =
(PFILE_NAME_INFORMATION)*Filename;
ntStatus = IoQueryFileInformation
(
FileObject,
FileNameInformation,
length,
nameInformation,
&lengthNeeded
);
if (NT_SUCCESS(ntStatus))
{
*Length = nameInformation->FileNameLength;
RtlMoveMemory
(
*Filename,
nameInformation->FileName,
nameInformation->FileNameLength
);
}
else
{
ExFreePool(*Filename);
*Filename = NULL;
}
}
else
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
return ntStatus;
}

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Maxim S. Shatskih
Sent: Sunday, April 29, 2001 6:48 AM
To: File Systems Developers
Subject: [ntfsd] Re: Best Method to get FullPathName

>There is also an undocumented function ObQueryNameString. I don’t know if
it exist in NT,
>but it does exist in Win2000 and WinXP. You might consider using
that one.

It exists in NT4 too.

Max


You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: xxxxx@osr.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

what about creating own irp and querying file name like filemon does?

-----Original Message-----
From: Tony Mason [mailto:xxxxx@osr.com]
Sent: Monday, April 30, 2001 10:44 AM
To: File Systems Developers
Subject: [ntfsd] Re: Best Method to get FullPathName

Jamey,

In most cases this mechanism will work. However, if the file is “opened by
ID” and the caller does not have traverse privilege, this call will fail
when made to the NTFS file system. There is essentially no way to guarantee
that you can extract the name of an arbitrary file, unfortunately. Yes,
this technique works MOST of the time, but anyone using this routine needs
to be prepared for it to fail (this code works if there is a failure, but
callers must also be able to handle this problem as well!)

Regards,

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: Jamey Kirby [mailto:xxxxx@storagecraft.com]
Sent: Sunday, April 29, 2001 1:36 PM
To: File Systems Developers
Subject: [ntfsd] Re: Best Method to get FullPathName

Here is how I do it:

// SciRtlGetFilename
// - Caller is responsible for freeing the name buffer.
NTSTATUS SciRtlGetFilename
(
PFILE_OBJECT FileObject,
PWCHAR *Filename,
PULONG Length
)
{
NTSTATUS ntStatus;
ULONG length = sizeof (FILE_NAME_INFORMATION) +
(sizeof (WCHAR) * (MAXIMUM_FILENAME_LENGTH -1));
ULONG lengthNeeded;
*Length = 0;
*Filename = ExAllocatePool(NonPagedPool, length);
if (*Filename != NULL)
{
PFILE_NAME_INFORMATION nameInformation =
(PFILE_NAME_INFORMATION)*Filename;
ntStatus = IoQueryFileInformation
(
FileObject,
FileNameInformation,
length,
nameInformation,
&lengthNeeded
);
if (NT_SUCCESS(ntStatus))
{
*Length = nameInformation->FileNameLength;
RtlMoveMemory
(
*Filename,
nameInformation->FileName,
nameInformation->FileNameLength
);
}
else
{
ExFreePool(*Filename);
*Filename = NULL;
}
}
else
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
return ntStatus;
}

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Maxim S. Shatskih
Sent: Sunday, April 29, 2001 6:48 AM
To: File Systems Developers
Subject: [ntfsd] Re: Best Method to get FullPathName

>There is also an undocumented function ObQueryNameString. I don’t know if
it exist in NT,
>but it does exist in Win2000 and WinXP. You might consider using
that one.

It exists in NT4 too.

Max


You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: xxxxx@osr.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: xxxxx@dvdjukebox.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

In SFilter sample they are using FileObject->FileName.Buffer field.

Regards,
Satish K.S

It should. In that case you can’t even determine the filename from the FileObject->FileName.Buffer because theoretically this buffer can be destroyed at the time you are in your completion routine.

There is also an undocumented function ObQueryNameString. I don’t know if it exist in NT, but it does exist in Win2000 and WinXP. You might consider using that one.

Maybe there is some info on this API in the archives, I’s not sure.

Bartjan.

At 07:22 PM 4/27/01 +0530, you wrote:

I will Query the file name After success of Open/Create by Setting I/O Completion routine like SFilter sample. Does this always works ?

You are currently subscribed to ntfsd as: xxxxx@aalayance.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Which doesn’t mean it’s correct-:wink:
Just a note on ObQueryNameString - it returns \Device\harddisk…
format of the filename! Parsing is needed to bring it back to human
readable form.

Regards, Dejan.

Satish wrote:

In SFilter sample they are using FileObject->FileName.Buffer
field. Regards,Satish K.S

It should. In that case you can’t even determine the
filename from the FileObject->FileName.Buffer because
theoretically this buffer can be destroyed at the time you
are in your completion routine.

There is also an undocumented function ObQueryNameString. I
don’t know if it exist in NT, but it does exist in Win2000
and WinXP. You might consider using that one.

Maybe there is some info on this API in the archives, I’s
not sure.

Bartjan.

At 07:22 PM 4/27/01 +0530, you wrote:

> I will Query the file name After success of Open/Create by
> Setting I/O Completion routine like SFilter sample. Does
> this always works ?


You are currently subscribed to ntfsd as:
xxxxx@aalayance.com
To unsubscribe send a blank email to
leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: xxxxx@ptt.yu
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


Kind regards, Dejan M. CEO Alfa Co. www.alfaunits.co.yu and
www.register.co.yu
E-mail : xxxxx@ptt.yu, xxxxx@register.co.yu and
xxxxx@alfaunits.co.yu
ICQ# : 56570367
Professional file&system related components and libraries for Win32
developers.
Alfa File Monitor - #1 file monitoring system for Win32 developers.
Alfa File Protector - #1 file protection and hiding system for Win32
developers.
Alfa Units - #1 file and system handling units for Delphi.


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

This is from SFilter. Does this work alsways … or else we have to handle
any error condition ?

DBGSTATIC
NTSTATUS
SfCreateCompletion(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context
)

/*++

Routine Description:

This function is the create/open completion routine for this filter
file system driver. If debugging is enabled, then this function prints
the name of the file that was successfully opened/created by the file
system as a result of the specified I/O request.

Arguments:

DeviceObject - Pointer to the device on which the file was created.

Irp - Pointer to the I/O Request Packet the represents the operation.

Context - This driver’s context parameter - unused;

Return Value:

The function value is STATUS_SUCCESS.

–*/

{
#define BUFFER_SIZE 1024

PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation( Irp );
PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
NTSTATUS status;
POBJECT_NAME_INFORMATION nameInfo;
ULONG size;

//
// If any debugging level is enabled, attempt to capture the name of the
// file that was just created/opened.
//

if (SfDebug) {
if (nameInfo = ExAllocatePool( NonPagedPool, BUFFER_SIZE )) {

//
// A buffer was successfully allocated. Attempt to determine
// whether this was a volume or a file open, based on the length
// of the file’s name. If it was a volume open, then simply
// query the name of the device. Note that it is not legal to
// perform a relative file open using a NULL name to obtain
another
// handle to the same file, so checking the RelatedFileObject
field
// is unnecessary.
//

if (irpSp->FileObject->FileName.Length) {
status = ObQueryNameString(
irpSp->FileObject,
nameInfo,
BUFFER_SIZE,
&size
);
}
else {
status = ObQueryNameString(
irpSp->FileObject->DeviceObject,
nameInfo,
BUFFER_SIZE,
&size
);
}

//
// If querying the name was successful, actually print the name
// on the debug terminal.
//

if (NT_SUCCESS( status )) {
if (SfDebug & 2) {
if (irpSp->Parameters.Create.Options &
FILE_OPEN_BY_FILE_ID) {
DbgPrint( “SFILTER: Opened %ws\(FID)\n”,
nameInfo->Name.Buffer );
}
else {
DbgPrint( “SFILTER: Opened %ws\n”,
nameInfo->Name.Buffer );
}
}
}
else {
DbgPrint( “SFILTER: Could not get the name for %x\n”,
irpSp->FileObject );
if (!(SfDebug & 4)) {
DbgBreakPoint();
}
}
ExFreePool( nameInfo );
}
}

//
// Propogate the IRP pending flag.
//

if (Irp->PendingReturned) {
IoMarkIrpPending( Irp );
}

return STATUS_SUCCESS;
}

Regards,
Satish K.S

----- Original Message -----
From: “Dejan Maksimovic”
To: “File Systems Developers”
Sent: Tuesday, May 01, 2001 12:00 PM
Subject: [ntfsd] Re: Best Method to get FullPathName

>
> Which doesn’t mean it’s correct-:wink:
> Just a note on ObQueryNameString - it returns \Device\harddisk…
> format of the filename! Parsing is needed to bring it back to human
> readable form.
>
> Regards, Dejan.
>
> Satish wrote:
>
> > In SFilter sample they are using FileObject->FileName.Buffer
> > field. Regards,Satish K.S
> >
> > It should. In that case you can’t even determine the
> > filename from the FileObject->FileName.Buffer because
> > theoretically this buffer can be destroyed at the time you
> > are in your completion routine.
> >
> > There is also an undocumented function ObQueryNameString. I
> > don’t know if it exist in NT, but it does exist in Win2000
> > and WinXP. You might consider using that one.
> >
> > Maybe there is some info on this API in the archives, I’s
> > not sure.
> >
> > Bartjan.
> >
> > At 07:22 PM 4/27/01 +0530, you wrote:
> >
> >
> > > I will Query the file name After success of Open/Create by
> > > Setting I/O Completion routine like SFilter sample. Does
> > > this always works ?
> >
> > —
> > You are currently subscribed to ntfsd as:
> > xxxxx@aalayance.com
> > To unsubscribe send a blank email to
> > leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@ptt.yu
> > To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
> –
> Kind regards, Dejan M. CEO Alfa Co. www.alfaunits.co.yu and
> www.register.co.yu
> E-mail : xxxxx@ptt.yu, xxxxx@register.co.yu and
> xxxxx@alfaunits.co.yu
> ICQ# : 56570367
> Professional file&system related components and libraries for Win32
> developers.
> Alfa File Monitor - #1 file monitoring system for Win32 developers.
> Alfa File Protector - #1 file protection and hiding system for Win32
> developers.
> Alfa Units - #1 file and system handling units for Delphi.
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@aalayance.com
> To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

No. This will not work for relative file opens. Look at FILEMON.

Jamey

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Satish
Sent: Monday, April 30, 2001 11:46 PM
To: File Systems Developers
Subject: [ntfsd] Re: Best Method to get FullPathName

This is from SFilter. Does this work alsways … or else we have to handle
any error condition ?

DBGSTATIC
NTSTATUS
SfCreateCompletion(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context
)

/*++

Routine Description:

This function is the create/open completion routine for this filter
file system driver. If debugging is enabled, then this
function prints
the name of the file that was successfully opened/created by the file
system as a result of the specified I/O request.

Arguments:

DeviceObject - Pointer to the device on which the file was created.

Irp - Pointer to the I/O Request Packet the represents the operation.

Context - This driver’s context parameter - unused;

Return Value:

The function value is STATUS_SUCCESS.

–*/

{
#define BUFFER_SIZE 1024

PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation( Irp );
PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
NTSTATUS status;
POBJECT_NAME_INFORMATION nameInfo;
ULONG size;

//
// If any debugging level is enabled, attempt to capture the
name of the
// file that was just created/opened.
//

if (SfDebug) {
if (nameInfo = ExAllocatePool( NonPagedPool, BUFFER_SIZE )) {

//
// A buffer was successfully allocated. Attempt to determine
// whether this was a volume or a file open, based on
the length
// of the file’s name. If it was a volume open, then simply
// query the name of the device. Note that it is not legal to
// perform a relative file open using a NULL name to obtain
another
// handle to the same file, so checking the RelatedFileObject
field
// is unnecessary.
//

if (irpSp->FileObject->FileName.Length) {
status = ObQueryNameString(
irpSp->FileObject,
nameInfo,
BUFFER_SIZE,
&size
);
}
else {
status = ObQueryNameString(
irpSp->FileObject->DeviceObject,
nameInfo,
BUFFER_SIZE,
&size
);
}

//
// If querying the name was successful, actually
print the name
// on the debug terminal.
//

if (NT_SUCCESS( status )) {
if (SfDebug & 2) {
if (irpSp->Parameters.Create.Options &
FILE_OPEN_BY_FILE_ID) {
DbgPrint( “SFILTER: Opened %ws\(FID)\n”,
nameInfo->Name.Buffer );
}
else {
DbgPrint( “SFILTER: Opened %ws\n”,
nameInfo->Name.Buffer );
}
}
}
else {
DbgPrint( “SFILTER: Could not get the name for %x\n”,
irpSp->FileObject );
if (!(SfDebug & 4)) {
DbgBreakPoint();
}
}
ExFreePool( nameInfo );
}
}

//
// Propogate the IRP pending flag.
//

if (Irp->PendingReturned) {
IoMarkIrpPending( Irp );
}

return STATUS_SUCCESS;
}

Regards,
Satish K.S

----- Original Message -----
From: “Dejan Maksimovic”
> To: “File Systems Developers”
> Sent: Tuesday, May 01, 2001 12:00 PM
> Subject: [ntfsd] Re: Best Method to get FullPathName
>
>
> >
> > Which doesn’t mean it’s correct-:wink:
> > Just a note on ObQueryNameString - it returns \Device\harddisk…
> > format of the filename! Parsing is needed to bring it back to human
> > readable form.
> >
> > Regards, Dejan.
> >
> > Satish wrote:
> >
> > > In SFilter sample they are using FileObject->FileName.Buffer
> > > field. Regards,Satish K.S
> > >
> > > It should. In that case you can’t even determine the
> > > filename from the FileObject->FileName.Buffer because
> > > theoretically this buffer can be destroyed at the time you
> > > are in your completion routine.
> > >
> > > There is also an undocumented function ObQueryNameString. I
> > > don’t know if it exist in NT, but it does exist in Win2000
> > > and WinXP. You might consider using that one.
> > >
> > > Maybe there is some info on this API in the archives, I’s
> > > not sure.
> > >
> > > Bartjan.
> > >
> > > At 07:22 PM 4/27/01 +0530, you wrote:
> > >
> > >
> > > > I will Query the file name After success of Open/Create by
> > > > Setting I/O Completion routine like SFilter sample. Does
> > > > this always works ?
> > >
> > > —
> > > You are currently subscribed to ntfsd as:
> > > xxxxx@aalayance.com
> > > To unsubscribe send a blank email to
> > > leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> > >
> > > —
> > > You are currently subscribed to ntfsd as: xxxxx@ptt.yu
> > > To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> >
> > –
> > Kind regards, Dejan M. CEO Alfa Co. www.alfaunits.co.yu and
> > www.register.co.yu
> > E-mail : xxxxx@ptt.yu, xxxxx@register.co.yu and
> > xxxxx@alfaunits.co.yu
> > ICQ# : 56570367
> > Professional file&system related components and libraries for Win32
> > developers.
> > Alfa File Monitor - #1 file monitoring system for Win32 developers.
> > Alfa File Protector - #1 file protection and hiding system for Win32
> > developers.
> > Alfa Units - #1 file and system handling units for Delphi.
> >
> >
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@aalayance.com
> > To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> >
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Ahh, that’s different - ObQueryNameString should work in any IRP.

Regards, Dejan.

Satish wrote:

This is from SFilter. Does this work alsways … or else we have to handle
any error condition ?

DBGSTATIC
NTSTATUS
SfCreateCompletion(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context
)

/*++

Routine Description:

This function is the create/open completion routine for this filter
file system driver. If debugging is enabled, then this function prints
the name of the file that was successfully opened/created by the file
system as a result of the specified I/O request.

Arguments:

DeviceObject - Pointer to the device on which the file was created.

Irp - Pointer to the I/O Request Packet the represents the operation.

Context - This driver’s context parameter - unused;

Return Value:

The function value is STATUS_SUCCESS.

–*/

{
#define BUFFER_SIZE 1024

PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation( Irp );
PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
NTSTATUS status;
POBJECT_NAME_INFORMATION nameInfo;
ULONG size;

//
// If any debugging level is enabled, attempt to capture the name of the
// file that was just created/opened.
//

if (SfDebug) {
if (nameInfo = ExAllocatePool( NonPagedPool, BUFFER_SIZE )) {

//
// A buffer was successfully allocated. Attempt to determine
// whether this was a volume or a file open, based on the length
// of the file’s name. If it was a volume open, then simply
// query the name of the device. Note that it is not legal to
// perform a relative file open using a NULL name to obtain
another
// handle to the same file, so checking the RelatedFileObject
field
// is unnecessary.
//

if (irpSp->FileObject->FileName.Length) {
status = ObQueryNameString(
irpSp->FileObject,
nameInfo,
BUFFER_SIZE,
&size
);
}
else {
status = ObQueryNameString(
irpSp->FileObject->DeviceObject,
nameInfo,
BUFFER_SIZE,
&size
);
}

//
// If querying the name was successful, actually print the name
// on the debug terminal.
//

if (NT_SUCCESS( status )) {
if (SfDebug & 2) {
if (irpSp->Parameters.Create.Options &
FILE_OPEN_BY_FILE_ID) {
DbgPrint( “SFILTER: Opened %ws\(FID)\n”,
nameInfo->Name.Buffer );
}
else {
DbgPrint( “SFILTER: Opened %ws\n”,
nameInfo->Name.Buffer );
}
}
}
else {
DbgPrint( “SFILTER: Could not get the name for %x\n”,
irpSp->FileObject );
if (!(SfDebug & 4)) {
DbgBreakPoint();
}
}
ExFreePool( nameInfo );
}
}

//
// Propogate the IRP pending flag.
//

if (Irp->PendingReturned) {
IoMarkIrpPending( Irp );
}

return STATUS_SUCCESS;
}

Regards,
Satish K.S

----- Original Message -----
From: “Dejan Maksimovic”
> To: “File Systems Developers”
> Sent: Tuesday, May 01, 2001 12:00 PM
> Subject: [ntfsd] Re: Best Method to get FullPathName
>
> >
> > Which doesn’t mean it’s correct-:wink:
> > Just a note on ObQueryNameString - it returns \Device\harddisk…
> > format of the filename! Parsing is needed to bring it back to human
> > readable form.
> >
> > Regards, Dejan.
> >
> > Satish wrote:
> >
> > > In SFilter sample they are using FileObject->FileName.Buffer
> > > field. Regards,Satish K.S
> > >
> > > It should. In that case you can’t even determine the
> > > filename from the FileObject->FileName.Buffer because
> > > theoretically this buffer can be destroyed at the time you
> > > are in your completion routine.
> > >
> > > There is also an undocumented function ObQueryNameString. I
> > > don’t know if it exist in NT, but it does exist in Win2000
> > > and WinXP. You might consider using that one.
> > >
> > > Maybe there is some info on this API in the archives, I’s
> > > not sure.
> > >
> > > Bartjan.
> > >
> > > At 07:22 PM 4/27/01 +0530, you wrote:
> > >
> > >
> > > > I will Query the file name After success of Open/Create by
> > > > Setting I/O Completion routine like SFilter sample. Does
> > > > this always works ?
> > >
> > > —
> > > You are currently subscribed to ntfsd as:
> > > xxxxx@aalayance.com
> > > To unsubscribe send a blank email to
> > > leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> > >
> > > —
> > > You are currently subscribed to ntfsd as: xxxxx@ptt.yu
> > > To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> >
> > –
> > Kind regards, Dejan M. CEO Alfa Co. www.alfaunits.co.yu and
> > www.register.co.yu
> > E-mail : xxxxx@ptt.yu, xxxxx@register.co.yu and
> > xxxxx@alfaunits.co.yu
> > ICQ# : 56570367
> > Professional file&system related components and libraries for Win32
> > developers.
> > Alfa File Monitor - #1 file monitoring system for Win32 developers.
> > Alfa File Protector - #1 file protection and hiding system for Win32
> > developers.
> > Alfa Units - #1 file and system handling units for Delphi.
> >
> >
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@aalayance.com
> > To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> >
>
> —
> You are currently subscribed to ntfsd as: xxxxx@ptt.yu
> To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


Kind regards, Dejan M. CEO Alfa Co. www.alfaunits.co.yu and www.register.co.yu
E-mail : xxxxx@ptt.yu, xxxxx@register.co.yu and xxxxx@alfaunits.co.yu
ICQ# : 56570367
Professional file&system related components and libraries for Win32 developers.
Alfa File Monitor - #1 file monitoring system for Win32 developers.
Alfa File Protector - #1 file protection and hiding system for Win32 developers.

Alfa Units - #1 file and system handling units for Delphi.


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Thanks u all,

Then We must use both methods.

  1. Constructing the Path using the File_Object
  2. Querying the FSD

Regards,
Satish K.S

----- Original Message -----
From: “Dejan Maksimovic”
To: “File Systems Developers”
Sent: Tuesday, May 01, 2001 11:56 PM
Subject: [ntfsd] Re: Best Method to get FullPathName

>
> Ahh, that’s different - ObQueryNameString should work in any IRP.
>
> Regards, Dejan.
>
> Satish wrote:
>
> > This is from SFilter. Does this work alsways … or else we have to
handle
> > any error condition ?
> >
> > DBGSTATIC
> > NTSTATUS
> > SfCreateCompletion(
> > IN PDEVICE_OBJECT DeviceObject,
> > IN PIRP Irp,
> > IN PVOID Context
> > )
> >
> > /++
> >
> > Routine Description:
> >
> > This function is the create/open completion routine for this filter
> > file system driver. If debugging is enabled, then this function
prints
> > the name of the file that was successfully opened/created by the
file
> > system as a result of the specified I/O request.
> >
> > Arguments:
> >
> > DeviceObject - Pointer to the device on which the file was created.
> >
> > Irp - Pointer to the I/O Request Packet the represents the
operation.
> >
> > Context - This driver’s context parameter - unused;
> >
> > Return Value:
> >
> > The function value is STATUS_SUCCESS.
> >
> > –
/
> >
> > {
> > #define BUFFER_SIZE 1024
> >
> > PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation( Irp );
> > PDEVICE_EXTENSION deviceExtension = DeviceObject->DeviceExtension;
> > NTSTATUS status;
> > POBJECT_NAME_INFORMATION nameInfo;
> > ULONG size;
> >
> > //
> > // If any debugging level is enabled, attempt to capture the name of
the
> > // file that was just created/opened.
> > //
> >
> > if (SfDebug) {
> > if (nameInfo = ExAllocatePool( NonPagedPool, BUFFER_SIZE )) {
> >
> > //
> > // A buffer was successfully allocated. Attempt to
determine
> > // whether this was a volume or a file open, based on the
length
> > // of the file’s name. If it was a volume open, then simply
> > // query the name of the device. Note that it is not legal
to
> > // perform a relative file open using a NULL name to obtain
> > another
> > // handle to the same file, so checking the
RelatedFileObject
> > field
> > // is unnecessary.
> > //
> >
> > if (irpSp->FileObject->FileName.Length) {
> > status = ObQueryNameString(
> > irpSp->FileObject,
> > nameInfo,
> > BUFFER_SIZE,
> > &size
> > );
> > }
> > else {
> > status = ObQueryNameString(
> > irpSp->FileObject->DeviceObject,
> > nameInfo,
> > BUFFER_SIZE,
> > &size
> > );
> > }
> >
> > //
> > // If querying the name was successful, actually print the
name
> > // on the debug terminal.
> > //
> >
> > if (NT_SUCCESS( status )) {
> > if (SfDebug & 2) {
> > if (irpSp->Parameters.Create.Options &
> > FILE_OPEN_BY_FILE_ID) {
> > DbgPrint( “SFILTER: Opened %ws\(FID)\n”,
> > nameInfo->Name.Buffer );
> > }
> > else {
> > DbgPrint( “SFILTER: Opened %ws\n”,
> > nameInfo->Name.Buffer );
> > }
> > }
> > }
> > else {
> > DbgPrint( “SFILTER: Could not get the name for %x\n”,
> > irpSp->FileObject );
> > if (!(SfDebug & 4)) {
> > DbgBreakPoint();
> > }
> > }
> > ExFreePool( nameInfo );
> > }
> > }
> >
> > //
> > // Propogate the IRP pending flag.
> > //
> >
> > if (Irp->PendingReturned) {
> > IoMarkIrpPending( Irp );
> > }
> >
> > return STATUS_SUCCESS;
> > }
> >
> > Regards,
> > Satish K.S
> >
> > ----- Original Message -----
> > From: “Dejan Maksimovic”
> > To: “File Systems Developers”
> > Sent: Tuesday, May 01, 2001 12:00 PM
> > Subject: [ntfsd] Re: Best Method to get FullPathName
> >
> > >
> > > Which doesn’t mean it’s correct-:wink:
> > > Just a note on ObQueryNameString - it returns \Device\harddisk…
> > > format of the filename! Parsing is needed to bring it back to human
> > > readable form.
> > >
> > > Regards, Dejan.
> > >
> > > Satish wrote:
> > >
> > > > In SFilter sample they are using FileObject->FileName.Buffer
> > > > field. Regards,Satish K.S
> > > >
> > > > It should. In that case you can’t even determine the
> > > > filename from the FileObject->FileName.Buffer because
> > > > theoretically this buffer can be destroyed at the time you
> > > > are in your completion routine.
> > > >
> > > > There is also an undocumented function ObQueryNameString. I
> > > > don’t know if it exist in NT, but it does exist in Win2000
> > > > and WinXP. You might consider using that one.
> > > >
> > > > Maybe there is some info on this API in the archives, I’s
> > > > not sure.
> > > >
> > > > Bartjan.
> > > >
> > > > At 07:22 PM 4/27/01 +0530, you wrote:
> > > >
> > > >
> > > > > I will Query the file name After success of Open/Create by
> > > > > Setting I/O Completion routine like SFilter sample. Does
> > > > > this always works ?
> > > >
> > > > —
> > > > You are currently subscribed to ntfsd as:
> > > > xxxxx@aalayance.com
> > > > To unsubscribe send a blank email to
> > > > leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> > > >
> > > > —
> > > > You are currently subscribed to ntfsd as: xxxxx@ptt.yu
> > > > To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> > >
> > > –
> > > Kind regards, Dejan M. CEO Alfa Co. www.alfaunits.co.yu and
> > > www.register.co.yu
> > > E-mail : xxxxx@ptt.yu, xxxxx@register.co.yu and
> > > xxxxx@alfaunits.co.yu
> > > ICQ# : 56570367
> > > Professional file&system related components and libraries for Win32
> > > developers.
> > > Alfa File Monitor - #1 file monitoring system for Win32 developers.
> > > Alfa File Protector - #1 file protection and hiding system for Win32
> > > developers.
> > > Alfa Units - #1 file and system handling units for Delphi.
> > >
> > >
> > >
> > > —
> > > You are currently subscribed to ntfsd as: xxxxx@aalayance.com
> > > To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> > >
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@ptt.yu
> > To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
> –
> Kind regards, Dejan M. CEO Alfa Co. www.alfaunits.co.yu and
www.register.co.yu
> E-mail : xxxxx@ptt.yu, xxxxx@register.co.yu and xxxxx@alfaunits.co.yu
> ICQ# : 56570367
> Professional file&system related components and libraries for Win32
developers.
> Alfa File Monitor - #1 file monitoring system for Win32 developers.
> Alfa File Protector - #1 file protection and hiding system for Win32
developers.
>
> Alfa Units - #1 file and system handling units for Delphi.
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@aalayance.com
> To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com