PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
File Table

File Table. More...

Collaboration diagram for File Table:

Detailed Description

File Table.

The file table is a per-process structure that keeps track of all open files for a process.

Data Structures

struct  file_table_t
 File table structure. More...
 

Functions

void file_table_init (file_table_t *table)
 Initialize a file table.
 
void file_table_deinit (file_table_t *table)
 Deinitialize a file table.
 
file_tfile_table_get (file_table_t *table, fd_t fd)
 Get a file from its file descriptor.
 
fd_t file_table_open (file_table_t *table, file_t *file)
 Allocate a new file descriptor for a file.
 
uint64_t file_table_close (file_table_t *table, fd_t fd)
 Free a file descriptor.
 
void file_table_close_all (file_table_t *table)
 Close all files in the file table.
 
void file_table_close_mode (file_table_t *table, mode_t mode)
 Close all files in the file table with the specified mode.
 
uint64_t file_table_close_range (file_table_t *table, fd_t min, fd_t max)
 Free a range of file descriptors.
 
fd_t file_table_set (file_table_t *table, fd_t fd, file_t *file)
 Set a specific file descriptor to a file.
 
fd_t file_table_dup (file_table_t *table, fd_t oldFd)
 Duplicate a file descriptor.
 
fd_t file_table_dup2 (file_table_t *table, fd_t oldFd, fd_t newFd)
 Duplicate a file descriptor to a specific file descriptor.
 
uint64_t file_table_copy (file_table_t *dest, file_table_t *src, fd_t min, fd_t max)
 Copy a file table, closing any overlapping file descriptors.
 

Function Documentation

◆ file_table_init()

void file_table_init ( file_table_t table)

Initialize a file table.

Parameters
tableThe file table to initialize.

Definition at line 9 of file file_table.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_table_deinit()

void file_table_deinit ( file_table_t table)

Deinitialize a file table.

This will close all open files in the table.

Parameters
tableThe file table to deinitialize.

Definition at line 19 of file file_table.c.

Here is the caller graph for this function:

◆ file_table_get()

file_t * file_table_get ( file_table_t table,
fd_t  fd 
)

Get a file from its file descriptor.

Parameters
tableThe file table.
fdThe file descriptor.
Returns
On success, a new reference to the file. On failure, returns NULL and errno is set to:
  • EINVAL: Invalid parameters.
  • EBADF: The file descriptor is invalid.

Definition at line 33 of file file_table.c.

Here is the caller graph for this function:

◆ file_table_open()

fd_t file_table_open ( file_table_t table,
file_t file 
)

Allocate a new file descriptor for a file.

Parameters
tableThe file table.
fileThe file to associate with the new file descriptor.
Returns
On success, the allocated file descriptor. On failure, ERR and errno is set to:
  • EINVAL: Invalid parameters.
  • EMFILE: Too many open files.

Definition at line 52 of file file_table.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_table_close()

uint64_t file_table_close ( file_table_t table,
fd_t  fd 
)

Free a file descriptor.

If the file has no other references, it will be closed.

Parameters
tableThe file table.
fdThe file descriptor to free.
Returns
On success, 0. On failure, ERR and errno is set to:
  • EINVAL: Invalid parameters.
  • EBADF: The file descriptor is invalid.

Definition at line 74 of file file_table.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_table_close_all()

void file_table_close_all ( file_table_t table)

Close all files in the file table.

Parameters
tableThe file table.

Definition at line 96 of file file_table.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_table_close_mode()

void file_table_close_mode ( file_table_t table,
mode_t  mode 
)

Close all files in the file table with the specified mode.

Parameters
tableThe file table.
modeThe mode to close files with.

Definition at line 116 of file file_table.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_table_close_range()

uint64_t file_table_close_range ( file_table_t table,
fd_t  min,
fd_t  max 
)

Free a range of file descriptors.

If the files have no other references, they will be closed.

Parameters
tableThe file table.
minThe minimum file descriptor to free, inclusive.
maxThe maximum file descriptor to free, exclusive.
Returns
On success, 0. On failure, ERR and errno is set to:
  • EINVAL: Invalid parameters.

Definition at line 136 of file file_table.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_table_set()

fd_t file_table_set ( file_table_t table,
fd_t  fd,
file_t file 
)

Set a specific file descriptor to a file.

If the file descriptor is already in use, the old file will be closed.

Parameters
tableThe file table.
fdThe file descriptor to set.
fileThe file to associate with the file descriptor.
Returns
On success, fd. On failure, ERR and errno is set to:
  • EINVAL: Invalid parameters.
  • EBADF: The file descriptor is invalid.

Definition at line 159 of file file_table.c.

Here is the call graph for this function:

◆ file_table_dup()

fd_t file_table_dup ( file_table_t table,
fd_t  oldFd 
)

Duplicate a file descriptor.

Allocates a new file descriptor that refers to the same file as oldFd.

Parameters
tableThe file table.
oldFdThe file descriptor to duplicate.
Returns
On success, the new file descriptor. On failure, ERR and errno is set to:
  • EINVAL: Invalid parameters.
  • EBADF: The file descriptor is invalid.
  • EMFILE: Too many open files.

Definition at line 186 of file file_table.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_table_dup2()

fd_t file_table_dup2 ( file_table_t table,
fd_t  oldFd,
fd_t  newFd 
)

Duplicate a file descriptor to a specific file descriptor.

If newFd is already in use, the old file will be closed.

Parameters
tableThe file table.
oldFdThe file descriptor to duplicate.
newFdThe file descriptor to duplicate to.
Returns
On success, newFd. On failure, ERR and errno is set to:
  • EINVAL: Invalid parameters.
  • EBADF: One of the file descriptors is invalid.
  • EMFILE: Too many open files.

Definition at line 214 of file file_table.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ file_table_copy()

uint64_t file_table_copy ( file_table_t dest,
file_table_t src,
fd_t  min,
fd_t  max 
)

Copy a file table, closing any overlapping file descriptors.

Parameters
destThe destination file table.
srcThe source file table.
minThe minimum file descriptor to copy, inclusive.
maxThe maximum file descriptor to copy, exclusive.
Returns
On success, the number of copied file descriptors. On failure, ERR and errno is set to:
  • EINVAL: Invalid parameters.

Definition at line 246 of file file_table.c.

Here is the call graph for this function:
Here is the caller graph for this function: