From 97dadced5e03caa05fc46abfe5a0d2881355eafd Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Mon, 17 Jun 2024 13:35:55 +0800 Subject: [PATCH 1/4] doc: posix: option_groups: mark msync as supported `msync()` has been implemented in #73799. Signed-off-by: Yong Cong Sin --- doc/services/portability/posix/option_groups/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/services/portability/posix/option_groups/index.rst b/doc/services/portability/posix/option_groups/index.rst index e67523ae3d7c..daa86ef65e96 100644 --- a/doc/services/portability/posix/option_groups/index.rst +++ b/doc/services/portability/posix/option_groups/index.rst @@ -805,7 +805,7 @@ _POSIX_SYNCHRONIZED_IO fdatasync(), fsync(),yes - msync(), + msync(),yes .. _posix_option_thread_attr_stackaddr: From aa4e6b7869752448f73ff7a45aa15acf72e0ea72 Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Mon, 17 Jun 2024 13:39:19 +0800 Subject: [PATCH 2/4] posix: fs: implement `fdatasync()` `fdatasync()` is basically equivalent to `fsync()` according to the standards. Added test for it. Signed-off-by: Yong Cong Sin --- .../portability/posix/option_groups/index.rst | 2 +- include/zephyr/posix/unistd.h | 4 ++ lib/posix/options/fsync.c | 7 ++++ tests/posix/fs/src/test_fs_file.c | 37 +++++++++++++++++++ tests/posix/headers/src/unistd_h.c | 2 +- 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/doc/services/portability/posix/option_groups/index.rst b/doc/services/portability/posix/option_groups/index.rst index daa86ef65e96..b494546411aa 100644 --- a/doc/services/portability/posix/option_groups/index.rst +++ b/doc/services/portability/posix/option_groups/index.rst @@ -803,7 +803,7 @@ _POSIX_SYNCHRONIZED_IO :header: API, Supported :widths: 50,10 - fdatasync(), + fdatasync(),yes fsync(),yes msync(),yes diff --git a/include/zephyr/posix/unistd.h b/include/zephyr/posix/unistd.h index 194b2bffe6f5..2d1e0244d59a 100644 --- a/include/zephyr/posix/unistd.h +++ b/include/zephyr/posix/unistd.h @@ -35,6 +35,10 @@ off_t lseek(int file, off_t offset, int whence); int fsync(int fd); int ftruncate(int fd, off_t length); +#ifdef CONFIG_POSIX_SYNCHRONIZED_IO +int fdatasync(int fd); +#endif /* CONFIG_POSIX_SYNCHRONIZED_IO */ + /* File System related operations */ int rename(const char *old, const char *newp); int unlink(const char *path); diff --git a/lib/posix/options/fsync.c b/lib/posix/options/fsync.c index 8ec28b4440dc..e41a1dc5bfac 100644 --- a/lib/posix/options/fsync.c +++ b/lib/posix/options/fsync.c @@ -16,3 +16,10 @@ int fsync(int fd) #ifdef CONFIG_POSIX_FILE_SYSTEM_ALIAS_FSYNC FUNC_ALIAS(fsync, _fsync, int); #endif + +#ifdef CONFIG_POSIX_SYNCHRONIZED_IO +int fdatasync(int fd) +{ + return fsync(fd); +} +#endif /* CONFIG_POSIX_SYNCHRONIZED_IO */ diff --git a/tests/posix/fs/src/test_fs_file.c b/tests/posix/fs/src/test_fs_file.c index 9614412a07a5..43fdaa3ac3f4 100644 --- a/tests/posix/fs/src/test_fs_file.c +++ b/tests/posix/fs/src/test_fs_file.c @@ -159,6 +159,26 @@ static int test_file_fsync(void) return res; } +#ifdef CONFIG_POSIX_SYNCHRONIZED_IO +static int test_file_fdatasync(void) +{ + int res = 0; + + if (file < 0) + return res; + + res = fdatasync(file); + if (res < 0) { + TC_ERROR("Failed to sync file: %d, errno = %d\n", res, errno); + res = TC_FAIL; + } + + close(file); + file = -1; + return res; +} +#endif /* CONFIG_POSIX_SYNCHRONIZED_IO */ + static int test_file_truncate(void) { int res = 0; @@ -251,6 +271,23 @@ ZTEST(posix_fs_file_test, test_fs_sync) zassert_true(test_file_fsync() == TC_PASS); } +/** + * @brief Test for POSIX fdatasync API + * + * @details Test sync the file through POSIX fdatasync API. + */ +ZTEST(posix_fs_file_test, test_fs_datasync) +{ +#ifdef CONFIG_POSIX_SYNCHRONIZED_IO + /* FIXME: restructure tests as per #46897 */ + zassert_true(test_file_open() == TC_PASS); + zassert_true(test_file_write() == TC_PASS); + zassert_true(test_file_fdatasync() == TC_PASS); +#else + ztest_test_skip(); +#endif +} + /** * @brief Test for POSIX ftruncate API * diff --git a/tests/posix/headers/src/unistd_h.c b/tests/posix/headers/src/unistd_h.c index 55d1218c14a5..c9560a2cefb2 100644 --- a/tests/posix/headers/src/unistd_h.c +++ b/tests/posix/headers/src/unistd_h.c @@ -230,7 +230,7 @@ ZTEST(posix_headers, test_unistd_h) /* zassert_not_null(fchdir); */ /* not implemented */ /* zassert_not_null(fchown); */ /* not implemented */ /* zassert_not_null(fchownat); */ /* not implemented */ - /* zassert_not_null(fdatasync); */ /* not implemented */ + zassert_not_null(fdatasync); /* zassert_not_null(fexecve); */ /* not implemented */ /* zassert_not_null(fork); */ /* not implemented */ /* zassert_not_null(fpathconf); */ /* not implemented */ From 8f69ecddaa4ce4601aed285807bc8969585d3bd2 Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Mon, 17 Jun 2024 13:41:15 +0800 Subject: [PATCH 3/4] posix: fs: mark _POSIX_SYNCHRONIZED_IO as supported The `_POSIX_SYNCHRONIZED_IO` option group is now fully supported. Signed-off-by: Yong Cong Sin --- doc/services/portability/posix/aep/index.rst | 2 +- doc/services/portability/posix/conformance/index.rst | 2 +- include/zephyr/posix/posix_features.h | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/services/portability/posix/aep/index.rst b/doc/services/portability/posix/aep/index.rst index aeb591f2ab0a..5a0743532afb 100644 --- a/doc/services/portability/posix/aep/index.rst +++ b/doc/services/portability/posix/aep/index.rst @@ -64,7 +64,7 @@ The *Minimal Realtime System Profile* (PSE51) includes all of the :ref:`_POSIX_MEMLOCK_RANGE `, 200809L, :kconfig:option:`CONFIG_POSIX_MEMLOCK_RANGE` :ref:`_POSIX_MONOTONIC_CLOCK `, 200809L, :kconfig:option:`CONFIG_POSIX_MONOTONIC_CLOCK` :ref:`_POSIX_SHARED_MEMORY_OBJECTS `, 200809L, :kconfig:option:`CONFIG_POSIX_SHARED_MEMORY_OBJECTS` - :ref:`_POSIX_SYNCHRONIZED_IO `, -1, :kconfig:option:`CONFIG_POSIX_SYNCHRONIZED_IO` + :ref:`_POSIX_SYNCHRONIZED_IO `, 200809L, :kconfig:option:`CONFIG_POSIX_SYNCHRONIZED_IO` :ref:`_POSIX_THREAD_ATTR_STACKADDR`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_ATTR_STACKADDR` :ref:`_POSIX_THREAD_ATTR_STACKSIZE`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_ATTR_STACKSIZE` :ref:`_POSIX_THREAD_CPUTIME `, 200809L, :kconfig:option:`CONFIG_POSIX_CPUTIME` diff --git a/doc/services/portability/posix/conformance/index.rst b/doc/services/portability/posix/conformance/index.rst index 4cd8687ebf4f..e27899fe0a3f 100644 --- a/doc/services/portability/posix/conformance/index.rst +++ b/doc/services/portability/posix/conformance/index.rst @@ -78,7 +78,7 @@ POSIX System Interfaces :ref:`_POSIX_SHARED_MEMORY_OBJECTS `, 200809L, :kconfig:option:`CONFIG_POSIX_SHARED_MEMORY_OBJECTS` _POSIX_SPAWN, -1, :ref:`†` _POSIX_SPORADIC_SERVER, -1, :ref:`†` - :ref:`_POSIX_SYNCHRONIZED_IO `, -1, :kconfig:option:`CONFIG_POSIX_SYNCHRONIZED_IO` + :ref:`_POSIX_SYNCHRONIZED_IO `, 200809L, :kconfig:option:`CONFIG_POSIX_SYNCHRONIZED_IO` :ref:`_POSIX_THREAD_ATTR_STACKADDR`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_ATTR_STACKADDR` :ref:`_POSIX_THREAD_ATTR_STACKSIZE`, 200809L, :kconfig:option:`CONFIG_POSIX_THREAD_ATTR_STACKSIZE` :ref:`_POSIX_THREAD_CPUTIME `, 200809L, :kconfig:option:`CONFIG_POSIX_CPUTIME` diff --git a/include/zephyr/posix/posix_features.h b/include/zephyr/posix/posix_features.h index 4e15fbd69501..f33417bc8ba9 100644 --- a/include/zephyr/posix/posix_features.h +++ b/include/zephyr/posix/posix_features.h @@ -123,7 +123,10 @@ #endif /* #define _POSIX_SPORADIC_SERVER (-1L) */ -/* #define _POSIX_SYNCHRONIZED_IO (-1L) */ + +#ifdef CONFIG_POSIX_SYNCHRONIZED_IO +#define _POSIX_SYNCHRONIZED_IO _POSIX_VERSION +#endif #ifdef CONFIG_POSIX_THREAD_ATTR_STACKADDR #define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION From 966a9c3a6b34c35bf23ad872eba2aea523e7639b Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Mon, 17 Jun 2024 13:51:10 +0800 Subject: [PATCH 4/4] tests: posix: unistd_h: mark fsync() & ftruncate() as supported These functions have been supported, update the test accordingly. Signed-off-by: Yong Cong Sin --- tests/posix/headers/src/unistd_h.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/posix/headers/src/unistd_h.c b/tests/posix/headers/src/unistd_h.c index c9560a2cefb2..33a17dc72f30 100644 --- a/tests/posix/headers/src/unistd_h.c +++ b/tests/posix/headers/src/unistd_h.c @@ -234,8 +234,8 @@ ZTEST(posix_headers, test_unistd_h) /* zassert_not_null(fexecve); */ /* not implemented */ /* zassert_not_null(fork); */ /* not implemented */ /* zassert_not_null(fpathconf); */ /* not implemented */ - /* zassert_not_null(fsync); */ /* not implemented */ - /* zassert_not_null(ftruncate); */ /* not implemented */ + zassert_not_null(fsync); + zassert_not_null(ftruncate); /* zassert_not_null(getcwd); */ /* not implemented */ /* zassert_not_null(getegid); */ /* not implemented */ /* zassert_not_null(geteuid); */ /* not implemented */