Compare commits
No commits in common. "23af4ccdab68fa7cf300dea1cf17c9a09a7370bf" and "ce905f1a36b7c9f7ad09ebb5676cf6f9fad37e81" have entirely different histories.
23af4ccdab
...
ce905f1a36
|
@ -5,9 +5,9 @@
|
||||||
|
|
||||||
#include "drivers/fs/vfs.h"
|
#include "drivers/fs/vfs.h"
|
||||||
|
|
||||||
void ramfs_file_delete (vfs_node_T* node);
|
void ramfs_file_delete (vfs_node_T* node);
|
||||||
uint64_t ramfs_file_write (vfs_node_T* node, uint64_t size, uint8_t* buffer_in);
|
void ramfs_file_write (vfs_node_T* node, uint64_t size, uint8_t* buffer_in);
|
||||||
uint64_t ramfs_file_read (vfs_node_T* node, uint64_t size, uint8_t* buffer_out);
|
void ramfs_file_read (vfs_node_T* node, uint64_t size, uint8_t* buffer_out);
|
||||||
|
|
||||||
|
|
||||||
#endif //NOX_RAMFS_H
|
#endif //NOX_RAMFS_H
|
||||||
|
|
|
@ -65,8 +65,8 @@ vfs_node_T* vfs_node_resolve_child (vfs_node_T* node, string_t chil
|
||||||
|
|
||||||
vfs_node_T* vfs_file_create (fs_T* filesystem, string_t path);
|
vfs_node_T* vfs_file_create (fs_T* filesystem, string_t path);
|
||||||
void vfs_file_delete (vfs_node_T* file);
|
void vfs_file_delete (vfs_node_T* file);
|
||||||
uint64_t vfs_file_write (vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_in);
|
void vfs_file_write (vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_in);
|
||||||
uint64_t vfs_file_read (vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_out);
|
void vfs_file_read (vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_out);
|
||||||
|
|
||||||
vfs_node_T* vfs_directory_create (fs_T* filesystem, string_t path);
|
vfs_node_T* vfs_directory_create (fs_T* filesystem, string_t path);
|
||||||
void vfs_directory_delete (vfs_node_T* directory);
|
void vfs_directory_delete (vfs_node_T* directory);
|
||||||
|
|
|
@ -10,7 +10,7 @@ void ramfs_file_delete(vfs_node_T* node) {
|
||||||
vfs_node_cache_destruct(node->cache);
|
vfs_node_cache_destruct(node->cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ramfs_file_write(vfs_node_T* node, uint64_t size, uint8_t* buffer_in) {
|
void ramfs_file_write(vfs_node_T* node, uint64_t size, uint8_t* buffer_in) {
|
||||||
if (node->cache != NULL) {
|
if (node->cache != NULL) {
|
||||||
vfs_node_cache_destruct(node->cache);
|
vfs_node_cache_destruct(node->cache);
|
||||||
}
|
}
|
||||||
|
@ -18,13 +18,10 @@ uint64_t ramfs_file_write(vfs_node_T* node, uint64_t size, uint8_t* buffer_in) {
|
||||||
vfs_node_cache_create(node, size);
|
vfs_node_cache_create(node, size);
|
||||||
|
|
||||||
memory_copy(buffer_in, node->cache->buffer, size);
|
memory_copy(buffer_in, node->cache->buffer, size);
|
||||||
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ramfs_file_read(vfs_node_T* node, uint64_t size, uint8_t* buffer_out) {
|
void ramfs_file_read(vfs_node_T* node, uint64_t size, uint8_t* buffer_out) {
|
||||||
if (node->cache == NULL) { return 0; }
|
if (node->cache == NULL) { return; }
|
||||||
|
|
||||||
memory_copy(node->cache->buffer, buffer_out, MIN(size, node->cache->buffer_size));
|
memory_copy(node->cache->buffer, buffer_out, MIN(size, node->cache->buffer_size));
|
||||||
return size;
|
|
||||||
}
|
}
|
|
@ -224,33 +224,31 @@ void vfs_file_delete(vfs_node_T* file) {
|
||||||
vfs_node_destruct(file);
|
vfs_node_destruct(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t vfs_file_write(vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_in) {
|
void vfs_file_write(vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_in) {
|
||||||
// in future this probably isn't a good way to determine the size of a file:
|
// in future this probably isn't a good way to determine the size of a file:
|
||||||
file->size = size;
|
file->size = size;
|
||||||
|
|
||||||
switch (file->filesystem->type) {
|
switch (file->filesystem->type) {
|
||||||
case FS_RAMFS: {
|
case FS_RAMFS: {
|
||||||
return ramfs_file_write(file, size, buffer_in);
|
ramfs_file_write(file, size, buffer_in);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t vfs_file_read(vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_out) {
|
void vfs_file_read(vfs_node_T* file, uint64_t position, uint64_t size, uint8_t* buffer_out) {
|
||||||
switch (file->filesystem->type) {
|
switch (file->filesystem->type) {
|
||||||
case FS_RAMFS: {
|
case FS_RAMFS: {
|
||||||
return ramfs_file_read(file, size, buffer_out);
|
ramfs_file_read(file, size, buffer_out);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vfs_node_T* vfs_directory_create(fs_T* filesystem, string_t path) {
|
vfs_node_T* vfs_directory_create(fs_T* filesystem, string_t path) {
|
||||||
|
|
|
@ -44,23 +44,28 @@ void syscall_handle_nx_fread(cpu_state_T* state) {
|
||||||
case FILE_DESCRIPTOR_INVALID:
|
case FILE_DESCRIPTOR_INVALID:
|
||||||
case FILE_DESCRIPTOR_STDOUT:
|
case FILE_DESCRIPTOR_STDOUT:
|
||||||
case FILE_DESCRIPTOR_STDERR: {
|
case FILE_DESCRIPTOR_STDERR: {
|
||||||
|
state->rax = STATUS_RESOURCE_NOT_AVAILABLE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case FILE_DESCRIPTOR_STDIN: {
|
case FILE_DESCRIPTOR_STDIN: {
|
||||||
read_bytes = pipe_read(&process->stdin, mem, n);
|
read_bytes = pipe_read(&process->stdin, mem, n);
|
||||||
|
state->rax = STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
vfs_node_T* node = file_descriptor_resolve(scheduler_get_current_process()->fd_array, fd);
|
vfs_node_T* node = file_descriptor_resolve(scheduler_get_current_process()->fd_array, fd);
|
||||||
|
|
||||||
read_bytes = vfs_file_read(node, offset, n, mem);
|
// TODO: set read_bytes
|
||||||
|
|
||||||
|
vfs_file_read(node, offset, n, mem);
|
||||||
|
|
||||||
|
state->rax = STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// TODO: return read_bytes to process
|
||||||
state->rax = read_bytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void syscall_handle_nx_fwrite(cpu_state_T* state) {
|
void syscall_handle_nx_fwrite(cpu_state_T* state) {
|
||||||
|
@ -75,6 +80,7 @@ void syscall_handle_nx_fwrite(cpu_state_T* state) {
|
||||||
switch (fd) {
|
switch (fd) {
|
||||||
case FILE_DESCRIPTOR_INVALID:
|
case FILE_DESCRIPTOR_INVALID:
|
||||||
case FILE_DESCRIPTOR_STDIN: {
|
case FILE_DESCRIPTOR_STDIN: {
|
||||||
|
state->rax = STATUS_RESOURCE_NOT_AVAILABLE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +88,8 @@ void syscall_handle_nx_fwrite(cpu_state_T* state) {
|
||||||
if (process->stderr != NULL) {
|
if (process->stderr != NULL) {
|
||||||
written_bytes = pipe_write(process->stderr, mem, n);
|
written_bytes = pipe_write(process->stderr, mem, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state->rax = STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,18 +97,23 @@ void syscall_handle_nx_fwrite(cpu_state_T* state) {
|
||||||
if (process->stdout != NULL) {
|
if (process->stdout != NULL) {
|
||||||
written_bytes = pipe_write(process->stdout, mem, n);
|
written_bytes = pipe_write(process->stdout, mem, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state->rax = STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
vfs_node_T* node = file_descriptor_resolve(scheduler_get_current_process()->fd_array, fd);
|
vfs_node_T* node = file_descriptor_resolve(scheduler_get_current_process()->fd_array, fd);
|
||||||
|
|
||||||
written_bytes = vfs_file_write(node, offset, n, mem);
|
// TODO: set written_bytes
|
||||||
|
|
||||||
|
vfs_file_write(node, offset, n, mem);
|
||||||
|
state->rax = STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
state->rax = written_bytes;
|
// TODO: return written_bytes to process
|
||||||
}
|
}
|
||||||
|
|
||||||
void syscall_handle_nx_fdelete(cpu_state_T* state) {
|
void syscall_handle_nx_fdelete(cpu_state_T* state) {
|
||||||
|
|
Loading…
Reference in New Issue