AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
posix.h File Reference
#include <fs/vfs.h>

Go to the source code of this file.

Functions

int posix_file_open (struct file *file)
 Finishes opening a file: with O_TRUNC, a regular file is truncated to 0 bytes.
int posix_file_close (struct file *file)
 Closes an open file by dropping its reference to its vnode.
ssize_t posix_file_read (struct file *file, struct iobuf *io)
 Reads from an open file at its offset, and moves the offset past what was read.
ssize_t posix_file_write (struct file *file, struct iobuf *io)
 Writes to an open file at its offset, and moves the offset past what was written.
ssize_t posix_file_readdir (struct file *file, struct dirent *dirent)
 Reads the directory entry at an open directory's offset, and moves the offset past it.
int posix_file_ioctl (struct file *file, int request, void *argp)
 Passes an ioctl() request on to the file's vnode (a device's, or its filesystem's).
off_t posix_file_lseek (struct file *file, off_t offset, int whence)
 Moves an open file's offset: to offset (SEEK_SET), by offset from where it is (SEEK_CUR), or by offset from the end of the file (SEEK_END).
int posix_file_trunc (struct file *file, off_t len)
 Truncates (or extends) an open file to a new length.
int posix_file_eof (struct file *file)
 Says whether a file's offset is at or past its end, so that a read returns nothing.

Function Documentation

◆ posix_file_close()

int posix_file_close ( struct file * file)

Closes an open file by dropping its reference to its vnode.

Parameters
filethe open file
Returns
0, or a negative errno

Definition at line 15 of file close.c.

References posix_file_close(), and vfs_close().

Referenced by kdev_file_close(), posix_file_close(), ps2mouse_file_close(), vfs_file_close(), and vt_file_close().

◆ posix_file_eof()

int posix_file_eof ( struct file * file)

Says whether a file's offset is at or past its end, so that a read returns nothing.

Parameters
filethe open file
Returns
whether the offset is at the end

Definition at line 17 of file helpers.c.

References file::offset, and posix_file_eof().

Referenced by posix_file_eof().

◆ posix_file_ioctl()

int posix_file_ioctl ( struct file * file,
int request,
void * argp )

Passes an ioctl() request on to the file's vnode (a device's, or its filesystem's).

Parameters
filethe open file
requestthe request
argpits argument, often a pointer to user memory
Returns
the request's result, or a negative errno

Definition at line 19 of file ioctl.c.

References posix_file_ioctl(), and vfs_ioctl().

Referenced by posix_file_ioctl().

◆ posix_file_lseek()

off_t posix_file_lseek ( struct file * file,
off_t offset,
int whence )

Moves an open file's offset: to offset (SEEK_SET), by offset from where it is (SEEK_CUR), or by offset from the end of the file (SEEK_END).

The offset may go past the end of the file.

Parameters
filethe open file
offsetthe offset, or the distance to move it
whenceSEEK_SET, SEEK_CUR or SEEK_END
Returns
the new offset, or -EINVAL if whence is wrong or the new offset would be negative

Definition at line 22 of file lseek.c.

References file::offset, posix_file_lseek(), and vnode::size.

Referenced by posix_file_lseek().

◆ posix_file_open()

int posix_file_open ( struct file * file)

Finishes opening a file: with O_TRUNC, a regular file is truncated to 0 bytes.

Parameters
filethe file being opened
Returns
0, or a negative errno if the truncation failed

Definition at line 17 of file open.c.

References file::flags, posix_file_open(), and vfs_file_trunc().

Referenced by kmsg_file_open(), posix_file_open(), ps2mouse_file_open(), and pts_open().

◆ posix_file_read()

ssize_t posix_file_read ( struct file * file,
struct iobuf * io )

Reads from an open file at its offset, and moves the offset past what was read.

If there is nothing to read yet, it waits for data (a pipe's, a terminal's), unless the file is non-blocking.

Parameters
filethe open file
iowhere the data goes, and how much is wanted
Returns
the number of bytes read, 0 at the end of the file, -EAGAIN if a non-blocking read would wait, -ERESTARTSYS if a signal came while it waited, or another negative errno

Definition at line 29 of file read.c.

References arch_rtime_ns(), file::flags, ISDEV, kdev_fops(), NULL, file::offset, posix_file_read(), fops::read_timeout, iobuf::resid, sched_wait(), vfs_file_eof(), vfs_read_io(), VNODE_DEV, and waitq_wakeup().

Referenced by posix_file_read().

◆ posix_file_readdir()

ssize_t posix_file_readdir ( struct file * file,
struct dirent * dirent )

Reads the directory entry at an open directory's offset, and moves the offset past it.

The offset counts entries, not bytes.

Parameters
filethe open directory
direntthe entry, filled in
Returns
1 if an entry was read, 0 at the end of the directory, or a negative errno

Definition at line 22 of file readdir.c.

References file::flags, file::offset, posix_file_readdir(), and vfs_readdir().

Referenced by posix_file_readdir().

◆ posix_file_trunc()

int posix_file_trunc ( struct file * file,
off_t len )

Truncates (or extends) an open file to a new length.

Parameters
filethe open file
lenthe new length, in bytes
Returns
0, or a negative errno

Definition at line 16 of file trunc.c.

References posix_file_trunc(), and vfs_trunc().

Referenced by posix_file_trunc().

◆ posix_file_write()

ssize_t posix_file_write ( struct file * file,
struct iobuf * io )

Writes to an open file at its offset, and moves the offset past what was written.

With O_APPEND, a regular file is written at its end. A blocking write waits for room (in a pipe, say) until everything is written; a non-blocking one writes only if it can without waiting.

Parameters
filethe open file
iothe data, and how much of it
Returns
the number of bytes written, -EAGAIN if a non-blocking write would wait, or a negative errno if nothing was written

Definition at line 25 of file write.c.

References iobuf::fault, file::flags, file::offset, posix_file_write(), iobuf::resid, vfs_file_can_write(), vfs_file_eof(), vfs_write_io(), waitq_sleep(), and waitq_wakeup().

Referenced by posix_file_write().