Skip to content

Commit f16f3f6

Browse files
Jakub Klimczaknashif
authored andcommitted
zvfs: Move fdtable into ZVFS
The file descriptor table is used in every area that expects to work on files through descriptor indices. It can only be operated on through functions whose names indicate a relationship with ZVFS (`zvfs_*fd*`). The integer file descriptor mechanism shouldn't be separate from ZVFS. This will make cooperation between different file access APIs much simpler. This commit also makes preparations for the fdtable becoming optional. Signed-off-by: Jakub Klimczak <[email protected]>
1 parent 735f0d7 commit f16f3f6

File tree

15 files changed

+38
-39
lines changed

15 files changed

+38
-39
lines changed

doc/services/portability/posix/kconfig/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ implementation of the POSIX API.
99
* :kconfig:option:`CONFIG_DYNAMIC_THREAD`
1010
* :kconfig:option:`CONFIG_DYNAMIC_THREAD_POOL_SIZE`
1111
* :kconfig:option:`CONFIG_EVENTFD`
12-
* :kconfig:option:`CONFIG_FDTABLE`
1312
* :kconfig:option:`CONFIG_GETOPT_LONG`
1413
* :kconfig:option:`CONFIG_MAX_PTHREAD_SPINLOCK_COUNT`
1514
* :kconfig:option:`CONFIG_MQUEUE_NAMELEN_MAX`
@@ -38,3 +37,4 @@ implementation of the POSIX API.
3837
* :kconfig:option:`CONFIG_TIMER_CREATE_WAIT`
3938
* :kconfig:option:`CONFIG_THREAD_STACK_INFO`
4039
* :kconfig:option:`CONFIG_ZVFS_EVENTFD_MAX`
40+
* :kconfig:option:`CONFIG_ZVFS_FDTABLE`

drivers/wifi/simplelink/Kconfig.simplelink

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ menuconfig WIFI_SIMPLELINK
88
select SIMPLELINK_HOST_DRIVER
99
select WIFI_OFFLOAD
1010
select NET_L2_WIFI_MGMT
11-
select FDTABLE
11+
select ZVFS
12+
select ZVFS_FDTABLE
1213
select POSIX_SEMAPHORES
1314

1415
if WIFI_SIMPLELINK

lib/os/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ endif()
4343

4444
zephyr_compile_definitions(ZVFS_OPEN_SIZE=${final_fd_size})
4545

46-
zephyr_sources_ifdef(CONFIG_FDTABLE fdtable.c)
47-
zephyr_syscall_header_ifdef(CONFIG_FDTABLE
48-
${ZEPHYR_BASE}/include/zephyr/sys/fdtable.h
49-
)
50-
5146
zephyr_sources_ifdef(CONFIG_CBPRINTF_COMPLETE cbprintf_complete.c)
5247
zephyr_sources_ifdef(CONFIG_CBPRINTF_NANO cbprintf_nano.c)
5348
add_subdirectory_ifdef(CONFIG_CPU_LOAD_METRIC cpu_load)
@@ -78,3 +73,7 @@ zephyr_library_include_directories(
7873
)
7974

8075
add_subdirectory_ifdef(CONFIG_ZVFS zvfs)
76+
77+
zephyr_syscall_header_ifdef(CONFIG_ZVFS_FDTABLE
78+
${ZEPHYR_BASE}/include/zephyr/sys/fdtable.h
79+
)

lib/os/Kconfig

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,6 @@
33

44
menu "OS Support Library"
55

6-
config FDTABLE
7-
bool "File descriptor table"
8-
help
9-
This file provides generic file descriptor table implementation, suitable
10-
for any I/O object implementing POSIX I/O semantics (i.e. read/write +
11-
aux operations).
12-
13-
if FDTABLE
14-
15-
config ZVFS_DEFAULT_FILE_VMETHODS
16-
bool "ZVFS default virtual methods for files"
17-
default y
18-
help
19-
Provide typical file operations, which can be referenced in a struct fd_op_vtable
20-
and subsequently called by ZVFS functions.
21-
22-
endif
23-
246
config ZVFS_OPEN_MAX
257
int "Maximum number of open file descriptors"
268
default 0

lib/os/zvfs/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: Apache-2.0
22

33
zephyr_library()
4+
zephyr_library_sources_ifdef(CONFIG_ZVFS_FDTABLE zvfs_fdtable.c)
45
zephyr_library_sources_ifdef(CONFIG_ZVFS_DEFAULT_FILE_VMETHODS zvfs_file_vmethods.c)
56
zephyr_library_sources_ifdef(CONFIG_ZVFS_EVENTFD zvfs_eventfd.c)
67
zephyr_library_sources_ifdef(CONFIG_ZVFS_POLL zvfs_poll.c)

lib/os/zvfs/Kconfig

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
menuconfig ZVFS
77
bool "Zephyr virtual filesystem (ZVFS) support [EXPERIMENTAL]"
8-
select FDTABLE
98
select EXPERIMENTAL
109
help
1110
ZVFS is a central, Zephyr-native library that provides a common interoperable API for all
@@ -14,9 +13,28 @@ menuconfig ZVFS
1413

1514
if ZVFS
1615

16+
config ZVFS_FDTABLE
17+
bool "ZVFS file descriptor table"
18+
default y
19+
help
20+
This file provides generic file descriptor table implementation, suitable
21+
for any I/O object implementing POSIX I/O semantics (i.e. read/write +
22+
aux operations).
23+
24+
if ZVFS_FDTABLE
25+
26+
config ZVFS_DEFAULT_FILE_VMETHODS
27+
bool "ZVFS default virtual methods for files"
28+
help
29+
Provide typical file operations, which can be referenced in a struct fd_op_vtable
30+
and subsequently called by ZVFS functions.
31+
32+
endif
33+
1734
config ZVFS_EVENTFD
1835
bool "ZVFS event file descriptor support"
1936
imply ZVFS_POLL
37+
select ZVFS_FDTABLE
2038
help
2139
Enable support for ZVFS event file descriptors. An eventfd can
2240
be used as an event wait/notify mechanism together with POSIX calls
@@ -37,6 +55,7 @@ endif # ZVFS_EVENTFD
3755
config ZVFS_POLL
3856
bool "ZVFS poll"
3957
select POLL
58+
select ZVFS_FDTABLE
4059
help
4160
Enable support for zvfs_poll().
4261

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ static int z_get_fd_by_obj_and_vtable(void *obj, const struct fd_op_vtable *vtab
236236
}
237237

238238
bool zvfs_get_obj_lock_and_cond(void *obj, const struct fd_op_vtable *vtable, struct k_mutex **lock,
239-
struct k_condvar **cond)
239+
struct k_condvar **cond)
240240
{
241241
int fd;
242242
struct fd_entry *entry;
@@ -259,8 +259,7 @@ bool zvfs_get_obj_lock_and_cond(void *obj, const struct fd_op_vtable *vtable, st
259259
return true;
260260
}
261261

262-
void *zvfs_get_fd_obj_and_vtable(int fd, const struct fd_op_vtable **vtable,
263-
struct k_mutex **lock)
262+
void *zvfs_get_fd_obj_and_vtable(int fd, const struct fd_op_vtable **vtable, struct k_mutex **lock)
264263
{
265264
struct fd_entry *entry;
266265

@@ -324,8 +323,7 @@ void zvfs_finalize_typed_fd(int fd, void *obj, const struct fd_op_vtable *vtable
324323
if (vtable && vtable->ioctl) {
325324
int prev_errno = errno;
326325

327-
(void)zvfs_fdtable_call_ioctl(vtable, obj, ZFD_IOCTL_SET_LOCK,
328-
&fdtable[fd].lock);
326+
(void)zvfs_fdtable_call_ioctl(vtable, obj, ZFD_IOCTL_SET_LOCK, &fdtable[fd].lock);
329327
if ((prev_errno != EOPNOTSUPP) && (errno == EOPNOTSUPP)) {
330328
/* restore backed-up errno value if the backend does not support locking */
331329
errno = prev_errno;
@@ -626,7 +624,6 @@ static int stdinout_ioctl_vmeth(void *obj, unsigned int request, va_list args)
626624
return -1;
627625
}
628626

629-
630627
static const struct fd_op_vtable stdinout_fd_op_vtable = {
631628
.read = stdinout_read_vmeth,
632629
.write = stdinout_write_vmeth,

lib/posix/options/Kconfig.device_io

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ config POSIX_DEVICE_IO
88
bool "POSIX device I/O"
99
select REQUIRES_FULL_LIBC
1010
select ZVFS
11+
select ZVFS_DEFAULT_FILE_VMETHODS
1112
select ZVFS_POLL
1213
select ZVFS_SELECT
1314
help

lib/posix/options/Kconfig.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ menuconfig POSIX_FILE_SYSTEM
66
bool "POSIX file system API support"
77
default y if POSIX_API
88
select FILE_SYSTEM
9-
select FDTABLE
9+
select ZVFS
10+
select ZVFS_FDTABLE
1011
help
1112
This enables POSIX style file system related APIs.
1213

lib/posix/options/Kconfig.mem

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ config POSIX_SHARED_MEMORY_OBJECTS
1616
bool "POSIX shared memory objects"
1717
select SYS_HASH_FUNC32
1818
select SYS_HASH_FUNC32_DJB2
19-
select FDTABLE
19+
select ZVFS
20+
select ZVFS_FDTABLE
2021
select POSIX_MAPPED_FILES
2122
help
2223
Select 'y' here and Zephyr will provide implementations of shm_open() and shm_unlink().

0 commit comments

Comments
 (0)