|
ginnOS
The reference: libc, the libraries and the kernel
|
#include "kernel/sync/atomic.h"#include "fd_table.h"#include "kernel/errno.h"#include "kernel/process/process.h"#include "kernel/memory/heap.h"#include "arch/arch.h"Functions | |
| fd_table_t * | fd_table_create (void) |
| make a table with every descriptor free and one user. | |
| fd_table_t * | fd_table_get (fd_table_t *table) |
| add a user to a table (a new thread that shares it). | |
| void | fd_table_put (fd_table_t *table) |
| remove a user from a table. | |
| int | fd_install (process_t *proc, file_t *file, uint32_t fd_flags, int min_fd) |
| put a description in the lowest free descriptor of a process, at or above min_fd. | |
| fd_entry_t * | fd_get (int fd) |
| get the entry for a descriptor of the current process. | |
| void | fd_release_held (process_t *proc) |
| let go of the files fd_get kept open during a syscall (the syscall handler calls this at its end). | |
| int | fd_close (int fd) |
| close a descriptor of the current process. | |
| void | fd_close_entry (fd_entry_t *entry) |
| close the description behind an entry and mark the entry free. | |
| void | fd_copy_entry (fd_entry_t *dst, const fd_entry_t *src) |
| make dst another descriptor for src's description (fork, spawn). | |
| fd_table_t * fd_table_create | ( | void | ) |
make a table with every descriptor free and one user.
| fd_table_t * fd_table_get | ( | fd_table_t * | table | ) |
add a user to a table (a new thread that shares it).
| void fd_table_put | ( | fd_table_t * | table | ) |
remove a user from a table.
the last user closes every descriptor (this may sleep) and frees it.
| table | the table, or NULL (nothing is done). |
put a description in the lowest free descriptor of a process, at or above min_fd.
the descriptor takes over the caller's reference.
| proc | the process. |
| file | the description. |
| fd_flags | FD_CLOEXEC or 0. |
| min_fd | the lowest descriptor to use. |
| fd_entry_t * fd_get | ( | int | fd | ) |
get the entry for a descriptor of the current process.
when the table is shared with other threads, the file is kept open until the syscall ends (fd_release_held), even if another thread closes fd meanwhile; use entry->file before any sleep, as the entry itself can change.
| fd | the file descriptor number. |
| void fd_release_held | ( | struct process * | proc | ) |
let go of the files fd_get kept open during a syscall (the syscall handler calls this at its end).
may sleep: a last close can.
| proc | the process. |
| int fd_close | ( | int | fd | ) |
close a descriptor of the current process.
| fd | the file descriptor number. |
| void fd_close_entry | ( | fd_entry_t * | entry | ) |
close the description behind an entry and mark the entry free.
works on any process's table, so it can tear down a process that isn't current. may sleep (the last close of a file takes the fs mutex).
| entry | the entry; a free entry is left as is. |
| void fd_copy_entry | ( | fd_entry_t * | dst, |
| const fd_entry_t * | src ) |
make dst another descriptor for src's description (fork, spawn).
the flags are copied too. dst must be free.
| dst | the entry to fill. |
| src | the entry to duplicate. |