From 9a1a0e428a19289c4e906f3a4c9b09909db6eb27 Mon Sep 17 00:00:00 2001 From: xamidev Date: Wed, 6 May 2026 14:04:28 +0200 Subject: [PATCH] tar_list --- include/fs/initfs.h | 1 + src/fs/initfs.c | 16 ++++++++++++++++ src/kapps/kshell.c | 27 ++++++++++++++++----------- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/include/fs/initfs.h b/include/fs/initfs.h index a8c12c9..f7a3ca8 100644 --- a/include/fs/initfs.h +++ b/include/fs/initfs.h @@ -13,5 +13,6 @@ int initfs_init(struct limine_file* tar_file); int tar_lookup(unsigned char* archive, char* filename, char** out); int tar_exists(const char* filename); int tar_read(char* filename, char* out, int count, int offset); +void tar_list(); #endif \ No newline at end of file diff --git a/src/fs/initfs.c b/src/fs/initfs.c index 40b314c..50c34dd 100644 --- a/src/fs/initfs.c +++ b/src/fs/initfs.c @@ -59,6 +59,22 @@ int tar_lookup(unsigned char* archive, char* filename, char** out) return -ENOENT; } +/* + * tar_list - list all files present in archive + */ +void tar_list() +{ + printf("++ Contents of initial filesystem ++\r\n\r\n"); + unsigned char *ptr = archive_start_addr; + + while (!memcmp(ptr + 257, "ustar", 5)) { + int filesize = tar_oct2bin(ptr + 0x7c, 11); + char* filename = (char*)ptr; + printf("file: %s\r\n", filename); + ptr += (((filesize + 511) / 512) + 1) * 512; + } +} + /* * tar_read - read a file in the TAR archive * @filename: file to read (absolute path) diff --git a/src/kapps/kshell.c b/src/kapps/kshell.c index 46cd6dc..fa44b51 100644 --- a/src/kapps/kshell.c +++ b/src/kapps/kshell.c @@ -4,6 +4,7 @@ * @license GPL-3.0-only */ +#include "fs/initfs.h" #include #include #include @@ -42,17 +43,16 @@ void pedicel_main(void* arg) keyboard_getline(input_buf, PEDICEL_INPUT_SIZE); if (strncmp(input_buf, "help", 4) == 0) { - printf("\r\nYou are currently running the test kernel shell. This is not\r\n" - "a fully-fledged shell like you'd find in a complete operating system,\r\n" - "but rather a toy to play around in the meantime.\r\n\r\n" - "clear - clear the screen\r\n" - "panic - trigger a test panic\r\n" - "syscall - trigger int 0x80\r\n" - "pf - trigger a page fault\r\n" - "now - get current date\r\n" - "smash - smash the stack\r\n" - "mem - get used heap info\r\n" - "load - load an user executable\r\n"); + printf("++ shell builtins ++\r\n\r\n" + "\tclear - clear the screen\r\n" + "\tpanic - trigger a test panic\r\n" + "\tsyscall - trigger int 0x80\r\n" + "\tpf - trigger a page fault\r\n" + "\tnow - get current date\r\n" + "\tsmash - smash the stack\r\n" + "\tmem - get used heap info\r\n" + "\tload - load an user executable\r\n" + "\tlist - list initfs.tar contents\r\n"); continue; } @@ -102,6 +102,11 @@ void pedicel_main(void* arg) continue; } + if (strncmp(input_buf, "list", 4) == 0) { + tar_list(); + continue; + } + printf("%s: command not found\r\n", input_buf); } } \ No newline at end of file