From 1d69a46f5d9823bbf2e6211ca367b409d2d5f7a7 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Mon, 1 Mar 2021 22:35:26 -0500 Subject: minimal file writing, shutdown keybinding (Win+Shift+Q) --- src/kernel/idt.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/kernel/idt.c') diff --git a/src/kernel/idt.c b/src/kernel/idt.c index c79ae7b..1a78da0 100644 --- a/src/kernel/idt.c +++ b/src/kernel/idt.c @@ -52,6 +52,12 @@ uint32_t sc_file_get_size(uint32_t handle) { return drives[handle >> 8].get_file_length(drives + (handle >> 8), handle & 0xff); } +void sc_file_set_size(uint32_t handle, uint32_t new_size) { + if (!handle) + return; + drives[handle >> 8].set_file_length(drives + (handle >> 8), handle & 0xff, new_size); +} + uint32_t sc_file_read(uint32_t handle, uint32_t file_offset, uint32_t count, void *buffer) { if (!handle) return 0; @@ -62,6 +68,23 @@ uint32_t sc_file_read(uint32_t handle, uint32_t file_offset, uint32_t count, voi return count; } +uint32_t sc_file_write(uint32_t handle, uint32_t file_offset, uint32_t count, void *buffer) { + if (!handle) + return 0; + const struct drive *const d = drives + (handle >> 8); + const fs_id_t fid = handle & 0xff; + + if (!d->is_writable(d, fid)) + return 0; + + const uint32_t l = d->get_file_length(d, fid); + if (file_offset + count > l) + count = l - file_offset; + + mfcpy(d, fid, file_offset, buffer, count); + return count; +} + uint32_t sc_start_task(uint32_t drive_number, char *path, const char *pass, uint32_t io_task) { switch_to_kernel_cr3(); uint32_t process_id = try_elf_run(drives + drive_number, vma_to_pma(active_task->page_directory, path), pass, io_task); @@ -183,7 +206,9 @@ void const *syscall_table[] = { &find_unread_ipc, &sc_wait_ipc_read, &sc_is_task_running, - &sc_get_timestamp + &sc_get_timestamp, + &sc_file_write, + &sc_file_set_size }; //these aren't really void ()'s, but gcc complains if we take an address of a void, so we give it a type -- cgit v1.2.3