diff --git a/kernel/inc/proc/file_descriptor.h b/kernel/inc/proc/file_descriptor.h index ffb74af..6a2bd49 100644 --- a/kernel/inc/proc/file_descriptor.h +++ b/kernel/inc/proc/file_descriptor.h @@ -9,10 +9,15 @@ #define FILE_DESCRIPTOR_ARRAY_CHUNK_SIZE 32 -typedef int32_t file_descriptor_t; +typedef uint32_t file_descriptor_t; typedef enum { - FILE_DESCRIPTOR_INVALID = -1 + 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; diff --git a/kernel/src/proc/file_descriptor.c b/kernel/src/proc/file_descriptor.c index d607b76..eef4974 100644 --- a/kernel/src/proc/file_descriptor.c +++ b/kernel/src/proc/file_descriptor.c @@ -5,7 +5,7 @@ file_descriptor_t file_descriptor_request(file_descriptor_array_T* fd_array, vfs_node_T* node) { - file_descriptor_t fd = 0; + file_descriptor_t fd = FILE_DESCRIPTORS_ENUM_END; file_descriptor_array_chunk_T* chunk = fd_array->base_chunk; while (chunk->amount == FILE_DESCRIPTOR_ARRAY_CHUNK_SIZE) { @@ -30,8 +30,9 @@ file_descriptor_t file_descriptor_request(file_descriptor_array_T* fd_array, vfs } vfs_node_T* file_descriptor_resolve(file_descriptor_array_T* fd_array, file_descriptor_t fd) { - if (fd == FILE_DESCRIPTOR_INVALID) return NULL; + if (fd < FILE_DESCRIPTORS_ENUM_END) return NULL; + fd -= FILE_DESCRIPTORS_ENUM_END; uint32_t chunk_selector = fd / FILE_DESCRIPTOR_ARRAY_CHUNK_SIZE; file_descriptor_array_chunk_T* chunk = fd_array->base_chunk; @@ -49,7 +50,9 @@ vfs_node_T* file_descriptor_resolve(file_descriptor_array_T* fd_array, file_desc } void file_descriptor_free(file_descriptor_array_T* fd_array, file_descriptor_t fd) { - if (fd == FILE_DESCRIPTOR_INVALID) return; + if (fd < FILE_DESCRIPTORS_ENUM_END) return; + + fd -= FILE_DESCRIPTORS_ENUM_END; uint32_t chunk_selector = fd / FILE_DESCRIPTOR_ARRAY_CHUNK_SIZE; file_descriptor_array_chunk_T* chunk = fd_array->base_chunk;