ReactOS  0.4.14-dev-554-g2f8d847
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  */
22 BOOL
23 WINAPI
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  */
37 BOOL
38 WINAPI
40 {
41  FILE_DISPOSITION_INFORMATION FileDispInfo;
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,
108  &IoStatusBlock,
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,
123  &IoStatusBlock,
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,
162  &IoStatusBlock,
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,
193  &IoStatusBlock,
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;
218  &IoStatusBlock,
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 */
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define IN
Definition: typedefs.h:38
PUNICODE_STRING WINAPI Basep8BitStringToStaticUnicodeString(IN LPCSTR String)
Definition: utils.c:188
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI NtSetInformationFile(HANDLE hFile, PIO_STATUS_BLOCK io, PVOID ptr, ULONG len, FILE_INFORMATION_CLASS FileInformationClass)
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
HANDLE ContainingDirectory
Definition: rtltypes.h:1375
VOID NTAPI RtlReleaseRelativeName(_In_ PRTL_RELATIVE_NAME_U RelativeName)
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define STATUS_IO_REPARSE_TAG_NOT_HANDLED
Definition: ntstatus.h:743
uint16_t * PWCHAR
Definition: typedefs.h:54
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
#define IO_REPARSE_TAG_MOUNT_POINT
Definition: iotypes.h:6875
HANDLE FileHandle
Definition: stats.c:38
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
const char * LPCSTR
Definition: xmlstorage.h:183
#define FILE_ATTRIBUTE_REPARSE_POINT
Definition: ntifs_ex.h:381
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:3951
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define WINAPI
Definition: msvc.h:8
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define SetLastError(x)
Definition: compat.h:417
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
NTSTATUS NTAPI NtQueryInformationFile(HANDLE hFile, PIO_STATUS_BLOCK io, PVOID ptr, ULONG len, FILE_INFORMATION_CLASS FileInformationClass)
Status
Definition: gdiplustypes.h:24
struct _FileName FileName
Definition: fatprocs.h:884
#define FILE_OPEN_FOR_BACKUP_INTENT
Definition: from_kernel.h:42
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
UNICODE_STRING RelativeName
Definition: rtltypes.h:1374
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
#define FILE_OPEN_REPARSE_POINT
Definition: from_kernel.h:46
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)
_In_ LPCSTR lpFileName
Definition: winbase.h:3028
#define DELETE
Definition: nt_native.h:57