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