rename in filter driver

Hi All,
My FS driver needs to intercept file rename operation and do
some additional file rename. For example: when user renames
c:\temp1\foo1.txt to c:\temp\bar1.txt, FS driver will rename other
file d:\temp2\foo2.txt d:\temp2\bar2.txt at the same time.
What I did is as follow:
When IO manager creates target file object(IRP_MJ_CREATE with flag
SL_OPEN_TARGET_DIRECTORY) for c:\temp1\foo1.txt, I also create
target file object for d:\temp2\foo2.txt via ZwCreateFile().
The parameters whitch I use in ZwCreateFile come from
IrpStack->Parameters.Create:

DesiredAccess = IrpStack->Parameters.Create.SecurityContext->DesiredAccess
FileAttributes = IrpStack->Parameters.Create.FileAttributes
ShareAccess = IrpStack->Parameters.Create.ShareAccess
CreateDisposition = IrpStack->Parameters.Create.Options >> 24) & 0xFF
CreateOptions =
IrpStack->Parameters.Create.SecurityContext->FullCreateOptions

The problem is the target file object created by IO manager
will return STATUS_SUCCESS with IoStatus.Information =
FILE_DOES_NOT_EXIST. But the target file object create by FS driver
will return STATUS_UNSUCCESSFUL with error STATUS_OBJECT_NAME_NOT_FOUND.

Also, I found when IO manager create target file object with
SL_OPEN_TARGET_DIRECTORY flag, the create option is always set as follow:
create options = 0x1000000 (FILE_OPEN, attributes = 0)
DesiredAccess (pSecurityContext->DesiredAccess) = 0x100002

When my FS driver call ZwCreateFile(), IO manager also dispatch
IRP_MJ_CREATE with the same create option but no SL_OPEN_TARGET_DIRECTORY
and it will fail with STATUS_OBJECT_NAME_NOT_FOUND.

I can not figure out what’s wrong in my driver. Can anyone give me
some help? Any info will be appreciated.

Thanks

SL_OPEN_TARGET_DIRECTORY flag is used to open the destination directory for
a rename operation. ZwCreateFile doesn’t allow to open target directory. You
need to use IoCreateFile to achieve this.

Alexei.

“David Wu” wrote in message news:xxxxx@ntfsd…
>
> Hi All,
> My FS driver needs to intercept file rename operation and do
> some additional file rename. For example: when user renames
> c:\temp1\foo1.txt to c:\temp\bar1.txt, FS driver will rename other
> file d:\temp2\foo2.txt d:\temp2\bar2.txt at the same time.
> What I did is as follow:
> When IO manager creates target file object(IRP_MJ_CREATE with flag
> SL_OPEN_TARGET_DIRECTORY) for c:\temp1\foo1.txt, I also create
> target file object for d:\temp2\foo2.txt via ZwCreateFile().
> The parameters whitch I use in ZwCreateFile come from
> IrpStack->Parameters.Create:
>
> DesiredAccess = IrpStack->Parameters.Create.SecurityContext->DesiredAccess
> FileAttributes = IrpStack->Parameters.Create.FileAttributes
> ShareAccess = IrpStack->Parameters.Create.ShareAccess
> CreateDisposition = IrpStack->Parameters.Create.Options >> 24) & 0xFF
> CreateOptions =
> IrpStack->Parameters.Create.SecurityContext->FullCreateOptions
>
> The problem is the target file object created by IO manager
> will return STATUS_SUCCESS with IoStatus.Information =
> FILE_DOES_NOT_EXIST. But the target file object create by FS driver
> will return STATUS_UNSUCCESSFUL with error STATUS_OBJECT_NAME_NOT_FOUND.
>
> Also, I found when IO manager create target file object with
> SL_OPEN_TARGET_DIRECTORY flag, the create option is always set as follow:
> create options = 0x1000000 (FILE_OPEN, attributes = 0)
> DesiredAccess (pSecurityContext->DesiredAccess) = 0x100002
>
> When my FS driver call ZwCreateFile(), IO manager also dispatch
> IRP_MJ_CREATE with the same create option but no SL_OPEN_TARGET_DIRECTORY
> and it will fail with STATUS_OBJECT_NAME_NOT_FOUND.
>
> I can not figure out what’s wrong in my driver. Can anyone give me
> some help? Any info will be appreciated.
>
> Thanks
>
>

Hi Alexei,
IoCreateFile() doesn’t work either. I still get the same error status.
What else can cause this error status?

Thanks

SL_OPEN_TARGET_DIRECTORY flag is used to open the destination directory for
a rename operation. ZwCreateFile doesn’t allow to open target directory. You
need to use IoCreateFile to achieve this.

Alexei.

“David Wu” wrote in message news:xxxxx@ntfsd…
> >
> > Hi All,
> > My FS driver needs to intercept file rename operation and do
> > some additional file rename. For example: when user renames
> > c:\temp1\foo1.txt to c:\temp\bar1.txt, FS driver will rename other
> > file d:\temp2\foo2.txt d:\temp2\bar2.txt at the same time.
> > What I did is as follow:
> > When IO manager creates target file object(IRP_MJ_CREATE with flag
> > SL_OPEN_TARGET_DIRECTORY) for c:\temp1\foo1.txt, I also create
> > target file object for d:\temp2\foo2.txt via ZwCreateFile().
> > The parameters whitch I use in ZwCreateFile come from
> > IrpStack->Parameters.Create:
> >
> > DesiredAccess = IrpStack->Parameters.Create.SecurityContext->DesiredAccess
> > FileAttributes = IrpStack->Parameters.Create.FileAttributes
> > ShareAccess = IrpStack->Parameters.Create.ShareAccess
> > CreateDisposition = IrpStack->Parameters.Create.Options >> 24) & 0xFF
> > CreateOptions =
> > IrpStack->Parameters.Create.SecurityContext->FullCreateOptions
> >
> > The problem is the target file object created by IO manager
> > will return STATUS_SUCCESS with IoStatus.Information =
> > FILE_DOES_NOT_EXIST. But the target file object create by FS driver
> > will return STATUS_UNSUCCESSFUL with error STATUS_OBJECT_NAME_NOT_FOUND.
> >
> > Also, I found when IO manager create target file object with
> > SL_OPEN_TARGET_DIRECTORY flag, the create option is always set as follow:
> > create options = 0x1000000 (FILE_OPEN, attributes = 0)
> > DesiredAccess (pSecurityContext->DesiredAccess) = 0x100002
> >
> > When my FS driver call ZwCreateFile(), IO manager also dispatch
> > IRP_MJ_CREATE with the same create option but no SL_OPEN_TARGET_DIRECTORY
> > and it will fail with STATUS_OBJECT_NAME_NOT_FOUND.
> >
> > I can not figure out what’s wrong in my driver. Can anyone give me
> > some help? Any info will be appreciated.
> >
> > Thanks
> >
> >

The error code doesn’t seem right to me for this to be
the problem, but the parent dir of the target exists,
right?

Randy

— David Wu wrote:
> Hi Alexei,
> IoCreateFile() doesn’t work either. I still get the
> same error status.
> What else can cause this error status?
>
> Thanks
>
>
> > SL_OPEN_TARGET_DIRECTORY flag is used to open the
> destination directory for
> > a rename operation. ZwCreateFile doesn’t allow to
> open target directory. You
> > need to use IoCreateFile to achieve this.
> >
> > Alexei.
> >
> > “David Wu” wrote in
> message news:xxxxx@ntfsd…
> > >
> > > Hi All,
> > > My FS driver needs to intercept file rename
> operation and do
> > > some additional file rename. For example: when
> user renames
> > > c:\temp1\foo1.txt to c:\temp\bar1.txt, FS driver
> will rename other
> > > file d:\temp2\foo2.txt d:\temp2\bar2.txt at the
> same time.
> > > What I did is as follow:
> > > When IO manager creates target file
> object(IRP_MJ_CREATE with flag
> > > SL_OPEN_TARGET_DIRECTORY) for c:\temp1\foo1.txt,
> I also create
> > > target file object for d:\temp2\foo2.txt via
> ZwCreateFile().
> > > The parameters whitch I use in ZwCreateFile come
> from
> > > IrpStack->Parameters.Create:
> > >
> > > DesiredAccess =
>
IrpStack->Parameters.Create.SecurityContext->DesiredAccess
> > > FileAttributes =
> IrpStack->Parameters.Create.FileAttributes
> > > ShareAccess =
> IrpStack->Parameters.Create.ShareAccess
> > > CreateDisposition =
> IrpStack->Parameters.Create.Options >> 24) & 0xFF
> > > CreateOptions =
> > >
>
IrpStack->Parameters.Create.SecurityContext->FullCreateOptions
> > >
> > > The problem is the target file object created by
> IO manager
> > > will return STATUS_SUCCESS with
> IoStatus.Information =
> > > FILE_DOES_NOT_EXIST. But the target file object
> create by FS driver
> > > will return STATUS_UNSUCCESSFUL with error
> STATUS_OBJECT_NAME_NOT_FOUND.
> > >
> > > Also, I found when IO manager create target file
> object with
> > > SL_OPEN_TARGET_DIRECTORY flag, the create option
> is always set as follow:
> > > create options = 0x1000000 (FILE_OPEN,
> attributes = 0)
> > > DesiredAccess (pSecurityContext->DesiredAccess)
> = 0x100002
> > >
> > > When my FS driver call ZwCreateFile(), IO
> manager also dispatch
> > > IRP_MJ_CREATE with the same create option but no
> SL_OPEN_TARGET_DIRECTORY
> > > and it will fail with
> STATUS_OBJECT_NAME_NOT_FOUND.
> > >
> > > I can not figure out what’s wrong in my driver.
> Can anyone give me
> > > some help? Any info will be appreciated.
> > >
> > > Thanks
> > >
> > >
>
> —
> You are currently subscribed to ntfsd as:
> xxxxx@yahoo.com
> To unsubscribe send a blank email to
xxxxx@lists.osr.com

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

This sounds like the correct behavior to me (if I am reading your
description right).

IRP_MJ_CREATE with the SL_OPEN_TARGET_DIRECTORY bit indicates the open
should succeed if the directory (everything except the last component of the
name then) exists. It tells you the open succeeds and that the TARGET does
not exist (FILE_DOES_NOT_EXIST) which indicates that the file object is
created but the file itself doesn’t exist (it will when the rename finishes,
though…)

As for doing this on your own, the previous suggestion (using IoCreateFile
or IoCreateFileSpecifyDeviceObjectHint) is the only viable option.

Have you built a debug version of FAT and traced through the code to figure
out why you are getting the error? I suspect that if you do, you will find
rather quickly what you are doing wrong.

Regards,

Tony

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

-----Original Message-----
From: David Wu [mailto:xxxxx@highstream.net]
Sent: Wednesday, October 22, 2003 12:46 PM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] Re: rename in filter driver

Hi Alexei,
IoCreateFile() doesn’t work either. I still get the same error status.
What else can cause this error status?

Thanks

SL_OPEN_TARGET_DIRECTORY flag is used to open the destination directory
for
a rename operation. ZwCreateFile doesn’t allow to open target directory.
You
need to use IoCreateFile to achieve this.

Alexei.

“David Wu” wrote in message news:xxxxx@ntfsd…
> >
> > Hi All,
> > My FS driver needs to intercept file rename operation and do
> > some additional file rename. For example: when user renames
> > c:\temp1\foo1.txt to c:\temp\bar1.txt, FS driver will rename other
> > file d:\temp2\foo2.txt d:\temp2\bar2.txt at the same time.
> > What I did is as follow:
> > When IO manager creates target file object(IRP_MJ_CREATE with flag
> > SL_OPEN_TARGET_DIRECTORY) for c:\temp1\foo1.txt, I also create
> > target file object for d:\temp2\foo2.txt via ZwCreateFile().
> > The parameters whitch I use in ZwCreateFile come from
> > IrpStack->Parameters.Create:
> >
> > DesiredAccess =
IrpStack->Parameters.Create.SecurityContext->DesiredAccess
> > FileAttributes = IrpStack->Parameters.Create.FileAttributes
> > ShareAccess = IrpStack->Parameters.Create.ShareAccess
> > CreateDisposition = IrpStack->Parameters.Create.Options >> 24) & 0xFF
> > CreateOptions =
> > IrpStack->Parameters.Create.SecurityContext->FullCreateOptions
> >
> > The problem is the target file object created by IO manager
> > will return STATUS_SUCCESS with IoStatus.Information =
> > FILE_DOES_NOT_EXIST. But the target file object create by FS driver
> > will return STATUS_UNSUCCESSFUL with error STATUS_OBJECT_NAME_NOT_FOUND.
> >
> > Also, I found when IO manager create target file object with
> > SL_OPEN_TARGET_DIRECTORY flag, the create option is always set as
follow:
> > create options = 0x1000000 (FILE_OPEN, attributes = 0)
> > DesiredAccess (pSecurityContext->DesiredAccess) = 0x100002
> >
> > When my FS driver call ZwCreateFile(), IO manager also dispatch
> > IRP_MJ_CREATE with the same create option but no
SL_OPEN_TARGET_DIRECTORY
> > and it will fail with STATUS_OBJECT_NAME_NOT_FOUND.
> >
> > I can not figure out what’s wrong in my driver. Can anyone give me
> > some help? Any info will be appreciated.
> >
> > Thanks
> >
> >


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

Yes, the parent dir of the target exists. Any suggestion?
The options of IoCreateFile() or ZwCreatefile() are from
IrpStack->Parameters.Create. Can those options cause
this error?

Thanks.

The error code doesn’t seem right to me for this to be
the problem, but the parent dir of the target exists,
right?

Randy

— David Wu wrote:
> > Hi Alexei,
> > IoCreateFile() doesn’t work either. I still get the
> > same error status.
> > What else can cause this error status?
> >
> > Thanks
> >
> >
> > > SL_OPEN_TARGET_DIRECTORY flag is used to open the
> > destination directory for
> > > a rename operation. ZwCreateFile doesn’t allow to
> > open target directory. You
> > > need to use IoCreateFile to achieve this.
> > >
> > > Alexei.
> > >
> > > “David Wu” wrote in
> > message news:xxxxx@ntfsd…
> > > >
> > > > Hi All,
> > > > My FS driver needs to intercept file rename
> > operation and do
> > > > some additional file rename. For example: when
> > user renames
> > > > c:\temp1\foo1.txt to c:\temp\bar1.txt, FS driver
> > will rename other
> > > > file d:\temp2\foo2.txt d:\temp2\bar2.txt at the
> > same time.
> > > > What I did is as follow:
> > > > When IO manager creates target file
> > object(IRP_MJ_CREATE with flag
> > > > SL_OPEN_TARGET_DIRECTORY) for c:\temp1\foo1.txt,
> > I also create
> > > > target file object for d:\temp2\foo2.txt via
> > ZwCreateFile().
> > > > The parameters whitch I use in ZwCreateFile come
> > from
> > > > IrpStack->Parameters.Create:
> > > >
> > > > DesiredAccess =
> >
> IrpStack->Parameters.Create.SecurityContext->DesiredAccess
> > > > FileAttributes =
> > IrpStack->Parameters.Create.FileAttributes
> > > > ShareAccess =
> > IrpStack->Parameters.Create.ShareAccess
> > > > CreateDisposition =
> > IrpStack->Parameters.Create.Options >> 24) & 0xFF
> > > > CreateOptions =
> > > >
> >
> IrpStack->Parameters.Create.SecurityContext->FullCreateOptions
> > > >
> > > > The problem is the target file object created by
> > IO manager
> > > > will return STATUS_SUCCESS with
> > IoStatus.Information =
> > > > FILE_DOES_NOT_EXIST. But the target file object
> > create by FS driver
> > > > will return STATUS_UNSUCCESSFUL with error
> > STATUS_OBJECT_NAME_NOT_FOUND.
> > > >
> > > > Also, I found when IO manager create target file
> > object with
> > > > SL_OPEN_TARGET_DIRECTORY flag, the create option
> > is always set as follow:
> > > > create options = 0x1000000 (FILE_OPEN,
> > attributes = 0)
> > > > DesiredAccess (pSecurityContext->DesiredAccess)
> > = 0x100002
> > > >
> > > > When my FS driver call ZwCreateFile(), IO
> > manager also dispatch
> > > > IRP_MJ_CREATE with the same create option but no
> > SL_OPEN_TARGET_DIRECTORY
> > > > and it will fail with
> > STATUS_OBJECT_NAME_NOT_FOUND.
> > > >
> > > > I can not figure out what’s wrong in my driver.
> > Can anyone give me
> > > > some help? Any info will be appreciated.
> > > >
> > > > Thanks
> > > >
> > > >
> >
> > —
> > You are currently subscribed to ntfsd as:
> > xxxxx@yahoo.com
> > To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Shopping - with improved product search
> http://shopping.yahoo.com

Can you post the code?

Randy

— David Wu wrote:
> Yes, the parent dir of the target exists. Any
> suggestion?
> The options of IoCreateFile() or ZwCreatefile() are
> from
> IrpStack->Parameters.Create. Can those options
> cause
> this error?
>
> Thanks.
>
> > The error code doesn’t seem right to me for this
> to be
> > the problem, but the parent dir of the target
> exists,
> > right?
> >
> > Randy
> >
> > — David Wu wrote:
> > > Hi Alexei,
> > > IoCreateFile() doesn’t work either. I still get
> the
> > > same error status.
> > > What else can cause this error status?
> > >
> > > Thanks
> > >
> > >
> > > > SL_OPEN_TARGET_DIRECTORY flag is used to open
> the
> > > destination directory for
> > > > a rename operation. ZwCreateFile doesn’t allow
> to
> > > open target directory. You
> > > > need to use IoCreateFile to achieve this.
> > > >
> > > > Alexei.
> > > >
> > > > “David Wu” wrote in
> > > message news:xxxxx@ntfsd…
> > > > >
> > > > > Hi All,
> > > > > My FS driver needs to intercept file rename
> > > operation and do
> > > > > some additional file rename. For example:
> when
> > > user renames
> > > > > c:\temp1\foo1.txt to c:\temp\bar1.txt, FS
> driver
> > > will rename other
> > > > > file d:\temp2\foo2.txt d:\temp2\bar2.txt at
> the
> > > same time.
> > > > > What I did is as follow:
> > > > > When IO manager creates target file
> > > object(IRP_MJ_CREATE with flag
> > > > > SL_OPEN_TARGET_DIRECTORY) for
> c:\temp1\foo1.txt,
> > > I also create
> > > > > target file object for d:\temp2\foo2.txt via
> > > ZwCreateFile().
> > > > > The parameters whitch I use in ZwCreateFile
> come
> > > from
> > > > > IrpStack->Parameters.Create:
> > > > >
> > > > > DesiredAccess =
> > >
> >
>
IrpStack->Parameters.Create.SecurityContext->DesiredAccess
> > > > > FileAttributes =
> > > IrpStack->Parameters.Create.FileAttributes
> > > > > ShareAccess =
> > > IrpStack->Parameters.Create.ShareAccess
> > > > > CreateDisposition =
> > > IrpStack->Parameters.Create.Options >> 24) &
> 0xFF
> > > > > CreateOptions =
> > > > >
> > >
> >
>
IrpStack->Parameters.Create.SecurityContext->FullCreateOptions
> > > > >
> > > > > The problem is the target file object
> created by
> > > IO manager
> > > > > will return STATUS_SUCCESS with
> > > IoStatus.Information =
> > > > > FILE_DOES_NOT_EXIST. But the target file
> object
> > > create by FS driver
> > > > > will return STATUS_UNSUCCESSFUL with error
> > > STATUS_OBJECT_NAME_NOT_FOUND.
> > > > >
> > > > > Also, I found when IO manager create target
> file
> > > object with
> > > > > SL_OPEN_TARGET_DIRECTORY flag, the create
> option
> > > is always set as follow:
> > > > > create options = 0x1000000 (FILE_OPEN,
> > > attributes = 0)
> > > > > DesiredAccess
> (pSecurityContext->DesiredAccess)
> > > = 0x100002
> > > > >
> > > > > When my FS driver call ZwCreateFile(), IO
> > > manager also dispatch
> > > > > IRP_MJ_CREATE with the same create option
> but no
> > > SL_OPEN_TARGET_DIRECTORY
> > > > > and it will fail with
> > > STATUS_OBJECT_NAME_NOT_FOUND.
> > > > >
> > > > > I can not figure out what’s wrong in my
> driver.
> > > Can anyone give me
> > > > > some help? Any info will be appreciated.
> > > > >
> > > > > Thanks
> > > > >
> > > > >
> > >
> > > —
> > > You are currently subscribed to ntfsd as:
> > > xxxxx@yahoo.com
> > > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> >
> >
> >
> > Do you Yahoo!?
> > The New Yahoo! Shopping - with improved product
> search
> > http://shopping.yahoo.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!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

Hi Randy,
Here is some code I did in complete routine.
when user renames c:\temp1\foo1.txt to c:\temp\bar1.txt, FS driver
want to rename d:\temp2\foo2.txt to d:\temp2\bar2.txt at the same time.
I understand other experts said when IO manager open target
c:\temp\bar1.txt
with flag SL_OPEN_TARGET_DIRECTORY, it return success with
FILE_DOES_NOT_EXIST
and prepare to rename. But FS driver follow this prepare to open its own
fully qualified target “\??\d:\temp2\bar2.txt”, I got unsuccessful
with STATUS_OBJECT_NAME_NOT_FOUND.
Should I only open the directory not the fully qualified target name?

Thanks
NTSTATUS CreateComplete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp,
IN PVOID Contex)
{
ULONG CreateDisposition;
ULONG IrpStatusInfo;
PIO_STACK_LOCATION currentIrpStack;
PUNICODE_STRING pusRealFileName;
HANDLE hFile;
POPENCONTEX pOpenContex;
OBJECT_ATTRIBUTES objectAttributes;
NTSTATUS status = STATUS_SUCCESS;

pOpenContex = (POPENCONTEX)Contex;

pusRealFileName = pOpenContex->pusRealFileName;

currentIrpStack = IoGetCurrentIrpStackLocation(Irp);

IrpStatusInfo = Irp->IoStatus.Information;
CreateDisposition = currentIrpStack->Parameters.Create.Options >> 24)
& 0xFF;

if (NT_SUCCESS(Irp->IoStatus.Status) && (currentIrpStack->Flags &
SL_OPEN_TARGET_DIRECTORY)) {

RtlZeroMemory(&objectAttributes, sizeof(objectAttributes));
InitializeObjectAttributes(&objectAttributes,
pusRealFileName,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL,
NULL);

status = ZwCreateFile(&hFile,
currentIrpStack->Parameters.Create.SecurityContext>DesiredAccess,
&objectAttributes, // IN POBJECT_ATTRIBUTES ObjectAttributes
&Irp->IoStatus, // OUT PIO_STATUS_BLOCK IoStatusBlock
NULL, // IN PLARGE_INTEGER AllocationSize
currentIrpStack->Parameters.Create.FileAttributes,
currentIrpStack->Parameters.Create.ShareAccess,
CreateDisposition,

currentIrpStack->Parameters.Create.SecurityContext->FullCreateOptions,
NULL, // EaBuffer
0); // EaLength
}
return status;
}

Can you post the code?

Randy

— David Wu wrote:
> > Yes, the parent dir of the target exists. Any
> > suggestion?
> > The options of IoCreateFile() or ZwCreatefile() are
> > from
> > IrpStack->Parameters.Create. Can those options
> > cause
> > this error?
> >
> > Thanks.
> >
> > > The error code doesn’t seem right to me for this
> > to be
> > > the problem, but the parent dir of the target
> > exists,
> > > right?
> > >
> > > Randy
> > >
> > > — David Wu wrote:
> > > > Hi Alexei,
> > > > IoCreateFile() doesn’t work either. I still get
> > the
> > > > same error status.
> > > > What else can cause this error status?
> > > >
> > > > Thanks
> > > >
> > > >
> > > > > SL_OPEN_TARGET_DIRECTORY flag is used to open
> > the
> > > > destination directory for
> > > > > a rename operation. ZwCreateFile doesn’t allow
> > to
> > > > open target directory. You
> > > > > need to use IoCreateFile to achieve this.
> > > > >
> > > > > Alexei.
> > > > >
> > > > > “David Wu” wrote in
> > > > message news:xxxxx@ntfsd…
> > > > > >
> > > > > > Hi All,
> > > > > > My FS driver needs to intercept file rename
> > > > operation and do
> > > > > > some additional file rename. For example:
> > when
> > > > user renames
> > > > > > c:\temp1\foo1.txt to c:\temp\bar1.txt, FS
> > driver
> > > > will rename other
> > > > > > file d:\temp2\foo2.txt d:\temp2\bar2.txt at
> > the
> > > > same time.
> > > > > > What I did is as follow:
> > > > > > When IO manager creates target file
> > > > object(IRP_MJ_CREATE with flag
> > > > > > SL_OPEN_TARGET_DIRECTORY) for
> > c:\temp1\foo1.txt,
> > > > I also create
> > > > > > target file object for d:\temp2\foo2.txt via
> > > > ZwCreateFile().
> > > > > > The parameters whitch I use in ZwCreateFile
> > come
> > > > from
> > > > > > IrpStack->Parameters.Create:
> > > > > >
> > > > > > DesiredAccess =
> > > >
> > >
> >
> IrpStack->Parameters.Create.SecurityContext->DesiredAccess
> > > > > > FileAttributes =
> > > > IrpStack->Parameters.Create.FileAttributes
> > > > > > ShareAccess =
> > > > IrpStack->Parameters.Create.ShareAccess
> > > > > > CreateDisposition =
> > > > IrpStack->Parameters.Create.Options >> 24) &
> > 0xFF
> > > > > > CreateOptions =
> > > > > >
> > > >
> > >
> >
> IrpStack->Parameters.Create.SecurityContext->FullCreateOptions
> > > > > >
> > > > > > The problem is the target file object
> > created by
> > > > IO manager
> > > > > > will return STATUS_SUCCESS with
> > > > IoStatus.Information =
> > > > > > FILE_DOES_NOT_EXIST. But the target file
> > object
> > > > create by FS driver
> > > > > > will return STATUS_UNSUCCESSFUL with error
> > > > STATUS_OBJECT_NAME_NOT_FOUND.
> > > > > >
> > > > > > Also, I found when IO manager create target
> > file
> > > > object with
> > > > > > SL_OPEN_TARGET_DIRECTORY flag, the create
> > option
> > > > is always set as follow:
> > > > > > create options = 0x1000000 (FILE_OPEN,
> > > > attributes = 0)
> > > > > > DesiredAccess
> > (pSecurityContext->DesiredAccess)
> > > > = 0x100002
> > > > > >
> > > > > > When my FS driver call ZwCreateFile(), IO
> > > > manager also dispatch
> > > > > > IRP_MJ_CREATE with the same create option
> > but no
> > > > SL_OPEN_TARGET_DIRECTORY
> > > > > > and it will fail with
> > > > STATUS_OBJECT_NAME_NOT_FOUND.
> > > > > >
> > > > > > I can not figure out what’s wrong in my
> > driver.
> > > > Can anyone give me
> > > > > > some help? Any info will be appreciated.
> > > > > >
> > > > > > Thanks
> > > > > >
> > > > > >
> > > >
> > > > —
> > > > You are currently subscribed to ntfsd as:
> > > > xxxxx@yahoo.com
> > > > To unsubscribe send a blank email to
> > > xxxxx@lists.osr.com
> > >
> > >
> > >
> > > Do you Yahoo!?
> > > The New Yahoo! Shopping - with improved product
> > search
> > > http://shopping.yahoo.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!?
> The New Yahoo! Shopping - with improved product search
> http://shopping.yahoo.com

You can’t use ZwCreateFile. There is no way to pass
it the SL_OPEN_TARGET_DIRECTORY flag. You must use
IoCreateFile.

In answer to your question, you need to specify the
full target name, not it’s parent directory name.

The target parent directory must exist.

You don’t show where you set up
pOpenContex->pusRealFileName. Make sure it is a
properly set up unicode string.

Windows opens many files with SL_OPEN_TARGET_DIRECTORY
that it never intends to rename. If you want to do
something when a rename happens, do it when you see
the SET_INFORMATION irp come through.

Be careful what you do in a completion routine. It
sometimes is executed at a different IRQL than you may
be expecting. Check everything you call to make sure
it is safe.

Don’t start variable names with pus. It’s yucky.
(just kidding :slight_smile:

Good luck.

— David Wu wrote:
> Hi Randy,
> Here is some code I did in complete routine.
> when user renames c:\temp1\foo1.txt to
> c:\temp\bar1.txt, FS driver
> want to rename d:\temp2\foo2.txt to
> d:\temp2\bar2.txt at the same time.
> I understand other experts said when IO manager open
> target
> c:\temp\bar1.txt
> with flag SL_OPEN_TARGET_DIRECTORY, it return
> success with
> FILE_DOES_NOT_EXIST
> and prepare to rename. But FS driver follow this
> prepare to open its own
> fully qualified target “\??\d:\temp2\bar2.txt”, I
> got unsuccessful
> with STATUS_OBJECT_NAME_NOT_FOUND.
> Should I only open the directory not the fully
> qualified target name?
>
> Thanks
> NTSTATUS CreateComplete(IN PDEVICE_OBJECT
> DeviceObject, IN PIRP Irp,
> IN PVOID Contex)
> {
> ULONG CreateDisposition;
> ULONG IrpStatusInfo;
> PIO_STACK_LOCATION currentIrpStack;
> PUNICODE_STRING pusRealFileName;
> HANDLE hFile;
> POPENCONTEX pOpenContex;
> OBJECT_ATTRIBUTES objectAttributes;
> NTSTATUS status = STATUS_SUCCESS;
>
> pOpenContex = (POPENCONTEX)Contex;
>
> pusRealFileName =
> pOpenContex->pusRealFileName;
>
> currentIrpStack =
> IoGetCurrentIrpStackLocation(Irp);
>
> IrpStatusInfo = Irp->IoStatus.Information;
> CreateDisposition =
> currentIrpStack->Parameters.Create.Options >> 24)
> & 0xFF;
>
> if (NT_SUCCESS(Irp->IoStatus.Status) &&
> (currentIrpStack->Flags &
> SL_OPEN_TARGET_DIRECTORY)) {
>
> RtlZeroMemory(&objectAttributes,
> sizeof(objectAttributes));
> InitializeObjectAttributes(&objectAttributes,
> pusRealFileName,
> OBJ_CASE_INSENSITIVE
> | OBJ_KERNEL_HANDLE,
> NULL,
> NULL);
>
> status = ZwCreateFile(&hFile,
>
>
currentIrpStack->Parameters.Create.SecurityContext>DesiredAccess,
> &objectAttributes, // IN POBJECT_ATTRIBUTES
> ObjectAttributes
> &Irp->IoStatus, // OUT
> PIO_STATUS_BLOCK IoStatusBlock
> NULL, // IN PLARGE_INTEGER
> AllocationSize
>
> currentIrpStack->Parameters.Create.FileAttributes,
>
> currentIrpStack->Parameters.Create.ShareAccess,
> CreateDisposition,
>
>
currentIrpStack->Parameters.Create.SecurityContext->FullCreateOptions,
> NULL, // EaBuffer
> 0); // EaLength
> }
> return status;
> }
>

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com