STATUS_REPARSE in IRP_CREATE redirection

Hi,
I’m trying to use STATUS_REPARSE to redidrect IRP_CREATE in FS driver.
I searched the archive in this list and found a lots of discusstions
on STATUS_REPARSE. But I still have some questions.

As my understanding, when I redirect the IRP_CREATE, I need to do
following in Irp->FileObject->FileName:

  • Allocate your own name buffer in a filter driver
  • Replace the original filename buffer with the new filename buffer
  • Free the original filename buffer
  • Set IoStatus.Information to IO_REPARSE
  • Return STATUS_REPARSE

But in NT4 DDK sample reparse.c, it only updated
Irp->Tail.Overlay.OriginalFileObject->FileName
I didn’t see it free the orignial filename buffer.

So, Do I need to update both of FileName buffer or just any one of them?
In NT4 DDK sample, who will release the original file name buffer?

Thank you for your help

If the original buffer is big enough for your new
filename, you can just put it in the original buffer.

Here’s some code:

if (FileObject->FileName.MaximumLength >=
(wcslen(wRedirPath) * sizeof(WCHAR)))
{
wcscpy(FileObject->FileName.Buffer, wRedirPath);

FileObject->FileName.Length = wcslen(wRedirPath) *
sizeof(WCHAR);
}
else
{
if (FileObject->FileName.Buffer != NULL)
{
ExFreePool(FileObject->FileName.Buffer);
}

FileObject->FileName.Buffer =
ExAllocatePoolWithTag(NonPagedPool,
(wcslen(wRedirPath) + 1) * sizeof(WCHAR), ‘aaaa’);

wcscpy(FileObject->FileName.Buffer, wRedirPath);

FileObject->FileName.Length = wcslen(wRedirPath) *
sizeof(WCHAR);

FileObject->FileName.MaximumLength =
FileObject->FileName.Length + sizeof(WCHAR);

FileObject->RelatedFileObject = NULL;
}

Irp->IoStatus.Information = IO_REPARSE;
Irp->IoStatus.Status = STATUS_REPARSE;

IoCompleteRequest(Irp, IO_NO_INCREMENT);

return STATUS_REPARSE;

Hope this helps,

Randy

— David Wu wrote:
> Hi,
> I’m trying to use STATUS_REPARSE to redidrect
> IRP_CREATE in FS driver.
> I searched the archive in this list and found a lots
> of discusstions
> on STATUS_REPARSE. But I still have some questions.
>
> As my understanding, when I redirect the IRP_CREATE,
> I need to do
> following in Irp->FileObject->FileName:
> - Allocate your own name buffer in a filter driver
> - Replace the original filename buffer with the new
> filename buffer
> - Free the original filename buffer
> - Set IoStatus.Information to IO_REPARSE
> - Return STATUS_REPARSE
>
> But in NT4 DDK sample reparse.c, it only updated
> Irp->Tail.Overlay.OriginalFileObject->FileName
> I didn’t see it free the orignial filename buffer.
>
> So, Do I need to update both of FileName buffer or
> just any one of them?
> In NT4 DDK sample, who will release the original
> file name buffer?
>
> Thank you for your help
>
> —
> You are currently subscribed to ntfsd as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
xxxxx@lists.osr.com

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

> As my understanding, when I redirect the IRP_CREATE, I need to do

following in Irp->FileObject->FileName:

  • Allocate your own name buffer in a filter driver
  • Replace the original filename buffer with the new filename buffer

This is necessary only if the new file name is longer then the old
one. Otherwise, you can reuse the buffer.

Max

Thanks Randy and Max.
I still have one question about this reparse.
What is different between updating Irp->FileObject->FileName and
Irp->Tail.Overlay.OriginalFileObject->FileName
In NT4 DDK reparse.c?

Thanks

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Thursday, July 03, 2003 2:33 PM
To: File Systems Developers
Subject: [ntfsd] Re: STATUS_REPARSE in IRP_CREATE redirection

As my understanding, when I redirect the IRP_CREATE, I need to do
following in Irp->FileObject->FileName:

  • Allocate your own name buffer in a filter driver
  • Replace the original filename buffer with the new filename buffer

This is necessary only if the new file name is longer then the old one.
Otherwise, you can reuse the buffer.

Max


You are currently subscribed to ntfsd as: xxxxx@highstream.net To
unsubscribe send a blank email to xxxxx@lists.osr.com

Most of the time it is the same file object. At least IoManager builds IRP
this way. If there is a filter above your filter it may decide to replace
FileObject in the StackLocation for next driver. Normally drivers are
expected to use FileObject from its StackLocation,
not the Irp->Tail.Overlay.OriginalFileObject.

Alexei.

“Dongli Wu” wrote in message news:xxxxx@ntfsd…
>
> Thanks Randy and Max.
> I still have one question about this reparse.
> What is different between updating Irp->FileObject->FileName and
> Irp->Tail.Overlay.OriginalFileObject->FileName
> In NT4 DDK reparse.c?
>
> Thanks

The function wcscpy appends the character L’\0’ to the end of string. This
code needs to be changed, for example replace wcscpy with wcsncpy.

Joze

-----Original Message-----
From: Randy Cook [mailto:xxxxx@yahoo.com]
Sent: Thursday, July 03, 2003 8:57 PM
To: File Systems Developers
Subject: [ntfsd] Re: STATUS_REPARSE in IRP_CREATE redirection

if (FileObject->FileName.MaximumLength >=
(wcslen(wRedirPath) * sizeof(WCHAR)))
{
wcscpy(FileObject->FileName.Buffer, wRedirPath);

FileObject->FileName.Length = wcslen(wRedirPath) *
sizeof(WCHAR);
}
else
{
if (FileObject->FileName.Buffer != NULL)
{
ExFreePool(FileObject->FileName.Buffer);
}

FileObject->FileName.Buffer =
ExAllocatePoolWithTag(NonPagedPool,
(wcslen(wRedirPath) + 1) * sizeof(WCHAR), ‘aaaa’);

wcscpy(FileObject->FileName.Buffer, wRedirPath);

FileObject->FileName.Length = wcslen(wRedirPath) *
sizeof(WCHAR);

FileObject->FileName.MaximumLength =
FileObject->FileName.Length + sizeof(WCHAR);

FileObject->RelatedFileObject = NULL;
}

Irp->IoStatus.Information = IO_REPARSE;
Irp->IoStatus.Status = STATUS_REPARSE;

IoCompleteRequest(Irp, IO_NO_INCREMENT);

return STATUS_REPARSE;

Hope this helps,

Randy

— David Wu wrote:
> Hi,
> I’m trying to use STATUS_REPARSE to redidrect
> IRP_CREATE in FS driver.
> I searched the archive in this list and found a lots
> of discusstions
> on STATUS_REPARSE. But I still have some questions.
>
> As my understanding, when I redirect the IRP_CREATE,
> I need to do
> following in Irp->FileObject->FileName:
> - Allocate your own name buffer in a filter driver
> - Replace the original filename buffer with the new
> filename buffer
> - Free the original filename buffer
> - Set IoStatus.Information to IO_REPARSE
> - Return STATUS_REPARSE
>
> But in NT4 DDK sample reparse.c, it only updated
> Irp->Tail.Overlay.OriginalFileObject->FileName
> I didn’t see it free the orignial filename buffer.
>
> So, Do I need to update both of FileName buffer or
> just any one of them?
> In NT4 DDK sample, who will release the original
> file name buffer?
>
> Thank you for your help
>
> —
> You are currently subscribed to ntfsd as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
xxxxx@lists.osr.com

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com


You are currently subscribed to ntfsd as: xxxxx@hermes.si
To unsubscribe send a blank email to xxxxx@lists.osr.com

Never ever touch OriginalFileObject. This is IO manager’s internal
field, to pass some context from IopSynchronousServiceTail to
IopCompleteRequest. Drivers are not supposed to be interested in it.

Max

----- Original Message -----
From: “Dongli Wu”
To: “File Systems Developers”
Sent: Friday, July 04, 2003 5:36 AM
Subject: [ntfsd] Re: STATUS_REPARSE in IRP_CREATE redirection

> Thanks Randy and Max.
> I still have one question about this reparse.
> What is different between updating Irp->FileObject->FileName and
> Irp->Tail.Overlay.OriginalFileObject->FileName
> In NT4 DDK reparse.c?
>
> Thanks
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S.
Shatskih
> Sent: Thursday, July 03, 2003 2:33 PM
> To: File Systems Developers
> Subject: [ntfsd] Re: STATUS_REPARSE in IRP_CREATE redirection
>
>
> > As my understanding, when I redirect the IRP_CREATE, I need to do
> > following in Irp->FileObject->FileName:
> > - Allocate your own name buffer in a filter driver
> > - Replace the original filename buffer with the new filename
buffer
>
> This is necessary only if the new file name is longer then the old
one.
> Otherwise, you can reuse the buffer.
>
> Max
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@highstream.net To
> unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

Yep, whups. This would work better:

if (FileObject->FileName.MaximumLength >=
(wcslen(wRedirPath) * sizeof(WCHAR)))
{
wcsncpy(FileObject->FileName.Buffer, wRedirPath,
wcslen(wRedirPath));

FileObject->FileName.Length = wcslen(wRedirPath) *
sizeof(WCHAR);
}

— Joze Fabcic wrote:
> The function wcscpy appends the character L’\0’ to
> the end of string. This
> code needs to be changed, for example replace wcscpy
> with wcsncpy.
>
> Joze
>
> -----Original Message-----
> From: Randy Cook [mailto:xxxxx@yahoo.com]
> Sent: Thursday, July 03, 2003 8:57 PM
> To: File Systems Developers
> Subject: [ntfsd] Re: STATUS_REPARSE in IRP_CREATE
> redirection
>
> if (FileObject->FileName.MaximumLength >=
> (wcslen(wRedirPath) * sizeof(WCHAR)))
> {
> wcscpy(FileObject->FileName.Buffer, wRedirPath);
>
> FileObject->FileName.Length = wcslen(wRedirPath) *
> sizeof(WCHAR);
> }
> else
> {
> if (FileObject->FileName.Buffer != NULL)
> {
> ExFreePool(FileObject->FileName.Buffer);
> }
>
> FileObject->FileName.Buffer =
> ExAllocatePoolWithTag(NonPagedPool,
> (wcslen(wRedirPath) + 1) * sizeof(WCHAR),
> ‘aaaa’);
>
> wcscpy(FileObject->FileName.Buffer, wRedirPath);
>
> FileObject->FileName.Length = wcslen(wRedirPath) *
> sizeof(WCHAR);
>
> FileObject->FileName.MaximumLength =
> FileObject->FileName.Length + sizeof(WCHAR);
>
> FileObject->RelatedFileObject = NULL;
> }
>
> Irp->IoStatus.Information = IO_REPARSE;
> Irp->IoStatus.Status = STATUS_REPARSE;
>
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
>
> return STATUS_REPARSE;
>
> Hope this helps,
>
> Randy
>
> — David Wu wrote:
> > Hi,
> > I’m trying to use STATUS_REPARSE to redidrect
> > IRP_CREATE in FS driver.
> > I searched the archive in this list and found a
> lots
> > of discusstions
> > on STATUS_REPARSE. But I still have some
> questions.
> >
> > As my understanding, when I redirect the
> IRP_CREATE,
> > I need to do
> > following in Irp->FileObject->FileName:
> > - Allocate your own name buffer in a filter driver
> > - Replace the original filename buffer with the
> new
> > filename buffer
> > - Free the original filename buffer
> > - Set IoStatus.Information to IO_REPARSE
> > - Return STATUS_REPARSE
> >
> > But in NT4 DDK sample reparse.c, it only updated
> > Irp->Tail.Overlay.OriginalFileObject->FileName
> > I didn’t see it free the orignial filename buffer.
>
> >
> > So, Do I need to update both of FileName buffer or
> > just any one of them?
> > In NT4 DDK sample, who will release the original
> > file name buffer?
> >
> > Thank you for your help
> >
> > —
> > You are currently subscribed to ntfsd as:
> > xxxxx@yahoo.com
> > To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>
>
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
>
>
> —
> You are currently subscribed to ntfsd as:
> xxxxx@hermes.si
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>
> —
> You are currently subscribed to ntfsd as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
xxxxx@lists.osr.com


Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

May be I’m missing something, but wouldn’t it be better done using the Rtl
routines, like this:

UNICODE_STRING uszRedirPath;
RtlInitUnicodeString(&uszRedirPath,wRedirPath);
if (FileObject->FileName.MaximumLength >= uszRedirPath.Length)
{
RtlCopyUnicodeString(&FileObject->FileName,&uszRedirPath);
}

I think I’ve read somewhere that MS advises against C RTL usage in drivers
where kernel RtlXXX routines are available.

----- Original Message -----
From: “Randy Cook”
To: “File Systems Developers”
Sent: Friday, July 04, 2003 6:41 PM
Subject: [ntfsd] Re: STATUS_REPARSE in IRP_CREATE redirection

> Yep, whups. This would work better:
>
> if (FileObject->FileName.MaximumLength >=
> (wcslen(wRedirPath) * sizeof(WCHAR)))
> {
> wcsncpy(FileObject->FileName.Buffer, wRedirPath,
> wcslen(wRedirPath));
>
> FileObject->FileName.Length = wcslen(wRedirPath) *
> sizeof(WCHAR);
> }
>
> …
>
> — Joze Fabcic wrote:
> > The function wcscpy appends the character L’\0’ to
> > the end of string. This
> > code needs to be changed, for example replace wcscpy
> > with wcsncpy.
> >
> > Joze
> >
> > -----Original Message-----
> > From: Randy Cook [mailto:xxxxx@yahoo.com]
> > Sent: Thursday, July 03, 2003 8:57 PM
> > To: File Systems Developers
> > Subject: [ntfsd] Re: STATUS_REPARSE in IRP_CREATE
> > redirection
> >
> > if (FileObject->FileName.MaximumLength >=
> > (wcslen(wRedirPath) * sizeof(WCHAR)))
> > {
> > wcscpy(FileObject->FileName.Buffer, wRedirPath);
> >
> > FileObject->FileName.Length = wcslen(wRedirPath) *
> > sizeof(WCHAR);
> > }
> > else
> > {
> > if (FileObject->FileName.Buffer != NULL)
> > {
> > ExFreePool(FileObject->FileName.Buffer);
> > }
> >
> > FileObject->FileName.Buffer =
> > ExAllocatePoolWithTag(NonPagedPool,
> > (wcslen(wRedirPath) + 1) * sizeof(WCHAR),
> > ‘aaaa’);
> >
> > wcscpy(FileObject->FileName.Buffer, wRedirPath);
> >
> > FileObject->FileName.Length = wcslen(wRedirPath) *
> > sizeof(WCHAR);
> >
> > FileObject->FileName.MaximumLength =
> > FileObject->FileName.Length + sizeof(WCHAR);
> >
> > FileObject->RelatedFileObject = NULL;
> > }
> >
> > Irp->IoStatus.Information = IO_REPARSE;
> > Irp->IoStatus.Status = STATUS_REPARSE;
> >
> > IoCompleteRequest(Irp, IO_NO_INCREMENT);
> >
> > return STATUS_REPARSE;
> >
> > Hope this helps,
> >
> > Randy
> >
> > — David Wu wrote:
> > > Hi,
> > > I’m trying to use STATUS_REPARSE to redidrect
> > > IRP_CREATE in FS driver.
> > > I searched the archive in this list and found a
> > lots
> > > of discusstions
> > > on STATUS_REPARSE. But I still have some
> > questions.
> > >
> > > As my understanding, when I redirect the
> > IRP_CREATE,
> > > I need to do
> > > following in Irp->FileObject->FileName:
> > > - Allocate your own name buffer in a filter driver
> > > - Replace the original filename buffer with the
> > new
> > > filename buffer
> > > - Free the original filename buffer
> > > - Set IoStatus.Information to IO_REPARSE
> > > - Return STATUS_REPARSE
> > >
> > > But in NT4 DDK sample reparse.c, it only updated
> > > Irp->Tail.Overlay.OriginalFileObject->FileName
> > > I didn’t see it free the orignial filename buffer.
> >
> > >
> > > So, Do I need to update both of FileName buffer or
> > > just any one of them?
> > > In NT4 DDK sample, who will release the original
> > > file name buffer?
> > >
> > > Thank you for your help
> > >
> > > —
> > > You are currently subscribed to ntfsd as:
> > > xxxxx@yahoo.com
> > > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> >
> >
> >
> > Do you Yahoo!?
> > SBC Yahoo! DSL - Now only $29.95 per month!
> > http://sbc.yahoo.com
> >
> >
> > —
> > You are currently subscribed to ntfsd as:
> > xxxxx@hermes.si
> > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> >
> >
> > —
> > You are currently subscribed to ntfsd as:
> > xxxxx@yahoo.com
> > To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>
>

> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@secureol.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>