ReactOS 0.4.16-dev-125-g798ea90
delete.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: dll/win32/kernel32/client/file/delete.c
5 * PURPOSE: Deleting files
6 * PROGRAMMER: Ariadne (ariadne@xs4all.nl)
7 * UPDATE HISTORY:
8 * Created 01/11/98
9 */
10
11/* INCLUDES ****************************************************************/
12
13#include <k32.h>
14#define NDEBUG
15#include <reactos/debug.h>
16
17/* FUNCTIONS ****************************************************************/
18
19/*
20 * @implemented
21 */
22BOOL
25{
27
28 /* Convert the string to unicode, and call the wide function */
30 if (FileName) return DeleteFileW(FileName->Buffer);
31 return FALSE;
32}
33
34/*
35 * @implemented
36 */
37BOOL
40{
44 UNICODE_STRING NtPathU;
47 RTL_RELATIVE_NAME_U RelativeName;
48 PWCHAR PathBuffer;
49 FILE_ATTRIBUTE_TAG_INFORMATION FileTagInformation;
50
51 /* Convert to NT path and get the relative name too */
53 &NtPathU,
54 NULL,
55 &RelativeName))
56 {
57 /* Bail out if the path name makes no sense */
59 return FALSE;
60 }
61
62 /* Save the path buffer in case we free it later */
63 PathBuffer = NtPathU.Buffer;
64
65 /* If we have a relative name... */
66 if (RelativeName.RelativeName.Length)
67 {
68 /* Do a relative open with only the relative path set */
69 NtPathU = RelativeName.RelativeName;
70 }
71 else
72 {
73 /* Do a full path open with no containing directory */
74 RelativeName.ContainingDirectory = NULL;
75 }
76
77 /* Now open the directory name that was passed in */
79 &NtPathU,
81 RelativeName.ContainingDirectory,
82 NULL);
91 if (NT_SUCCESS(Status))
92 {
93 /* Check if there's a reparse point associated with this file handle */
96 &FileTagInformation,
97 sizeof(FileTagInformation),
99 if ((NT_SUCCESS(Status)) &&
100 (FileTagInformation.FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) &&
101 (FileTagInformation.ReparseTag != IO_REPARSE_TAG_MOUNT_POINT))
102 {
103 /* There is, so now try to open it with reparse behavior */
106 DELETE,
114 if (!NT_SUCCESS(Status))
115 {
116 /* We failed -- maybe whoever is handling this tag isn't there */
118 {
119 /* Try to open it for delete, without reparse behavior */
121 DELETE,
130 }
131
132 if (!NT_SUCCESS(Status))
133 {
134 RtlReleaseRelativeName(&RelativeName);
135 RtlFreeHeap(RtlGetProcessHeap(), 0, PathBuffer);
137 return FALSE;
138 }
139 }
140 }
141 else if (!(NT_SUCCESS(Status)) &&
144 {
145 /* We had some critical error querying the attributes, bail out */
146 RtlReleaseRelativeName(&RelativeName);
147 RtlFreeHeap(RtlGetProcessHeap(), 0, PathBuffer);
150 return FALSE;
151 }
152 }
153 else
154 {
155 /* It's possible that FILE_OPEN_REPARSE_POINT was not understood */
157 {
158 /* Try opening the file normally, with reparse behavior */
160 DELETE,
168 if (!NT_SUCCESS(Status))
169 {
170 /* This failed too, fail */
171 RtlReleaseRelativeName(&RelativeName);
172 RtlFreeHeap(RtlGetProcessHeap(), 0, PathBuffer);
174 return FALSE;
175 }
176 }
177 else
178 {
179 /* Maybe we didn't have READ_ATTRIBUTE rights? */
181 {
182 /* Nope, it was something else, let's fail */
183 RtlReleaseRelativeName(&RelativeName);
184 RtlFreeHeap(RtlGetProcessHeap(), 0, PathBuffer);
186 return FALSE;
187 }
188
189 /* Let's try again, without querying attributes */
191 DELETE,
200 if (!NT_SUCCESS(Status))
201 {
202 /* This failed too, so bail out */
203 RtlReleaseRelativeName(&RelativeName);
204 RtlFreeHeap(RtlGetProcessHeap(), 0, PathBuffer);
206 return FALSE;
207 }
208 }
209 }
210
211 /* Ready to delete the file, so cleanup temporary data */
212 RtlReleaseRelativeName(&RelativeName);
213 RtlFreeHeap(RtlGetProcessHeap(), 0, PathBuffer);
214
215 /* Ask for the file to be deleted */
216 FileDispInfo.DeleteFile = TRUE;
219 &FileDispInfo,
223 if (!NT_SUCCESS(Status))
224 {
225 /* Deletion failed, tell the caller */
227 return FALSE;
228 }
229
230 /* Tell the caller deletion worked */
231 return TRUE;
232}
233
234/* EOF */
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define SetLastError(x)
Definition: compat.h:752
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
PUNICODE_STRING WINAPI Basep8BitStringToStaticUnicodeString(IN LPCSTR String)
Definition: utils.c:188
struct _FileName FileName
Definition: fatprocs.h:897
unsigned int BOOL
Definition: ntddk_ex.h:94
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
@ FileAttributeTagInformation
Definition: from_kernel.h:96
@ FileDispositionInformation
Definition: from_kernel.h:74
#define FILE_OPEN_REPARSE_POINT
Definition: from_kernel.h:46
#define FILE_OPEN_FOR_BACKUP_INTENT
Definition: from_kernel.h:42
Status
Definition: gdiplustypes.h:25
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
VOID NTAPI RtlReleaseRelativeName(_In_ PRTL_RELATIVE_NAME_U RelativeName)
NTSYSAPI BOOLEAN NTAPI RtlDosPathNameToNtPathName_U(_In_opt_z_ PCWSTR DosPathName, _Out_ PUNICODE_STRING NtPathName, _Out_opt_ PCWSTR *NtFileNamePart, _Out_opt_ PRTL_RELATIVE_NAME_U DirectoryInfo)
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3952
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
NTSYSAPI NTSTATUS NTAPI NtSetInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
Definition: iofunc.c:3096
NTSYSAPI NTSTATUS NTAPI NtQueryInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, OUT PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
#define DELETE
Definition: nt_native.h:57
#define FILE_ATTRIBUTE_REPARSE_POINT
Definition: ntifs_ex.h:381
#define STATUS_IO_REPARSE_TAG_NOT_HANDLED
Definition: ntstatus.h:757
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:167
UNICODE_STRING RelativeName
Definition: rtltypes.h:1380
HANDLE ContainingDirectory
Definition: rtltypes.h:1381
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ LPCSTR lpFileName
Definition: winbase.h:3071
#define WINAPI
Definition: msvc.h:6
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
#define IO_REPARSE_TAG_MOUNT_POINT
Definition: iotypes.h:7231
const char * LPCSTR
Definition: xmlstorage.h:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185