noxos (docs): documented file descriptos and the overall code style
This commit is contained in:
parent
6fe11ea213
commit
68f0b590fd
|
@ -0,0 +1,53 @@
|
|||
---
|
||||
title: "file_descriptor.h"
|
||||
summary: "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_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.
|
|
@ -0,0 +1,68 @@
|
|||
---
|
||||
title: "Code Style"
|
||||
summary: "Read this, before contributing!"
|
||||
---
|
||||
|
||||
The following code style should be applied to the whole noxos codebase.
|
||||
Pull Requests that don't follow this code style will be rejected.
|
||||
|
||||
# Naming conventions
|
||||
- **structs** are suffixed with **_T**
|
||||
- **typedefs** are suffixed with **_t**
|
||||
- **enums** are suffixed with **_E**
|
||||
- **global** variables are prefixed with **g_**
|
||||
|
||||
Everything is **snake_case**.
|
||||
|
||||
# Code readability
|
||||
To make the code as readable and self explaining as possible, there are a few patterns that should be used.
|
||||
|
||||
## Avoid abbreviations
|
||||
Give your variables, functions, etc. meaningfully names.
|
||||
The times of 80-char wide screens are over, feel free to use that space :D
|
||||
|
||||
Example: `sym_at_idx` -> `get_symbol_at_index`
|
||||
|
||||
But you're not forced to (anything) write out everything.
|
||||
For example the **Interrupt Descriptor Table** is simply referred to as **idt** (this abbreviation is btw standard).
|
||||
|
||||
## Avoid indentation nesting
|
||||
In a perfect codebase, the maximum indention level would be 3.
|
||||
The goal of NoxOS is not to be a perfect codebase, but please avoid huge indention nesting.
|
||||
To achieve this, you can break parts into extra functions and/or use the early return pattern.
|
||||
|
||||
Example (definitely written 100% sober):
|
||||
```c
|
||||
bool likes_pigs (void* a) {
|
||||
if (a != NULL) {
|
||||
if (a == 0xACAB) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
```
|
||||
->
|
||||
```c
|
||||
bool likes_pigs (void* a) {
|
||||
if (a == NULL) { return true; }
|
||||
if (a != 0xACAB) { return true; }
|
||||
|
||||
return false;
|
||||
}
|
||||
```
|
||||
|
||||
## align declarations
|
||||
|
||||
Please align declarations, definitions, etc like in the example:
|
||||
```c
|
||||
char am_i_a_variable = '?';
|
||||
uint64_t number = 0;
|
||||
bool i_waste_bits = true;
|
||||
```
|
||||
|
||||
## namespaces
|
||||
Unlike C++, C has no namespaces.
|
||||
To achieve the goal of namespaces, please prefix your functions, structs, etc. with the "namespace" they are in.
|
||||
|
||||
Example: `out_byte` -> `io_out_byte`
|
Reference in New Issue