diff --git a/fs/fs.c b/fs/fs.c index f60ce96b..f8994beb 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -25,8 +25,9 @@ vfs_node_t* fs_root = NULL; // The root of the filesystem. -ssize_t read_fs(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset) +ssize_t read_fs(fildes_t* file, uint8_t* buffer, size_t size) { + vfs_node_t* node = file->node; ssize_t ret = -EINVAL; if (BUILTIN_EXPECT(!node || !buffer, 0)) @@ -35,14 +36,15 @@ ssize_t read_fs(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset) spinlock_lock(&node->lock); // Has the node got a read callback? if (node->read != 0) - ret = node->read(node, buffer, size, offset); + ret = node->read(node, buffer, size, file->offset); spinlock_unlock(&node->lock); return ret; } -ssize_t write_fs(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset) +ssize_t write_fs(fildes_t* file, uint8_t* buffer, size_t size) { + vfs_node_t* node = file->node; ssize_t ret = -EINVAL; if (BUILTIN_EXPECT(!node || !buffer, 0)) @@ -51,7 +53,7 @@ ssize_t write_fs(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset) spinlock_lock(&node->lock); // Has the node got a write callback? if (node->write != 0) - ret = node->write(node, buffer, size, offset); + ret = node->write(node, buffer, size, file->offset); spinlock_unlock(&node->lock); return ret; diff --git a/include/metalsvm/fs.h b/include/metalsvm/fs.h index 33e30090..a515dea0 100644 --- a/include/metalsvm/fs.h +++ b/include/metalsvm/fs.h @@ -38,6 +38,10 @@ //#define FS_MOUNTPOINT 0x08 // Is the file an active mountpoint? +/*file descriptor init*/ +#define NR_OPEN 10 +#define FS_INIT { [0 ... NR_OPEN-1] = {NULL, 0, 0} } + /*open flags*/ //#define O_RDONLY 0 @@ -135,8 +139,16 @@ typedef struct vfs_node { block_list_t block_list; } vfs_node_t; +/** @brief file descriptor structure */ +typedef struct fildes { + vfs_node_t* node; /* */ + off_t offset; /* */ + int flags; /* */ + int mode; /* */ +} fildes_t; + /** @brief Directory entry structure */ -typedef struct dirent{ +typedef struct dirent { /// Directory name char name[MAX_FNAME]; /// Corresponding VFS node pointer @@ -174,7 +186,7 @@ extern vfs_node_t* fs_root; // The root of the filesystem. * - number of bytes copied (size) * - 0 on error */ -ssize_t read_fs(vfs_node_t * node, uint8_t* buffer, size_t size, off_t offset); +ssize_t read_fs(fildes_t* file, uint8_t* buffer, size_t size); /** @brief Write into the file system from the buffer * @param node Pointer to the node to write to @@ -185,7 +197,7 @@ ssize_t read_fs(vfs_node_t * node, uint8_t* buffer, size_t size, off_t offset); * - number of bytes copied (size) * - 0 on error */ -ssize_t write_fs(vfs_node_t * node, uint8_t* buffer, size_t size, off_t offset); +ssize_t write_fs(fildes_t* file, uint8_t* buffer, size_t size); /** @brief Yet to be documented */ vfs_node_t* open_fs(const char* name, int flags); diff --git a/include/metalsvm/fs_types.h b/include/metalsvm/fs_types.h deleted file mode 100644 index da4e4b64..00000000 --- a/include/metalsvm/fs_types.h +++ /dev/null @@ -1,44 +0,0 @@ -/* -+ * Copyright 2011 Stefan Lankes, Chair for Operating Systems, -+ * RWTH Aachen University -+ * -+ * Licensed under the Apache License, Version 2.0 (the "License"); -+ * you may not use this file except in compliance with the License. -+ * You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the License for the specific language governing permissions and -+ * limitations under the License. -+ * -+ * This file is part of MetalSVM. - */ - -#ifndef __FS_TYPES_H__ -#define __FS_TYPES_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct fildes { - vfs_node_t* node; /* */ - off_t offset; /* */ - int flags; /* */ - int mode; /* */ -} fildes_t; - -#define NR_OPEN 10 -#define FS_INIT { [0 ... NR_OPEN-1] = {NULL, 0, 0} } - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/metalsvm/tasks_types.h b/include/metalsvm/tasks_types.h index fdb35f5c..12564a02 100644 --- a/include/metalsvm/tasks_types.h +++ b/include/metalsvm/tasks_types.h @@ -32,10 +32,9 @@ #include #include #include -#include +#include #include #include -#include #include #ifdef __cplusplus diff --git a/kernel/main.c b/kernel/main.c index daf7f3af..8e861932 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -47,7 +47,7 @@ extern char __BUILD_TIME; static void list_fs(vfs_node_t* node, uint32_t depth) { - int j, i = 0; +/* int j, i = 0; dirent_t* dirent = NULL; while ((dirent = readdir_fs(node, i)) != 0) { @@ -70,7 +70,7 @@ static void list_fs(vfs_node_t* node, uint32_t depth) } i++; - } + }*/ } static void list_root(void) { diff --git a/kernel/syscall.c b/kernel/syscall.c index ba1769dd..d0031e57 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -34,7 +34,7 @@ static int sys_write(int fd, const char *buf, size_t len) per_core(current_task)->fildes_table[fd].offset = per_core(current_task)->fildes_table[fd].node->block_size; } - wrotebytes = write_fs(per_core(current_task)->fildes_table[fd].node, (uint8_t*)buf, len, per_core(current_task)->fildes_table[fd].offset); + wrotebytes = write_fs(&(per_core(current_task)->fildes_table[fd]), (uint8_t*)buf, len); //kprintf("writing into filesystem -- fd:%i, Filelength:%i, Writtenbytes: %i, Bufferlength: %s \n", fd, len, wrotebytes, buf); per_core(current_task)->fildes_table[fd].offset += wrotebytes; @@ -83,9 +83,8 @@ static int sys_read(int fd, const char *buf, size_t len) { unsigned int readbytes; readbytes = read_fs( - per_core(current_task)->fildes_table[fd].node, - (uint8_t*)buf, len, - per_core(current_task)->fildes_table[fd].offset); + &(per_core(current_task)->fildes_table[fd]), + (uint8_t*)buf, len); per_core(current_task)->fildes_table[fd].offset += readbytes; /*kprintf("fd:%i, Filelength:%i, Bufferlength: %s X: %i\n", fd, len, buf, readbytes); */ /* Beware: still reading above file limit! */ diff --git a/kernel/tasks.c b/kernel/tasks.c index 9f931763..f928aaa4 100644 --- a/kernel/tasks.c +++ b/kernel/tasks.c @@ -327,16 +327,20 @@ static int load_task(load_args_t* largs) elf_header_t header; elf_program_header_t prog_header; //elf_section_header_t sec_header; - vfs_node_t* node; + fildes_t file; + file.offset = 0; + + //TODO: init the hole fildes_t struct! + if (!largs) return -EINVAL; - node = largs->node; - if (!node) + file.node = largs->node; + if (!file.node) return -EINVAL; - read_fs(node, (uint8_t*)&header, sizeof(elf_header_t), 0); + read_fs(&file, (uint8_t*)&header, sizeof(elf_header_t)); if (BUILTIN_EXPECT(header.ident.magic != ELF_MAGIC, 0)) goto invalid; @@ -357,7 +361,8 @@ static int load_task(load_args_t* largs) // interpret program header table for (i=0; istart_heap = per_core(current_task)->end_heap = prog_header.virt_addr+prog_header.mem_size; // load program - read_fs(node, (uint8_t*)prog_header.virt_addr, prog_header.file_size, prog_header.offset); + file.offset = prog_header.offset; + read_fs(&file, (uint8_t*)prog_header.virt_addr, prog_header.file_size); flags = VMA_CACHEABLE; if (prog_header.flags & PF_R) @@ -436,7 +442,8 @@ static int load_task(load_args_t* largs) #if 0 // interpret section header table for (i=0; i