From 8c7535c523aa140b3a5d43e674ba42c8345a16ad Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 14 Jan 2021 17:08:48 -0500 Subject: [PATCH] Fix #718, deprecate OS_fsBlocksFree and OS_fsBytesFree Users should call OS_FileSysStatVolume() and read the respective output members of the structure as indicated. --- src/os/inc/osapi-filesys.h | 11 + src/os/shared/src/osapi-filesys.c | 4 + .../shared/src/coveragetest-filesys.c | 77 ------- .../osfilesys-test/ut_osfilesys_diskio_test.c | 217 ------------------ .../osfilesys-test/ut_osfilesys_diskio_test.h | 2 - .../osfilesys-test/ut_osfilesys_test.c | 2 - src/ut-stubs/osapi-utstub-filesys.c | 4 + 7 files changed, 19 insertions(+), 298 deletions(-) diff --git a/src/os/inc/osapi-filesys.h b/src/os/inc/osapi-filesys.h index 8e37bdfb4..b0f719ce3 100644 --- a/src/os/inc/osapi-filesys.h +++ b/src/os/inc/osapi-filesys.h @@ -189,6 +189,8 @@ int32 OS_rmfs(const char *devname); */ int32 OS_unmount(const char *mountpoint); +#ifndef OSAL_OMIT_DEPRECATED + /*-------------------------------------------------------------------------------------*/ /** * @brief Obtain number of blocks free @@ -201,6 +203,10 @@ int32 OS_unmount(const char *mountpoint); * @retval #OS_INVALID_POINTER if name is NULL * @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long * @retval #OS_ERROR if the OS call failed + * + * @deprecated Replaced by OS_FileSysStatVolume() - + * Value can be obtained by reading the "blocks_free" struct member. + * */ int32 OS_fsBlocksFree(const char *name); @@ -221,9 +227,14 @@ int32 OS_fsBlocksFree(const char *name); * @retval #OS_INVALID_POINTER if name is NULL * @retval #OS_FS_ERR_PATH_TOO_LONG if the name is too long * @retval #OS_ERROR if the OS call failed + * + * @deprecated Replaced by OS_FileSysStatVolume(). + * Value can be obtained by multiplying the "blocks_free" by the "block_size" struct members. */ int32 OS_fsBytesFree(const char *name, uint64 *bytes_free); +#endif /* OSAL_OMIT_DEPRECATED */ + /*-------------------------------------------------------------------------------------*/ /** * @brief Obtains information about size and free space in a volume diff --git a/src/os/shared/src/osapi-filesys.c b/src/os/shared/src/osapi-filesys.c index 135e4ca77..6db99f794 100644 --- a/src/os/shared/src/osapi-filesys.c +++ b/src/os/shared/src/osapi-filesys.c @@ -533,6 +533,8 @@ int32 OS_unmount(const char *mountpoint) return return_code; } /* end OS_unmount */ +#ifndef OSAL_OMIT_DEPRECATED + /*---------------------------------------------------------------- * * Function: OS_fsBlocksFree @@ -616,6 +618,8 @@ int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) } /* end OS_fsBytesFree */ +#endif /* OSAL_OMIT_DEPRECATED */ + /*---------------------------------------------------------------- * * Function: OS_FileSysStatVolume diff --git a/src/unit-test-coverage/shared/src/coveragetest-filesys.c b/src/unit-test-coverage/shared/src/coveragetest-filesys.c index 6d3c7191b..8d3180866 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/shared/src/coveragetest-filesys.c @@ -253,81 +253,6 @@ void Test_OS_unmount(void) UtAssert_True(actual == expected, "OS_unmount() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); } -void Test_OS_fsBlocksFree(void) -{ - /* - * Test Case For: - * int32 OS_fsBlocksFree (const char *name) - */ - int32 expected = 1111; - int32 actual = ~OS_SUCCESS; - OS_statvfs_t statval; - - statval.block_size = OSAL_SIZE_C(1024); - statval.blocks_free = OSAL_BLOCKCOUNT_C(1111); - statval.total_blocks = OSAL_BLOCKCOUNT_C(2222); - UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume_Impl), &statval, sizeof(statval), false); - OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | - OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; - - actual = OS_fsBlocksFree("/cf"); - UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == 1111", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_fsBlocksFree(NULL); - UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == OS_INVALID_POINTER", (long)actual); - - UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); - expected = OS_FS_ERR_PATH_TOO_LONG; - actual = OS_fsBlocksFree("/cf"); - UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_memchr)); - - UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); - expected = OS_FS_ERR_PATH_INVALID; - actual = OS_fsBlocksFree("invalid"); - UtAssert_True(actual == expected, "OS_fsBlocksFree() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); -} - -void Test_OS_fsBytesFree(void) -{ - /* - * Test Case For: - * int32 OS_fsBytesFree (const char *name, uint64 *bytes_free) - */ - int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - OS_statvfs_t statval; - uint64 bytes_free = 0; - - statval.block_size = OSAL_SIZE_C(1024); - statval.blocks_free = OSAL_BLOCKCOUNT_C(1111); - statval.total_blocks = OSAL_BLOCKCOUNT_C(2222); - UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume_Impl), &statval, sizeof(statval), false); - OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_READY | OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | - OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; - - actual = OS_fsBytesFree("/cf", &bytes_free); - - UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(bytes_free == (1024 * 1111), "bytes_free (%lu) == (1024*1111)", (unsigned long)bytes_free); - - expected = OS_INVALID_POINTER; - actual = OS_fsBytesFree(NULL, NULL); - UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_INVALID_POINTER", (long)actual); - - UT_SetDefaultReturnValue(UT_KEY(OCS_memchr), OS_ERROR); - expected = OS_FS_ERR_PATH_TOO_LONG; - actual = OS_fsBytesFree("/cf", &bytes_free); - UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_FS_ERR_PATH_TOO_LONG", (long)actual); - UT_ClearForceFail(UT_KEY(OCS_memchr)); - - UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdGetBySearch), OS_ERR_NAME_NOT_FOUND); - expected = OS_FS_ERR_PATH_INVALID; - actual = OS_fsBytesFree("invalid", &bytes_free); - UtAssert_True(actual == expected, "OS_fsBytesFree() (%ld) == OS_FS_ERR_PATH_INVALID", (long)actual); -} - void Test_OS_FileSysStatVolume(void) { /* @@ -625,8 +550,6 @@ void UtTest_Setup(void) ADD_TEST(OS_initfs); ADD_TEST(OS_mount); ADD_TEST(OS_unmount); - ADD_TEST(OS_fsBlocksFree); - ADD_TEST(OS_fsBytesFree); ADD_TEST(OS_chkfs); ADD_TEST(OS_FS_GetPhysDriveName); ADD_TEST(OS_GetFsInfo); diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c index 410e1efbf..e9938c84a 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c @@ -1053,223 +1053,6 @@ void UT_os_checkfs_test() return; } -/*--------------------------------------------------------------------------------* -** Syntax: int32 OS_fsBlocksFree(const char *name) -** Purpose: Returns the number of blocks free in a the file system -** Parameters: *name - a pointer to the name of the drive to check for free blocks -** Returns: OS_INVALID_POINTER if the pointer passed in is NULL -** OS_FS_ERR_PATH_TOO_LONG if the path passed in is too long -** OS_ERROR if the OS call failed -** Number of blocks free in a volume if succeeded -** OS_ERR_NOT_IMPLEMENTED if not implemented -** ----------------------------------------------------- -** Test #0: Not-implemented condition -** 1) Call this routine -** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test -** 3) Otherwise, continue. -** ----------------------------------------------------- -** Test #1: Null-pointer-arg condition -** 1) Call this routine with a null pointer as one of the arguments -** 2) Expect the returned value to be -** (a) OS_INVALID_POINTER -** ----------------------------------------------------- -** Test #2: Path-too-long-arg condition -** 1) Call this routine with a path name of length greater than Volume table's -** name as argument -** 2) Expect the returned value to be -** (a) OS_FS_ERR_PATH_TOO_LONG -** ----------------------------------------------------- -** Test #3: OS-call-failure condition -** 1) Setup the test to cause the OS call to fail inside this routine -** 2) Call this routine -** 3) Expect the returned value to be -** (a) OS_ERROR -** ----------------------------------------------------- -** Test#4: Nominal condition -** 1) Make sure no file system has been previously created -** 2) Call OS_mkfs -** 3) Expect the returned value to be -** (a) OS_SUCCESS -** 4) Call OS_mount with device name used in #2 -** 5) Expect the returned value to be -** (a) OS_SUCCESS -** 6) Call this routine with mount-point used in #4 -** 7) Expect the returned value to be -** (a) greater than or equal to 0 -** --------------------------------------------------------------------------------*/ -void UT_os_fsblocksfree_test() -{ - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_fsBlocksFree(NULL) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_fsblocksfree_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; - - if (OS_fsBlocksFree(NULL) == OS_INVALID_POINTER) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 Path-too-long-arg"; - - if (OS_fsBlocksFree(g_fsLongName) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; - - if (OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-system-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_fsblocksfree_test_exit_tag; - } - - if (OS_mount(g_devNames[4], g_mntNames[4]) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-system-mount failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_fsblocksfree_test_exit_tag; - } - - if (OS_fsBlocksFree(g_mntNames[4]) >= 0) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_unmount(g_mntNames[4]); - OS_rmfs(g_devNames[4]); - -UT_os_fsblocksfree_test_exit_tag: - return; -} - -/*--------------------------------------------------------------------------------* -** Syntax: int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) -** Purpose: Returns the number of bytes free in a the file system -** Parameters: *name - a pointer to the name of the drive to check for free bytes -** *bytes_free - a pointer that will hold the number of bytes free -** Returns: OS_INVALID_POINTER if the pointer passed in is NULL -** OS_ERROR if the OS call failed -** OS_SUCCESS if succeeded -** OS_ERR_NOT_IMPLEMENTED if not implemented -** ----------------------------------------------------- -** Test #0: Not-implemented condition -** 1) Call this routine -** 2) If the returned value is OS_ERR_NOT_IMPLEMENTED, then exit test -** 3) Otherwise, continue. -** ----------------------------------------------------- -** Test #1: Null-pointer-arg condition -** 1) Call this routine with a null pointer as one of the arguments -** 2) Expect the returned value to be -** (a) OS_INVALID_POINTER -** ----------------------------------------------------- -** Test #2: Path-too-long-arg condition -** 1) Call this routine with a path name of length greater than Volume table's -** name as argument -** 2) Expect the returned value to be -** (a) OS_FS_ERR_PATH_TOO_LONG -** ----------------------------------------------------- -** Test #3: OS-call-failure condition -** 1) Setup the test to cause the OS call to fail inside this routine -** 2) Call this routine -** 3) Expect the returned value to be -** (a) OS_ERROR -** ----------------------------------------------------- -** Test#4: Nominal condition -** 1) Make sure no file system has been previously created -** 2) Call OS_mkfs -** 3) Expect the returned value to be -** (a) OS_SUCCESS -** 4) Call OS_mount with device name used in #2 -** 5) Expect the returned value to be -** (a) OS_SUCCESS -** 6) Call this routine with mount-point used in #4 -** 7) Expect the returned value to be -** (a) greater than or equal to 0 -** --------------------------------------------------------------------------------*/ -void UT_os_fsbytesfree_test() -{ - uint64 retBytes = 0; - const char *testDesc; - - /*-----------------------------------------------------*/ - testDesc = "API not implemented"; - - if (OS_fsBytesFree(NULL, NULL) == OS_ERR_NOT_IMPLEMENTED) - { - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_fsbytesfree_test_exit_tag; - } - - /*-----------------------------------------------------*/ - testDesc = "#1 Null-pointer-arg"; - - if ((OS_fsBytesFree(NULL, &retBytes) == OS_INVALID_POINTER) && - (OS_fsBytesFree(g_mntNames[1], NULL) == OS_INVALID_POINTER)) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#2 Path-too-long-arg"; - - if (OS_fsBytesFree(g_fsLongName, &retBytes) == OS_FS_ERR_PATH_TOO_LONG) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /*-----------------------------------------------------*/ - testDesc = "#3 OS-call-failure"; - - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_INFO); - - /*-----------------------------------------------------*/ - testDesc = "#4 Nominal"; - - if (OS_mkfs(g_fsAddrPtr, g_devNames[4], g_volNames[4], g_blkSize, g_blkCnt) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-system-create failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_fsbytesfree_test_exit_tag; - } - - if (OS_mount(g_devNames[4], g_mntNames[4]) != OS_SUCCESS) - { - testDesc = "#4 Nominal - File-system-mount failed"; - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_TSF); - goto UT_os_fsbytesfree_test_exit_tag; - } - - if (OS_fsBytesFree(g_mntNames[4], &retBytes) == OS_SUCCESS) - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_PASS); - else - UT_OS_TEST_RESULT(testDesc, UTASSERT_CASETYPE_FAILURE); - - /* Reset test environment */ - OS_unmount(g_mntNames[4]); - OS_rmfs(g_devNames[4]); - -UT_os_fsbytesfree_test_exit_tag: - return; -} /*--------------------------------------------------------------------------------* ** Syntax: int32 OS_fsstatvolume(const char *name) diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h index f1420c68c..b9141a773 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.h @@ -69,8 +69,6 @@ void UT_os_translatepath_test(void); void UT_os_checkfs_test(void); -void UT_os_fsblocksfree_test(void); -void UT_os_fsbytesfree_test(void); void UT_os_fsstatvolume_test(void); /*--------------------------------------------------------------------------------*/ diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_test.c b/src/unit-tests/osfilesys-test/ut_osfilesys_test.c index 3850eff52..5a8496d72 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_test.c +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_test.c @@ -135,8 +135,6 @@ void UtTest_Setup(void) UtTest_Add(UT_os_translatepath_test, NULL, NULL, "OS_TranslatePath (internal)"); UtTest_Add(UT_os_checkfs_test, NULL, NULL, "OS_chkfs"); - UtTest_Add(UT_os_fsblocksfree_test, NULL, NULL, "OS_fsBlocksFree"); - UtTest_Add(UT_os_fsbytesfree_test, NULL, NULL, "OS_fsBytesFree"); UtTest_Add(UT_os_fsstatvolume_test, NULL, NULL, "OS_FileSysStatVolume"); } diff --git a/src/ut-stubs/osapi-utstub-filesys.c b/src/ut-stubs/osapi-utstub-filesys.c index b696751e5..f0f4d6175 100644 --- a/src/ut-stubs/osapi-utstub-filesys.c +++ b/src/ut-stubs/osapi-utstub-filesys.c @@ -153,6 +153,8 @@ int32 OS_unmount(const char *mountpoint) return status; } +#ifndef OSAL_OMIT_DEPRECATED + /***************************************************************************** * * Stub function for OS_fsBlocksFree() @@ -192,6 +194,8 @@ int32 OS_fsBytesFree(const char *name, uint64 *bytes_free) return status; } +#endif /* OSAL_OMIT_DEPRECATED */ + /***************************************************************************** * * Stub function for OS_FileSysStatVolume()