kernel/inc/proc/file_descriptor.h

47 lines
1.8 KiB
C
Raw Permalink Normal View History

// This file is part of noxos and licensed under the MIT open source license
#ifndef NOX_FILE_DESCRIPTOR_H
#define NOX_FILE_DESCRIPTOR_H
#include "utils/stdtypes.h"
#include "utils/bitmap.h"
#include "drivers/builtin/fs/vfs.h"
#define FILE_DESCRIPTOR_ARRAY_CHUNK_SIZE 32
typedef uint32_t file_descriptor_t;
typedef enum {
FILE_DESCRIPTOR_INVALID,
FILE_DESCRIPTOR_STDOUT,
FILE_DESCRIPTOR_STDIN,
FILE_DESCRIPTOR_STDERR,
FILE_DESCRIPTORS_ENUM_END
} std_file_descriptors_E;
typedef struct file_descriptor_array_chunk_T file_descriptor_array_chunk_T;
struct file_descriptor_array_chunk_T {
file_descriptor_array_chunk_T* prev;
file_descriptor_array_chunk_T* next;
vfs_node_T* lookup [FILE_DESCRIPTOR_ARRAY_CHUNK_SIZE];
bitmap_T bitmap;
uint32_t amount;
};
typedef struct {
file_descriptor_array_chunk_T* base_chunk;
} file_descriptor_array_T;
file_descriptor_t file_descriptor_request (file_descriptor_array_T* fd_array, vfs_node_T* node);
vfs_node_T* file_descriptor_resolve (file_descriptor_array_T* fd_array, file_descriptor_t fd);
void file_descriptor_free (file_descriptor_array_T* fd_array, file_descriptor_t fd);
file_descriptor_array_T* file_descriptor_array_alloc ();
void file_descriptor_array_destruct (file_descriptor_array_T* fd_array);
file_descriptor_array_chunk_T* file_descriptor_array_chunk_alloc (file_descriptor_array_chunk_T* prev);
void file_descriptor_array_chunk_destruct (file_descriptor_array_chunk_T* chunk);
#endif //NOX_FILE_DESCRIPTOR_H