Zephyr API Documentation 3.7.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/kernel.h>
14#include <zephyr/sys/util.h>
15
16/* File mode bits */
17#define ZVFS_MODE_IFMT 0170000
18#define ZVFS_MODE_UNSPEC 0000000
19#define ZVFS_MODE_IFIFO 0010000
20#define ZVFS_MODE_IFCHR 0020000
21#define ZVFS_MODE_IMSGQ 0030000
22#define ZVFS_MODE_IFDIR 0040000
23#define ZVFS_MODE_IFSEM 0050000
24#define ZVFS_MODE_IFBLK 0060000
25#define ZVFS_MODE_IFSHM 0070000
26#define ZVFS_MODE_IFREG 0100000
27#define ZVFS_MODE_IFLNK 0120000
28#define ZVFS_MODE_IFSOCK 0140000
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
39 union {
40 ssize_t (*read)(void *obj, void *buf, size_t sz);
41 ssize_t (*read_offs)(void *obj, void *buf, size_t sz, size_t offset);
42 };
43 union {
44 ssize_t (*write)(void *obj, const void *buf, size_t sz);
45 ssize_t (*write_offs)(void *obj, const void *buf, size_t sz, size_t offset);
46 };
47 int (*close)(void *obj);
48 int (*ioctl)(void *obj, unsigned int request, va_list args);
49};
50
62
79void zvfs_finalize_typed_fd(int fd, void *obj, const struct fd_op_vtable *vtable, uint32_t mode);
80
91static inline void zvfs_finalize_fd(int fd, void *obj, const struct fd_op_vtable *vtable)
92{
94}
95
107int zvfs_alloc_fd(void *obj, const struct fd_op_vtable *vtable);
108
117void zvfs_free_fd(int fd);
118
135void *zvfs_get_fd_obj(int fd, const struct fd_op_vtable *vtable, int err);
136
149void *zvfs_get_fd_obj_and_vtable(int fd, const struct fd_op_vtable **vtable,
150 struct k_mutex **lock);
151
167bool zvfs_get_obj_lock_and_cond(void *obj, const struct fd_op_vtable *vtable, struct k_mutex **lock,
168 struct k_condvar **cond);
169
182static inline int zvfs_fdtable_call_ioctl(const struct fd_op_vtable *vtable, void *obj,
183 unsigned long request, ...)
184{
185 va_list args;
186 int res;
187
188 va_start(args, request);
189 res = vtable->ioctl(obj, request, args);
190 va_end(args);
191
192 return res;
193}
194
203enum {
204 /* Codes below 0x100 are reserved for fcntl() codes. */
214
215 /* Codes above 0x5400 and below 0x5500 are reserved for termios, FIO, etc */
218};
219
220#ifdef __cplusplus
221}
222#endif
223
224#endif /* ZEPHYR_INCLUDE_SYS_FDTABLE_H_ */
int zvfs_alloc_fd(void *obj, const struct fd_op_vtable *vtable)
Allocate file descriptor for underlying I/O object.
int zvfs_reserve_fd(void)
Reserve file descriptor.
void * zvfs_get_fd_obj_and_vtable(int fd, const struct fd_op_vtable **vtable, struct k_mutex **lock)
Get underlying object pointer and vtable pointer from file descriptor.
static void zvfs_finalize_fd(int fd, void *obj, const struct fd_op_vtable *vtable)
Finalize creation of file descriptor.
Definition fdtable.h:91
void zvfs_finalize_typed_fd(int fd, void *obj, const struct fd_op_vtable *vtable, uint32_t mode)
Finalize creation of file descriptor, with type.
#define ZVFS_MODE_UNSPEC
Definition fdtable.h:18
bool zvfs_get_obj_lock_and_cond(void *obj, const struct fd_op_vtable *vtable, struct k_mutex **lock, struct k_condvar **cond)
Get the mutex and condition variable associated with the given object and vtable.
void zvfs_free_fd(int fd)
Release reserved file descriptor.
static int zvfs_fdtable_call_ioctl(const struct fd_op_vtable *vtable, void *obj, unsigned long request,...)
Call ioctl vmethod on an object using varargs.
Definition fdtable.h:182
void * zvfs_get_fd_obj(int fd, const struct fd_op_vtable *vtable, int err)
Get underlying object pointer from file descriptor.
@ ZFD_IOCTL_SET_LOCK
Definition fdtable.h:210
@ ZFD_IOCTL_FIONREAD
Definition fdtable.h:216
@ ZFD_IOCTL_POLL_PREPARE
Definition fdtable.h:207
@ ZFD_IOCTL_FSYNC
Definition fdtable.h:205
@ ZFD_IOCTL_LSEEK
Definition fdtable.h:206
@ ZFD_IOCTL_FIONBIO
Definition fdtable.h:217
@ ZFD_IOCTL_POLL_OFFLOAD
Definition fdtable.h:209
@ ZFD_IOCTL_POLL_UPDATE
Definition fdtable.h:208
@ ZFD_IOCTL_TRUNCATE
Definition fdtable.h:212
@ ZFD_IOCTL_STAT
Definition fdtable.h:211
@ ZFD_IOCTL_MMAP
Definition fdtable.h:213
Public kernel APIs.
__SIZE_TYPE__ ssize_t
Definition types.h:28
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
File descriptor virtual method table.
Definition fdtable.h:38
ssize_t(* write_offs)(void *obj, const void *buf, size_t sz, size_t offset)
Definition fdtable.h:45
ssize_t(* read_offs)(void *obj, void *buf, size_t sz, size_t offset)
Definition fdtable.h:41
int(* close)(void *obj)
Definition fdtable.h:47
ssize_t(* read)(void *obj, void *buf, size_t sz)
Definition fdtable.h:40
ssize_t(* write)(void *obj, const void *buf, size_t sz)
Definition fdtable.h:44
int(* ioctl)(void *obj, unsigned int request, va_list args)
Definition fdtable.h:48
Definition kernel.h:3106
Mutex Structure.
Definition kernel.h:2994
Misc utilities.