!!!!! -> increasing the offset has to be done inside the fs/chardriver.
- rewrite the initrd_read/write, char_driver r/w. Now all functions use fildes_t instead of vfs_node_t structs. - eleminate some compiler warnings - some changes in open, to reduce compiler warnings. This function isn't working yet!
This commit is contained in:
parent
3d74f1b514
commit
7b63bf1d27
10 changed files with 67 additions and 51 deletions
|
@ -51,7 +51,9 @@ typedef struct
|
|||
tid_t tid;
|
||||
} kb_buffer_t;
|
||||
|
||||
kb_buffer_t kb_buffer;
|
||||
extern kb_buffer_t kb_buffer;
|
||||
|
||||
void kb_flush();
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -17,8 +17,10 @@
|
|||
* This file is part of MetalSVM.
|
||||
*/
|
||||
|
||||
#include <metalsvm/stdlib.h>
|
||||
#include <metalsvm/stdio.h>
|
||||
#include <metalsvm/string.h>
|
||||
#include <metalsvm/tasks.h>
|
||||
#include <asm/kb.h>
|
||||
#include <asm/irq.h>
|
||||
|
||||
|
@ -26,12 +28,13 @@
|
|||
|
||||
kb_buffer_t kb_buffer = {NULL, 0, 0, 0 };
|
||||
|
||||
kb_flush() {
|
||||
void kb_flush() {
|
||||
kfree(kb_buffer.buffer, (kb_buffer.maxsize * sizeof(char)));
|
||||
kb_buffer.buffer = NULL;
|
||||
kb_buffer.size = 0;
|
||||
kb_buffer.maxsize = 0;
|
||||
kb_buffer.tid = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -26,14 +26,15 @@
|
|||
|
||||
/* Implementation of a simple null device */
|
||||
|
||||
static ssize_t null_read(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset)
|
||||
static ssize_t null_read(fildes_t* file, uint8_t* buffer, size_t size)
|
||||
{
|
||||
memset(buffer, 0x00, size);
|
||||
|
||||
file->offset += size;
|
||||
return size;
|
||||
}
|
||||
|
||||
static ssize_t null_write(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset)
|
||||
static ssize_t null_write(fildes_t* file, uint8_t* buffer, size_t size)
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
|
|
@ -26,18 +26,20 @@
|
|||
|
||||
/* Implementation of a simple stderr device */
|
||||
|
||||
static ssize_t stderr_read(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset)
|
||||
static ssize_t stderr_read(fildes_t* file, uint8_t* buffer, size_t size)
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
static ssize_t stderr_write(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset)
|
||||
static ssize_t stderr_write(fildes_t* file, uint8_t* buffer, size_t size)
|
||||
{
|
||||
kprintf("\nError: ");
|
||||
int i;
|
||||
for (i = 0; i<size; i++, buffer++) {
|
||||
kputchar(*buffer);
|
||||
}
|
||||
|
||||
file->offset += size;
|
||||
return size;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,10 +25,9 @@
|
|||
#include <metalsvm/spinlock.h>
|
||||
#include <asm/kb.h>
|
||||
|
||||
|
||||
/* Implementation of a simple stdin device */
|
||||
|
||||
static ssize_t stdin_read(vfs_node_t* node, const uint8_t* buffer, size_t size, off_t offset)
|
||||
static ssize_t stdin_read(fildes_t* file, uint8_t* buffer, size_t size)
|
||||
{
|
||||
kb_buffer.buffer = kmalloc(size * sizeof(char));
|
||||
kb_buffer.maxsize = size;
|
||||
|
@ -44,10 +43,11 @@ static ssize_t stdin_read(vfs_node_t* node, const uint8_t* buffer, size_t size,
|
|||
kb_flush();
|
||||
|
||||
//kprintf("Size: %i, offset: %i, buffer: %s", size, buffer, offset);
|
||||
file->offset += size;
|
||||
return size;
|
||||
}
|
||||
|
||||
static ssize_t stdin_write(vfs_node_t* node, const uint8_t* buffer, size_t size, off_t offset)
|
||||
static ssize_t stdin_write(fildes_t* file, uint8_t* buffer, size_t size)
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
|
|
@ -26,17 +26,19 @@
|
|||
|
||||
/* Implementation of a simple stdout device */
|
||||
|
||||
static ssize_t stdout_read(vfs_node_t* node, const uint8_t* buffer, size_t size, off_t offset)
|
||||
static ssize_t stdout_read(fildes_t* file, uint8_t* buffer, size_t size)
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
static ssize_t stdout_write(vfs_node_t* node, const uint8_t* buffer, size_t size, off_t offset)
|
||||
static ssize_t stdout_write(fildes_t* file, uint8_t* buffer, size_t size)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i<size; i++, buffer++) {
|
||||
kputchar(*buffer);
|
||||
}
|
||||
|
||||
file->offset += size;
|
||||
return size;
|
||||
}
|
||||
|
||||
|
|
6
fs/fs.c
6
fs/fs.c
|
@ -36,7 +36,7 @@ ssize_t read_fs(fildes_t* file, uint8_t* buffer, size_t size)
|
|||
spinlock_lock(&node->lock);
|
||||
// Has the node got a read callback?
|
||||
if (node->read != 0)
|
||||
ret = node->read(node, buffer, size, file->offset);
|
||||
ret = node->read(file, buffer, size);
|
||||
spinlock_unlock(&node->lock);
|
||||
|
||||
return ret;
|
||||
|
@ -53,7 +53,7 @@ ssize_t write_fs(fildes_t* file, uint8_t* buffer, size_t size)
|
|||
spinlock_lock(&node->lock);
|
||||
// Has the node got a write callback?
|
||||
if (node->write != 0)
|
||||
ret = node->write(node, buffer, size, file->offset);
|
||||
ret = node->write(file, buffer, size);
|
||||
spinlock_unlock(&node->lock);
|
||||
|
||||
return ret;
|
||||
|
@ -96,7 +96,7 @@ vfs_node_t* open_fs(const char* name, int flags)
|
|||
spinlock_lock(&node->lock);
|
||||
// Has the node got an open callback?
|
||||
if (node->open != 0)
|
||||
ret = node->open(node, (uint8_t*) fname);
|
||||
ret = node->open(node);
|
||||
spinlock_unlock(&node->lock);
|
||||
|
||||
return ret;
|
||||
|
|
50
fs/initrd.c
50
fs/initrd.c
|
@ -55,12 +55,17 @@ typedef struct {
|
|||
char fname[MAX_FNAME];
|
||||
} initrd_file_desc_t;
|
||||
|
||||
static ssize_t initrd_read(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset)
|
||||
static ssize_t initrd_read(fildes_t* file, uint8_t* buffer, size_t size)
|
||||
{
|
||||
uint32_t i, pos = 0, found = 0;
|
||||
off_t offset = 0;
|
||||
char* data = NULL;
|
||||
vfs_node_t* node = file->node;
|
||||
block_list_t* blist = &node->block_list;
|
||||
|
||||
/* init the tmp offset */
|
||||
offset = file->offset;
|
||||
|
||||
/* searching for the valid data block */
|
||||
if (offset) {
|
||||
pos = offset / node->block_size;
|
||||
|
@ -87,24 +92,32 @@ static ssize_t initrd_read(vfs_node_t* node, uint8_t* buffer, size_t size, off_t
|
|||
* The user has to restart the read operation
|
||||
* for the next block.
|
||||
*/
|
||||
if (offset+size >= node->block_size)
|
||||
if ((offset + size) >= node->block_size)
|
||||
size = node->block_size - offset;
|
||||
|
||||
memcpy(buffer, data + offset, size);
|
||||
|
||||
file->offset += size;
|
||||
return size;
|
||||
}
|
||||
|
||||
static ssize_t initrd_write(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset)
|
||||
static ssize_t initrd_write(fildes_t* file, uint8_t* buffer, size_t size)
|
||||
{
|
||||
uint32_t i, pos = 0, found = 0;
|
||||
off_t nodeoffset = offset;
|
||||
off_t offset = 0;
|
||||
char* data = NULL;
|
||||
vfs_node_t* node = file->node;
|
||||
block_list_t* blist = &node->block_list;
|
||||
|
||||
if (BUILTIN_EXPECT(node->type != FS_FILE, 0))
|
||||
return 0;
|
||||
|
||||
if (file->flags & O_APPEND)
|
||||
file->offset = node->block_size;
|
||||
|
||||
/* init the tmp offset */
|
||||
offset = file->offset;
|
||||
|
||||
/* searching for the valid data block */
|
||||
if (offset) {
|
||||
pos = offset / MAX_DATAENTRIES;
|
||||
|
@ -116,9 +129,11 @@ static ssize_t initrd_write(vfs_node_t* node, uint8_t* buffer, size_t size, off_
|
|||
if ((size + offset) >= MAX_DATAENTRIES)
|
||||
size = MAX_DATAENTRIES - offset;
|
||||
if(!blist->data[i]) {
|
||||
blist->data[i] = (data_block_t*) kmalloc(sizeof(data_block_t));
|
||||
blist->data[i] = (data_block_t*)
|
||||
kmalloc(sizeof(data_block_t));
|
||||
if (blist->data[i])
|
||||
memset(blist->data[i], 0x00, sizeof(data_block_t));
|
||||
memset(blist->data[i], 0x00,
|
||||
sizeof(data_block_t));
|
||||
}
|
||||
found++;
|
||||
if (found > pos) {
|
||||
|
@ -127,16 +142,18 @@ static ssize_t initrd_write(vfs_node_t* node, uint8_t* buffer, size_t size, off_
|
|||
}
|
||||
|
||||
if (!blist->next) {
|
||||
blist->next = (block_list_t*) kmalloc(sizeof(block_list_t));
|
||||
blist->next = (block_list_t*)
|
||||
kmalloc(sizeof(block_list_t));
|
||||
if (blist->next)
|
||||
memset(blist->next, 0x00, sizeof(block_list_t));
|
||||
memset(blist->next, 0x00,
|
||||
sizeof(block_list_t));
|
||||
}
|
||||
blist = blist->next;
|
||||
} while(blist && !data);
|
||||
|
||||
/* you may have to increase nodesize */
|
||||
if (node->block_size < (nodeoffset + size))
|
||||
node->block_size = nodeoffset + size;
|
||||
if (node->block_size < (file->offset + size))
|
||||
node->block_size = file->offset + size;
|
||||
/*
|
||||
* If the data block is not large engough,
|
||||
* we copy only the rest of the current block.
|
||||
|
@ -144,20 +161,22 @@ static ssize_t initrd_write(vfs_node_t* node, uint8_t* buffer, size_t size, off_
|
|||
* for the next block.
|
||||
*/
|
||||
memcpy(data + offset, buffer, size);
|
||||
file->offset += size;
|
||||
return size;
|
||||
}
|
||||
|
||||
static vfs_node_t* initrd_open(vfs_node_t* node, uint8_t* name)
|
||||
static int initrd_open(vfs_node_t* node)
|
||||
{
|
||||
|
||||
uint32_t i, j;
|
||||
char* data = NULL;
|
||||
block_list_t* blist = NULL;
|
||||
|
||||
if (BUILTIN_EXPECT(node->type != FS_DIRECTORY, 0)) {
|
||||
/*CREATE FILE */
|
||||
/* CREATE FILE */
|
||||
vfs_node_t* new_node = kmalloc(sizeof(vfs_node_t));
|
||||
if (BUILTIN_EXPECT(!new_node, 0))
|
||||
return NULL;
|
||||
return 0;
|
||||
|
||||
blist = &node->block_list;
|
||||
dir_block_t* dir_block;
|
||||
|
@ -179,7 +198,7 @@ static vfs_node_t* initrd_open(vfs_node_t* node, uint8_t* name)
|
|||
dirent = &dir_block->entries[j];
|
||||
if (!dirent->vfs_node) {
|
||||
dirent->vfs_node = new_node;
|
||||
strncpy(dirent->name, (char*) name, MAX_FNAME);
|
||||
//strncpy(dirent->name, (char*) name, MAX_FNAME);
|
||||
goto exit_for; /* there might be a better Solution *********************************/
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +236,8 @@ exit_for:
|
|||
node->block_size = 0;
|
||||
//&node->block_list = NULL;
|
||||
|
||||
return node;
|
||||
//return node;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
#endif
|
||||
|
||||
struct vfs_node;
|
||||
|
||||
struct fildes;
|
||||
/** @defgroup fsprototypes FS access function prototypes
|
||||
*
|
||||
* These typedefs define the type of callbacks - called when read/write/open/close are called.\n
|
||||
|
@ -79,11 +79,11 @@ struct vfs_node;
|
|||
*/
|
||||
|
||||
/** @brief Read function pointer */
|
||||
typedef ssize_t (*read_type_t) (struct vfs_node *, uint8_t*, size_t, off_t);
|
||||
typedef ssize_t (*read_type_t) (struct fildes *, uint8_t*, size_t);
|
||||
/** @brief Write function pointer */
|
||||
typedef ssize_t (*write_type_t) (struct vfs_node *, uint8_t*, size_t, off_t);
|
||||
typedef ssize_t (*write_type_t) (struct fildes *, uint8_t*, size_t);
|
||||
/** @brief Open function pointer */
|
||||
typedef struct vfs_node *(*open_type_t) (struct vfs_node *, uint8_t);
|
||||
typedef int (*open_type_t) (struct vfs_node *);
|
||||
/** @brief Close function pointer */
|
||||
typedef int (*close_type_t) (struct vfs_node *);
|
||||
/** @brief Read directory function pointer */
|
||||
|
|
|
@ -29,16 +29,8 @@
|
|||
|
||||
static int sys_write(int fd, const char *buf, size_t len)
|
||||
{
|
||||
unsigned int wrotebytes;
|
||||
if (per_core(current_task)->fildes_table[fd].flags & O_APPEND) {
|
||||
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]), (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;
|
||||
|
||||
return wrotebytes;
|
||||
return write_fs(&(per_core(current_task)->fildes_table[fd]),
|
||||
(uint8_t*)buf, len);
|
||||
}
|
||||
|
||||
static int sys_open(const char* file, int flags, int mode)
|
||||
|
@ -81,14 +73,8 @@ static int sys_close(int fd)
|
|||
|
||||
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]),
|
||||
(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! */
|
||||
return readbytes;
|
||||
return read_fs(&(per_core(current_task)->fildes_table[fd]),
|
||||
(uint8_t*)buf, len);
|
||||
}
|
||||
|
||||
static int sys_lseek(int fd, off_t pos, int origin)
|
||||
|
|
Loading…
Add table
Reference in a new issue