ReactOS  0.4.13-dev-241-g63286c6
arcname.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

BOOLEAN ArcPathNormalize (OUT PUNICODE_STRING NormalizedArcPath, IN PCWSTR ArcPath)
 
BOOLEAN ArcPathToNtPath (OUT PUNICODE_STRING NtPath, IN PCWSTR ArcPath, IN PPARTLIST PartList OPTIONAL)
 

Function Documentation

◆ ArcPathNormalize()

BOOLEAN ArcPathNormalize ( OUT PUNICODE_STRING  NormalizedArcPath,
IN PCWSTR  ArcPath 
)

Definition at line 304 of file arcname.c.

307 {
309  PCWSTR EndOfArcName;
310  PCWSTR p;
311 
312  if (NormalizedArcPath->MaximumLength < sizeof(UNICODE_NULL))
313  return FALSE;
314 
315  *NormalizedArcPath->Buffer = UNICODE_NULL;
316  NormalizedArcPath->Length = 0;
317 
318  EndOfArcName = wcschr(ArcPath, OBJ_NAME_PATH_SEPARATOR);
319  if (!EndOfArcName)
320  EndOfArcName = ArcPath + wcslen(ArcPath);
321 
322  while ((p = wcsstr(ArcPath, L"()")) && (p < EndOfArcName))
323  {
324 #if 0
325  Status = RtlStringCbCopyNW(NormalizedArcPath->Buffer,
326  NormalizedArcPath->MaximumLength,
327  ArcPath, (p - ArcPath) * sizeof(WCHAR));
328 #else
329  Status = RtlStringCbCatNW(NormalizedArcPath->Buffer,
330  NormalizedArcPath->MaximumLength,
331  ArcPath, (p - ArcPath) * sizeof(WCHAR));
332 #endif
333  if (!NT_SUCCESS(Status))
334  return FALSE;
335 
336  Status = RtlStringCbCatW(NormalizedArcPath->Buffer,
337  NormalizedArcPath->MaximumLength,
338  L"(0)");
339  if (!NT_SUCCESS(Status))
340  return FALSE;
341 #if 0
342  NormalizedArcPath->Buffer += wcslen(NormalizedArcPath->Buffer);
343 #endif
344  ArcPath = p + 2;
345  }
346 
347  Status = RtlStringCbCatW(NormalizedArcPath->Buffer,
348  NormalizedArcPath->MaximumLength,
349  ArcPath);
350  if (!NT_SUCCESS(Status))
351  return FALSE;
352 
353  NormalizedArcPath->Length = wcslen(NormalizedArcPath->Buffer) * sizeof(WCHAR);
354  return TRUE;
355 }
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define TRUE
Definition: types.h:120
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
NTSTRSAFEAPI RtlStringCbCatNW(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_reads_bytes_(cbToAppend) STRSAFE_LPCWSTR pszSrc, _In_ size_t cbToAppend)
Definition: ntstrsafe.h:806
LONG NTSTATUS
Definition: precomp.h:26
NTSTRSAFEAPI RtlStringCbCatW(_Inout_updates_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCWSTR pszSrc)
Definition: ntstrsafe.h:623
#define UNICODE_NULL
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
NTSTRSAFEAPI RtlStringCbCopyNW(_Out_writes_bytes_(cbDest) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_reads_bytes_(cbToCopy) STRSAFE_LPCWSTR pszSrc, _In_ size_t cbToCopy)
Definition: ntstrsafe.h:411
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
GLfloat GLfloat p
Definition: glext.h:8902
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by _tmain().

◆ ArcPathToNtPath()

BOOLEAN ArcPathToNtPath ( OUT PUNICODE_STRING  NtPath,
IN PCWSTR  ArcPath,
IN PPARTLIST PartList  OPTIONAL 
)

Definition at line 797 of file arcname.c.

801 {
803  PCWSTR BeginOfPath;
804  UNICODE_STRING ArcName;
805 
806  /* TODO: We should "normalize" the path, i.e. expand all the xxx() into xxx(0) */
807 
808  if (NtPath->MaximumLength < sizeof(UNICODE_NULL))
809  return FALSE;
810 
811  *NtPath->Buffer = UNICODE_NULL;
812  NtPath->Length = 0;
813 
814  /*
815  * - First, check whether the ARC path is already inside \\ArcName
816  * and if so, map it to the corresponding NT path.
817  * - Only then, if we haven't found any ArcName, try to build a
818  * NT path by deconstructing the ARC path, using its disk and
819  * partition numbers. We may use here our disk/partition list.
820  *
821  * See also freeldr/arcname.c
822  *
823  * Note that it would be nice to maintain a cache of these mappings.
824  */
825 
826  /*
827  * Initialize the ARC name to resolve, by cutting the ARC path at the first
828  * NT path separator. The ARC name therefore ends where the NT path part starts.
829  */
830  RtlInitUnicodeString(&ArcName, ArcPath);
831  BeginOfPath = wcschr(ArcName.Buffer, OBJ_NAME_PATH_SEPARATOR);
832  if (BeginOfPath)
833  ArcName.Length = (ULONG_PTR)BeginOfPath - (ULONG_PTR)ArcName.Buffer;
834 
835  /* Resolve the ARC name via NT SymLinks. Note that NtPath is returned NULL-terminated. */
836  Status = ResolveArcNameNtSymLink(NtPath, &ArcName);
837  if (!NT_SUCCESS(Status))
838  {
839  /* We failed, attempt a manual resolution */
840  DPRINT1("ResolveArcNameNtSymLink(ArcName = '%wZ') for ArcPath = '%S' failed, Status 0x%08lx\n", &ArcName, ArcPath, Status);
841 
842  /*
843  * We failed at directly resolving the ARC path, and we cannot perform
844  * a manual resolution because we don't have any disk/partition list,
845  * we therefore fail here.
846  */
847  if (!PartList)
848  {
849  DPRINT1("PartList == NULL, cannot perform a manual resolution\n");
850  return FALSE;
851  }
852 
853  *NtPath->Buffer = UNICODE_NULL;
854  NtPath->Length = 0;
855 
856  BeginOfPath = ArcPath;
857  Status = ResolveArcNameManually(NtPath, &BeginOfPath, PartList);
858  if (!NT_SUCCESS(Status))
859  {
860  /* We really failed this time, bail out */
861  DPRINT1("ResolveArcNameManually(ArcPath = '%S') failed, Status 0x%08lx\n", ArcPath, Status);
862  return FALSE;
863  }
864  }
865 
866  /*
867  * We succeeded. Concatenate the rest of the system-specific path. We know the path is going
868  * to be inside the NT namespace, therefore we can use the path string concatenation function
869  * that uses '\\' as the path separator.
870  */
871  if (BeginOfPath && *BeginOfPath)
872  {
873  Status = ConcatPaths(NtPath->Buffer, NtPath->MaximumLength / sizeof(WCHAR), 1, BeginOfPath);
874  if (!NT_SUCCESS(Status))
875  {
876  /* Buffer not large enough, or whatever...: just bail out */
877  return FALSE;
878  }
879  }
880  NtPath->Length = wcslen(NtPath->Buffer) * sizeof(WCHAR);
881 
882  return TRUE;
883 }
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS ConcatPaths(IN OUT PWSTR PathBuffer, IN SIZE_T cchPathSize, IN ULONG NumberOfPathComponents, IN ...)
Definition: filesup.c:659
static NTSTATUS ResolveArcNameNtSymLink(OUT PUNICODE_STRING NtName, IN PUNICODE_STRING ArcName)
Definition: arcname.c:584
uint32_t ULONG_PTR
Definition: typedefs.h:63
static NTSTATUS ResolveArcNameManually(OUT PUNICODE_STRING NtName, IN OUT PCWSTR *ArcNamePath, IN PPARTLIST PartList)
Definition: arcname.c:674
#define UNICODE_NULL
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define ULONG_PTR
Definition: config.h:101
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by _tmain(), and EnumerateInstallations().