From 387777438bb9f5f1121a51c065c7c55fb5cd45c0 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Thu, 27 Feb 2014 22:47:00 +0100 Subject: [PATCH] Improve handling of root directory --- kernel/src/scheduler.cpp | 6 +----- kernel/src/vfs.cpp | 16 +++++++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/kernel/src/scheduler.cpp b/kernel/src/scheduler.cpp index c687cb0d..14a26720 100644 --- a/kernel/src/scheduler.cpp +++ b/kernel/src/scheduler.cpp @@ -851,11 +851,7 @@ void scheduler::release_handle(size_t fd){ } bool scheduler::has_handle(size_t fd){ - if(fd < pcb[current_pid].handles.size()){ - return !pcb[current_pid].handles[fd].empty(); - } - - return false; + return fd < pcb[current_pid].handles.size(); } const std::vector& scheduler::get_handle(size_t fd){ diff --git a/kernel/src/vfs.cpp b/kernel/src/vfs.cpp index cd8661e2..25822641 100644 --- a/kernel/src/vfs.cpp +++ b/kernel/src/vfs.cpp @@ -53,6 +53,11 @@ int64_t vfs::open(const char* file_path, size_t flags){ auto path = get_path(file_path); + //Special handling for opening the root + if(path.empty()){ + return scheduler::register_new_handle(path); + } + auto last = path.back(); path.pop_back(); @@ -157,8 +162,13 @@ int64_t vfs::stat(size_t fd, stat_info& info){ auto path = scheduler::get_handle(fd); + //Special handling for root if(path.empty()){ - return -std::ERROR_INVALID_FILE_PATH; + //TODO Add file system support for stat of the root directory + info.size = 4096; + info.flags = STAT_FLAG_DIRECTORY; + + return 0; } auto last = path.back(); @@ -241,10 +251,6 @@ int64_t vfs::entries(size_t fd, char* buffer, size_t size){ auto path = scheduler::get_handle(fd); - if(path.empty()){ - return -std::ERROR_INVALID_FILE_PATH; - } - //TODO file search should be done entirely by the file system auto files = fat32::ls(*disks::mounted_disk(), *disks::mounted_partition(), path);