-serial file:serial.log -monitor none -no-reboot -no-shutdown \
$(QEMU_DFLAGS)
+cppcheck:
+ @cppcheck --version >/dev/null
+ @cppcheck --quiet --enable=warning,performance,portability --error-exitcode=1 \
+ -I include $(SRC_DIR)
+
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(dir $@)
@echo " CC $<"
clean:
rm -rf build $(KERNEL_NAME)
-.PHONY: all clean iso run
+.PHONY: all clean iso run cppcheck
void vfs_open(fs_node_t* node);
void vfs_close(fs_node_t* node);
+fs_node_t* vfs_lookup(const char* path);
+
// Global root of the filesystem
extern fs_node_t* fs_root;
if (!filename || !entry_out || !user_stack_top_out) return -1;
if (!fs_root) return -1;
- fs_node_t* node = fs_root->finddir ? fs_root->finddir(fs_root, (char*)filename) : NULL;
+ fs_node_t* node = vfs_lookup(filename);
if (!node) {
uart_print("[ELF] file not found: ");
uart_print(filename);
#include "fs.h"
+#include "utils.h"
+
fs_node_t* fs_root = NULL;
uint32_t vfs_read(fs_node_t* node, uint32_t offset, uint32_t size, uint8_t* buffer) {
if (node->close)
node->close(node);
}
+
+fs_node_t* vfs_lookup(const char* path) {
+ if (!path || !fs_root) return NULL;
+
+ if (strcmp(path, "/") == 0) return fs_root;
+
+ const char* p = path;
+ while (*p == '/') p++;
+ if (*p == 0) return fs_root;
+
+ fs_node_t* cur = fs_root;
+
+ char part[128];
+ while (*p != 0) {
+ size_t i = 0;
+ while (*p != 0 && *p != '/') {
+ if (i + 1 < sizeof(part)) {
+ part[i++] = *p;
+ }
+ p++;
+ }
+ part[i] = 0;
+
+ while (*p == '/') p++;
+
+ if (part[0] == 0) continue;
+
+ if (!cur || !cur->finddir) return NULL;
+ cur = cur->finddir(cur, part);
+ if (!cur) return NULL;
+ }
+
+ return cur;
+}
uart_print("No filesystem mounted.\n");
} else {
char* fname = cmd + 4;
- fs_node_t* file = fs_root->finddir(fs_root, fname);
+ fs_node_t* file = NULL;
+ if (fname[0] == '/') {
+ file = vfs_lookup(fname);
+ } else {
+ char abs[132];
+ abs[0] = '/';
+ abs[1] = 0;
+ strcpy(abs + 1, fname);
+ file = vfs_lookup(abs);
+ }
if (file) {
uart_print("Reading "); uart_print(fname); uart_print("...\n");
uint8_t* buf = (uint8_t*)kmalloc(file->length + 1);