feat: Vfs and Ext2 support. Code style/attribute improvements
Added VFS and Ext2 support. Optimized attributes of methods to improve code highlighting. Printf attribute, malloc attribute, etc.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include <myke/mem/mem.h>
|
||||
#include <myke/tasks/task.h>
|
||||
#include <myke/util/power.h>
|
||||
#include <myke/vfs/vfs.h>
|
||||
|
||||
#ifdef ENABLE_SELF_TEST
|
||||
|
||||
@@ -54,6 +55,12 @@ void shutdown(const char *args);
|
||||
|
||||
void ps(const char *args);
|
||||
|
||||
void mount(const char *args);
|
||||
|
||||
void ls(const char *args);
|
||||
|
||||
void cat(const char *args);
|
||||
|
||||
#ifdef ENABLE_SELF_TEST
|
||||
|
||||
void explode(const char *args);
|
||||
@@ -75,6 +82,9 @@ cmd_handler cmd_handlers[] = {
|
||||
{"ide", ide},
|
||||
{"shutdown", shutdown},
|
||||
{"ps", ps},
|
||||
{"mount", mount},
|
||||
{"ls", ls},
|
||||
{"cat", cat},
|
||||
#ifdef ENABLE_SELF_TEST
|
||||
{"slingurl", slingurl},
|
||||
{"kill-self", kill_self},
|
||||
@@ -185,17 +195,74 @@ void ide(const char *arg) {
|
||||
}
|
||||
}
|
||||
|
||||
void mount(const char *arg) {
|
||||
vfs_mount("/", "ide0p0", "ext2");
|
||||
}
|
||||
|
||||
void ls(const char *arg) {
|
||||
vfs_fd_t *fd = vfs_open("/", 0, 0);
|
||||
if (fd == NULL) {
|
||||
printf("could not open /\n");
|
||||
return;
|
||||
}
|
||||
void *data = malloc(1024);
|
||||
if (data == NULL) {
|
||||
printf("malloc fail\n");
|
||||
vfs_close(fd);
|
||||
return;
|
||||
}
|
||||
uint32_t num = 0;
|
||||
while ((num = vfs_getdents(fd, data, 1024)) > 0) {
|
||||
vfs_dirent_t *ent = data;
|
||||
while (true) {
|
||||
printf("%s\n", ent->name);
|
||||
if (ent->offset_next >= 1024) {
|
||||
break;
|
||||
}
|
||||
ent = &data[ent->offset_next];
|
||||
}
|
||||
}
|
||||
free(data);
|
||||
vfs_close(fd);
|
||||
}
|
||||
|
||||
void cat(const char *arg) {
|
||||
vfs_fd_t *fd = vfs_open("/sda1", 0, 0);
|
||||
vfs_close(fd);
|
||||
fd = vfs_open("/test.txt", 0, 0);
|
||||
if (fd == NULL) {
|
||||
printf("could not open /test.txt\n");
|
||||
return;
|
||||
}
|
||||
char *data = malloc(1024);
|
||||
if (data == NULL) {
|
||||
printf("no mem\n");
|
||||
vfs_close(fd);
|
||||
return;
|
||||
}
|
||||
int read = vfs_read(fd, data, 1024);
|
||||
if (read < 0) {
|
||||
printf("Failed to read\n");
|
||||
} else if (read == 0) {
|
||||
printf("emtpy file\n");
|
||||
} else {
|
||||
printf("first 10 chars %10s\n", data);
|
||||
}
|
||||
free(data);
|
||||
vfs_close(fd);
|
||||
}
|
||||
|
||||
void store_bootloader_info(multiboot_info_t *multiboot_info) {
|
||||
// get bootloader and cmdline
|
||||
if (multiboot_info->flags & MULTIBOOT_INFO_CMDLINE) {
|
||||
int cmdline_length = strlen((const char *) multiboot_info->cmdline);
|
||||
size_t cmdline_length = strlen((const char *) multiboot_info->cmdline);
|
||||
if (cmdline_length > CMDLINE_MAX_LENGTH) {
|
||||
k_panics("cmdline to long!\n");
|
||||
}
|
||||
memcpy(cmdline, (char *) multiboot_info->cmdline, cmdline_length);
|
||||
}
|
||||
if (multiboot_info->flags & MULTIBOOT_INFO_BOOT_LOADER_NAME) {
|
||||
int bootloader_length = strlen((const char *) multiboot_info->boot_loader_name);
|
||||
size_t bootloader_length = strlen((const char *) multiboot_info->boot_loader_name);
|
||||
if (bootloader_length > BOOTLOADER_NAME_MAX_LENGTH) {
|
||||
k_panics("bootloader name to long!\n");
|
||||
}
|
||||
@@ -226,6 +293,7 @@ void att_noreturn main_loop(void *data) {
|
||||
}
|
||||
|
||||
#ifdef K_SHELL
|
||||
|
||||
void main_loop_start() {
|
||||
task_spawn(main_loop, NULL, "main");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user