- rewrite the read_fs and write_fs. Now both functions use fildes_t instead of vfs_node_t structs.

INFO:	typedef struct fildes {
        	vfs_node_t* 	node;
        	off_t 		offset;
		int 		flags;
		int 		mode;
	} fildes_t;

- merge fs_types.h and fs.h into one file fs.h
This commit is contained in:
Marian Ohligs 2011-07-01 17:50:08 +02:00
parent 0cd8ea9e37
commit 3d74f1b514
7 changed files with 41 additions and 66 deletions

10
fs/fs.c
View file

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

View file

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

View file

@ -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 <metalsvm/stddef.h>
#include <metalsvm/fs.h>
#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

View file

@ -32,10 +32,9 @@
#include <metalsvm/stddef.h>
#include <metalsvm/vma.h>
#include <metalsvm/spinlock_types.h>
#include <metalsvm/fs_types.h>
#include <metalsvm/fs.h>
#include <metalsvm/mailbox_types.h>
#include <asm/tasks_types.h>
#include <metalsvm/fs_types.h>
#include <asm/atomic.h>
#ifdef __cplusplus

View file

@ -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) {

View file

@ -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! */

View file

@ -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; i<header.ph_entry_count; i++) {
if (read_fs(node, (uint8_t*)&prog_header, sizeof(elf_program_header_t), header.ph_offset+i*header.ph_entry_size) == 0) {
file.offset = header.ph_offset+i*header.ph_entry_size;
if (read_fs(&file, (uint8_t*)&prog_header, sizeof(elf_program_header_t)) == 0) {
kprintf("Could not read programm header!\n");
continue;
}
@ -390,7 +395,8 @@ static int load_task(load_args_t* largs)
per_core(current_task)->start_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<header.sh_entry_count; i++) {
if (read_fs(node, (uint8_t*)&sec_header, sizeof(elf_section_header_t), header.sh_offset+i*header.sh_entry_size) == 0) {
file.offset = header.sh_offset+i*header.sh_entry_size;
if (read_fs(&file, (uint8_t*)&sec_header, sizeof(elf_section_header_t)) == 0) {
kprintf("Could not read section header!\n");
continue;
}