Fastfat FILE_RENAME_INFORMATION

Hi!
I’m curious how this code in fastfat function FatSetRenameInfo() can be reached?
Neither ‘ren A B’ command nor ‘MoveFile(“A”,“B”);’ led me there.

if (TargetFileObject == NULL) {

//
// In the case of a simple rename the target dcb is the
// same as the source file’s parent dcb, and the new file name
// is taken from the system buffer
//

PFILE_RENAME_INFORMATION Buffer;

Buffer = Irp->AssociatedIrp.SystemBuffer;

TargetDcb = Fcb->ParentDcb;

NewName.Length = (USHORT) Buffer->FileNameLength;
NewName.Buffer = (PWSTR) &Buffer->FileName;

//
// Make sure the name is of legal length.
//

if (NewName.Length >= 255*sizeof(WCHAR)) {

try_return( Status = STATUS_OBJECT_NAME_INVALID );
}

} else {

And one more question.
Isn’t it an error that 255 characters long names are rejected by this code?

I would suggest using FileTest and use the NtSetInformationFile tab with the FileRenameInformation class and then set the FileName to the new name and you should be good to go.

Also see this thread: http://www.osronline.com/showThread.cfm?link=144011.

Keep in mind that different file systems have different restrictions. So it’s up to Fat to implement the namespace in anyway it wants, including not having a name longer than 255.

Thanks,
Alex.

> I’m curious how this code in fastfat function FatSetRenameInfo() can be

reached?
Neither ‘ren A B’ command nor ‘MoveFile(“A”,“B”);’ led me there.

[snip]

The command line (or explorer) isn’t the only way of sending these things
down to NtSetFileInformation. In particular there is absolutely no need to
specify RootDirectory in the RENAME_FILE_INFORMATION. If you build one of
these then IrpSp->Parameters.SetFile.FileObject is not going to be set.

Why are there so may ways of doing this? Why do you get the handle as well
as the TargetFileObject? I just don’t know, but it does make for an
exciting life.

By the way if you do decide to build your own rename, my bitter experience
is that if you don’t do things the same as explorer/cmd and just rely on
something random like the specification of how the operation should work
(that is irony by the way before someone calls me on it) you you will suffer
eventually because someone will have assumed that there is only one way to
do a rename “like MoveFile” and things will break (this occasionally
includes the FSD itself).

> I would suggest using FileTest and use the NtSetInformationFile tab with the

FileRenameInformation class and then set the FileName to the new name and you
should be good to go.

Thanks! It helped.

Keep in mind that different file systems have different restrictions. So it’s up
to Fat to implement the namespace in anyway it wants, including not having a
name longer than 255.

I did not write about names longer than 255.
GetVolumeInformation returns MaximumComponentLength=255 for FAT.
Renaming into a 255-characters-long name using MoveFile API works.
But it fails when using NtSetInformationFile with FILE_RENAME_INFORMATION::FileName.

Oh, sorry, I see your point. You’re right, it does look like an error.

Thanks,
Alex.