Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
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 <fs/fs.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
23 ssize_t (*read)(void *obj, void *buf, size_t sz);
24 ssize_t (*write)(void *obj, const void *buf, size_t sz);
25 int (*close)(void *obj);
26 int (*ioctl)(void *obj, unsigned int request, va_list args);
27};
28
39int z_reserve_fd(void);
40
51void z_finalize_fd(int fd, void *obj, const struct fd_op_vtable *vtable);
52
64int z_alloc_fd(void *obj, const struct fd_op_vtable *vtable);
65
74void z_free_fd(int fd);
75
92void *z_get_fd_obj(int fd, const struct fd_op_vtable *vtable, int err);
93
106void *z_get_fd_obj_and_vtable(int fd, const struct fd_op_vtable **vtable,
107 struct k_mutex **lock);
108
121static inline int z_fdtable_call_ioctl(const struct fd_op_vtable *vtable, void *obj,
122 unsigned long request, ...)
123{
124 va_list args;
125 int res;
126
127 va_start(args, request);
128 res = vtable->ioctl(obj, request, args);
129 va_end(args);
130
131 return res;
132}
133
142enum {
143 /* Codes below 0x100 are reserved for fcntl() codes. */
150};
151
152#ifdef __cplusplus
153}
154#endif
155
156#endif /* ZEPHYR_INCLUDE_SYS_FDTABLE_H_ */
@ ZFD_IOCTL_SET_LOCK
Definition: fdtable.h:149
@ ZFD_IOCTL_POLL_PREPARE
Definition: fdtable.h:146
@ ZFD_IOCTL_FSYNC
Definition: fdtable.h:144
@ ZFD_IOCTL_LSEEK
Definition: fdtable.h:145
@ ZFD_IOCTL_POLL_OFFLOAD
Definition: fdtable.h:148
@ ZFD_IOCTL_POLL_UPDATE
Definition: fdtable.h:147
__SIZE_TYPE__ ssize_t
Definition: types.h:28
static struct k_spinlock lock
Definition: spinlock_error_case.c:12
Definition: fdtable.h:22
int(* close)(void *obj)
Definition: fdtable.h:25
ssize_t(* read)(void *obj, void *buf, size_t sz)
Definition: fdtable.h:23
ssize_t(* write)(void *obj, const void *buf, size_t sz)
Definition: fdtable.h:24
int(* ioctl)(void *obj, unsigned int request, va_list args)
Definition: fdtable.h:26
Definition: kernel.h:2680