mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
[FREELDR] fs.c: Move the "()" -> "(0)" ARC path normalization code into a function (#7385)
This function will be useful in other places later.
This commit is contained in:
parent
829ad06179
commit
689b9e0475
1 changed files with 70 additions and 32 deletions
|
@ -77,16 +77,75 @@ PFS_MOUNT FileSystems[] =
|
||||||
|
|
||||||
/* ARC FUNCTIONS **************************************************************/
|
/* ARC FUNCTIONS **************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* Replace "()" by "(0)" in the given ARC device name, if necessary.
|
||||||
|
*
|
||||||
|
* @param[in] DeviceName
|
||||||
|
* The original ARC device name string to normalize.
|
||||||
|
*
|
||||||
|
* @param[in,out] Length
|
||||||
|
* Points to a SIZE_T variable that:
|
||||||
|
* - on input, specifies the length of the ARC device name string pointed
|
||||||
|
* by DeviceName;
|
||||||
|
* - on output, receives the length of the normalized ARC device name,
|
||||||
|
* returned by value by this function.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* - On success, returns a string pointer to the normalized ARC device name.
|
||||||
|
* If the device name string had to be normalized, this returned string is
|
||||||
|
* allocated from the temporary heap, with TAG_DEVICE_NAME tag.
|
||||||
|
* Otherwise, the function returns the original device name string pointer.
|
||||||
|
* - On failure, the function returns NULL.
|
||||||
|
**/
|
||||||
|
PCHAR
|
||||||
|
NormalizeArcDeviceName(
|
||||||
|
_In_ PCCH DeviceName,
|
||||||
|
_Inout_ PSIZE_T Length)
|
||||||
|
{
|
||||||
|
ULONG Count;
|
||||||
|
SIZE_T NameLength;
|
||||||
|
PCCH p, End;
|
||||||
|
PCHAR q, NormName;
|
||||||
|
|
||||||
|
NameLength = *Length;
|
||||||
|
End = DeviceName + NameLength;
|
||||||
|
|
||||||
|
/* Count the number of "()", which needs to be replaced by "(0)" */
|
||||||
|
Count = 0;
|
||||||
|
for (p = DeviceName; p < End; ++p)
|
||||||
|
{
|
||||||
|
if ((p + 1) < End && *p == '(' && *(p + 1) == ')')
|
||||||
|
++Count; //, ++p;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Count == 0) /* No need to duplicate the device name */
|
||||||
|
return (PCHAR)DeviceName;
|
||||||
|
|
||||||
|
/* Return the updated length */
|
||||||
|
*Length = NameLength + Count;
|
||||||
|
|
||||||
|
/* Duplicate the device name and replace "()" by "(0)" */
|
||||||
|
NormName = FrLdrTempAlloc(*Length, TAG_DEVICE_NAME);
|
||||||
|
if (!NormName)
|
||||||
|
return NULL;
|
||||||
|
for (p = DeviceName, q = NormName; p < End; ++p)
|
||||||
|
{
|
||||||
|
*q++ = *p;
|
||||||
|
if ((p + 1) < End && *p == '(' && *(p + 1) == ')')
|
||||||
|
*q++ = '0'; //, *q++ = *++p;
|
||||||
|
}
|
||||||
|
return NormName;
|
||||||
|
}
|
||||||
|
|
||||||
ARC_STATUS ArcOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
|
ARC_STATUS ArcOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
|
||||||
{
|
{
|
||||||
ARC_STATUS Status;
|
ARC_STATUS Status;
|
||||||
ULONG Count, i;
|
ULONG i;
|
||||||
PLIST_ENTRY pEntry;
|
PLIST_ENTRY pEntry;
|
||||||
DEVICE* pDevice;
|
DEVICE* pDevice;
|
||||||
CHAR* DeviceName;
|
PCHAR DeviceName;
|
||||||
CHAR* FileName;
|
PSTR FileName;
|
||||||
CHAR* p;
|
|
||||||
CHAR* q;
|
|
||||||
SIZE_T Length;
|
SIZE_T Length;
|
||||||
OPENMODE DeviceOpenMode;
|
OPENMODE DeviceOpenMode;
|
||||||
ULONG DeviceId;
|
ULONG DeviceId;
|
||||||
|
@ -100,34 +159,13 @@ ARC_STATUS ArcOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
|
||||||
FileName = strrchr(Path, ')');
|
FileName = strrchr(Path, ')');
|
||||||
if (!FileName)
|
if (!FileName)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
FileName++;
|
++FileName;
|
||||||
|
|
||||||
/* Count number of "()", which needs to be replaced by "(0)" */
|
/* Normalize the device name, replacing "()" by "(0)" if necessary */
|
||||||
Count = 0;
|
Length = FileName - Path;
|
||||||
for (p = Path; p != FileName; p++)
|
DeviceName = NormalizeArcDeviceName(Path, &Length);
|
||||||
{
|
if (!DeviceName)
|
||||||
if (*p == '(' && *(p + 1) == ')')
|
return ENOMEM;
|
||||||
Count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Duplicate device name, and replace "()" by "(0)" (if required) */
|
|
||||||
Length = FileName - Path + Count;
|
|
||||||
if (Count != 0)
|
|
||||||
{
|
|
||||||
DeviceName = FrLdrTempAlloc(FileName - Path + Count, TAG_DEVICE_NAME);
|
|
||||||
if (!DeviceName)
|
|
||||||
return ENOMEM;
|
|
||||||
for (p = Path, q = DeviceName; p != FileName; p++)
|
|
||||||
{
|
|
||||||
*q++ = *p;
|
|
||||||
if (*p == '(' && *(p + 1) == ')')
|
|
||||||
*q++ = '0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DeviceName = Path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Search for the device */
|
/* Search for the device */
|
||||||
if (OpenMode == OpenReadOnly || OpenMode == OpenWriteOnly)
|
if (OpenMode == OpenReadOnly || OpenMode == OpenWriteOnly)
|
||||||
|
|
Loading…
Reference in a new issue