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
This commit is contained in:
Yann MAGNIN 2022-02-01 12:59:24 +01:00
parent b4f6fd74e9
commit 63f1e3b957
4 changed files with 34 additions and 127 deletions

View File

@ -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);
}

View File

@ -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|<log_leval>]\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);
}

View File

@ -7,7 +7,7 @@
#include <string.h>
/* 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);

View File

@ -1,107 +0,0 @@
#include "vxBoot/loader.h"
#include "vxBoot/terminal.h"
#include "vxBoot/fs/smemfs.h"
#include <stdio.h>
#include <string.h>
/* 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);
}