From 2ea826b428246eb62be81630f441a4367a675968 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sat, 17 Aug 2024 17:10:04 +0200 Subject: *: getxattr --- src/bootstrap/tar.c | 70 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 27 deletions(-) (limited to 'src/bootstrap/tar.c') diff --git a/src/bootstrap/tar.c b/src/bootstrap/tar.c index 678f54f..61b5b03 100644 --- a/src/bootstrap/tar.c +++ b/src/bootstrap/tar.c @@ -1,12 +1,13 @@ #include "tar.h" +#include #include +#include #include #include +#include #include #include #include -#include -#include #define BUF_SIZE 64 @@ -27,29 +28,46 @@ void tar_driver(void *base) { void *ptr; while (!c0_fs_wait(buf, BUF_SIZE, &res)) { switch (res.op) { - case VFSOP_OPEN: - ptr = tar_open(buf, res.len, base, ~0); - c0_fs_respond(ptr, ptr ? 0 : -1, 0); - break; - - case VFSOP_READ: - tar_read(&res, base, ~0); - break; - - case VFSOP_GETSIZE: - if (tar_type(res.id) != '5') { - c0_fs_respond(NULL, tar_size(res.id), 0); - } else { - struct dirbuild db; - dir_start(&db, res.offset, NULL, 0); - tar_dirbuild(&db, res.id, base, ~0); - c0_fs_respond(NULL, dir_finish(&db), 0); - } - break; - - default: - c0_fs_respond(NULL, -1, 0); // unsupported - break; + case VFSOP_OPEN: + ptr = tar_open(buf, res.len, base, ~0); + c0_fs_respond(ptr, ptr ? 0 : -1, 0); + break; + + case VFSOP_READ: + tar_read(&res, base, ~0); + break; + + case VFSOP_GETSIZE: + if (tar_type(res.id) != '5') { + c0_fs_respond(NULL, tar_size(res.id), 0); + } else { + struct dirbuild db; + dir_start(&db, res.offset, NULL, 0); + tar_dirbuild(&db, res.id, base, ~0); + c0_fs_respond(NULL, dir_finish(&db), 0); + } + break; + + case VFSOP_GETXATTR: + if (strcmp("virt.index", buf) == 0) { + char res[] = "virt.mode\0virt.owner\0virt.group"; + c0_fs_respond(res, sizeof(res), 0); + } else if (strcmp("virt.mode", buf) == 0) { + c0_fs_respond(res.id + 100, 7, 0); + } else if (strcmp("virt.owner", buf) == 0) { + ssize_t ret = snprintf(buf, BUF_SIZE, "%d", oct_parse(res.id + 108, 7)); + c0_fs_respond(buf, ret, 0); + } else if (strcmp("virt.group", buf) == 0) { + ssize_t ret = snprintf(buf, BUF_SIZE, "%d", oct_parse(res.id + 116, 7)); + c0_fs_respond(buf, ret, 0); + } else { + c0_fs_respond(NULL, -ENOENT, 0); + } + break; + + default: + c0_fs_respond(NULL, -ENOSYS, 0); // unsupported + break; } } exit(0); @@ -60,7 +78,6 @@ static char tar_type(void *meta) { return *(char*)(meta + 156); } -#include static void *tar_open(const char *path, int len, void *base, size_t base_len) { void *res; if (len <= 0) return NULL; @@ -78,7 +95,6 @@ static void *tar_open(const char *path, int len, void *base, size_t base_len) { res = tar_find(path, len, base, base_len); if (res && tar_type(res) == '1') { /* hard link */ - _klogf("hard link to %s", res+157); res = tar_find(res + 157, strnlen(res + 157, 100), base, base_len); } return res; -- cgit v1.2.3