summaryrefslogtreecommitdiff
path: root/src/init
diff options
context:
space:
mode:
authordzwdz2021-11-07 18:06:50 +0100
committerdzwdz2021-11-07 18:06:50 +0100
commit82151d33b168536a3eb12d1cf2e9703cae2e65b7 (patch)
treec5442851caff133116410fb71e77e8ff24d88709 /src/init
parent18470f2b4571d6779d1ee3f721d4b262349f373c (diff)
init/tar: refactor init_tar, add some very basic directory support
Diffstat (limited to 'src/init')
-rw-r--r--src/init/tar.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/src/init/tar.c b/src/init/tar.c
index 1a064d6..6856db1 100644
--- a/src/init/tar.c
+++ b/src/init/tar.c
@@ -5,10 +5,8 @@
#define BUF_SIZE 64
-extern int tty_fd;
-
-// TODO struct tar
static int tar_open(const char *path, int len, void *base, size_t base_len);
+static int tar_read(struct fs_wait_response *res);
static int tar_size(void *sector);
static void *tar_find(const char *path, size_t path_len, void *base, size_t base_len);
static int oct_parse(char *str, size_t len);
@@ -22,17 +20,9 @@ void tar_driver(void *base) {
_syscall_fs_respond(NULL, tar_open(buf, res.len, base, ~0));
break;
- case VFSOP_READ: {
- void *meta = (void*)res.id;
- int size = tar_size(meta);
- if (res.offset < 0 || res.offset > size) {
- // TODO support negative offsets
- _syscall_fs_respond(NULL, -1);
- } else {
- _syscall_fs_respond(meta + 512 + res.offset, size - res.offset);
- }
+ case VFSOP_READ:
+ tar_read(&res);
break;
- }
default:
_syscall_fs_respond(NULL, -1); // unsupported
@@ -53,6 +43,32 @@ static int tar_open(const char *path, int len, void *base, size_t base_len) {
return (int)ptr;
}
+static int tar_read(struct fs_wait_response *res) {
+ void *meta = (void*)res->id;
+ char type = *(char*)(meta + 156);
+ switch (type) {
+ case '\0':
+ case '0': { /* normal files */
+ int size = tar_size(meta);
+ if (res->offset < 0 || res->offset > size) {
+ // TODO support negative offsets
+ _syscall_fs_respond(NULL, -1);
+ } else {
+ _syscall_fs_respond(meta + 512 + res->offset, size - res->offset);
+ }
+ break;
+ }
+
+ case '5': /* directory */
+ _syscall_fs_respond("[directory]", 11);
+ break;
+
+ default:
+ _syscall_fs_respond(NULL, -1);
+ break;
+ }
+}
+
static int tar_size(void *sector) {
return oct_parse(sector + 124, 11);
}