|
PatchworkOS
19e446b
A non-POSIX operating system.
|
File Table. More...
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_t * | file_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. | |
| void file_table_init | ( | file_table_t * | table | ) |
Initialize a file table.
| table | The file table to initialize. |
Definition at line 9 of file file_table.c.
| void file_table_deinit | ( | file_table_t * | table | ) |
Deinitialize a file table.
This will close all open files in the table.
| table | The file table to deinitialize. |
Definition at line 19 of file file_table.c.
| file_t * file_table_get | ( | file_table_t * | table, |
| fd_t | fd | ||
| ) |
Get a file from its file descriptor.
| table | The file table. |
| fd | The file descriptor. |
NULL and errno is set to:EINVAL: Invalid parameters.EBADF: The file descriptor is invalid. Definition at line 33 of file file_table.c.
| fd_t file_table_open | ( | file_table_t * | table, |
| file_t * | file | ||
| ) |
Allocate a new file descriptor for a file.
| table | The file table. |
| file | The file to associate with the new file descriptor. |
ERR and errno is set to:EINVAL: Invalid parameters.EMFILE: Too many open files. Definition at line 52 of file file_table.c.
| 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.
| table | The file table. |
| fd | The file descriptor to free. |
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.
| void file_table_close_all | ( | file_table_t * | table | ) |
Close all files in the file table.
| table | The file table. |
Definition at line 96 of file file_table.c.
| void file_table_close_mode | ( | file_table_t * | table, |
| mode_t | mode | ||
| ) |
Close all files in the file table with the specified mode.
| table | The file table. |
| mode | The mode to close files with. |
Definition at line 116 of file file_table.c.
| 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.
| table | The file table. |
| min | The minimum file descriptor to free, inclusive. |
| max | The maximum file descriptor to free, exclusive. |
0. On failure, ERR and errno is set to:EINVAL: Invalid parameters. Definition at line 136 of file file_table.c.
| 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.
| table | The file table. |
| fd | The file descriptor to set. |
| file | The file to associate with the file descriptor. |
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.
| 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.
| table | The file table. |
| oldFd | The file descriptor to duplicate. |
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.
| 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.
| table | The file table. |
| oldFd | The file descriptor to duplicate. |
| newFd | The file descriptor to duplicate to. |
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.
| 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.
| dest | The destination file table. |
| src | The source file table. |
| min | The minimum file descriptor to copy, inclusive. |
| max | The maximum file descriptor to copy, exclusive. |
ERR and errno is set to:EINVAL: Invalid parameters. Definition at line 246 of file file_table.c.