Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
fdtable.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Linaro Limited
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef ZEPHYR_INCLUDE_SYS_FDTABLE_H_
7#define ZEPHYR_INCLUDE_SYS_FDTABLE_H_
8
9#include <stdarg.h>
10#include <sys/types.h>
11/* FIXME: For native_posix ssize_t, off_t. */
12#include <zephyr/fs/fs.h>
13#include <zephyr/sys/mutex.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
24 ssize_t (*read)(void *obj, void *buf, size_t sz);
25 ssize_t (*write)(void *obj, const void *buf, size_t sz);
26 int (*close)(void *obj);
27 int (*ioctl)(void *obj, unsigned int request, va_list args);
28};
29
40int z_reserve_fd(void);
41
52void z_finalize_fd(int fd, void *obj, const struct fd_op_vtable *vtable);
53
65int z_alloc_fd(void *obj, const struct fd_op_vtable *vtable);
66
75void z_free_fd(int fd);
76
93void *z_get_fd_obj(int fd, const struct fd_op_vtable *vtable, int err);
94
107void *z_get_fd_obj_and_vtable(int fd, const struct fd_op_vtable **vtable,
108 struct k_mutex **lock);
109
125bool z_get_obj_lock_and_cond(void *obj, const struct fd_op_vtable *vtable, struct k_mutex **lock,
126 struct k_condvar **cond);
127
140static inline int z_fdtable_call_ioctl(const struct fd_op_vtable *vtable, void *obj,
141 unsigned long request, ...)
142{
143 va_list args;
144 int res;
145
146 va_start(args, request);
147 res = vtable->ioctl(obj, request, args);
148 va_end(args);
149
150 return res;
151}
152
161enum {
162 /* Codes below 0x100 are reserved for fcntl() codes. */
169
170 /* Codes above 0x5400 and below 0x5500 are reserved for termios, FIO, etc */
173};
174
175#ifdef __cplusplus
176}
177#endif
178
179#endif /* ZEPHYR_INCLUDE_SYS_FDTABLE_H_ */
@ ZFD_IOCTL_SET_LOCK
Definition: fdtable.h:168
@ ZFD_IOCTL_FIONREAD
Definition: fdtable.h:171
@ ZFD_IOCTL_POLL_PREPARE
Definition: fdtable.h:165
@ ZFD_IOCTL_FSYNC
Definition: fdtable.h:163
@ ZFD_IOCTL_LSEEK
Definition: fdtable.h:164
@ ZFD_IOCTL_FIONBIO
Definition: fdtable.h:172
@ ZFD_IOCTL_POLL_OFFLOAD
Definition: fdtable.h:167
@ ZFD_IOCTL_POLL_UPDATE
Definition: fdtable.h:166
__SIZE_TYPE__ ssize_t
Definition: types.h:28
File descriptor virtual method table.
Definition: fdtable.h:23
int(* close)(void *obj)
Definition: fdtable.h:26
ssize_t(* read)(void *obj, void *buf, size_t sz)
Definition: fdtable.h:24
ssize_t(* write)(void *obj, const void *buf, size_t sz)
Definition: fdtable.h:25
int(* ioctl)(void *obj, unsigned int request, va_list args)
Definition: fdtable.h:27
Definition: kernel.h:3026
Mutex Structure.
Definition: kernel.h:2914