documentation/kernel/proc/file_descriptor.h.md

55 lines
3.3 KiB
Markdown

# file_descriptor.h
Processes have no direct access to the VFS, instead they have file descriptors.
File descriptors are numbers that represent files.
They are mostly used in file related syscalls.
# `FILE_DESCRIPTOR_ARRAY_CHUNK_SIZE` - macro
The amount of file descriptors a `file_descriptor_array_chunk_T` (reference needed) can hold.
# `file_descriptor_t` - typedef
This is a typedef of `ìnt32_t` and represents a file descriptor.
# `std_file_descriptors_E` - enum
These are reserved file descriptors.
* `FILE_DESCRIPTOR_INVALID` - This represents an invalid file descriptor, just like NULL is an invalid pointer.
* `FILE_DESCRIPTOR_STDOUT` - This represents the file descriptor that is used, when writing to the Standard-Output stream.
* `FILE_DESCRIPTOR_STDIN` - This represents the file descriptor that is used, when reading from the Standard-Input stream.
* `FILE_DESCRIPTOR_STDERR` - This represents the file descriptor that is used, when writing to the Standard-Error stream.
# `file_descriptor_array_chunk_T` - struct
| Name | Type | Description |
|--------|------------------------------------------------|----------------------------------------------------------------------------------------|
| prev | file_descriptor_array_chunk_T* | The previous chunk |
| next | file_descriptor_array_chunk_T* | The next chunk |
| lookup | vfs_node_T* [FILE_DESCRIPTOR_ARRAY_CHUNK_SIZE] | The array of file pointers, that the file descriptors reference |
| bitmap | bitmap_T | This bitmap indicates which file descriptors of this chunk are free nad which are used |
| amount | uint32_t | The amount of file descriptors which the chunk actually holds |
# `file_descriptor_array_T` - struct
| Name | Type | Description |
|------------|--------------------------------|------------------------------|
| base_chunk | file_descriptor_array_chunk_T* | The first chunk in the array |
# `file_descriptor_request(fd_array, node)` - function (file_descriptor_t)
Requests and returns new file descriptor, which will be linked with _**node**_.
# `file_descriptor_resolve(fd_array, fd)` - function (vfs_node_T*)
Returns the VFS node, with which _**fd**_ is linked.
# `file_descriptor_free(fd_array, fd)` - function (void)
Frees _**fd**_ and marks it as reclaimable.
# `file_descriptor_array_alloc()` - function (file_descriptor_array_T*)
Allocates a new chunked file descriptor array.
# `file_descriptor_array_destruct(fd_array)` - function (void)
Destructs _**fd_array**_ and all its resources, like e.g. chunks.
# `file_descriptor_array_chunk_alloc(prev)` - function (file_descriptor_array_chunk_T*)
Allocates a new chunk for a file descriptor array.
_**prev**_ has to be the last chunk of an array or NULL when the chunk is the base chunk for a fresh file descriptor array.
# `file_descriptor_array_chunk_destruct(chunk)` - function (void)
Destructs _**chunk**_ and all its resources.