From 63f1e3b957286a5571146b8e7368f2dda22b5b07 Mon Sep 17 00:00:00 2001 From: Yann MAGNIN Date: Tue, 1 Feb 2022 12:59:24 +0100 Subject: [PATCH] vxBoot - 1.2.1 : Clean up @fix <> vxBoot/builtin/help : help message <> vxBoot/builtin/ls : help message <> vxBoot/builtin/log : help message <> vxBoot/loader/info : remove useless file --- src/builtin/help.c | 6 ++- src/builtin/log.c | 35 +++++++++------ src/builtin/ls.c | 13 +++--- src/loader/info.c | 107 --------------------------------------------- 4 files changed, 34 insertions(+), 127 deletions(-) delete mode 100644 src/loader/info.c diff --git a/src/builtin/help.c b/src/builtin/help.c index 0500d77..ac63378 100644 --- a/src/builtin/help.c +++ b/src/builtin/help.c @@ -14,8 +14,10 @@ int help_main(int argc, char **argv) "\n" "The available commands are:\n" " help - display this help message\n" -" ls - list files in storage memory\n" -" os - allows you to interact with the bootstraper\n" +" ls - list files in storage memory\n" +" ld - allows you to load the kernel in the physical memory\n" +" hw - display hardware information\n" +" log - allows you to manage the log level\n" ); return (0); } diff --git a/src/builtin/log.c b/src/builtin/log.c index d58188e..50b5e0a 100644 --- a/src/builtin/log.c +++ b/src/builtin/log.c @@ -8,19 +8,27 @@ extern int user_log_level; static int log_help(void) { terminal_write( - "+---+-----------+---------------------+\n" - "|Lvl|Name |Description |\n" - "| 0 |LOG_EMERG |system is unusable |\n" - "| 1 |LOG_ALERT |action must be taken |\n" - "| 2 |LOG_CRIT |critical condition |\n" - "| 3 |LOG_ERR |error condition |\n" - "| 4 |LOG_WARNING|warning condition |\n" - "| 5 |LOG_NOTICE |significant condition|\n" - "| 6 |LOG_INFO |informational message|\n" - "| 7 |LOG_DEBUG |debug-level message |\n" - "\n" - "current level = %d\n", - user_log_level +"NAME\n" +" log - handle log level" +"\n" +"SYNOPSIS:\n" +" log [-h|--help|]\n" +"DESCRIPTION:\n" +" The log level define the importance of message sended througt the logger." +" There is a list of all supported log level with their importance:\n" +" +---+-----------+---------------------+\n" +" |Lvl|Name |Description |\n" +" | 0 |LOG_EMERG |system is unusable |\n" +" | 1 |LOG_ALERT |action must be taken |\n" +" | 2 |LOG_CRIT |critical condition |\n" +" | 3 |LOG_ERR |error condition |\n" +" | 4 |LOG_WARNING|warning condition |\n" +" | 5 |LOG_NOTICE |significant condition|\n" +" | 6 |LOG_INFO |informational message|\n" +" | 7 |LOG_DEBUG |debug-level message |\n" +"\n" +"current level = %d\n", +user_log_level ); return (0); } @@ -36,5 +44,6 @@ int log_main(int argc, char **argv) return (-1); } user_log_level = argv[1][0] - '0'; + terminal_write("current level = %d\n", user_log_level); return (0); } diff --git a/src/builtin/ls.c b/src/builtin/ls.c index ddc04d8..a50c06d 100644 --- a/src/builtin/ls.c +++ b/src/builtin/ls.c @@ -7,7 +7,7 @@ #include /* ls_help() : Display the hep message */ -static void ls_help(void) +static int ls_help(void) { terminal_write( "NAME\n" @@ -17,12 +17,13 @@ static void ls_help(void) " ls [-h|--help]\n" "\n" "DESCRIPTION\n" -" List file information about FILEs (from the root directory only). The" +" List information about FILEs from the root directory only. The" " display is inspired from the utilitary `tree` in UNIX environment.\n" "\n" " -h,--help\n" " Display this help message\n" ); + return (0); } /* inode_walk() : walk onto the filesystem and display files */ @@ -68,9 +69,11 @@ int ls_main(int argc, char **argv) terminal_write("smemfs not mounted !\n"); return (84); } - if (argc > 1 && strcmp(argv[1], "-help") == 0) { - ls_help(); - return (0); + if (argc > 1) { + if (strcmp(argv[1], "-help") == 0) + return (ls_help()); + if (strcmp(argv[1], "-h") == 0) + return (ls_help()); } terminal_write("/:\n"); inode_walk(smemfs_superblock.root_inode, 0, 0x00000000); diff --git a/src/loader/info.c b/src/loader/info.c deleted file mode 100644 index 98efa34..0000000 --- a/src/loader/info.c +++ /dev/null @@ -1,107 +0,0 @@ -#include "vxBoot/loader.h" -#include "vxBoot/terminal.h" -#include "vxBoot/fs/smemfs.h" - -#include -#include - -/* section_get_id() : generate id string */ -static char *section_get_id(int id) -{ - static char buff[6]; - - snprintf(buff, 6, "[%2d]", id); - return (buff); -} - -/* section_get_name() : get the section name*/ -static char *section_get_name(void const *inode, int nameoff, off_t shstroff) -{ - static char buff[10]; - - smemfs_pread(inode, buff, 9, nameoff + shstroff); - if (strlen(buff) >= 8) { - buff[8] = '\0'; - buff[7] = '.'; - } - return (buff); -} - -/* section_get_type() : return the section type*/ -static char const *section_get_type(int type) -{ - static struct { - int type; - char const * const name; - } const types[] = { - {.type = SHT_NULL, .name = "NULL"}, - {.type = SHT_PROGBITS, .name = "PROGBITS"}, - {.type = SHT_SYMTAB, .name = "SYMTAB"}, - {.type = SHT_STRTAB, .name = "STRTAB"}, - {.type = SHT_RELA, .name = "RELA"}, - {.type = SHT_HASH, .name = "HASH"}, - {.type = SHT_DYNAMIC, .name = "DYNAMIC"}, - {.type = SHT_NOTE, .name = "NOTE"}, - {.type = SHT_NOBITS, .name = "NOBITS"}, - {.type = SHT_REL, .name = "REL"}, - {.type = SHT_SHLIB, .name = "SHLIB"}, - {.type = SHT_DYNSYM, .name = "DYNSYM"}, - {.type = SHT_INIT_ARRAY, .name = "INIT_ARRAY"}, - {.type = SHT_FINI_ARRAY, .name = "FINI_ARRAY"}, - {.type = SHT_PREINIT_ARRAY, .name = "PREINIT_ARRAY"}, - {.type = SHT_GROUP, .name = "GROUP"}, - {.type = SHT_SYMTAB_SHNDX, .name = "SYMTAB SECTION INDICES"}, - {.type = -1, .name = NULL}, - }; - for (int i = 0; types[i].name != NULL; ++i) { - if (types[i].type == type) - return (types[i].name); - } - return ("UNKNOWN"); -} - - - -/* loader_info() : display ELF PIE file information */ -//TODO: secure -int loader_info(struct smemfs_inode const * inode, Elf32_Ehdr *hdr) -{ - Elf32_Shdr shdr; - off_t stroff; - off_t shoff; - - /* find the section header table */ - shoff = hdr->e_shoff; - - /* find the section string table ".strtable" */ - smemfs_pread( - inode, - &shdr, sizeof(Elf32_Shdr), - shoff + (sizeof(Elf32_Shdr) * hdr->e_shstrndx) - ); - stroff = shdr.sh_offset; - - /* display section information */ - terminal_write( - "There are %d section headers, startting at offset %#x\n", - hdr->e_shnum, hdr->e_shoff - ); - terminal_write("Section Headers:\n"); - terminal_write( - "%4s %-8s %-8s %-8s %-8s\n", - "[Nr]", "Name", "Type", "Address", "Offset" - ); - for (int i = 0; i < hdr->e_shnum; ++i) { - smemfs_pread(inode, &shdr, sizeof(Elf32_Shdr), shoff); - terminal_write( - "%4s %-8s %-8s %08x %08x\n", - section_get_id(i), - section_get_name(inode, shdr.sh_name, stroff), - section_get_type(shdr.sh_type), - shdr.sh_addr, - shdr.sh_offset - ); - shoff += sizeof(Elf32_Shdr); - } - return (0); -}