diff options
author | Benji Dial <benji6283@gmail.com> | 2021-03-01 22:35:26 -0500 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2021-03-01 22:35:26 -0500 |
commit | 1d69a46f5d9823bbf2e6211ca367b409d2d5f7a7 (patch) | |
tree | a49a5498080551270a827a205cde49477d4d89ff /src/kernel/idt.c | |
parent | 6f1b50a4cc6c232ee505a543f006abb1c6cd33cf (diff) | |
download | portland-os-1d69a46f5d9823bbf2e6211ca367b409d2d5f7a7.tar.gz |
minimal file writing, shutdown keybinding (Win+Shift+Q)
Diffstat (limited to 'src/kernel/idt.c')
-rw-r--r-- | src/kernel/idt.c | 27 |
1 files changed, 26 insertions, 1 deletions
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 |