|
PatchworkOS
966e257
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_alloc (file_table_t *table, file_t *file) |
| Allocate a new file descriptor for a file. | |
| uint64_t | file_table_free (file_table_t *table, fd_t fd) |
| Free a file descriptor. | |
| uint64_t | file_table_free_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_close_all (file_table_t *table) |
| Close all files in the file table. | |
| void file_table_init | ( | file_table_t * | table | ) |
Initialize a file table.
| table | The file table to initialize. |
Definition at line 7 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 17 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 31 of file file_table.c.
| fd_t file_table_alloc | ( | 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 50 of file file_table.c.
| uint64_t file_table_free | ( | 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 72 of file file_table.c.
| uint64_t file_table_free_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 94 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 117 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 144 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 172 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 204 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 235 of file file_table.c.