From 9f6590c7b7dcbe1f3e30c1257f60993168ea4c81 Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Wed, 22 May 2024 19:56:11 -0400 Subject: [PATCH] posix: deprecate POSIX_FS for POSIX_FILE_SYSTEM This change deprecates CONFIG_POSIX_FS in favour of CONFIG_POSIX_FILE_SYSTEM, which maps directly to the name of the standard POSIX Option Group. Signed-off-by: Chris Friedt --- doc/services/portability/posix/aep/index.rst | 4 +- .../portability/posix/conformance/index.rst | 2 +- .../portability/posix/kconfig/index.rst | 1 - include/zephyr/posix/dirent.h | 4 +- lib/libc/Kconfig | 1 + lib/libc/newlib/libc-hooks.c | 2 + lib/os/fdtable.c | 5 +-- lib/posix/options/CMakeLists.txt | 7 ++-- lib/posix/options/Kconfig | 1 + lib/posix/options/Kconfig.deprecated | 9 +++++ lib/posix/options/Kconfig.fs | 15 ++++--- lib/posix/options/Kconfig.sync_io | 39 +++++++++++++++++++ lib/posix/options/fs.c | 12 ++++++ lib/posix/options/fsync.c | 18 +++++++++ tests/posix/fs/prj.conf | 2 +- tests/posix/headers/prj.conf | 4 +- 16 files changed, 102 insertions(+), 24 deletions(-) create mode 100644 lib/posix/options/Kconfig.sync_io create mode 100644 lib/posix/options/fsync.c diff --git a/doc/services/portability/posix/aep/index.rst b/doc/services/portability/posix/aep/index.rst index ad02c3e4cb8..83ff41c5a21 100644 --- a/doc/services/portability/posix/aep/index.rst +++ b/doc/services/portability/posix/aep/index.rst @@ -65,7 +65,7 @@ The *Minimal Realtime System Profile* (PSE51) includes all of the :ref:`_POSIX_MEMLOCK_RANGE `, -1, :ref:`_POSIX_MONOTONIC_CLOCK `, 200809L, :kconfig:option:`CONFIG_POSIX_MONOTONIC_CLOCK` :ref:`_POSIX_SHARED_MEMORY_OBJECTS `, -1, - :ref:`_POSIX_SYNCHRONIZED_IO `, -1, + :ref:`_POSIX_SYNCHRONIZED_IO `, -1, :kconfig:option:`CONFIG_POSIX_SYNCHRONIZED_IO` :ref:`_POSIX_THREAD_ATTR_STACKADDR`, 200809L, :kconfig:option:`CONFIG_PTHREAD` :ref:`_POSIX_THREAD_ATTR_STACKSIZE`, 200809L, :kconfig:option:`CONFIG_PTHREAD` :ref:`_POSIX_THREAD_CPUTIME `, 200809L, :kconfig:option:`CONFIG_POSIX_CPUTIME` @@ -103,7 +103,7 @@ The *Realtime Controller System Profile* (PSE52) includes all features from PSE5 :ref:`POSIX_C_LANG_MATH `, yes, :ref:`POSIX_FD_MGMT `,, :kconfig:option:`CONFIG_POSIX_FD_MGMT` - :ref:`POSIX_FILE_SYSTEM `,, + :ref:`POSIX_FILE_SYSTEM `,, :kconfig:option:`CONFIG_POSIX_FILE_SYSTEM` .. csv-table:: PSE52 Option Requirements :header: Symbol, Support, Remarks diff --git a/doc/services/portability/posix/conformance/index.rst b/doc/services/portability/posix/conformance/index.rst index ef0522107d0..439f12b86d6 100644 --- a/doc/services/portability/posix/conformance/index.rst +++ b/doc/services/portability/posix/conformance/index.rst @@ -94,7 +94,7 @@ POSIX System Interfaces _POSIX_SHARED_MEMORY_OBJECTS, -1, _POSIX_SPAWN, -1, :ref:`†` _POSIX_SPORADIC_SERVER, -1, :ref:`†` - _POSIX_SYNCHRONIZED_IO, -1, + :ref:`_POSIX_SYNCHRONIZED_IO `, -1, :kconfig:option:`CONFIG_POSIX_SYNCHRONIZED_IO` :ref:`_POSIX_THREAD_ATTR_STACKADDR`, 200809L, :kconfig:option:`CONFIG_PTHREAD` :ref:`_POSIX_THREAD_ATTR_STACKSIZE`, 200809L, :kconfig:option:`CONFIG_PTHREAD` :ref:`_POSIX_THREAD_CPUTIME `, 200809L, :kconfig:option:`CONFIG_POSIX_CPUTIME` diff --git a/doc/services/portability/posix/kconfig/index.rst b/doc/services/portability/posix/kconfig/index.rst index 14a77e3a3e7..cc2954c00af 100644 --- a/doc/services/portability/posix/kconfig/index.rst +++ b/doc/services/portability/posix/kconfig/index.rst @@ -21,7 +21,6 @@ implementation of the POSIX API. * :kconfig:option:`CONFIG_NET_SOCKETS` * :kconfig:option:`CONFIG_NET_SOCKETS_POLL_MAX` * :kconfig:option:`CONFIG_POSIX_API` -* :kconfig:option:`CONFIG_POSIX_FS` * :kconfig:option:`CONFIG_ZVFS_OPEN_MAX` * :kconfig:option:`CONFIG_POSIX_OPEN_MAX` * :kconfig:option:`CONFIG_POSIX_RTSIG_MAX` diff --git a/include/zephyr/posix/dirent.h b/include/zephyr/posix/dirent.h index 43c68983ebb..12f5d44380d 100644 --- a/include/zephyr/posix/dirent.h +++ b/include/zephyr/posix/dirent.h @@ -9,7 +9,7 @@ #include #include "posix_types.h" -#ifdef CONFIG_POSIX_FS +#ifdef CONFIG_POSIX_FILE_SYSTEM #include #ifdef __cplusplus @@ -32,6 +32,6 @@ struct dirent *readdir(DIR *dirp); } #endif -#endif /* CONFIG_POSIX_FS */ +#endif /* CONFIG_POSIX_FILE_SYSTEM */ #endif /* ZEPHYR_INCLUDE_POSIX_DIRENT_H_ */ diff --git a/lib/libc/Kconfig b/lib/libc/Kconfig index 062dd875cb0..af3230554dd 100644 --- a/lib/libc/Kconfig +++ b/lib/libc/Kconfig @@ -107,6 +107,7 @@ config NEWLIB_LIBC imply POSIX_DEVICE_IO_ALIAS_READ imply POSIX_DEVICE_IO_ALIAS_WRITE imply POSIX_FD_MGMT_ALIAS_LSEEK + imply POSIX_FILE_SYSTEM_ALIAS_FSTAT help Build with newlib library. The newlib library is expected to be part of the SDK in this case. diff --git a/lib/libc/newlib/libc-hooks.c b/lib/libc/newlib/libc-hooks.c index 048aa97a5be..8cbb8f80ab9 100644 --- a/lib/libc/newlib/libc-hooks.c +++ b/lib/libc/newlib/libc-hooks.c @@ -23,6 +23,7 @@ #include #include +int _fstat(int fd, struct stat *st); int _read(int fd, void *buf, int nbytes); int _write(int fd, const void *buf, int nbytes); int _open(const char *name, int mode); @@ -272,6 +273,7 @@ int _getpid(void) } __weak FUNC_ALIAS(_getpid, getpid, int); +#ifndef CONFIG_POSIX_FILE_SYSTEM int _fstat(int file, struct stat *st) { st->st_mode = S_IFCHR; diff --git a/lib/os/fdtable.c b/lib/os/fdtable.c index 1770bd008a8..4970fa6fbf2 100644 --- a/lib/os/fdtable.c +++ b/lib/os/fdtable.c @@ -349,8 +349,7 @@ int zvfs_close(int fd) return res; } -#ifdef CONFIG_POSIX_FSYNC -int fsync(int fd) +int zvfs_fsync(int fd) { if (_check_fd(fd) < 0) { return -1; @@ -358,8 +357,6 @@ int fsync(int fd) return z_fdtable_call_ioctl(fdtable[fd].vtable, fdtable[fd].obj, ZFD_IOCTL_FSYNC); } -FUNC_ALIAS(fsync, _fsync, int); -#endif /* CONFIG_POSIX_FSYNC */ off_t zvfs_lseek(int fd, off_t offset, int whence) { diff --git a/lib/posix/options/CMakeLists.txt b/lib/posix/options/CMakeLists.txt index 9826156fd14..e488fe263b2 100644 --- a/lib/posix/options/CMakeLists.txt +++ b/lib/posix/options/CMakeLists.txt @@ -25,8 +25,8 @@ if(CONFIG_POSIX_SIGNAL) endif() if(CONFIG_POSIX_API OR CONFIG_PTHREAD_IPC OR CONFIG_POSIX_TIMERS OR - CONFIG_POSIX_MESSAGE_PASSING OR CONFIG_POSIX_FS OR CONFIG_EVENTFD OR CONFIG_POSIX_C_LIB_EXT OR - CONFIG_POSIX_SINGLE_PROCESS) + CONFIG_POSIX_MESSAGE_PASSING OR CONFIG_POSIX_FILE_SYSTEM OR CONFIG_EVENTFD OR + CONFIG_POSIX_C_LIB_EXT OR CONFIG_POSIX_SINGLE_PROCESS) # This is a temporary workaround so that Newlib declares the appropriate # types for us. POSIX features to be formalized as part of #51211 zephyr_compile_options($<$:-D_POSIX_THREADS>) @@ -51,7 +51,8 @@ zephyr_library_sources_ifdef(CONFIG_POSIX_DEVICE_IO zephyr_library_sources_ifdef(CONFIG_POSIX_FD_MGMT fd_mgmt.c ) -zephyr_library_sources_ifdef(CONFIG_POSIX_FS fs.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_FILE_SYSTEM fs.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_FSYNC fsync.c) zephyr_library_sources_ifdef(CONFIG_POSIX_MESSAGE_PASSING mqueue.c) zephyr_library_sources_ifdef(CONFIG_POSIX_MULTI_PROCESS sleep.c diff --git a/lib/posix/options/Kconfig b/lib/posix/options/Kconfig index 8e1f0918196..49bed90880c 100644 --- a/lib/posix/options/Kconfig +++ b/lib/posix/options/Kconfig @@ -44,6 +44,7 @@ rsource "Kconfig.semaphore" rsource "Kconfig.signal" rsource "Kconfig.spinlock" rsource "Kconfig.stropts" +rsource "Kconfig.sync_io" rsource "Kconfig.syslog" rsource "Kconfig.timer" rsource "Kconfig.xsi" diff --git a/lib/posix/options/Kconfig.deprecated b/lib/posix/options/Kconfig.deprecated index f0e14373600..719105d12bc 100644 --- a/lib/posix/options/Kconfig.deprecated +++ b/lib/posix/options/Kconfig.deprecated @@ -82,6 +82,15 @@ config POSIX_ENV Please use CONFIG_POSIX_SINGLE_PROCESS instead. +config POSIX_FS + bool "Support for environ, getenv(), getenv_r(), setenv(), and unsetenv() [DEPRECATED]" + select DEPRECATED + select POSIX_FILE_SYSTEM + help + This option is deprecated. + + Please use CONFIG_POSIX_FILE_SYSTEM instead. + config POSIX_LIMITS_RTSIG_MAX int "_POSIX_RTSIG_MAX value in limits.h [DEPRECATED]" default POSIX_RTSIG_MAX if POSIX_REALTIME_SIGNALS diff --git a/lib/posix/options/Kconfig.fs b/lib/posix/options/Kconfig.fs index 35c01cf72a1..663d706e3fb 100644 --- a/lib/posix/options/Kconfig.fs +++ b/lib/posix/options/Kconfig.fs @@ -2,20 +2,19 @@ # # SPDX-License-Identifier: Apache-2.0 -menuconfig POSIX_FS +menuconfig POSIX_FILE_SYSTEM bool "POSIX file system API support" default y if POSIX_API - depends on FILE_SYSTEM + select FILE_SYSTEM select FDTABLE help This enables POSIX style file system related APIs. -if POSIX_FS +if POSIX_FILE_SYSTEM -config POSIX_FSYNC - bool "Support for fsync()" - default y +config POSIX_FILE_SYSTEM_ALIAS_FSTAT + bool help - This enables fsync() support. + Select 'y' here and Zephyr will provide an alias for fstat() as _fstat(). -endif # POSIX_FS +endif # POSIX_FILE_SYSTEM diff --git a/lib/posix/options/Kconfig.sync_io b/lib/posix/options/Kconfig.sync_io new file mode 100644 index 00000000000..4575ff06020 --- /dev/null +++ b/lib/posix/options/Kconfig.sync_io @@ -0,0 +1,39 @@ +# Copyright (c) 2024 Tenstorrent AI ULC +# +# SPDX-License-Identifier: Apache-2.0 + +menu "POSIX synchronized I/O" + +config POSIX_FSYNC + bool "Support for fsync()" + help + Select 'y' here and Zephyr will provide an implementation of fsync(). + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html + + +config POSIX_SYNCHRONIZED_IO + bool "POSIX synchronized I/O" + select POSIX_FSYNC + help + Select 'y' here and Zephyr will provide an implementation of fdatasync(), fsync(), + and msync(). + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/functions/msync.html + https://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html + +if POSIX_FSYNC + +# These options are intended to be used for compatibility with external POSIX +# implementations such as those in Newlib or Picolibc. + +config POSIX_FILE_SYSTEM_ALIAS_FSYNC + bool + help + Select 'y' here and Zephyr will provide an alias for fsync() as _fsync(). + +endif # POSIX_FSYNC + +endmenu diff --git a/lib/posix/options/fs.c b/lib/posix/options/fs.c index caec36692d6..6a572c278f4 100644 --- a/lib/posix/options/fs.c +++ b/lib/posix/options/fs.c @@ -429,3 +429,15 @@ int zvfs_ftruncate(int fd, off_t length) return 0; } + +int fstat(int fildes, struct stat *buf) +{ + ARG_UNUSED(fildes); + ARG_UNUSED(buf); + + errno = ENOTSUP; + return -1; +} +#ifdef CONFIG_POSIX_FILE_SYSTEM_ALIAS_FSTAT +FUNC_ALIAS(fstat, _fstat, int); +#endif diff --git a/lib/posix/options/fsync.c b/lib/posix/options/fsync.c new file mode 100644 index 00000000000..8ec28b4440d --- /dev/null +++ b/lib/posix/options/fsync.c @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2024 Tenstorrent AI ULC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/* prototypes for external, not-yet-public, functions in fdtable.c */ +int zvfs_fsync(int fd); + +int fsync(int fd) +{ + return zvfs_fsync(fd); +} +#ifdef CONFIG_POSIX_FILE_SYSTEM_ALIAS_FSYNC +FUNC_ALIAS(fsync, _fsync, int); +#endif diff --git a/tests/posix/fs/prj.conf b/tests/posix/fs/prj.conf index bb6d36b836e..da73481ef4d 100644 --- a/tests/posix/fs/prj.conf +++ b/tests/posix/fs/prj.conf @@ -2,7 +2,7 @@ CONFIG_FILE_SYSTEM=y CONFIG_LOG=y CONFIG_FAT_FILESYSTEM_ELM=y CONFIG_POSIX_API=y -CONFIG_POSIX_FS=y +CONFIG_POSIX_FILE_SYSTEM=y CONFIG_ZTEST=y CONFIG_MAIN_STACK_SIZE=4096 CONFIG_EVENTFD=n diff --git a/tests/posix/headers/prj.conf b/tests/posix/headers/prj.conf index c785e459293..4a75f1ac46f 100644 --- a/tests/posix/headers/prj.conf +++ b/tests/posix/headers/prj.conf @@ -1,7 +1,7 @@ CONFIG_POSIX_API=y CONFIG_ZTEST=y -# for POSIX_FS +# for POSIX_FILESYSTEM CONFIG_FILE_SYSTEM=y # for select to work @@ -15,7 +15,7 @@ CONFIG_NET_SOCKETPAIR=y # for when CONFIG_POSIX_API is not selected CONFIG_PTHREAD_IPC=y -CONFIG_POSIX_FS=y +CONFIG_POSIX_FILE_SYSTEM=y CONFIG_POSIX_TIMERS=y CONFIG_POSIX_MESSAGE_PASSING=y CONFIG_EVENTFD=y