Author: ion
Date: Fri Jul 15 01:29:10 2011
New Revision: 52685
URL:
http://svn.reactos.org/svn/reactos?rev=52685&view=rev
Log:
[RTL]: Implement RtlDoesFileExists_UstrEx, RtlDoesFileExists_UStr, RtlDoesFileExists_UEx.
[RTL]: Make RtlDoesFileExists_UStrEx use the new RTL_RELATIVE_NAME structure and also
support whether or not sharing violations should return success or not.
[RTL]: For now, use the old RtlDosPathNameToNtPathName API instead of the newer one.
Modified:
trunk/reactos/lib/rtl/path.c
Modified: trunk/reactos/lib/rtl/path.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/rtl/path.c?rev=52685&a…
==============================================================================
--- trunk/reactos/lib/rtl/path.c [iso-8859-1] (original)
+++ trunk/reactos/lib/rtl/path.c [iso-8859-1] Fri Jul 15 01:29:10 2011
@@ -44,6 +44,21 @@
/* FUNCTIONS *****************************************************************/
+/*
+ * @implemented
+ */
+VOID
+NTAPI
+RtlReleaseRelativeName(IN PRTL_RELATIVE_NAME_U RelativeName)
+{
+ /* Check if a directory reference was grabbed */
+ if (RelativeName->CurDirRef)
+ {
+ /* FIXME: Not yet supported */
+ UNIMPLEMENTED;
+ RelativeName->CurDirRef = NULL;
+ }
+}
/*
* @implemented
@@ -903,49 +918,130 @@
return len;
}
-
-/*
- * @implemented
- */
-BOOLEAN NTAPI
+/*
+ * @implemented
+ */
+BOOLEAN
+NTAPI
+RtlDoesFileExists_UstrEx(IN PCUNICODE_STRING FileName,
+ IN BOOLEAN SucceedIfBusy)
+{
+ BOOLEAN Result;
+ RTL_RELATIVE_NAME_U RelativeName;
+ UNICODE_STRING NtPathName;
+ PVOID Buffer;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ NTSTATUS Status;
+ FILE_BASIC_INFORMATION BasicInformation;
+
+#if 0
+ /* Get the NT Path */
+ Result = RtlDosPathNameToRelativeNtPathName_Ustr(FileName,
+ &NtPathName,
+ NULL,
+ &RelativeName);
+#else
+ /* FIXME: Use the old API for now */
+ Result = RtlDosPathNameToNtPathName_U(FileName->Buffer,
+ &NtPathName,
+ NULL,
+ &RelativeName);
+#endif
+ if (!Result) return FALSE;
+
+ /* Save the buffer */
+ Buffer = NtPathName.Buffer;
+
+ /* Check if we have a relative name */
+ if (RelativeName.RelativeName.Length)
+ {
+ /* Use it */
+ NtPathName = RelativeName.RelativeName;
+ }
+ else
+ {
+ /* Otherwise ignore it */
+ RelativeName.ContainingDirectory = NULL;
+ }
+
+ /* Initialize the object attributes */
+ InitializeObjectAttributes(&ObjectAttributes,
+ &NtPathName,
+ OBJ_CASE_INSENSITIVE,
+ RelativeName.ContainingDirectory,
+ NULL);
+
+ /* Query the attributes and free the buffer now */
+ Status = ZwQueryAttributesFile(&ObjectAttributes, &BasicInformation);
+ RtlReleaseRelativeName(&RelativeName);
+ RtlFreeHeap(RtlGetProcessHeap(), 0, Buffer);
+
+ /* Check if we failed */
+ if (!NT_SUCCESS(Status))
+ {
+ /* Check if we failed because the file is in use */
+ if ((Status == STATUS_SHARING_VIOLATION) ||
+ (Status == STATUS_ACCESS_DENIED))
+ {
+ /* Check if the caller wants this to be considered OK */
+ Result = SucceedIfBusy ? TRUE : FALSE;
+ }
+ else
+ {
+ /* A failure because the file didn't exist */
+ Result = FALSE;
+ }
+ }
+ else
+ {
+ /* The file exists */
+ Result = TRUE;
+ }
+
+ /* Return the result */
+ return Result;
+}
+
+BOOLEAN
+NTAPI
+RtlDoesFileExists_UStr(IN PUNICODE_STRING FileName)
+{
+ /* Call the updated API */
+ return RtlDoesFileExists_UstrEx(FileName, TRUE);
+}
+
+/*
+ * @implemented
+ */
+BOOLEAN
+BOOLEAN
+NTAPI
+RtlDoesFileExists_UEx(IN PCWSTR FileName,
+ IN BOOLEAN SucceedIfBusy)
+{
+ UNICODE_STRING NameString;
+
+ /* Create the unicode name*/
+ if (NT_SUCCESS(RtlInitUnicodeStringEx(&NameString, FileName)))
+ {
+ /* Call the unicode function */
+ return NT_SUCCESS(RtlDoesFileExists_UstrEx(&NameString, SucceedIfBusy));
+ }
+
+ /* Fail */
+ return FALSE;
+}
+
+/*
+ * @implemented
+ */
+BOOLEAN
+NTAPI
RtlDoesFileExists_U(IN PCWSTR FileName)
{
- UNICODE_STRING NtFileName;
- OBJECT_ATTRIBUTES Attr;
- FILE_BASIC_INFORMATION Info;
- NTSTATUS Status;
- RTL_RELATIVE_NAME_U RelativeName;
-
- if (!RtlDosPathNameToNtPathName_U (FileName,
- &NtFileName,
- NULL,
- &RelativeName))
- return FALSE;
-
- if (RelativeName.RelativeName.Length)
- NtFileName = RelativeName.RelativeName;
- else
- RelativeName.ContainingDirectory = 0;
-
- InitializeObjectAttributes (&Attr,
- &NtFileName,
- OBJ_CASE_INSENSITIVE,
- RelativeName.ContainingDirectory,
- NULL);
-
- Status = ZwQueryAttributesFile (&Attr, &Info);
-
- RtlFreeUnicodeString(&NtFileName);
-
-
- if (NT_SUCCESS(Status) ||
- Status == STATUS_SHARING_VIOLATION ||
- Status == STATUS_ACCESS_DENIED)
- return TRUE;
-
- return FALSE;
-}
-
+ /* Call the new function */
+ return RtlDoesFileExists_UEx(FileName, TRUE);
+}
/*
* @unimplemented
@@ -961,16 +1057,6 @@
return FALSE;
}
-
-/*
- * @unimplemented
- */
-VOID NTAPI
-RtlReleaseRelativeName(PVOID Unknown)
-{
- DPRINT1("RtlReleaseRelativeName(0x%p) UNIMPLEMENTED\n", Unknown);
-}
-
NTSTATUS NTAPI
RtlpEnsureBufferSize(ULONG Unknown1, ULONG Unknown2, ULONG Unknown3)
{