Windows Driver Kit: Installable File System Drivers
ZwDeleteFile
The ZwDeleteFile routine deletes the specified file.
NTSTATUS
ZwDeleteFile(
IN POBJECT_ATTRIBUTES ObjectAttributes
);
Parameters
- ObjectAttributes
- The attributes supplied by the caller to be used for the file object. These attributes would include the ObjectName and the SECURITY_DESCRIPTOR, for example. This parameter is initialized by calling the InitializeAttributes macro.
Return Value
ZwDeleteFile returns STATUS_SUCCESS or an appropriate error status representing the final completion status of the operation. Possible error status codes include the following:
- STATUS_INSUFFICIENT_RESOURCES
- A temporary buffer required by this function could not be allocated.
- STATUS_INVALID_PARAMETER
- The specified ObjectAttributes parameter was a NULL pointer, not a valid pointer to an OBJECT_ATTRIBUTES structure, or some of the specified ObjectAttributes structure members were invalid.
- STATUS_OBJECT_NAME_INVALID
- The ObjectAttributes parameter contained an ObjectName in the OBJECT_ATTRIBUTES structure that was invalid because an empty string was found after the OBJECT_NAME_PATH_SEPARATOR character.
- STATUS_OBJECT_NAME_NOT_FOUND
- The ObjectAttributes parameter contained an ObjectName member in the OBJECT_ATTRIBUTES structure that could not be found.
- STATUS_OBJECT_PATH_NOT_FOUND
- The ObjectAttributes parameter contained an ObjectName member in the OBJECT_ATTRIBUTES structure with an object path that could not be found.
- STATUS_OBJECT_PATH_SYNTAX_BAD
- The ObjectAttributes parameter did not contain a RootDirectory member, but the ObjectName member in the OBJECT_ATTRIBUTES structure was an empty string or did not contain an OBJECT_NAME_PATH_SEPARATOR character. This indicates incorrect syntax for the object path.
Comments
ZwDeleteFile deletes the specified file object.
The ZwDeleteFile function is called after the InitializeAttributes macro is used to set attributes in the OBJECT_ATTRIBUTES structure for the file object to be deleted.
There are two alternate ways to specify the name of the file to be deleted with ZwDeleteFile:
- As a fully qualified pathname, supplied in the ObjectName member of the input ObjectAttributes
- As pathname relative to the directory file represented by the handle in the RootDirectory member of the input ObjectAttributes
Callers of ZwDeleteFile must be running at IRQL = PASSIVE_LEVEL and with APCs enabled.
Requirements
Versions: This routine is available on Microsoft Windows XP and later versions of Windows.
IRQL: PASSIVE_LEVEL (see Comments section)
Headers: The ZwDeleteFile function is declared in ntifs.h. The OBJECT_ATTRIBUTES structure is defined in ntdef.h.
Include ntifs.h.
See Also
InitializeObjectAttributes