Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/os/inc/osapi-filesys.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,16 @@ int32 OS_chkfs(const char *name, bool repair);
*/
int32 OS_FS_GetPhysDriveName(char *PhysDriveName, const char *MountPoint);

#ifndef OSAL_OMIT_DEPRECATED

/*-------------------------------------------------------------------------------------*/
/**
* @brief Translates an OSAL Virtual file system path to a host Local path
*
* Translates a virtual path to an actual system path name
*
* @note The buffer provided in the LocalPath argument is required to be at
* least OS_MAX_PATH_LEN characters in length.
* least OS_MAX_LOCAL_PATH_LEN characters in length.
*
* @param[in] VirtualPath OSAL virtual path name @nonnull
* @param[out] LocalPath Buffer to store native/translated path name @nonnull
Expand All @@ -287,6 +289,27 @@ int32 OS_FS_GetPhysDriveName(char *PhysDriveName, const char *MountPoint);
*/
int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath);

#endif

/*-------------------------------------------------------------------------------------*/
/**
* @brief Translates an OSAL Virtual file system path to a host Local path
*
* Translates a virtual path to an actual system path name
*
* @param[in] VirtualPath OSAL virtual path name @nonnull
* @param[out] LocalPath Buffer to store native/translated path name @nonnull
* @param[out] LocalPathSize Size of buffer to store native/translated path name @nonnull
*
* @return Execution status, see @ref OSReturnCodes
* @retval #OS_SUCCESS @copybrief OS_SUCCESS
* @retval #OS_INVALID_POINTER if either parameter is NULL
* @retval #OS_FS_ERR_NAME_TOO_LONG if the filename component is too long
* @retval #OS_FS_ERR_PATH_INVALID if either parameter cannot be interpreted as a path
* @retval #OS_FS_ERR_PATH_TOO_LONG if either input or output pathnames are too long
*/
int32 OS_TranslatePathWithSize(const char *VirtualPath, char *LocalPath, size_t LocalPathSize);

/*-------------------------------------------------------------------------------------*/
/**
* @brief Returns information about the file system
Expand Down
6 changes: 3 additions & 3 deletions src/os/shared/src/osapi-dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int32 OS_mkdir(const char *path, uint32 access)
int32 return_code;
char local_path[OS_MAX_LOCAL_PATH_LEN];

return_code = OS_TranslatePath(path, local_path);
return_code = OS_TranslatePathWithSize(path, local_path, sizeof(local_path));
if (return_code == OS_SUCCESS)
{
return_code = OS_DirCreate_Impl(local_path, access);
Expand All @@ -112,7 +112,7 @@ int32 OS_DirectoryOpen(osal_id_t *dir_id, const char *path)
/* Check parameters */
OS_CHECK_POINTER(dir_id);

return_code = OS_TranslatePath(path, local_path);
return_code = OS_TranslatePathWithSize(path, local_path, sizeof(local_path));
if (return_code == OS_SUCCESS)
{
/* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */
Expand Down Expand Up @@ -227,7 +227,7 @@ int32 OS_rmdir(const char *path)
int32 return_code;
char local_path[OS_MAX_LOCAL_PATH_LEN];

return_code = OS_TranslatePath(path, local_path);
return_code = OS_TranslatePathWithSize(path, local_path, sizeof(local_path));
if (return_code == OS_SUCCESS)
{
return_code = OS_DirRemove_Impl(local_path);
Expand Down
12 changes: 6 additions & 6 deletions src/os/shared/src/osapi-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ int32 OS_OpenCreate(osal_id_t *filedes, const char *path, int32 flags, int32 acc
/*
* Translate the path
*/
return_code = OS_TranslatePath(path, (char *)local_path);
return_code = OS_TranslatePathWithSize(path, (char *)local_path, sizeof(local_path));

if (return_code == OS_SUCCESS)
{
Expand Down Expand Up @@ -282,7 +282,7 @@ int32 OS_chmod(const char *path, uint32 access_mode)
char local_path[OS_MAX_LOCAL_PATH_LEN];
int32 return_code;

return_code = OS_TranslatePath(path, local_path);
return_code = OS_TranslatePathWithSize(path, local_path, sizeof(local_path));
if (return_code == OS_SUCCESS)
{
return_code = OS_FileChmod_Impl(local_path, access_mode);
Expand All @@ -307,7 +307,7 @@ int32 OS_stat(const char *path, os_fstat_t *filestats)

memset(filestats, 0, sizeof(*filestats));

return_code = OS_TranslatePath(path, local_path);
return_code = OS_TranslatePathWithSize(path, local_path, sizeof(local_path));
if (return_code == OS_SUCCESS)
{
return_code = OS_FileStat_Impl(local_path, filestats);
Expand Down Expand Up @@ -398,7 +398,7 @@ int32 OS_remove(const char *path)
int32 return_code;
char local_path[OS_MAX_LOCAL_PATH_LEN];

return_code = OS_TranslatePath(path, local_path);
return_code = OS_TranslatePathWithSize(path, local_path, sizeof(local_path));
if (return_code == OS_SUCCESS)
{
return_code = OS_FileRemove_Impl(local_path);
Expand All @@ -421,10 +421,10 @@ int32 OS_rename(const char *old_filename, const char *new_filename)
char old_path[OS_MAX_LOCAL_PATH_LEN];
char new_path[OS_MAX_LOCAL_PATH_LEN];

return_code = OS_TranslatePath(old_filename, old_path);
return_code = OS_TranslatePathWithSize(old_filename, old_path, sizeof(old_path));
if (return_code == OS_SUCCESS)
{
return_code = OS_TranslatePath(new_filename, new_path);
return_code = OS_TranslatePathWithSize(new_filename, new_path, sizeof(new_path));
}

if (return_code == OS_SUCCESS)
Expand Down
17 changes: 15 additions & 2 deletions src/os/shared/src/osapi-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,20 @@ int32 OS_GetFsInfo(os_fsinfo_t *filesys_info)
* See description in API and header file for detail
*
*-----------------------------------------------------------------*/
#ifndef OSAL_OMIT_DEPRECATED
int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath)
{
return OS_TranslatePathWithSize(VirtualPath, LocalPath, OS_MAX_LOCAL_PATH_LEN);
}
#endif

/*----------------------------------------------------------------
*
* Purpose: Implemented per public OSAL API
* See description in API and header file for detail
*
*-----------------------------------------------------------------*/
int32 OS_TranslatePathWithSize(const char *VirtualPath, char *LocalPath, size_t LocalPathSize)
{
OS_object_token_t token;
int32 return_code;
Expand Down Expand Up @@ -750,7 +763,7 @@ int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath)
{
SysMountPointLen = OS_strnlen(filesys->system_mountpt, sizeof(filesys->system_mountpt));
VirtPathBegin = OS_strnlen(filesys->virtual_mountpt, sizeof(filesys->virtual_mountpt));
if (SysMountPointLen < OS_MAX_LOCAL_PATH_LEN)
if (SysMountPointLen < LocalPathSize)
{
memcpy(LocalPath, filesys->system_mountpt, SysMountPointLen);
}
Expand All @@ -772,7 +785,7 @@ int32 OS_TranslatePath(const char *VirtualPath, char *LocalPath)
else
{
VirtPathLen -= VirtPathBegin;
if ((SysMountPointLen + VirtPathLen) < OS_MAX_LOCAL_PATH_LEN)
if ((SysMountPointLen + VirtPathLen) < LocalPathSize)
{
memcpy(&LocalPath[SysMountPointLen], &VirtualPath[VirtPathBegin], VirtPathLen);
LocalPath[SysMountPointLen + VirtPathLen] = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/os/shared/src/osapi-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f
* Check parameters
*
* Note "filename" is not checked, because in certain configurations it can be validly
* null. filename is checked for NULL-ness by the OS_TranslatePath() later.
* null. filename is checked for NULL-ness by the OS_TranslatePathWithSize() later.
*/
OS_CHECK_POINTER(module_id);
OS_CHECK_APINAME(module_name);
Expand All @@ -208,7 +208,7 @@ int32 OS_ModuleLoad(osal_id_t *module_id, const char *module_name, const char *f
* The status of this operation is stored separately, because it may or
* may not be relevant, depending on whether the static module table is enabled.
*/
filename_status = OS_TranslatePath(filename, translated_path);
filename_status = OS_TranslatePathWithSize(filename, translated_path, sizeof(translated_path));

/* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */
return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, module_name, &token);
Expand Down Expand Up @@ -443,7 +443,7 @@ int32 OS_SymbolTableDump(const char *filename, size_t size_limit)
/*
** Translate the filename to the Host System
*/
return_code = OS_TranslatePath(filename, translated_path);
return_code = OS_TranslatePathWithSize(filename, translated_path, sizeof(translated_path));
if (return_code != OS_SUCCESS)
{
return return_code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ void TestFileSysAddFixedMapApi(void)
* Just map /test to a dir of the same name, relative to current dir.
*/

UtAssert_INT32_EQ(OS_TranslatePath("/test/myfile.txt", translated_path), OS_FS_ERR_PATH_INVALID);
UtAssert_INT32_EQ(OS_TranslatePathWithSize("/test/myfile.txt", translated_path, sizeof(translated_path)),
OS_FS_ERR_PATH_INVALID);
UtAssert_INT32_EQ(OS_FileSysAddFixedMap(&fs_id, "./test", "/test"), OS_SUCCESS);
UtAssert_INT32_EQ(OS_TranslatePath("/test/myfile.txt", translated_path), OS_SUCCESS);
UtAssert_INT32_EQ(OS_TranslatePathWithSize("/test/myfile.txt", translated_path, sizeof(translated_path)),
OS_SUCCESS);

/* Test for invalid inputs */
UtAssert_INT32_EQ(OS_FileSysAddFixedMap(NULL, "./test", "/test"), OS_INVALID_POINTER);
Expand Down
6 changes: 3 additions & 3 deletions src/unit-test-coverage/shared/src/coveragetest-dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void Test_OS_mkdir(void)
*/
OSAPI_TEST_FUNCTION_RC(OS_mkdir("Dir", OS_READ_WRITE), OS_SUCCESS);

UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePathWithSize), OS_ERROR);
OSAPI_TEST_FUNCTION_RC(OS_mkdir("Dir", OS_READ_WRITE), OS_ERROR);
}

Expand All @@ -67,7 +67,7 @@ void Test_OS_DirectoryOpen(void)
UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdAllocateNew), OS_ERR_NO_FREE_IDS);
OSAPI_TEST_FUNCTION_RC(OS_DirectoryOpen(&objid, "Dir"), OS_ERR_NO_FREE_IDS);

UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePathWithSize), OS_ERROR);
OSAPI_TEST_FUNCTION_RC(OS_DirectoryOpen(&objid, "Dir"), OS_ERROR);

/*
Expand Down Expand Up @@ -128,7 +128,7 @@ void Test_OS_rmdir(void)
*/
OSAPI_TEST_FUNCTION_RC(OS_rmdir("Dir"), OS_SUCCESS);

UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePathWithSize), OS_ERROR);
OSAPI_TEST_FUNCTION_RC(OS_rmdir("Dir"), OS_ERROR);
}

Expand Down
18 changes: 9 additions & 9 deletions src/unit-test-coverage/shared/src/coveragetest-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ void Test_OS_OpenCreate(void)
OSAPI_TEST_FUNCTION_RC(OS_OpenCreate(&filedes, "/cf/file", OS_FILE_FLAG_NONE, OS_READ_WRITE), OS_ERR_NO_FREE_IDS);

/* Test failure to convert path */
UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePathWithSize), OS_ERROR);
expected = OS_ERROR;
actual = OS_OpenCreate(&filedes, "/cf/file", OS_FILE_FLAG_NONE, OS_READ_WRITE);
UtAssert_True(actual == OS_ERROR, "OS_OpenCreate() (%ld) == OS_ERROR (bad path)", (long)actual);
UT_ClearDefaultReturnValue(UT_KEY(OS_TranslatePath));
UT_ClearDefaultReturnValue(UT_KEY(OS_TranslatePathWithSize));
}

void Test_OS_close(void)
Expand Down Expand Up @@ -187,7 +187,7 @@ void Test_OS_chmod(void)
*/
OSAPI_TEST_FUNCTION_RC(OS_chmod("/cf/file", 0), OS_SUCCESS);

UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePathWithSize), OS_ERROR);
OSAPI_TEST_FUNCTION_RC(OS_chmod("/cf/file", 0), OS_ERROR);
}

Expand All @@ -201,7 +201,7 @@ void Test_OS_stat(void)

OSAPI_TEST_FUNCTION_RC(OS_stat("/cf/file", &statbuf), OS_SUCCESS);

UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePathWithSize), OS_ERROR);
OSAPI_TEST_FUNCTION_RC(OS_stat("/cf/file", &statbuf), OS_ERROR);

OSAPI_TEST_FUNCTION_RC(OS_stat("/cf/file", NULL), OS_INVALID_POINTER);
Expand All @@ -227,7 +227,7 @@ void Test_OS_remove(void)
*/
OSAPI_TEST_FUNCTION_RC(OS_remove("/cf/file"), OS_SUCCESS);

UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePathWithSize), OS_ERROR);
OSAPI_TEST_FUNCTION_RC(OS_remove("/cf/file"), OS_ERROR);
}

Expand All @@ -245,9 +245,9 @@ void Test_OS_rename(void)
"OS_stream_table[1].stream_name (%s) == /cf/file2",
OS_stream_table[1].stream_name);

UT_SetDeferredRetcode(UT_KEY(OS_TranslatePath), 2, OS_ERROR);
UT_SetDeferredRetcode(UT_KEY(OS_TranslatePathWithSize), 2, OS_ERROR);
OSAPI_TEST_FUNCTION_RC(OS_rename("/cf/file1", "/cf/file2"), OS_ERROR);
UT_SetDeferredRetcode(UT_KEY(OS_TranslatePath), 1, OS_ERROR);
UT_SetDeferredRetcode(UT_KEY(OS_TranslatePathWithSize), 1, OS_ERROR);
OSAPI_TEST_FUNCTION_RC(OS_rename("/cf/file1", "/cf/file2"), OS_ERROR);
}

Expand Down Expand Up @@ -275,7 +275,7 @@ void Test_OS_cp(void)
UT_SetDefaultReturnValue(UT_KEY(OS_GenericWrite_Impl), -555);
OSAPI_TEST_FUNCTION_RC(OS_cp("/cf/file1", "/cf/file2"), -555);

UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), -666);
UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePathWithSize), -666);
OSAPI_TEST_FUNCTION_RC(OS_cp("/cf/file1", "/cf/file2"), -666);
}

Expand All @@ -293,7 +293,7 @@ void Test_OS_mv(void)
OSAPI_TEST_FUNCTION_RC(OS_mv("/cf/file1", "/cf/file2"), OS_SUCCESS);

/* Fail the OS_cp/OS_OpenCreate */
UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_ERROR);
UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePathWithSize), OS_ERROR);
OSAPI_TEST_FUNCTION_RC(OS_mv("/cf/file1", "/cf/file2"), OS_ERROR);
}

Expand Down
Loading
Loading