FILE_RENAME_INFORMATION - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
#ifndef _NTIOAPI_H

/**
 * The FILE_RENAME_INFORMATION structure is used to rename a file.
 * \sa https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_file_rename_information
 */
typedef struct _FILE_RENAME_INFORMATION
{
    BOOLEAN ReplaceIfExists;
    HANDLE RootDirectory;
    ULONG FileNameLength;
    _Field_size_bytes_(FileNameLength) WCHAR FileName[1];
} FILE_RENAME_INFORMATION, *PFILE_RENAME_INFORMATION;

#endif

View code on GitHub
// ntifs.h

typedef struct _FILE_RENAME_INFORMATION {
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10_RS1)
    union {
        BOOLEAN ReplaceIfExists;  // FileRenameInformation
        ULONG Flags;              // FileRenameInformationEx
    } DUMMYUNIONNAME;
#else
    BOOLEAN ReplaceIfExists;
#endif
    HANDLE RootDirectory;
    ULONG FileNameLength;
    WCHAR FileName[1];
} FILE_RENAME_INFORMATION, *PFILE_RENAME_INFORMATION;

View the official Windows Driver Kit DDI reference

NtDoc

No description available.

Windows Driver Kit DDI reference (ns-ntifs-_file_rename_information)

FILE_RENAME_INFORMATION structure

Description

The FILE_RENAME_INFORMATION structure is used to rename a file.

Members

DUMMYUNIONNAME

DUMMYUNIONNAME.ReplaceIfExists

Set to TRUE to specify that if a file with the given name already exists, it should be replaced with the given file. Set to FALSE if the rename operation should fail if a file with the given name already exists.

DUMMYUNIONNAME.Flags

Flags for the rename operation. This field is only applicable when used with the FileRenameInformationEx information class.

Here are the possible values:

Value Meaning
FILE_RENAME_REPLACE_IF_EXISTS (0x00000001) If a file with the given name already exists, it should be replaced with the given file. Equivalent to the ReplaceIfExists field used with the FileRenameInformation information class.
FILE_RENAME_POSIX_SEMANTICS (0x00000002) If FILE_RENAME_REPLACE_IF_EXISTS is also specified, allow replacing a file even if there are existing handles to it. Existing handles to the replaced file continue to be valid for operations such as read and write. Any subsequent opens of the target name will open the renamed file, not the replaced file.
FILE_RENAME_SUPPRESS_PIN_STATE_INHERITANCE (0x00000004) When renaming a file to a new directory, suppress any inheritance rules related to the FILE_ATTRIBUTE_PINNED and FILE_ATTRIBUTE_UNPINNED attributes of the file.
FILE_RENAME_SUPPRESS_STORAGE_RESERVE_INHERITANCE (0x00000008) When renaming a file to a new directory, suppress any inheritance rules related to the storage reserve ID property of the file.
FILE_RENAME_NO_INCREASE_AVAILABLE_SPACE (0x00000010) If FILE_RENAME_SUPPRESS_STORAGE_RESERVE_INHERITANCE is not also specified, when renaming a file to a new directory, automatically resize affected storage reserve areas as needed to prevent the user visible free space on the volume from increasing. Requires manage volume access.
FILE_RENAME_NO_DECREASE_AVAILABLE_SPACE (0x00000020) If FILE_RENAME_SUPPRESS_STORAGE_RESERVE_INHERITANCE is not also specified, when renaming a file to a new directory, automatically resize affected storage reserve areas as needed to prevent the user visible free space on the volume from decreasing. Requires manage volume access.
FILE_RENAME_PRESERVE_AVAILABLE_SPACE (0x00000030) Equivalent to specifying both FILE_RENAME_NO_INCREASE_AVAILABLE_SPACE and FILE_RENAME_NO_DECREASE_AVAILABLE_SPACE.
FILE_RENAME_IGNORE_READONLY_ATTRIBUTE (0x00000040) If FILE_RENAME_REPLACE_IF_EXISTS is also specified, allow replacing a file even if it is read-only. Requires WRITE_ATTRIBUTES access to the replaced file.
FILE_RENAME_FORCE_RESIZE_TARGET_SR (0x00000080) If FILE_RENAME_SUPPRESS_STORAGE_RESERVE_INHERITANCE is not also specified, when renaming a file to a new directory that is part of a different storage reserve area, always grow the target directory's storage reserve area by the full size of the file being renamed. Requires manage volume access.
FILE_RENAME_FORCE_RESIZE_SOURCE_SR (0x00000100) If FILE_RENAME_SUPPRESS_STORAGE_RESERVE_INHERITANCE is not also specified, when renaming a file to a new directory that is part of a different storage reserve area, always shrink the source directory's storage reserve area by the full size of the file being renamed. Requires manage volume access.
FILE_RENAME_FORCE_RESIZE_SR (0x00000180) Equivalent to specifying both FILE_RENAME_FORCE_RESIZE_TARGET_SR and FILE_RENAME_FORCE_RESIZE_SOURCE_SR.

ReplaceIfExists

Set to TRUE to specify that if a file with the given name already exists, it should be replaced with the given file. Set to FALSE if the rename operation should fail if a file with the given name already exists.

RootDirectory

A handle that IopOpenLinkOrRenameTarget uses to open the target directory.

If the file is not being moved to a different directory, or if the FileName member contains the full pathname, this member is NULL. Otherwise, it is a handle for the root directory under which the file will reside after it is renamed.

To perform two open operations that won't cause a sharing conflict, you can open RootDirectory by requesting traverse | read-attribute. IopOpenLinkOrRenameTarget can then perform a relative open by requesting FILE_WRITE_DATA | SYNCHRONIZE. These two opens would not cause sharing conflict.

FileNameLength

Length, in bytes, of the new name for the file.

FileName

The first character of a wide-character string containing the new name for the file. This is followed in memory by the remainder of the string. If the RootDirectory member is NULL, and the file is being moved to a different directory, this member specifies the full pathname to be assigned to the file. Otherwise, it specifies only the file name or a relative pathname.

Syntax

typedef struct _FILE_RENAME_INFORMATION {
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10_RS1)
    union {
        BOOLEAN ReplaceIfExists;  // FileRenameInformation
        ULONG Flags;              // FileRenameInformationEx
    } DUMMYUNIONNAME;
#else
    BOOLEAN ReplaceIfExists;
#endif
    HANDLE RootDirectory;
    ULONG FileNameLength;
    WCHAR FileName[1];
} FILE_RENAME_INFORMATION, *PFILE_RENAME_INFORMATION;

Remarks

The FILE_RENAME_INFORMATION structure is used to rename a file. This operation can be performed in either of the following ways:

File system minifilters must use FltSetInformationFile, not ZwSetInformationFile, to rename a file.

Renaming a file requires DELETE access to the file so that the directory entry can be removed from the current parent directory, as well as the appropriate access to create the new entry in the new parent directory file.

The file name string in the FileName member must be specified in one of the following forms.

General rules for rename operations:

Special rules for renaming open files:

Special rules for renaming NTFS data streams:

The size of the FileInformation buffer passed to ZwSetInformationFile or FltSetInformationFile must be >= sizeof(FILE_RENAME_INFORMATION) plus the size in bytes of the FileName string.

See also

FltSetInformationFile

IRP_MJ_SET_INFORMATION

ZwSetInformationFile


NTinternals.net (undocumented.ntinternals.net)

This structure is documented in Windows Driver Kit.


Structure FILE_RENAME_INFORMATION is used as input buffer for function NtSetInformationFile, called with FileRenameInformation information class. Using this structure caller can rename file, or move it into other directory.

ReplaceIfExists

If set, and file with the same name as destination exist, it will be replaced. If no, STATUS_OBJECT_NAME_COLLISION is returned.

RootDirectory

Optional HANDLE to parent directory for destination file.

FileNameLength

Length of FileName array, in bytes.

FileName[1]

UNICODE string specifying destination file name. If RootDirectory is NULL, it must contains full system path, or only destination file name for in-place rename operation.

Documented by

See also