File Rename failing with STATUS_OBJECT_NAME_INVALID.

Hi,
I am trying to rename a file (move to recycler managed by us) whenever
user deletes the file. I went through this post and also article on OSR:
http://www.osronline.com/showThread.cfm?link=15483
http://www.osronline.com/showThread.cfm?link=53443

My Rename is failing with STATUS_OBJECT_NAME_INVALID. If I try simple name
(setting both FileObject and RootDirectory NULL) then it works fine. How can
I find out which object name is invalid - Source object, Target Directory or
Filename. I cannot use Zw function as it causes to post
IRP_MJ_SET_INFORMATION back to my driver which interferes with our own logic
to disallow user to manage our recycler. So we use IRP_MJ call to send the
request down.

There was other thing which I notice in OSR article - When getting full
target path for Relative Name, we first get directory object using handle
passed in RootHandle but according to MSDN documentation, the target
directory file object is passed in IRP:

*IrpSp->Parameters.SetFile.FileObject*For rename or link operations. If *
Irp->AssociatedIrp.SystemBuffer->FileName* contains a fully qualified file
name, or if *Irp->AssociatedIrp.SystemBuffer->RootDirectory* is non-NULL,
this member is a file object pointer for the parent directory of the file
that is the target of the operation. Otherwise it is NULL.

So why we need to explicitly get FileObject of the directory object ??
Here is the code I am using to do a Rename using IRP.
swprintf(pFullFileName,
L"\DosDevices\F:\DxLogs\Recycler\Rename");

RtlInitUnicodeString(&uFullFileName, pFullFileName);

DbgPrint(“Unicode String Buffer %ws Length : %d Max Length : %d\n”,
uFullFileName.Buffer, uFullFileName.Length, uFullFileName.MaximumLength);

InitializeObjectAttributes(&ObjectAttr, &uFullFileName,
OBJ_CASE_INSENSITIVE, NULL, NULL );

Status = IoCreateFileSpecifyDeviceObjectHint( &Handle, 0,
&ObjectAttr, &IoStatus, NULL, 0, 0, FILE_OPEN_IF,

FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT | FILE_WRITE_THROUGH,
NULL, 0,
CreateFileTypeNone, NULL, 0, pDO );

if ( NT_SUCCESS(Status) )
Status = ObReferenceObjectByHandle(Handle, SYNCHRONIZE, *IoFileObjectType,
KernelMode, (PVOID *)ppFO, NULL);

I am doing a Relative Rename where I pass the handle obtained above and just
the filename of the target filename. Here is how I setup my File Rename
Structure.

wcscpy(pNameInfo->FileName, “Target.txt”);

pNameInfo->FileNameLength =
(wcslen(pNameInfo->FileName)*sizeof(WCHAR)); //filename

pNameInfo->ReplaceIfExists = TRUE;

pNameInfo->RootDirectory = Handle;

Here is how I create a IRP

Length = sizeof(FILE_RENAME_INFORMATION)+pNameInfo->FileNameLength;

irp = IoAllocateIrp( pDO->StackSize, FALSE );

irp->Tail.Overlay.OriginalFileObject = pFO;
irp->Tail.Overlay.Thread = PsGetCurrentThread();

irp->RequestorMode = KernelMode;
irp->UserEvent = &event;
irp->Flags = IRP_SYNCHRONOUS_API | IRP_BUFFERED_IO;
irp->UserIosb = &IoStatus;
irp->Overlay.AsynchronousParameters.UserApcRoutine = (PIO_APC_ROUTINE)
NULL;
irp->AssociatedIrp.SystemBuffer = pNameInfo;

irpSp = IoGetNextIrpStackLocation( irp );
irpSp->FileObject = pFO;
irpSp->DeviceObject = pDO;
irpSp->MajorFunction = IRP_MJ_SET_INFORMATION;
irpSp->Parameters.SetFile.Length = Length;
irpSp->Parameters.SetFile.FileInformationClass =
FileRenameInformation;
irpSp->Parameters.SetFile.AdvanceOnly = FALSE;
irpSp->Parameters.SetFile.FileObject = *ppFO;

IoSetCompletionRoutine( irp,
SetFileInfoCompletionRoutine,
0,
TRUE,
TRUE,
TRUE );

status = IoCallDriver( pDO, irp );

Any help ?

Thanks
Ash

Does this also fail over FAT? Sometimes the fastest thing to do is install a
checked build of FASTFAT and step through the failing call.

-scott


Scott Noone
Consulting Associate
OSR Open Systems Resources, Inc.
http://www.osronline.com

“Ashish Goyal” wrote in message
news:xxxxx@ntfsd…
Hi,
I am trying to rename a file (move to recycler managed by us) whenever
user deletes the file. I went through this post and also article on OSR:
http://www.osronline.com/showThread.cfm?link=15483
http://www.osronline.com/showThread.cfm?link=53443

My Rename is failing with STATUS_OBJECT_NAME_INVALID. If I try simple name
(setting both FileObject and RootDirectory NULL) then it works fine. How can
I find out which object name is invalid - Source object, Target Directory or
Filename. I cannot use Zw function as it causes to post
IRP_MJ_SET_INFORMATION back to my driver which interferes with our own logic
to disallow user to manage our recycler. So we use IRP_MJ call to send the
request down.

There was other thing which I notice in OSR article - When getting full
target path for Relative Name, we first get directory object using handle
passed in RootHandle but according to MSDN documentation, the target
directory file object is passed in IRP:

IrpSp->Parameters.SetFile.FileObject
For rename or link operations. If Irp->AssociatedIrp.SystemBuffer->FileName
contains a fully qualified file name, or if
Irp->AssociatedIrp.SystemBuffer->RootDirectory is non-NULL, this member is a
file object pointer for the parent directory of the file that is the target
of the operation. Otherwise it is NULL.

So why we need to explicitly get FileObject of the directory object ??

Here is the code I am using to do a Rename using IRP.

swprintf(pFullFileName,
L"\DosDevices\F:\DxLogs\Recycler\Rename");

RtlInitUnicodeString(&uFullFileName, pFullFileName);

DbgPrint(“Unicode String Buffer %ws Length : %d Max Length : %d\n”,
uFullFileName.Buffer, uFullFileName.Length, uFullFileName.MaximumLength);

InitializeObjectAttributes(&ObjectAttr, &uFullFileName,
OBJ_CASE_INSENSITIVE, NULL, NULL );

Status = IoCreateFileSpecifyDeviceObjectHint( &Handle, 0,
&ObjectAttr, &IoStatus, NULL, 0, 0, FILE_OPEN_IF,
FILE_DIRECTORY_FILE
| FILE_SYNCHRONOUS_IO_NONALERT | FILE_WRITE_THROUGH,
NULL, 0,
CreateFileTypeNone, NULL, 0, pDO );

if ( NT_SUCCESS(Status) )
Status = ObReferenceObjectByHandle(Handle, SYNCHRONIZE, *IoFileObjectType,
KernelMode, (PVOID *)ppFO, NULL);

I am doing a Relative Rename where I pass the handle obtained above and just
the filename of the target filename. Here is how I setup my File Rename
Structure.

wcscpy(pNameInfo->FileName, “Target.txt”);

pNameInfo->FileNameLength =
(wcslen(pNameInfo->FileName)*sizeof(WCHAR)); //filename

pNameInfo->ReplaceIfExists = TRUE;

pNameInfo->RootDirectory = Handle;

Here is how I create a IRP

Length = sizeof(FILE_RENAME_INFORMATION)+pNameInfo->FileNameLength;

irp = IoAllocateIrp( pDO->StackSize, FALSE );

irp->Tail.Overlay.OriginalFileObject = pFO;
irp->Tail.Overlay.Thread = PsGetCurrentThread();

irp->RequestorMode = KernelMode;
irp->UserEvent = &event;
irp->Flags = IRP_SYNCHRONOUS_API | IRP_BUFFERED_IO;
irp->UserIosb = &IoStatus;
irp->Overlay.AsynchronousParameters.UserApcRoutine = (PIO_APC_ROUTINE)
NULL;
irp->AssociatedIrp.SystemBuffer = pNameInfo;

irpSp = IoGetNextIrpStackLocation( irp );
irpSp->FileObject = pFO;
irpSp->DeviceObject = pDO;
irpSp->MajorFunction = IRP_MJ_SET_INFORMATION;
irpSp->Parameters.SetFile.Length = Length;
irpSp->Parameters.SetFile.FileInformationClass =
FileRenameInformation;
irpSp->Parameters.SetFile.AdvanceOnly = FALSE;
irpSp->Parameters.SetFile.FileObject = *ppFO;

IoSetCompletionRoutine( irp,
SetFileInfoCompletionRoutine,
0,
TRUE,
TRUE,
TRUE );

status = IoCallDriver( pDO, irp );

Any help ?

Thanks
Ash

I did not try on FAT but I did check the FASTFAT code to check FIle Rename
function and I found two places where it returns STATUS_OBJECT_NAME_INVALID:

  1. If the filename is greater then 255*sizeof(WCHAR)
  2. If it is not a valid 8.3 DOS name.

But none of the case is valid here as I printed the size of FileName buffer
below and they are far below then 255 limit.

Thanks
Ashish

On Mon, Mar 1, 2010 at 9:58 PM, Scott Noone wrote:

> Does this also fail over FAT? Sometimes the fastest thing to do is install
> a checked build of FASTFAT and step through the failing call.
>
>
> -scott
>
> –
> Scott Noone
> Consulting Associate
> OSR Open Systems Resources, Inc.
> http://www.osronline.com
>
> “Ashish Goyal” wrote in message
> news:xxxxx@ntfsd…
>
> Hi,
> I am trying to rename a file (move to recycler managed by us) whenever
> user deletes the file. I went through this post and also article on OSR:
> http://www.osronline.com/showThread.cfm?link=15483
> http://www.osronline.com/showThread.cfm?link=53443
>
>
> My Rename is failing with STATUS_OBJECT_NAME_INVALID. If I try simple name
> (setting both FileObject and RootDirectory NULL) then it works fine. How can
> I find out which object name is invalid - Source object, Target Directory or
> Filename. I cannot use Zw function as it causes to post
> IRP_MJ_SET_INFORMATION back to my driver which interferes with our own logic
> to disallow user to manage our recycler. So we use IRP_MJ call to send the
> request down.
>
>
> There was other thing which I notice in OSR article - When getting full
> target path for Relative Name, we first get directory object using handle
> passed in RootHandle but according to MSDN documentation, the target
> directory file object is passed in IRP:
>
>
> IrpSp->Parameters.SetFile.FileObject
> For rename or link operations. If Irp->AssociatedIrp.SystemBuffer->FileName
> contains a fully qualified file name, or if
> Irp->AssociatedIrp.SystemBuffer->RootDirectory is non-NULL, this member is a
> file object pointer for the parent directory of the file that is the target
> of the operation. Otherwise it is NULL.
>
>
>
>
> So why we need to explicitly get FileObject of the directory object ??
>
>
> Here is the code I am using to do a Rename using IRP.
>
>
> swprintf(pFullFileName,
> L"\DosDevices\F:\DxLogs\Recycler\Rename");
>
>
> RtlInitUnicodeString(&uFullFileName, pFullFileName);
>
>
> DbgPrint(“Unicode String Buffer %ws Length : %d Max Length : %d\n”,
> uFullFileName.Buffer, uFullFileName.Length, uFullFileName.MaximumLength);
>
>
> InitializeObjectAttributes(&ObjectAttr, &uFullFileName,
> OBJ_CASE_INSENSITIVE, NULL, NULL );
>
>
> Status = IoCreateFileSpecifyDeviceObjectHint( &Handle, 0,
> &ObjectAttr, &IoStatus, NULL, 0, 0, FILE_OPEN_IF,
> FILE_DIRECTORY_FILE
> | FILE_SYNCHRONOUS_IO_NONALERT | FILE_WRITE_THROUGH,
> NULL, 0,
> CreateFileTypeNone, NULL, 0, pDO );
>
>
> if ( NT_SUCCESS(Status) )
> Status = ObReferenceObjectByHandle(Handle, SYNCHRONIZE, *IoFileObjectType,
> KernelMode, (PVOID *)ppFO, NULL);
>
>
> I am doing a Relative Rename where I pass the handle obtained above and
> just the filename of the target filename. Here is how I setup my File Rename
> Structure.
>
>
> wcscpy(pNameInfo->FileName, “Target.txt”);
>
>
> pNameInfo->FileNameLength =
> (wcslen(pNameInfo->FileName)*sizeof(WCHAR)); //filename
>
> pNameInfo->ReplaceIfExists = TRUE;
>
>
> pNameInfo->RootDirectory = Handle;
>
>
>
>
> Here is how I create a IRP
>
>
> Length = sizeof(FILE_RENAME_INFORMATION)+pNameInfo->FileNameLength;
>
>
> irp = IoAllocateIrp( pDO->StackSize, FALSE );
>
>
> irp->Tail.Overlay.OriginalFileObject = pFO;
> irp->Tail.Overlay.Thread = PsGetCurrentThread();
>
>
> irp->RequestorMode = KernelMode;
> irp->UserEvent = &event;
> irp->Flags = IRP_SYNCHRONOUS_API | IRP_BUFFERED_IO;
> irp->UserIosb = &IoStatus;
> irp->Overlay.AsynchronousParameters.UserApcRoutine = (PIO_APC_ROUTINE)
> NULL;
> irp->AssociatedIrp.SystemBuffer = pNameInfo;
>
>
> irpSp = IoGetNextIrpStackLocation( irp );
> irpSp->FileObject = pFO;
> irpSp->DeviceObject = pDO;
> irpSp->MajorFunction = IRP_MJ_SET_INFORMATION;
> irpSp->Parameters.SetFile.Length = Length;
> irpSp->Parameters.SetFile.FileInformationClass = FileRenameInformation;
> irpSp->Parameters.SetFile.AdvanceOnly = FALSE;
> irpSp->Parameters.SetFile.FileObject = *ppFO;
>
> IoSetCompletionRoutine( irp,
> SetFileInfoCompletionRoutine,
> 0,
> TRUE,
> TRUE,
> TRUE );
>
>
> status = IoCallDriver( pDO, irp );
>
>
> Any help ?
>
>
> Thanks
> Ash
>
> —
> NTFSD is sponsored by OSR
>
> For our schedule of debugging and file system seminars
> (including our new fs mini-filter seminar) 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
>

Try change the following
???swprintf(pFullFileName, L"\DosDevices\F:\DxLogs\Recycler\Rename");
to

???swprintf(pFullFileName, L\Recycler\Rename);

?
Note you are sending the rename to an existing file object and the device is already known, you cannot do a rename to another device anyway.
So just give the path in the context of that device.
?
Lijun
?


From: Ashish Goyal
To: Windows File Systems Devs Interest List
Sent: Mon, March 1, 2010 6:19:48 AM
Subject: [ntfsd] File Rename failing with STATUS_OBJECT_NAME_INVALID.

Hi,
??I am trying to rename a file (move to recycler managed by us) whenever user deletes the file. I went through this post and also article on OSR:
http://www.osronline.com/showThread.cfm?link=15483
http://www.osronline.com/showThread.cfm?link=53443

My Rename is failing with STATUS_OBJECT_NAME_INVALID. If I try simple name (setting both FileObject and RootDirectory NULL) then it works fine. How can I find out which object name is invalid - Source object, Target Directory or Filename. I cannot use Zw function as it causes to post IRP_MJ_SET_INFORMATION back to my driver which interferes with our own logic to disallow user to manage our recycler. So we use IRP_MJ call to send the request down.?

There was other thing which I notice in OSR article - When getting full target path for Relative Name, we first get directory object using handle passed in RootHandle but according to MSDN documentation, the target directory file object is passed in IRP:

IrpSp->Parameters.SetFile.FileObject
For rename or link operations. If?Irp->AssociatedIrp.SystemBuffer->FileName?contains a fully qualified file name, or if?Irp->AssociatedIrp.SystemBuffer->RootDirectory?is non-NULL, this member is a file object pointer for the parent directory of the file that is the target of the operation. Otherwise it is NULL.

So why we need to explicitly get FileObject of the directory object ??

Here is the code I am using to do a Rename using IRP.

?? ??? ?swprintf(pFullFileName, L"\DosDevices\F:\DxLogs\Recycler\Rename");

?? ? ? ? ? ?RtlInitUnicodeString(&uFullFileName, pFullFileName);

DbgPrint(“Unicode String Buffer %wsLength : %dMax Length : %d\n”, uFullFileName.Buffer, uFullFileName.Length, uFullFileName.MaximumLength);

?? ? ? ? ? ?InitializeObjectAttributes(&ObjectAttr, &uFullFileName, OBJ_CASE_INSENSITIVE, NULL, NULL );

?? ? ? ? ? ?Status = IoCreateFileSpecifyDeviceObjectHint( &Handle, 0, &ObjectAttr, &IoStatus, NULL, 0, 0, FILE_OPEN_IF,?
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT | FILE_WRITE_THROUGH,?
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?NULL, 0, CreateFileTypeNone, NULL, 0, pDO );

if ( NT_SUCCESS(Status) )
Status = ObReferenceObjectByHandle(Handle, SYNCHRONIZE, *IoFileObjectType, KernelMode, (PVOID *)ppFO, NULL);

I am doing a Relative Rename where I pass the handle obtained above and just the filename of the target filename. Here is how I setup my File Rename Structure.

?? ? ? ? ? ? ? ? wcscpy(pNameInfo->FileName, “Target.txt”);

?? ? ? ? ? ? ? ? ?pNameInfo->FileNameLength = (wcslen(pNameInfo->FileName)*sizeof(WCHAR)); //filename
??
??pNameInfo->ReplaceIfExists = TRUE;

??pNameInfo->RootDirectory = Handle;

Here is how I create a IRP

Length =?sizeof(FILE_RENAME_INFORMATION)+pNameInfo->FileNameLength;

irp = IoAllocateIrp( pDO->StackSize, FALSE );

?? ? ?irp->Tail.Overlay.OriginalFileObject = pFO;
?? ? ?irp->Tail.Overlay.Thread = PsGetCurrentThread();

?? ? ?irp->RequestorMode = KernelMode;
?? ? ?irp->UserEvent = &event;
?? ? ?irp->Flags = IRP_SYNCHRONOUS_API | IRP_BUFFERED_IO;
?? ? ?irp->UserIosb = &IoStatus;
?? ? ?irp->Overlay.AsynchronousParameters.UserApcRoutine = (PIO_APC_ROUTINE) NULL;
?? ? ?irp->AssociatedIrp.SystemBuffer = pNameInfo;

?? ? ?irpSp = IoGetNextIrpStackLocation( irp );
?? ? ?irpSp->FileObject = pFO;
?? ? ?irpSp->DeviceObject = pDO;
?? ? ?irpSp->MajorFunction = IRP_MJ_SET_INFORMATION;
?? ? ?irpSp->Parameters.SetFile.Length = Length;
?? ? ?irpSp->Parameters.SetFile.FileInformationClass = FileRenameInformation;
?? ? ?irpSp->Parameters.SetFile.AdvanceOnly = FALSE;
?? ? ?irpSp->Parameters.SetFile.FileObject = *ppFO;
?? ? ?
?? ? ?IoSetCompletionRoutine( irp,
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?SetFileInfoCompletionRoutine,
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0,
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TRUE,
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TRUE,
?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TRUE );

?? ? ?status = IoCallDriver( pDO, irp );

Any help ?

Thanks
Ash
— NTFSD is sponsored by OSR For our schedule of debugging and file system seminars (including our new fs mini-filter seminar) 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

But InitializeObjectAttributes requires fully Qualified name. See the
documentation below:

*PUNICODE_STRING ObjectName*A pointer to a buffered Unicode string naming
the file to be created or opened. This value must be a fully qualified file
specification, unless it is the name of a file relative to the directory
specified by *RootDirectory.*For example, *\Device\Floppy1\myfile.dat *or *
??\B:\myfile.dat* could be the fully qualified file specification, provided
that the floppy driver and overlying file system are already loaded. (Note
that *??*replaces *\DosDevices *as the name of the Win32 object namespace.
*\DosDevices *will still work, but *?? *is translated faster by the object
manager.)
On Mon, Mar 1, 2010 at 11:24 PM, Lijun Wang wrote:

> Try change the following
> swprintf(pFullFileName,
> L"\DosDevices\F:\DxLogs\Recycler\Rename");
>
> to
> swprintf(pFullFileName, L\Recycler\Rename);
>
>
> Note you are sending the rename to an existing file object and the device
> is already known, you cannot do a rename to another device anyway.
> So just give the path in the context of that device.
>
> Lijun
>
> ------------------------------
> From: Ashish Goyal
> To: Windows File Systems Devs Interest List
> Sent: Mon, March 1, 2010 6:19:48 AM
> Subject: [ntfsd] File Rename failing with STATUS_OBJECT_NAME_INVALID.
>
> Hi,
> I am trying to rename a file (move to recycler managed by us) whenever
> user deletes the file. I went through this post and also article on OSR:
> http://www.osronline.com/showThread.cfm?link=15483
> http://www.osronline.com/showThread.cfm?link=53443
>
> My Rename is failing with STATUS_OBJECT_NAME_INVALID. If I try simple name
> (setting both FileObject and RootDirectory NULL) then it works fine. How can
> I find out which object name is invalid - Source object, Target Directory or
> Filename. I cannot use Zw function as it causes to post
> IRP_MJ_SET_INFORMATION back to my driver which interferes with our own logic
> to disallow user to manage our recycler. So we use IRP_MJ call to send the
> request down.
>
> There was other thing which I notice in OSR article - When getting full
> target path for Relative Name, we first get directory object using handle
> passed in RootHandle but according to MSDN documentation, the target
> directory file object is passed in IRP:
>
> IrpSp->Parameters.SetFile.FileObject For rename or link operations. If
> Irp->AssociatedIrp.SystemBuffer->FileName contains a fully qualified
> file name, or if Irp->AssociatedIrp.SystemBuffer->RootDirectory is
> non-NULL, this member is a file object pointer for the parent directory of
> the file that is the target of the operation. Otherwise it is NULL.
>
> So why we need to explicitly get FileObject of the directory object ??
> Here is the code I am using to do a Rename using IRP.
> swprintf(pFullFileName,
> L"\DosDevices\F:\DxLogs\Recycler\Rename");
>
> RtlInitUnicodeString(&uFullFileName, pFullFileName);
>
> DbgPrint(“Unicode String Buffer %ws Length : %d Max Length : %d\n”,
> uFullFileName.Buffer, uFullFileName.Length, uFullFileName.MaximumLength);
>
> InitializeObjectAttributes(&ObjectAttr, &uFullFileName,
> OBJ_CASE_INSENSITIVE, NULL, NULL );
>
> Status = IoCreateFileSpecifyDeviceObjectHint( &Handle, 0,
> &ObjectAttr, &IoStatus, NULL, 0, 0, FILE_OPEN_IF,
>
> FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT | FILE_WRITE_THROUGH,
> NULL, 0,
> CreateFileTypeNone, NULL, 0, pDO );
>
> if ( NT_SUCCESS(Status) )
> Status = ObReferenceObjectByHandle(Handle, SYNCHRONIZE, *IoFileObjectType,
> KernelMode, (PVOID *)ppFO, NULL);
>
> I am doing a Relative Rename where I pass the handle obtained above and
> just the filename of the target filename. Here is how I setup my File Rename
> Structure.
>
> wcscpy(pNameInfo->FileName, “Target.txt”);
>
> pNameInfo->FileNameLength =
> (wcslen(pNameInfo->FileName)*sizeof(WCHAR)); //filename
>
> pNameInfo->ReplaceIfExists = TRUE;
>
> pNameInfo->RootDirectory = Handle;
>
>
> Here is how I create a IRP
>
> Length = sizeof(FILE_RENAME_INFORMATION)+pNameInfo->FileNameLength;
>
> irp = IoAllocateIrp( pDO->StackSize, FALSE );
>
> irp->Tail.Overlay.OriginalFileObject = pFO;
> irp->Tail.Overlay.Thread = PsGetCurrentThread();
>
> irp->RequestorMode = KernelMode;
> irp->UserEvent = &event;
> irp->Flags = IRP_SYNCHRONOUS_API | IRP_BUFFERED_IO;
> irp->UserIosb = &IoStatus;
> irp->Overlay.AsynchronousParameters.UserApcRoutine =
> (PIO_APC_ROUTINE) NULL;
> irp->AssociatedIrp.SystemBuffer = pNameInfo;
>
> irpSp = IoGetNextIrpStackLocation( irp );
> irpSp->FileObject = pFO;
> irpSp->DeviceObject = pDO;
> irpSp->MajorFunction = IRP_MJ_SET_INFORMATION;
> irpSp->Parameters.SetFile.Length = Length;
> irpSp->Parameters.SetFile.FileInformationClass =
> FileRenameInformation;
> irpSp->Parameters.SetFile.AdvanceOnly = FALSE;
> irpSp->Parameters.SetFile.FileObject = *ppFO;
>
> IoSetCompletionRoutine( irp,
> SetFileInfoCompletionRoutine,
> 0,
> TRUE,
> TRUE,
> TRUE );
>
> status = IoCallDriver( pDO, irp );
>
> Any help ?
>
> Thanks
> Ash
> — NTFSD is sponsored by OSR For our schedule of debugging and file system
> seminars (including our new fs mini-filter seminar) 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
>
> For our schedule of debugging and file system seminars
> (including our new fs mini-filter seminar) 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
>

I think there is something subtly wrong… instead try

  • Compute the full path for the target
  • Call IoCreateFileSpecifyDeviceObjectHint with that path, and specify the extended option IO_OPEN_TARGET_DIRECTORY
  • Use that file object for the SetFile information irpSp->Parameters.SetFile.FileObject
  • Do not set the Root Directory in the Rename information
  • Specify the full path in the rename information.
  • You probably want FILE_OPEN not FILE_OPEN_IF in IoCreateFileSpe…
  • You probably want FILE_SHARE_VALID_FLAGS as the sharing in that call as well…

I dunno if you should specify FILE_DIRECTORY_FILE if you are trying to do an SL_OPEN_TARGET_DIRECTORY…

Stepping through the FAT implementation of it will probably make some things clearer.

Ok. Sorry, I miss read your code. I thought pFullFileName?is for the target. Here is what?I think is wrong,

The file opened by IoCreateFileSpecifyDeviceObjectHint must be your source file being renamed. And???pNameInfo->RootDirectory? must be the parent folder of your destination file. In your case, you are making them the same!

If you are directly renaming a file say a.txt to b.txt, you should not specifiy the parent folder at all.

In case of you are renaming to a different folder, you need to do two opens if you want to use RootDirectory: open the source file and then the parent folder of the destination if you want to use the and do the rename. You specify?RootDirectory?usually?only when you already have a destination parent folder open.

If you you do not, then, you should instead directly give the abolute path for the destination file – stripping the device prefixes.

Lijun


From: Ashish Goyal
To: Windows File Systems Devs Interest List
Sent: Tue, March 2, 2010 12:02:22 AM
Subject: Re: [ntfsd] File Rename failing with STATUS_OBJECT_NAME_INVALID.

But InitializeObjectAttributes requires fully Qualified name. See the documentation below:

PUNICODE_STRING ObjectName A pointer to a buffered Unicode string naming the file to be created or opened. This value must be a fully qualified file specification, unless it is the name of a file relative to the directory specified by?RootDirectory.For example,?\Device\Floppy1\myfile.dat?or???\B:\myfile.dat?could be the fully qualified file specification, provided that the floppy driver and overlying file system are already loaded. (Note that???replaces?\DosDevices?as the name of the Win32 object namespace.?\DosDevices?will still work, but????is translated faster by the object manager.)

On Mon, Mar 1, 2010 at 11:24 PM, Lijun Wang wrote:

Try change the following
>???swprintf(pFullFileName, L"\DosDevices\F:\DxLogs\Recycler\Rename");
>
>to
>
>???swprintf(pFullFileName, L\Recycler\Rename);
>
>?
>Note you are sending the rename to an existing file object and the device is already known, you cannot do a rename to another device anyway.
>So just give the path in the context of that device.
>?
>Lijun
>?
>
________________________________

>From: Ashish Goyal
>To: Windows File Systems Devs Interest List
>Sent: Mon, March 1, 2010 6:19:48 AM
>Subject: [ntfsd] File Rename failing with STATUS_OBJECT_NAME_INVALID.
>
>
>Hi,
>??I am trying to rename a file (move to recycler managed by us) whenever user deletes the file. I went through this post and also article on OSR:
>http://www.osronline.com/showThread.cfm?link=15483
>http://www.osronline.com/showThread.cfm?link=53443
>
>
>My Rename is failing with STATUS_OBJECT_NAME_INVALID. If I try simple name (setting both FileObject and RootDirectory NULL) then it works fine. How can I find out which object name is invalid - Source object, Target Directory or Filename. I cannot use Zw function as it causes to post IRP_MJ_SET_INFORMATION back to my driver which interferes with our own logic to disallow user to manage our recycler. So we use IRP_MJ call to send the request down.?
>
>
>There was other thing which I notice in OSR article - When getting full target path for Relative Name, we first get directory object using handle passed in RootHandle but according to MSDN documentation, the target directory file object is passed in IRP:
>
>
>IrpSp->Parameters.SetFile.FileObject
>For rename or link operations. If?Irp->AssociatedIrp.SystemBuffer->FileName?contains a fully qualified file name, or if?Irp->AssociatedIrp.SystemBuffer->RootDirectory?is non-NULL, this member is a file object pointer for the parent directory of the file that is the target of the operation. Otherwise it is NULL.
>
>
>
>
>So why we need to explicitly get FileObject of the directory object ??
>
>
>Here is the code I am using to do a Rename using IRP.
>
>
>?? ??? ?swprintf(pFullFileName, L"\DosDevices\F:\DxLogs\Recycler\Rename");
>
>
>?? ? ? ? ? ?RtlInitUnicodeString(&uFullFileName, pFullFileName);
>
>
>DbgPrint(“Unicode String Buffer %wsLength : %dMax Length : %d\n”, uFullFileName.Buffer, uFullFileName.Length, uFullFileName.MaximumLength);
>
>
>?? ? ? ? ? ?InitializeObjectAttributes(&ObjectAttr, &uFullFileName, OBJ_CASE_INSENSITIVE, NULL, NULL );
>
>
>?? ? ? ? ? ?Status = IoCreateFileSpecifyDeviceObjectHint( &Handle, 0, &ObjectAttr, &IoStatus, NULL, 0, 0, FILE_OPEN_IF,?
>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT | FILE_WRITE_THROUGH,?
>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?NULL, 0, CreateFileTypeNone, NULL, 0, pDO );
>
>
>if ( NT_SUCCESS(Status) )
>Status = ObReferenceObjectByHandle(Handle, SYNCHRONIZE, *IoFileObjectType, KernelMode, (PVOID *)ppFO, NULL);
>
>
>I am doing a Relative Rename where I pass the handle obtained above and just the filename of the target filename. Here is how I setup my File Rename Structure.
>
>
>?? ? ? ? ? ? ? ? wcscpy(pNameInfo->FileName, “Target.txt”);
>
>
>?? ? ? ? ? ? ? ? ?pNameInfo->FileNameLength = (wcslen(pNameInfo->FileName)*sizeof(WCHAR)); //filename
>??
>??pNameInfo->ReplaceIfExists = TRUE;
>
>
>??pNameInfo->RootDirectory = Handle;
>
>
>
>
>Here is how I create a IRP
>
>
>Length =?sizeof(FILE_RENAME_INFORMATION)+pNameInfo->FileNameLength;
>
>
>irp = IoAllocateIrp( pDO->StackSize, FALSE );
>
>
>?? ? ?irp->Tail.Overlay.OriginalFileObject = pFO;
>?? ? ?irp->Tail.Overlay.Thread = PsGetCurrentThread();
>
>
>?? ? ?irp->RequestorMode = KernelMode;
>?? ? ?irp->UserEvent = &event;
>?? ? ?irp->Flags = IRP_SYNCHRONOUS_API | IRP_BUFFERED_IO;
>?? ? ?irp->UserIosb = &IoStatus;
>?? ? ?irp->Overlay.AsynchronousParameters.UserApcRoutine = (PIO_APC_ROUTINE) NULL;
>?? ? ?irp->AssociatedIrp.SystemBuffer = pNameInfo;
>
>
>?? ? ?irpSp = IoGetNextIrpStackLocation( irp );
>?? ? ?irpSp->FileObject = pFO;
>?? ? ?irpSp->DeviceObject = pDO;
>?? ? ?irpSp->MajorFunction = IRP_MJ_SET_INFORMATION;
>?? ? ?irpSp->Parameters.SetFile.Length = Length;
>?? ? ?irpSp->Parameters.SetFile.FileInformationClass = FileRenameInformation;
>?? ? ?irpSp->Parameters.SetFile.AdvanceOnly = FALSE;
>?? ? ?irpSp->Parameters.SetFile.FileObject = *ppFO;
>?? ? ?
>?? ? ?IoSetCompletionRoutine( irp,
>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?SetFileInfoCompletionRoutine,
>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0,
>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TRUE,
>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TRUE,
>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TRUE );
>
>
>?? ? ?status = IoCallDriver( pDO, irp );
>
>
>Any help ?
>
>
>Thanks
>Ash
>— NTFSD is sponsored by OSR For our schedule of debugging and file system seminars (including our new fs mini-filter seminar) 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
>
>For our schedule of debugging and file system seminars
>(including our new fs mini-filter seminar) 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 For our schedule of debugging and file system seminars (including our new fs mini-filter seminar) 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

I am not sure…According to docs, I am doing correct.
“this member is a file object pointer for the parent directory of the file
that is the target of the operation.”

On Tue, Mar 2, 2010 at 9:32 PM, Lijun Wang wrote:

> Ok. Sorry, I miss read your code. I thought pFullFileName is for the
> target. Here is what I think is wrong,
>
> The file opened by IoCreateFileSpecifyDeviceObjectHint must be your source
> file being renamed. And pNameInfo->RootDirectory must be the parent
> folder of your destination file. In your case, you are making them the same!
>
> If you are directly renaming a file say a.txt to b.txt, you should not
> specifiy the parent folder at all.
>
> In case of you are renaming to a different folder, you need to do two opens
> if you want to use RootDirectory: open the source file and then the parent
> folder of the destination if you want to use the and do the rename. You
> specify RootDirectory usually only when you already have a destination
> parent folder open.
>
> If you you do not, then, you should instead directly give the abolute path
> for the destination file – stripping the device prefixes.
>
>
> Lijun
>
> ------------------------------
> From: Ashish Goyal
> To: Windows File Systems Devs Interest List
> Sent: Tue, March 2, 2010 12:02:22 AM
> Subject: Re: [ntfsd] File Rename failing with
> STATUS_OBJECT_NAME_INVALID.
>
> But InitializeObjectAttributes requires fully Qualified name. See the
> documentation below:
>
> PUNICODE_STRING ObjectName A pointer to a buffered Unicode string
> naming the file to be created or opened. This value must be a fully
> qualified file specification, unless it is the name of a file relative to
> the directory specified by *RootDirectory.*For example, *
> \Device\Floppy1\myfile.dat *or ??\B:\myfile.dat could be the fully
> qualified file specification, provided that the floppy driver and overlying
> file system are already loaded. (Note that *??*replaces *\DosDevices *as
> the name of the Win32 object namespace. *\DosDevices *will still work,
> but *?? *is translated faster by the object manager.)
> On Mon, Mar 1, 2010 at 11:24 PM, Lijun Wang wrote:
>
>> Try change the following
>> swprintf(pFullFileName,
>> L"\DosDevices\F:\DxLogs\Recycler\Rename");
>>
>> to
>> swprintf(pFullFileName, L\Recycler\Rename);
>>
>>
>> Note you are sending the rename to an existing file object and the device
>> is already known, you cannot do a rename to another device anyway.
>> So just give the path in the context of that device.
>>
>> Lijun
>>
>> ------------------------------
>> From: Ashish Goyal
>> To: Windows File Systems Devs Interest List
>> Sent: Mon, March 1, 2010 6:19:48 AM
>> Subject: [ntfsd] File Rename failing with STATUS_OBJECT_NAME_INVALID.
>>
>> Hi,
>> I am trying to rename a file (move to recycler managed by us) whenever
>> user deletes the file. I went through this post and also article on OSR:
>> http://www.osronline.com/showThread.cfm?link=15483
>> http://www.osronline.com/showThread.cfm?link=53443
>>
>> My Rename is failing with STATUS_OBJECT_NAME_INVALID. If I try simple name
>> (setting both FileObject and RootDirectory NULL) then it works fine. How can
>> I find out which object name is invalid - Source object, Target Directory or
>> Filename. I cannot use Zw function as it causes to post
>> IRP_MJ_SET_INFORMATION back to my driver which interferes with our own logic
>> to disallow user to manage our recycler. So we use IRP_MJ call to send the
>> request down.
>>
>> There was other thing which I notice in OSR article - When getting full
>> target path for Relative Name, we first get directory object using handle
>> passed in RootHandle but according to MSDN documentation, the target
>> directory file object is passed in IRP:
>>
>> IrpSp->Parameters.SetFile.FileObject For rename or link operations.
>> If Irp->AssociatedIrp.SystemBuffer->FileName contains a fully qualified
>> file name, or if Irp->AssociatedIrp.SystemBuffer->RootDirectory is
>> non-NULL, this member is a file object pointer for the parent directory of
>> the file that is the target of the operation. Otherwise it is NULL.
>>
>> So why we need to explicitly get FileObject of the directory object ??
>> Here is the code I am using to do a Rename using IRP.
>> swprintf(pFullFileName,
>> L"\DosDevices\F:\DxLogs\Recycler\Rename");
>>
>> RtlInitUnicodeString(&uFullFileName, pFullFileName);
>>
>> DbgPrint(“Unicode String Buffer %ws Length : %d Max Length : %d\n”,
>> uFullFileName.Buffer, uFullFileName.Length, uFullFileName.MaximumLength);
>>
>> InitializeObjectAttributes(&ObjectAttr, &uFullFileName,
>> OBJ_CASE_INSENSITIVE, NULL, NULL );
>>
>> Status = IoCreateFileSpecifyDeviceObjectHint( &Handle, 0,
>> &ObjectAttr, &IoStatus, NULL, 0, 0, FILE_OPEN_IF,
>>
>> FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT | FILE_WRITE_THROUGH,
>> NULL, 0,
>> CreateFileTypeNone, NULL, 0, pDO );
>>
>> if ( NT_SUCCESS(Status) )
>> Status = ObReferenceObjectByHandle(Handle, SYNCHRONIZE, *IoFileObjectType,
>> KernelMode, (PVOID *)ppFO, NULL);
>>
>> I am doing a Relative Rename where I pass the handle obtained above and
>> just the filename of the target filename. Here is how I setup my File Rename
>> Structure.
>>
>> wcscpy(pNameInfo->FileName, “Target.txt”);
>>
>> pNameInfo->FileNameLength =
>> (wcslen(pNameInfo->FileName)*sizeof(WCHAR)); //filename
>>
>> pNameInfo->ReplaceIfExists = TRUE;
>>
>> pNameInfo->RootDirectory = Handle;
>>
>>
>> Here is how I create a IRP
>>
>> Length = sizeof(FILE_RENAME_INFORMATION)+pNameInfo->FileNameLength;
>>
>> irp = IoAllocateIrp( pDO->StackSize, FALSE );
>>
>> irp->Tail.Overlay.OriginalFileObject = pFO;
>> irp->Tail.Overlay.Thread = PsGetCurrentThread();
>>
>> irp->RequestorMode = KernelMode;
>> irp->UserEvent = &event;
>> irp->Flags = IRP_SYNCHRONOUS_API | IRP_BUFFERED_IO;
>> irp->UserIosb = &IoStatus;
>> irp->Overlay.AsynchronousParameters.UserApcRoutine =
>> (PIO_APC_ROUTINE) NULL;
>> irp->AssociatedIrp.SystemBuffer = pNameInfo;
>>
>> irpSp = IoGetNextIrpStackLocation( irp );
>> irpSp->FileObject = pFO;
>> irpSp->DeviceObject = pDO;
>> irpSp->MajorFunction = IRP_MJ_SET_INFORMATION;
>> irpSp->Parameters.SetFile.Length = Length;
>> irpSp->Parameters.SetFile.FileInformationClass =
>> FileRenameInformation;
>> irpSp->Parameters.SetFile.AdvanceOnly = FALSE;
>> irpSp->Parameters.SetFile.FileObject = *ppFO;
>>
>> IoSetCompletionRoutine( irp,
>> SetFileInfoCompletionRoutine,
>> 0,
>> TRUE,
>> TRUE,
>> TRUE );
>>
>> status = IoCallDriver( pDO, irp );
>>
>> Any help ?
>>
>> Thanks
>> Ash
>> — NTFSD is sponsored by OSR For our schedule of debugging and file
>> system seminars (including our new fs mini-filter seminar) 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
>>
>> For our schedule of debugging and file system seminars
>> (including our new fs mini-filter seminar) 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 For our schedule of debugging and file system
> seminars (including our new fs mini-filter seminar) 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
>
> For our schedule of debugging and file system seminars
> (including our new fs mini-filter seminar) 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
>

I tried this and now I am getting STATUS_ACCESS_VIOLATION. I have double
checked all the buffers and they are all fine. IO_OPEN_TARGET_DIRECTORY is
not mentioned in docs anywhere (I can found only in header file) so I am not
sure if this flag requires something extra to be setup.

On Tue, Mar 2, 2010 at 12:18 PM, wrote:

> I think there is something subtly wrong… instead try
> - Compute the full path for the target
> - Call IoCreateFileSpecifyDeviceObjectHint with that path, and specify the
> extended option IO_OPEN_TARGET_DIRECTORY
> - Use that file object for the SetFile information
> irpSp->Parameters.SetFile.FileObject
> - Do not set the Root Directory in the Rename information
> - Specify the full path in the rename information.
> - You probably want FILE_OPEN not FILE_OPEN_IF in IoCreateFileSpe…
> - You probably want FILE_SHARE_VALID_FLAGS as the sharing in that call as
> well…
>
> I dunno if you should specify FILE_DIRECTORY_FILE if you are trying to do
> an SL_OPEN_TARGET_DIRECTORY…
>
> Stepping through the FAT implementation of it will probably make some
> things clearer.
>
>
> —
> NTFSD is sponsored by OSR
>
> For our schedule of debugging and file system seminars
> (including our new fs mini-filter seminar) 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
>

It is not clear?you get the pFO – under what context? Also, which function actually fails with STATUS_OBJECT_NAME_INVALID? IoCreateFileSpecifyDeviceObjectHint or the IoCallDriver for the rename?

Lijun


From: Ashish Goyal
To: Windows File Systems Devs Interest List
Sent: Tue, March 2, 2010 11:32:47 AM
Subject: Re: [ntfsd] File Rename failing with STATUS_OBJECT_NAME_INVALID.

I am not sure…According to docs, I am doing correct.
“this member is a file object pointer for the parent directory of the file that is the target of the operation.”

On Tue, Mar 2, 2010 at 9:32 PM, Lijun Wang wrote:

Ok. Sorry, I miss read your code. I thought pFullFileName?is for the target. Here is what?I think is wrong,
>
>The file opened by IoCreateFileSpecifyDeviceObjectHint must be your source file being renamed. And???pNameInfo->RootDirectory? must be the parent folder of your destination file. In your case, you are making them the same!
>
>If you are directly renaming a file say a.txt to b.txt, you should not specifiy the parent folder at all.
>
>In case of you are renaming to a different folder, you need to do two opens if you want to use RootDirectory: open the source file and then the parent folder of the destination if you want to use the and do the rename. You specify?RootDirectory?usually?only when you already have a destination parent folder open.
>
>If you you do not, then, you should instead directly give the abolute path for the destination file – stripping the device prefixes.
>
>
>Lijun
>
>
>

From: Ashish Goyal
>To: Windows File Systems Devs Interest List
>Sent: Tue, March 2, 2010 12:02:22 AM
>Subject: Re: [ntfsd] File Rename failing with STATUS_OBJECT_NAME_INVALID.
>
>
>But InitializeObjectAttributes requires fully Qualified name. See the documentation below:
>
>
>PUNICODE_STRING ObjectName A pointer to a buffered Unicode string naming the file to be created or opened. This value must be a fully qualified file specification, unless it is the name of a file relative to the directory specified by?RootDirectory.For example,?\Device\Floppy1\myfile.dat?or???\B:\myfile.dat?could be the fully qualified file specification, provided that the floppy driver and overlying file system are already loaded. (Note that???replaces?\DosDevices?as the name of the Win32 object namespace.?\DosDevices?will still work, but????is translated faster by the object manager.)
>
>On Mon, Mar 1, 2010 at 11:24 PM, Lijun Wang wrote:
>
>Try change the following
>>???swprintf(pFullFileName, L"\DosDevices\F:\DxLogs\Recycler\Rename");
>>
>>to
>>
>>???swprintf(pFullFileName, L\Recycler\Rename);
>>
>>?
>>Note you are sending the rename to an existing file object and the device is already known, you cannot do a rename to another device anyway.
>>So just give the path in the context of that device.
>>?
>>Lijun
>>?
>>


>>From: Ashish Goyal
>>To: Windows File Systems Devs Interest List
>>Sent: Mon, March 1, 2010 6:19:48 AM
>>Subject: [ntfsd] File Rename failing with STATUS_OBJECT_NAME_INVALID.
>>
>>
>>Hi,
>>??I am trying to rename a file (move to recycler managed by us) whenever user deletes the file. I went through this post and also article on OSR:
>>http://www.osronline.com/showThread.cfm?link=15483
>>http://www.osronline.com/showThread.cfm?link=53443
>>
>>
>>My Rename is failing with STATUS_OBJECT_NAME_INVALID. If I try simple name (setting both FileObject and RootDirectory NULL) then it works fine. How can I find out which object name is invalid - Source object, Target Directory or Filename. I cannot use Zw function as it causes to post IRP_MJ_SET_INFORMATION back to my driver which interferes with our own logic to disallow user to manage our recycler. So we use IRP_MJ call to send the request down.?
>>
>>
>>There was other thing which I notice in OSR article - When getting full target path for Relative Name, we first get directory object using handle passed in RootHandle but according to MSDN documentation, the target directory file object is passed in IRP:
>>
>>
>>IrpSp->Parameters.SetFile.FileObject
>>For rename or link operations. If?Irp->AssociatedIrp.SystemBuffer->FileName?contains a fully qualified file name, or if?Irp->AssociatedIrp.SystemBuffer->RootDirectory?is non-NULL, this member is a file object pointer for the parent directory of the file that is the target of the operation. Otherwise it is NULL.
>>
>>
>>
>>
>>So why we need to explicitly get FileObject of the directory object ??
>>
>>
>>Here is the code I am using to do a Rename using IRP.
>>
>>
>>?? ??? ?swprintf(pFullFileName, L"\DosDevices\F:\DxLogs\Recycler\Rename");
>>
>>
>>?? ? ? ? ? ?RtlInitUnicodeString(&uFullFileName, pFullFileName);
>>
>>
>>DbgPrint(“Unicode String Buffer %wsLength : %dMax Length : %d\n”, uFullFileName.Buffer, uFullFileName.Length, uFullFileName.MaximumLength);
>>
>>
>>?? ? ? ? ? ?InitializeObjectAttributes(&ObjectAttr, &uFullFileName, OBJ_CASE_INSENSITIVE, NULL, NULL );
>>
>>
>>?? ? ? ? ? ?Status = IoCreateFileSpecifyDeviceObjectHint( &Handle, 0, &ObjectAttr, &IoStatus, NULL, 0, 0, FILE_OPEN_IF,?
>>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT | FILE_WRITE_THROUGH,?
>>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?NULL, 0, CreateFileTypeNone, NULL, 0, pDO );
>>
>>
>>if ( NT_SUCCESS(Status) )
>>Status = ObReferenceObjectByHandle(Handle, SYNCHRONIZE, *IoFileObjectType, KernelMode, (PVOID *)ppFO, NULL);
>>
>>
>>I am doing a Relative Rename where I pass the handle obtained above and just the filename of the target filename. Here is how I setup my File Rename Structure.
>>
>>
>>?? ? ? ? ? ? ? ? wcscpy(pNameInfo->FileName, “Target.txt”);
>>
>>
>>?? ? ? ? ? ? ? ? ?pNameInfo->FileNameLength = (wcslen(pNameInfo->FileName)*sizeof(WCHAR)); //filename
>>??
>>??pNameInfo->ReplaceIfExists = TRUE;
>>
>>
>>??pNameInfo->RootDirectory = Handle;
>>
>>
>>
>>
>>Here is how I create a IRP
>>
>>
>>Length =?sizeof(FILE_RENAME_INFORMATION)+pNameInfo->FileNameLength;
>>
>>
>>irp = IoAllocateIrp( pDO->StackSize, FALSE );
>>
>>
>>?? ? ?irp->Tail.Overlay.OriginalFileObject = pFO;
>>?? ? ?irp->Tail.Overlay.Thread = PsGetCurrentThread();
>>
>>
>>?? ? ?irp->RequestorMode = KernelMode;
>>?? ? ?irp->UserEvent = &event;
>>?? ? ?irp->Flags = IRP_SYNCHRONOUS_API | IRP_BUFFERED_IO;
>>?? ? ?irp->UserIosb = &IoStatus;
>>?? ? ?irp->Overlay.AsynchronousParameters.UserApcRoutine = (PIO_APC_ROUTINE) NULL;
>>?? ? ?irp->AssociatedIrp.SystemBuffer = pNameInfo;
>>
>>
>>?? ? ?irpSp = IoGetNextIrpStackLocation( irp );
>>?? ? ?irpSp->FileObject = pFO;
>>?? ? ?irpSp->DeviceObject = pDO;
>>?? ? ?irpSp->MajorFunction = IRP_MJ_SET_INFORMATION;
>>?? ? ?irpSp->Parameters.SetFile.Length = Length;
>>?? ? ?irpSp->Parameters.SetFile.FileInformationClass = FileRenameInformation;
>>?? ? ?irpSp->Parameters.SetFile.AdvanceOnly = FALSE;
>>?? ? ?irpSp->Parameters.SetFile.FileObject = *ppFO;
>>?? ? ?
>>?? ? ?IoSetCompletionRoutine( irp,
>>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?SetFileInfoCompletionRoutine,
>>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0,
>>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TRUE,
>>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TRUE,
>>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TRUE );
>>
>>
>>?? ? ?status = IoCallDriver( pDO, irp );
>>
>>
>>Any help ?
>>
>>
>>Thanks
>>Ash
>>— NTFSD is sponsored by OSR For our schedule of debugging and file system seminars (including our new fs mini-filter seminar) 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
>>
>>For our schedule of debugging and file system seminars
>>(including our new fs mini-filter seminar) 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 For our schedule of debugging and file system seminars (including our new fs mini-filter seminar) 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
>
>For our schedule of debugging and file system seminars
>(including our new fs mini-filter seminar) 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 For our schedule of debugging and file system seminars (including our new fs mini-filter seminar) 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

Your call to InitializeObjectAttributes should almost certainly specify the OBJ_KERNEL_HANDLE flag.

This information might be useful…cracking rename operations… http://www.osronline.com/article.cfm?id=85

You may not need to use the IO(SL)_OPEN_TARGET_DIRECTORY option if it assuages some doubts. That is what the io manager uses in response to a request via Zw(Nt)SetInformationFile to handle the rename.

Essentially what the IO manager does is this,

  • Construct full file path of target
  • Do a create with the SL_OPEN_TARGET_DIRECTORY flag set, this causes the open to succeed even if the file doesn’t exist (as long as the parent exists). The actual opened handle is the parent directory, but the IO_STATUS_BLOCK gets filled in with information that says whether or not the target exists. It probably checks the ReplaceIfExists flags against this.
  • Checks that the opened file object is on the same volume as the source file object (by comparing some pointers in the FILE_OBJECT structure).
  • Issues a set information to the filesystem stack that asks for the actual rename operation. The file object it opened above is the one that is passed in that IRP parameter block you are looking at.

Lijun pointed out that you can’t do a set information to rename across volumes… it may be the case that the actual rename information buffer received by the filesystem is allocated by the Io Manager with the relative name in it. I’m not sure, as I’ve mostly worked with rename in the mini-filter context where there is a utility function FltGetDestinationFileNameInformation that handles the details of getting a filename for you.

Once you’re sure of which of those two calls (calldriver v iocreatefile) is failing, scott’s suggestion to step through the FAT code is probably the way to go, that should help gain an understanding of exactly what’s going on. Rename is a pretty tricky operation.

pFO is original FileObject - Source fileObject which I get from above
function whoever called me.

I got this error from IoCallDriver().

On Tue, Mar 2, 2010 at 10:55 PM, Lijun Wang wrote:

> It is not clear you get the pFO – under what context? Also, which function
> actually fails with STATUS_OBJECT_NAME_INVALID?
> IoCreateFileSpecifyDeviceObjectHint or the IoCallDriver for the rename?
> Lijun
> ------------------------------
> From: Ashish Goyal
> To: Windows File Systems Devs Interest List
> Sent: Tue, March 2, 2010 11:32:47 AM
>
> Subject: Re: [ntfsd] File Rename failing with
> STATUS_OBJECT_NAME_INVALID.
>
> I am not sure…According to docs, I am doing correct.
> “this member is a file object pointer for the parent directory of the file
> that is the target of the operation.”
>
>
> On Tue, Mar 2, 2010 at 9:32 PM, Lijun Wang wrote:
>
>> Ok. Sorry, I miss read your code. I thought pFullFileName is for the
>> target. Here is what I think is wrong,
>>
>> The file opened by IoCreateFileSpecifyDeviceObjectHint must be your source
>> file being renamed. And pNameInfo->RootDirectory must be the parent
>> folder of your destination file. In your case, you are making them the same!
>>
>> If you are directly renaming a file say a.txt to b.txt, you should not
>> specifiy the parent folder at all.
>>
>> In case of you are renaming to a different folder, you need to do two
>> opens if you want to use RootDirectory: open the source file and then the
>> parent folder of the destination if you want to use the and do the rename.
>> You specify RootDirectory usually only when you already have a destination
>> parent folder open.
>>
>> If you you do not, then, you should instead directly give the abolute path
>> for the destination file – stripping the device prefixes.
>>
>>
>> Lijun
>>
>> ------------------------------
>> From: Ashish Goyal
>> To: Windows File Systems Devs Interest List
>> Sent: Tue, March 2, 2010 12:02:22 AM
>> Subject: Re: [ntfsd] File Rename failing with
>> STATUS_OBJECT_NAME_INVALID.
>>
>> But InitializeObjectAttributes requires fully Qualified name. See the
>> documentation below:
>>
>> PUNICODE_STRING ObjectName A pointer to a buffered Unicode string
>> naming the file to be created or opened. This value must be a fully
>> qualified file specification, unless it is the name of a file relative to
>> the directory specified by *RootDirectory.*For example, *
>> \Device\Floppy1\myfile.dat *or ??\B:\myfile.dat could be the fully
>> qualified file specification, provided that the floppy driver and overlying
>> file system are already loaded. (Note that *??*replaces *\DosDevices *as
>> the name of the Win32 object namespace. *\DosDevices *will still work,
>> but *?? *is translated faster by the object manager.)
>> On Mon, Mar 1, 2010 at 11:24 PM, Lijun Wang wrote:
>>
>>> Try change the following
>>> swprintf(pFullFileName,
>>> L"\DosDevices\F:\DxLogs\Recycler\Rename");
>>>
>>> to
>>> swprintf(pFullFileName, L\Recycler\Rename);
>>>
>>>
>>> Note you are sending the rename to an existing file object and the device
>>> is already known, you cannot do a rename to another device anyway.
>>> So just give the path in the context of that device.
>>>
>>> Lijun
>>>
>>> ------------------------------
>>> From: Ashish Goyal
>>> To: Windows File Systems Devs Interest List
>>> Sent: Mon, March 1, 2010 6:19:48 AM
>>> Subject: [ntfsd] File Rename failing with STATUS_OBJECT_NAME_INVALID.
>>>
>>> Hi,
>>> I am trying to rename a file (move to recycler managed by us) whenever
>>> user deletes the file. I went through this post and also article on OSR:
>>> http://www.osronline.com/showThread.cfm?link=15483
>>> http://www.osronline.com/showThread.cfm?link=53443
>>>
>>> My Rename is failing with STATUS_OBJECT_NAME_INVALID. If I try simple
>>> name (setting both FileObject and RootDirectory NULL) then it works fine.
>>> How can I find out which object name is invalid - Source object, Target
>>> Directory or Filename. I cannot use Zw function as it causes to post
>>> IRP_MJ_SET_INFORMATION back to my driver which interferes with our own logic
>>> to disallow user to manage our recycler. So we use IRP_MJ call to send the
>>> request down.
>>>
>>> There was other thing which I notice in OSR article - When getting full
>>> target path for Relative Name, we first get directory object using handle
>>> passed in RootHandle but according to MSDN documentation, the target
>>> directory file object is passed in IRP:
>>>
>>> IrpSp->Parameters.SetFile.FileObject For rename or link operations.
>>> If Irp->AssociatedIrp.SystemBuffer->FileName contains a fully
>>> qualified file name, or if
>>> Irp->AssociatedIrp.SystemBuffer->RootDirectory
is non-NULL, this member
>>> is a file object pointer for the parent directory of the file that is the
>>> target of the operation. Otherwise it is NULL.
>>>
>>> So why we need to explicitly get FileObject of the directory object ??
>>> Here is the code I am using to do a Rename using IRP.
>>> swprintf(pFullFileName,
>>> L"\DosDevices\F:\DxLogs\Recycler\Rename");
>>>
>>> RtlInitUnicodeString(&uFullFileName, pFullFileName);
>>>
>>> DbgPrint(“Unicode String Buffer %ws Length : %d Max Length : %d\n”,
>>> uFullFileName.Buffer, uFullFileName.Length, uFullFileName.MaximumLength);
>>>
>>> InitializeObjectAttributes(&ObjectAttr, &uFullFileName,
>>> OBJ_CASE_INSENSITIVE, NULL, NULL );
>>>
>>> Status = IoCreateFileSpecifyDeviceObjectHint( &Handle, 0,
>>> &ObjectAttr, &IoStatus, NULL, 0, 0, FILE_OPEN_IF,
>>>
>>> FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT | FILE_WRITE_THROUGH,
>>> NULL, 0,
>>> CreateFileTypeNone, NULL, 0, pDO );
>>>
>>> if ( NT_SUCCESS(Status) )
>>> Status = ObReferenceObjectByHandle(Handle, SYNCHRONIZE,
>>> *IoFileObjectType, KernelMode, (PVOID *)ppFO, NULL);
>>>
>>> I am doing a Relative Rename where I pass the handle obtained above and
>>> just the filename of the target filename. Here is how I setup my File Rename
>>> Structure.
>>>
>>> wcscpy(pNameInfo->FileName, “Target.txt”);
>>>
>>> pNameInfo->FileNameLength =
>>> (wcslen(pNameInfo->FileName)*sizeof(WCHAR)); //filename
>>>
>>> pNameInfo->ReplaceIfExists = TRUE;
>>>
>>> pNameInfo->RootDirectory = Handle;
>>>
>>>
>>> Here is how I create a IRP
>>>
>>> Length = sizeof(FILE_RENAME_INFORMATION)+pNameInfo->FileNameLength;
>>>
>>> irp = IoAllocateIrp( pDO->StackSize, FALSE );
>>>
>>> irp->Tail.Overlay.OriginalFileObject = pFO;
>>> irp->Tail.Overlay.Thread = PsGetCurrentThread();
>>>
>>> irp->RequestorMode = KernelMode;
>>> irp->UserEvent = &event;
>>> irp->Flags = IRP_SYNCHRONOUS_API | IRP_BUFFERED_IO;
>>> irp->UserIosb = &IoStatus;
>>> irp->Overlay.AsynchronousParameters.UserApcRoutine =
>>> (PIO_APC_ROUTINE) NULL;
>>> irp->AssociatedIrp.SystemBuffer = pNameInfo;
>>>
>>> irpSp = IoGetNextIrpStackLocation( irp );
>>> irpSp->FileObject = pFO;
>>> irpSp->DeviceObject = pDO;
>>> irpSp->MajorFunction = IRP_MJ_SET_INFORMATION;
>>> irpSp->Parameters.SetFile.Length = Length;
>>> irpSp->Parameters.SetFile.FileInformationClass =
>>> FileRenameInformation;
>>> irpSp->Parameters.SetFile.AdvanceOnly = FALSE;
>>> irpSp->Parameters.SetFile.FileObject = *ppFO;
>>>
>>> IoSetCompletionRoutine( irp,
>>> SetFileInfoCompletionRoutine,
>>> 0,
>>> TRUE,
>>> TRUE,
>>> TRUE );
>>>
>>> status = IoCallDriver( pDO, irp );
>>>
>>> Any help ?
>>>
>>> Thanks
>>> Ash
>>> — NTFSD is sponsored by OSR For our schedule of debugging and file
>>> system seminars (including our new fs mini-filter seminar) 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
>>>
>>> For our schedule of debugging and file system seminars
>>> (including our new fs mini-filter seminar) 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 For our schedule of debugging and file
>> system seminars (including our new fs mini-filter seminar) 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
>>
>> For our schedule of debugging and file system seminars
>> (including our new fs mini-filter seminar) 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 For our schedule of debugging and file system
> seminars (including our new fs mini-filter seminar) 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
>
> For our schedule of debugging and file system seminars
> (including our new fs mini-filter seminar) 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
>

What about the other question? Which function actually fails with STATUS_OBJECT_NAME_INVALID? IoCreateFileSpecifyDeviceObjectHint or the IoCallDriver for the rename. You need to make sure the source and destination file reside on the same volume.

Again, IMO, since you already know the absolute path of the destination path, there is really no need to do an open for the destination parent directory just to do a relative rename. See the following documentation:

The file name string in the FileName member must be specified in one of the following forms.
* A simple file name. (The RootDirectory member is NULL.) In this case, the file is simply renamed within the same directory. That is, the rename operation changes the name of the file but not its location.
* A fully qualified file name. (The RootDirectory member is NULL.) In this case, the rename operation changes the name and location of the file.
* A relative file name. In this case, the RootDirectory member contains a handle to the target directory for the rename operation. The file name itself must be a simple file name.

Lijun


From: Ashish Goyal
To: Windows File Systems Devs Interest List
Sent: Tue, March 2, 2010 12:52:14 PM
Subject: Re: [ntfsd] File Rename failing with STATUS_OBJECT_NAME_INVALID.

pFO is original FileObject - Source fileObject which I get from above function whoever called me.

I got this error from IoCallDriver().

On Tue, Mar 2, 2010 at 10:55 PM, Lijun Wang wrote:

It is not clear?you get the pFO – under what context? Also, which function actually fails with STATUS_OBJECT_NAME_INVALID? IoCreateFileSpecifyDeviceObjectHint or the IoCallDriver for the rename?
>
>Lijun
>
>

From: Ashish Goyal
>To: Windows File Systems Devs Interest List
>Sent: Tue, March 2, 2010 11:32:47 AM
>
>Subject: Re: [ntfsd] File Rename failing with STATUS_OBJECT_NAME_INVALID.
>
>
>I am not sure…According to docs, I am doing correct.
>“this member is a file object pointer for the parent directory of the file that is the target of the operation.”
>
>
>
>
>On Tue, Mar 2, 2010 at 9:32 PM, Lijun Wang wrote:
>
>Ok. Sorry, I miss read your code. I thought pFullFileName?is for the target. Here is what?I think is wrong,
>>
>>The file opened by IoCreateFileSpecifyDeviceObjectHint must be your source file being renamed. And???pNameInfo->RootDirectory? must be the parent folder of your destination file. In your case, you are making them the same!
>>
>>If you are directly renaming a file say a.txt to b.txt, you should not specifiy the parent folder at all.
>>
>>In case of you are renaming to a different folder, you need to do two opens if you want to use RootDirectory: open the source file and then the parent folder of the destination if you want to use the and do the rename. You specify?RootDirectory?usually?only when you already have a destination parent folder open.
>>
>>If you you do not, then, you should instead directly give the abolute path for the destination file – stripping the device prefixes.
>>
>>
>>Lijun
>>
>>
>>

From: Ashish Goyal
>>To: Windows File Systems Devs Interest List
>>Sent: Tue, March 2, 2010 12:02:22 AM
>>Subject: Re: [ntfsd] File Rename failing with STATUS_OBJECT_NAME_INVALID.
>>
>>
>>But InitializeObjectAttributes requires fully Qualified name. See the documentation below:
>>
>>
>>PUNICODE_STRING ObjectName A pointer to a buffered Unicode string naming the file to be created or opened. This value must be a fully qualified file specification, unless it is the name of a file relative to the directory specified by?RootDirectory.For example,?\Device\Floppy1\myfile.dat?or???\B:\myfile.dat?could be the fully qualified file specification, provided that the floppy driver and overlying file system are already loaded. (Note that???replaces?\DosDevices?as the name of the Win32 object namespace.?\DosDevices?will still work, but????is translated faster by the object manager.)
>>
>>On Mon, Mar 1, 2010 at 11:24 PM, Lijun Wang wrote:
>>
>>Try change the following
>>>???swprintf(pFullFileName, L"\DosDevices\F:\DxLogs\Recycler\Rename");
>>>
>>>to
>>>
>>>???swprintf(pFullFileName, L\Recycler\Rename);
>>>
>>>?
>>>Note you are sending the rename to an existing file object and the device is already known, you cannot do a rename to another device anyway.
>>>So just give the path in the context of that device.
>>>?
>>>Lijun
>>>?
>>>
________________________________

>>>From: Ashish Goyal
>>>To: Windows File Systems Devs Interest List
>>>Sent: Mon, March 1, 2010 6:19:48 AM
>>>Subject: [ntfsd] File Rename failing with STATUS_OBJECT_NAME_INVALID.
>>>
>>>
>>>Hi,
>>>??I am trying to rename a file (move to recycler managed by us) whenever user deletes the file. I went through this post and also article on OSR:
>>>http://www.osronline.com/showThread.cfm?link=15483
>>>http://www.osronline.com/showThread.cfm?link=53443
>>>
>>>
>>>My Rename is failing with STATUS_OBJECT_NAME_INVALID. If I try simple name (setting both FileObject and RootDirectory NULL) then it works fine. How can I find out which object name is invalid - Source object, Target Directory or Filename. I cannot use Zw function as it causes to post IRP_MJ_SET_INFORMATION back to my driver which interferes with our own logic to disallow user to manage our recycler. So we use IRP_MJ call to send the request down.?
>>>
>>>
>>>There was other thing which I notice in OSR article - When getting full target path for Relative Name, we first get directory object using handle passed in RootHandle but according to MSDN documentation, the target directory file object is passed in IRP:
>>>
>>>
>>>IrpSp->Parameters.SetFile.FileObject
>>>For rename or link operations. If?Irp->AssociatedIrp.SystemBuffer->FileName?contains a fully qualified file name, or if?Irp->AssociatedIrp.SystemBuffer->RootDirectory?is non-NULL, this member is a file object pointer for the parent directory of the file that is the target of the operation. Otherwise it is NULL.
>>>
>>>
>>>
>>>
>>>So why we need to explicitly get FileObject of the directory object ??
>>>
>>>
>>>Here is the code I am using to do a Rename using IRP.
>>>
>>>
>>>?? ??? ?swprintf(pFullFileName, L"\DosDevices\F:\DxLogs\Recycler\Rename");
>>>
>>>
>>>?? ? ? ? ? ?RtlInitUnicodeString(&uFullFileName, pFullFileName);
>>>
>>>
>>>DbgPrint(“Unicode String Buffer %wsLength : %dMax Length : %d\n”, uFullFileName.Buffer, uFullFileName.Length, uFullFileName.MaximumLength);
>>>
>>>
>>>?? ? ? ? ? ?InitializeObjectAttributes(&ObjectAttr, &uFullFileName, OBJ_CASE_INSENSITIVE, NULL, NULL );
>>>
>>>
>>>?? ? ? ? ? ?Status = IoCreateFileSpecifyDeviceObjectHint( &Handle, 0, &ObjectAttr, &IoStatus, NULL, 0, 0, FILE_OPEN_IF,?
>>>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT | FILE_WRITE_THROUGH,?
>>>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?NULL, 0, CreateFileTypeNone, NULL, 0, pDO );
>>>
>>>
>>>if ( NT_SUCCESS(Status) )
>>>Status = ObReferenceObjectByHandle(Handle, SYNCHRONIZE, *IoFileObjectType, KernelMode, (PVOID *)ppFO, NULL);
>>>
>>>
>>>I am doing a Relative Rename where I pass the handle obtained above and just the filename of the target filename. Here is how I setup my File Rename Structure.
>>>
>>>
>>>?? ? ? ? ? ? ? ? wcscpy(pNameInfo->FileName, “Target.txt”);
>>>
>>>
>>>?? ? ? ? ? ? ? ? ?pNameInfo->FileNameLength = (wcslen(pNameInfo->FileName)*sizeof(WCHAR)); //filename
>>>??
>>>??pNameInfo->ReplaceIfExists = TRUE;
>>>
>>>
>>>??pNameInfo->RootDirectory = Handle;
>>>
>>>
>>>
>>>
>>>Here is how I create a IRP
>>>
>>>
>>>Length =?sizeof(FILE_RENAME_INFORMATION)+pNameInfo->FileNameLength;
>>>
>>>
>>>irp = IoAllocateIrp( pDO->StackSize, FALSE );
>>>
>>>
>>>?? ? ?irp->Tail.Overlay.OriginalFileObject = pFO;
>>>?? ? ?irp->Tail.Overlay.Thread = PsGetCurrentThread();
>>>
>>>
>>>?? ? ?irp->RequestorMode = KernelMode;
>>>?? ? ?irp->UserEvent = &event;
>>>?? ? ?irp->Flags = IRP_SYNCHRONOUS_API | IRP_BUFFERED_IO;
>>>?? ? ?irp->UserIosb = &IoStatus;
>>>?? ? ?irp->Overlay.AsynchronousParameters.UserApcRoutine = (PIO_APC_ROUTINE) NULL;
>>>?? ? ?irp->AssociatedIrp.SystemBuffer = pNameInfo;
>>>
>>>
>>>?? ? ?irpSp = IoGetNextIrpStackLocation( irp );
>>>?? ? ?irpSp->FileObject = pFO;
>>>?? ? ?irpSp->DeviceObject = pDO;
>>>?? ? ?irpSp->MajorFunction = IRP_MJ_SET_INFORMATION;
>>>?? ? ?irpSp->Parameters.SetFile.Length = Length;
>>>?? ? ?irpSp->Parameters.SetFile.FileInformationClass = FileRenameInformation;
>>>?? ? ?irpSp->Parameters.SetFile.AdvanceOnly = FALSE;
>>>?? ? ?irpSp->Parameters.SetFile.FileObject = *ppFO;
>>>?? ? ?
>>>?? ? ?IoSetCompletionRoutine( irp,
>>>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?SetFileInfoCompletionRoutine,
>>>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0,
>>>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TRUE,
>>>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TRUE,
>>>?? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TRUE );
>>>
>>>
>>>?? ? ?status = IoCallDriver( pDO, irp );
>>>
>>>
>>>Any help ?
>>>
>>>
>>>Thanks
>>>Ash
>>>— NTFSD is sponsored by OSR For our schedule of debugging and file system seminars (including our new fs mini-filter seminar) 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
>>>
>>>For our schedule of debugging and file system seminars
>>>(including our new fs mini-filter seminar) 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 For our schedule of debugging and file system seminars (including our new fs mini-filter seminar) 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
>>
>>For our schedule of debugging and file system seminars
>>(including our new fs mini-filter seminar) 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 For our schedule of debugging and file system seminars (including our new fs mini-filter seminar) 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
>
>For our schedule of debugging and file system seminars
>(including our new fs mini-filter seminar) 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 For our schedule of debugging and file system seminars (including our new fs mini-filter seminar) 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

Hi,
Thanks for all the input. At last I was able to perform rename operation.
The trick was to use IO_OPEN_TARGET_DIRECTORY with IoCreateFile(). I am not
sure why IoCreateFileSpecifyDeviceObjectHint did not work.

The question is : Is it safe to use IO_OPEN_TARGET_DIRECTORY with
IoCreateFile() as this is not documented in IoCreateFile help. As somebody
pointed out that docs are generally outdated.

Thanks
Ashish

On Tue, Mar 2, 2010 at 12:18 PM, wrote:

> I think there is something subtly wrong… instead try
> - Compute the full path for the target
> - Call IoCreateFileSpecifyDeviceObjectHint with that path, and specify the
> extended option IO_OPEN_TARGET_DIRECTORY
> - Use that file object for the SetFile information
> irpSp->Parameters.SetFile.FileObject
> - Do not set the Root Directory in the Rename information
> - Specify the full path in the rename information.
> - You probably want FILE_OPEN not FILE_OPEN_IF in IoCreateFileSpe…
> - You probably want FILE_SHARE_VALID_FLAGS as the sharing in that call as
> well…
>
> I dunno if you should specify FILE_DIRECTORY_FILE if you are trying to do
> an SL_OPEN_TARGET_DIRECTORY…
>
> Stepping through the FAT implementation of it will probably make some
> things clearer.
>
>
> —
> NTFSD is sponsored by OSR
>
> For our schedule of debugging and file system seminars
> (including our new fs mini-filter seminar) 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
>