posix-next API 0.1.0
Out-of-tree Zephyr POSIX module
Loading...
Searching...
No Matches
POSIX_DEVICE_IO

POSIX Device Input and Output option group. More...

Files

file  poll.h
 POSIX poll API (<poll.h>)
 
file  select.h
 POSIX select API (<sys/select.h>)
 

Data Structures

struct  sigset_t
 Type representing a set of signals (bitmask). More...
 

Macros

#define O_CLOEXEC   ZVFS_O_CLOEXEC
 Close file descriptor on exec (open() flag).
 
#define O_CREAT   ZVFS_O_CREAT
 Create file if it does not exist (open() flag).
 
#define O_DIRECTORY   ZVFS_O_DIRECTORY
 Fail if path does not name a directory (open() flag).
 
#define O_EXCL   ZVFS_O_EXCL
 Exclusive creation: fail if file already exists (open() flag, with O_CREAT).
 
#define O_NOCTTY   ZVFS_O_NOCTTY
 Do not assign a controlling terminal (open() flag).
 
#define O_NOFOLLOW   ZVFS_O_NOFOLLOW
 Do not follow symbolic links (open() flag).
 
#define O_TRUNC   ZVFS_O_TRUNC
 Truncate file to zero length on open (open() flag).
 
#define O_TTY_INIT   ZVFS_O_TTY_INIT
 Initialise terminal to conforming state (open() flag).
 
#define O_APPEND   ZVFS_O_APPEND
 Write operations append to end of file.
 
#define O_DSYNC   ZVFS_O_DSYNC
 Write I/O completes as defined for synchronised I/O data integrity.
 
#define O_NONBLOCK   ZVFS_O_NONBLOCK
 Non-blocking I/O mode.
 
#define O_RSYNC   ZVFS_O_RSYNC
 Synchronised read I/O (same as O_SYNC for reads).
 
#define O_SYNC   ZVFS_O_SYNC
 Write I/O completes as defined for synchronised I/O file integrity.
 
#define O_EXEC   ZVFS_O_EXEC
 Open for execute only (no read, write, or search).
 
#define O_RDONLY   ZVFS_O_RDONLY
 Open for reading only.
 
#define O_RDWR   ZVFS_O_RDWR
 Open for reading and writing.
 
#define O_SEARCH   ZVFS_O_SEARCH
 Open directory for search only.
 
#define O_WRONLY   ZVFS_O_WRONLY
 Open for writing only.
 
#define O_ACCMODE   (ZVFS_O_RDONLY | ZVFS_O_RDWR | ZVFS_O_WRONLY)
 Mask to extract the file access mode from open flags.
 
#define pollfd   zvfs_pollfd
 Poll file descriptor structure (alias for zvfs_pollfd).
 
#define POLLIN   ZVFS_POLLIN
 Data other than high-priority data may be read without blocking.
 
#define POLLRDNORM   ZVFS_POLLRDNORM
 Normal data may be read without blocking.
 
#define POLLRDBAND   ZVFS_POLLRDBAND
 Priority data may be read without blocking.
 
#define POLLPRI   ZVFS_POLLPRI
 High-priority data may be read without blocking.
 
#define POLLOUT   ZVFS_POLLOUT
 Normal data may be written without blocking.
 
#define POLLWRNORM   ZVFS_POLLWRNORM
 Equivalent to POLLOUT.
 
#define POLLWRBAND   ZVFS_POLLWRBAND
 Priority data may be written.
 
#define POLLERR   ZVFS_POLLERR
 An error has occurred on the file descriptor (output only).
 
#define POLLHUP   ZVFS_POLLHUP
 The file descriptor has been hung up (output only).
 
#define POLLNVAL   ZVFS_POLLNVAL
 The file descriptor is not open (output only).
 
#define EFD_SEMAPHORE   ZVFS_EFD_SEMAPHORE
 Semaphore-mode flag: each read decrements the counter by 1 instead of resetting to 0.
 
#define EFD_NONBLOCK   ZVFS_EFD_NONBLOCK
 Non-blocking flag: reads and writes return EAGAIN instead of blocking.
 
#define FD_SETSIZE   ZVFS_FD_SETSIZE
 Maximum number of file descriptors in an fd_set.
 
#define SIGRTMAX   (SIGRTMIN + CONFIG_POSIX_RTSIG_MAX)
 Largest real-time signal number.
 
#define STDERR_FILENO   2
 File descriptor for standard error.
 
#define STDIN_FILENO   0
 File descriptor for standard input.
 
#define STDOUT_FILENO   1
 File descriptor for standard output.
 
#define _POSIX_VDISABLE   ('\0')
 Value used to disable a special character in a terminal.
 

Typedefs

typedef int nfds_t
 Type for the number of file descriptors passed to poll().
 
typedef zvfs_eventfd_t eventfd_t
 Counter value type for eventfd operations.
 
typedef long suseconds_t
 Microsecond time component type.
 
typedef struct zvfs_fd_set fd_set
 Set of file descriptors for select()/pselect().
 

Functions

int creat (const char *path, mode_t mode)
 Create or truncate a file.
 
int open (const char *name, int flags,...)
 Open or create a file.
 
int openat (int fd, const char *path, int oflag,...)
 Open or create a file relative to a directory file descriptor.
 
int poll (struct zvfs_pollfd *fds, nfds_t nfds, int timeout)
 Wait for events on a set of file descriptors.
 
int eventfd (unsigned int initval, int flags)
 Create a file descriptor for event notification.
 
int eventfd_read (int fd, eventfd_t *value)
 Read the current counter value from an eventfd.
 
int eventfd_write (int fd, eventfd_t value)
 Add a value to an eventfd counter.
 
int pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask)
 Synchronous multiplexed I/O with signal-mask and nanosecond timeout.
 
int select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout)
 Synchronous multiplexed I/O (legacy interface, use pselect() for new code).
 
void FD_CLR (int fd, fd_set *fdset)
 Remove a file descriptor from an fd_set.
 
int FD_ISSET (int fd, fd_set *fdset)
 Test whether a file descriptor is in an fd_set.
 
void FD_SET (int fd, fd_set *fdset)
 Add a file descriptor to an fd_set.
 
void FD_ZERO (fd_set *fdset)
 Clear all file descriptors from an fd_set.
 
int close (int fildes)
 Close a file descriptor.
 
int isatty (int fildes)
 Determine whether a file descriptor refers to a terminal.
 
ssize_t pread (int fildes, void *buf, size_t nbyte, off_t offset)
 Read from a file at a given offset without changing the file offset.
 
ssize_t pwrite (int fildes, const void *buf, size_t nbyte, off_t offset)
 Write to a file at a given offset without changing the file offset.
 
ssize_t read (int fildes, void *buf, size_t nbyte)
 Read from a file descriptor.
 
char * ttyname (int fildes)
 Get the name of the terminal associated with a file descriptor.
 
ssize_t write (int fildes, const void *buf, size_t nbyte)
 Write to a file descriptor.
 

Detailed Description

POSIX Device Input and Output option group.

Covers open(), close(), read(), write(), pread(), pwrite(), isatty(), ttyname(), ttyname_r(), and related device-I/O primitives.

Macro Definition Documentation

◆ _POSIX_VDISABLE

#define _POSIX_VDISABLE   ('\0')

Value used to disable a special character in a terminal.

Definition at line 123 of file unistd.h.

◆ EFD_NONBLOCK

#define EFD_NONBLOCK   ZVFS_EFD_NONBLOCK

Non-blocking flag: reads and writes return EAGAIN instead of blocking.

Definition at line 32 of file eventfd.h.

◆ EFD_SEMAPHORE

#define EFD_SEMAPHORE   ZVFS_EFD_SEMAPHORE

Semaphore-mode flag: each read decrements the counter by 1 instead of resetting to 0.

Definition at line 30 of file eventfd.h.

◆ FD_SETSIZE

#define FD_SETSIZE   ZVFS_FD_SETSIZE

Maximum number of file descriptors in an fd_set.

Definition at line 30 of file select.h.

◆ O_ACCMODE

#define O_ACCMODE   (ZVFS_O_RDONLY | ZVFS_O_RDWR | ZVFS_O_WRONLY)

Mask to extract the file access mode from open flags.

Definition at line 130 of file fcntl.h.

◆ O_APPEND

#define O_APPEND   ZVFS_O_APPEND

Write operations append to end of file.

Definition at line 108 of file fcntl.h.

◆ O_CLOEXEC

#define O_CLOEXEC   ZVFS_O_CLOEXEC

Close file descriptor on exec (open() flag).

Definition at line 91 of file fcntl.h.

◆ O_CREAT

#define O_CREAT   ZVFS_O_CREAT

Create file if it does not exist (open() flag).

Definition at line 93 of file fcntl.h.

◆ O_DIRECTORY

#define O_DIRECTORY   ZVFS_O_DIRECTORY

Fail if path does not name a directory (open() flag).

Definition at line 95 of file fcntl.h.

◆ O_DSYNC

#define O_DSYNC   ZVFS_O_DSYNC

Write I/O completes as defined for synchronised I/O data integrity.

Definition at line 110 of file fcntl.h.

◆ O_EXCL

#define O_EXCL   ZVFS_O_EXCL

Exclusive creation: fail if file already exists (open() flag, with O_CREAT).

Definition at line 97 of file fcntl.h.

◆ O_EXEC

#define O_EXEC   ZVFS_O_EXEC

Open for execute only (no read, write, or search).

Definition at line 119 of file fcntl.h.

◆ O_NOCTTY

#define O_NOCTTY   ZVFS_O_NOCTTY

Do not assign a controlling terminal (open() flag).

Definition at line 99 of file fcntl.h.

◆ O_NOFOLLOW

#define O_NOFOLLOW   ZVFS_O_NOFOLLOW

Do not follow symbolic links (open() flag).

Definition at line 101 of file fcntl.h.

◆ O_NONBLOCK

#define O_NONBLOCK   ZVFS_O_NONBLOCK

Non-blocking I/O mode.

Definition at line 112 of file fcntl.h.

◆ O_RDONLY

#define O_RDONLY   ZVFS_O_RDONLY

Open for reading only.

Definition at line 121 of file fcntl.h.

◆ O_RDWR

#define O_RDWR   ZVFS_O_RDWR

Open for reading and writing.

Definition at line 123 of file fcntl.h.

◆ O_RSYNC

#define O_RSYNC   ZVFS_O_RSYNC

Synchronised read I/O (same as O_SYNC for reads).

Definition at line 114 of file fcntl.h.

◆ O_SEARCH

#define O_SEARCH   ZVFS_O_SEARCH

Open directory for search only.

Definition at line 125 of file fcntl.h.

◆ O_SYNC

#define O_SYNC   ZVFS_O_SYNC

Write I/O completes as defined for synchronised I/O file integrity.

Definition at line 116 of file fcntl.h.

◆ O_TRUNC

#define O_TRUNC   ZVFS_O_TRUNC

Truncate file to zero length on open (open() flag).

Definition at line 103 of file fcntl.h.

◆ O_TTY_INIT

#define O_TTY_INIT   ZVFS_O_TTY_INIT

Initialise terminal to conforming state (open() flag).

Definition at line 105 of file fcntl.h.

◆ O_WRONLY

#define O_WRONLY   ZVFS_O_WRONLY

Open for writing only.

Definition at line 127 of file fcntl.h.

◆ POLLERR

#define POLLERR   ZVFS_POLLERR

An error has occurred on the file descriptor (output only).

Definition at line 57 of file poll.h.

◆ pollfd

#define pollfd   zvfs_pollfd

Poll file descriptor structure (alias for zvfs_pollfd).

Definition at line 40 of file poll.h.

◆ POLLHUP

#define POLLHUP   ZVFS_POLLHUP

The file descriptor has been hung up (output only).

Definition at line 59 of file poll.h.

◆ POLLIN

#define POLLIN   ZVFS_POLLIN

Data other than high-priority data may be read without blocking.

Definition at line 43 of file poll.h.

◆ POLLNVAL

#define POLLNVAL   ZVFS_POLLNVAL

The file descriptor is not open (output only).

Definition at line 61 of file poll.h.

◆ POLLOUT

#define POLLOUT   ZVFS_POLLOUT

Normal data may be written without blocking.

Definition at line 51 of file poll.h.

◆ POLLPRI

#define POLLPRI   ZVFS_POLLPRI

High-priority data may be read without blocking.

Definition at line 49 of file poll.h.

◆ POLLRDBAND

#define POLLRDBAND   ZVFS_POLLRDBAND

Priority data may be read without blocking.

Definition at line 47 of file poll.h.

◆ POLLRDNORM

#define POLLRDNORM   ZVFS_POLLRDNORM

Normal data may be read without blocking.

Definition at line 45 of file poll.h.

◆ POLLWRBAND

#define POLLWRBAND   ZVFS_POLLWRBAND

Priority data may be written.

Definition at line 55 of file poll.h.

◆ POLLWRNORM

#define POLLWRNORM   ZVFS_POLLWRNORM

Equivalent to POLLOUT.

Definition at line 53 of file poll.h.

◆ SIGRTMAX

#define SIGRTMAX   (SIGRTMIN + CONFIG_POSIX_RTSIG_MAX)

Largest real-time signal number.

Definition at line 40 of file select.h.

◆ STDERR_FILENO

#define STDERR_FILENO   2

File descriptor for standard error.

Definition at line 107 of file unistd.h.

◆ STDIN_FILENO

#define STDIN_FILENO   0

File descriptor for standard input.

Definition at line 112 of file unistd.h.

◆ STDOUT_FILENO

#define STDOUT_FILENO   1

File descriptor for standard output.

Definition at line 117 of file unistd.h.

Typedef Documentation

◆ eventfd_t

typedef zvfs_eventfd_t eventfd_t

Counter value type for eventfd operations.

Definition at line 35 of file eventfd.h.

◆ fd_set

typedef struct zvfs_fd_set fd_set

Set of file descriptors for select()/pselect().

Definition at line 88 of file select.h.

◆ nfds_t

typedef int nfds_t

Type for the number of file descriptors passed to poll().

Definition at line 34 of file poll.h.

◆ suseconds_t

typedef long suseconds_t

Microsecond time component type.

Definition at line 55 of file select.h.

Function Documentation

◆ close()

int close ( int  fildes)

◆ creat()

int creat ( const char *  path,
mode_t  mode 
)

Create or truncate a file.

Equivalent to open(path, O_WRONLY|O_CREAT|O_TRUNC, mode).

Parameters
pathFile path.
modePermission bits applied if the file is created.
Returns
New file descriptor on success, or -1 with errno set on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/creat.html

◆ eventfd()

int eventfd ( unsigned int  initval,
int  flags 
)

Create a file descriptor for event notification.

The returned file descriptor can be used with POSIX read()/write() or with eventfd_read()/eventfd_write(). It also integrates with poll(), allowing a writing thread to wake a polling thread simply by writing to the eventfd.

When using read()/write(), the buffer size must be exactly 8 bytes or the call will fail with EINVAL.

Parameters
initvalInitial counter value.
flags0, EFD_SEMAPHORE, EFD_NONBLOCK, or their combination.
Returns
New eventfd file descriptor on success, -1 with errno set on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/eventfd.html

◆ eventfd_read()

int eventfd_read ( int  fd,
eventfd_t value 
)

Read the current counter value from an eventfd.

In normal mode the counter is reset to 0; in EFD_SEMAPHORE mode it is decremented by 1. Blocks if the counter is 0 (unless EFD_NONBLOCK).

Parameters
fdEventfd file descriptor.
valueOutput: counter value read.
Returns
0 on success, -1 with errno set on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/eventfd_read.html

◆ eventfd_write()

int eventfd_write ( int  fd,
eventfd_t  value 
)

Add a value to an eventfd counter.

Wakes any thread blocked in eventfd_read(), read(), or poll() on fd.

Parameters
fdEventfd file descriptor.
valueValue to add to the counter.
Returns
0 on success, -1 with errno set on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/eventfd_write.html

◆ FD_CLR()

void FD_CLR ( int  fd,
fd_set fdset 
)

Remove a file descriptor from an fd_set.

Parameters
fdFile descriptor to clear.
fdsetFile descriptor set to modify.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/FD_CLR.html

◆ FD_ISSET()

int FD_ISSET ( int  fd,
fd_set fdset 
)

Test whether a file descriptor is in an fd_set.

Parameters
fdFile descriptor to test.
fdsetFile descriptor set.
Returns
Non-zero if fd is set, 0 otherwise.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/FD_ISSET.html

◆ FD_SET()

void FD_SET ( int  fd,
fd_set fdset 
)

Add a file descriptor to an fd_set.

Parameters
fdFile descriptor to add.
fdsetFile descriptor set to modify.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/FD_SET.html

◆ FD_ZERO()

void FD_ZERO ( fd_set fdset)

Clear all file descriptors from an fd_set.

Parameters
fdsetFile descriptor set to clear.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/FD_ZERO.html

◆ isatty()

int isatty ( int  fildes)

Determine whether a file descriptor refers to a terminal.

See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/isatty.html

◆ open()

int open ( const char *  name,
int  flags,
  ... 
)

Open or create a file.

Parameters
nameFile path.
flagsAccess and creation flags (O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, …).
...If O_CREAT: mode_t mode.
Returns
New file descriptor on success, or -1 with errno set on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/open.html

◆ openat()

int openat ( int  fd,
const char *  path,
int  oflag,
  ... 
)

Open or create a file relative to a directory file descriptor.

Parameters
fdDirectory file descriptor, or AT_FDCWD.
pathFile path (relative to fd, or absolute).
oflagAccess and creation flags.
...If O_CREAT: mode_t mode.
Returns
New file descriptor on success, or -1 with errno set on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/openat.html

◆ poll()

int poll ( struct zvfs_pollfd *  fds,
nfds_t  nfds,
int  timeout 
)

Wait for events on a set of file descriptors.

Examines each file descriptor in fds for the events specified in its events field. Blocks until at least one descriptor is ready, the timeout expires, or a signal is caught.

Parameters
fdsArray of struct pollfd descriptors to monitor.
nfdsNumber of entries in fds.
timeoutTimeout in milliseconds; -1 to block indefinitely, 0 to return immediately.
Returns
Number of file descriptors with non-zero revents on success, 0 on timeout, or -1 with errno set on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html

◆ pread()

ssize_t pread ( int  fildes,
void *  buf,
size_t  nbyte,
off_t  offset 
)

Read from a file at a given offset without changing the file offset.

See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/pread.html

◆ pselect()

int pselect ( int  nfds,
fd_set readfds,
fd_set writefds,
fd_set exceptfds,
const struct timespec timeout,
const sigset_t sigmask 
)

Synchronous multiplexed I/O with signal-mask and nanosecond timeout.

Parameters
nfdsHighest-numbered file descriptor in any set + 1.
readfdsSet of file descriptors to watch for readability, or NULL.
writefdsSet of file descriptors to watch for writability, or NULL.
exceptfdsSet of file descriptors to watch for exceptions, or NULL.
timeoutMaximum wait time, or NULL to block indefinitely.
sigmaskSignal mask to apply during the wait, or NULL.
Returns
Number of ready file descriptors on success, 0 on timeout, or -1 with errno set on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/pselect.html

◆ pwrite()

ssize_t pwrite ( int  fildes,
const void *  buf,
size_t  nbyte,
off_t  offset 
)

Write to a file at a given offset without changing the file offset.

See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html

◆ read()

ssize_t read ( int  fildes,
void *  buf,
size_t  nbyte 
)

◆ select()

int select ( int  nfds,
fd_set readfds,
fd_set writefds,
fd_set errorfds,
struct timeval timeout 
)

Synchronous multiplexed I/O (legacy interface, use pselect() for new code).

Parameters
nfdsHighest-numbered file descriptor in any set + 1.
readfdsSet of file descriptors to watch for readability, or NULL.
writefdsSet of file descriptors to watch for writability, or NULL.
errorfdsSet of file descriptors to watch for errors, or NULL.
timeoutMaximum wait time, or NULL to block indefinitely.
Returns
Number of ready file descriptors on success, 0 on timeout, or -1 with errno set on failure.
See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/select.html

◆ ttyname()

char * ttyname ( int  fildes)

Get the name of the terminal associated with a file descriptor.

See also
https://pubs.opengroup.org/onlinepubs/9699919799/functions/ttyname.html

◆ write()

ssize_t write ( int  fildes,
const void *  buf,
size_t  nbyte 
)