add to dev folder: stdin, stdout and stderr

This commit is contained in:
Marian Ohligs 2011-04-19 00:33:45 +02:00
parent 489ed562c9
commit aefc7e1165
9 changed files with 339 additions and 2 deletions

View file

@ -1,4 +1,5 @@
C_source := null.c
MODULE := drivers_char
include $(TOPDIR)/Makefile.inc

5
drivers/stderr/Makefile Normal file
View file

@ -0,0 +1,5 @@
C_source := stderr.c
MODULE := drivers_stderr
include $(TOPDIR)/Makefile.inc

106
drivers/stderr/stderr.c Normal file
View file

@ -0,0 +1,106 @@
/*
* Copyright 2010 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.
*/
#include <metalsvm/stdlib.h>
#include <metalsvm/string.h>
#include <metalsvm/stdio.h>
#include <metalsvm/errno.h>
#include <metalsvm/fs.h>
#include <metalsvm/spinlock.h>
/* Implementation of a simple stderr device */
static ssize_t stderr_read(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset)
{
return size;
}
static ssize_t stderr_write(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset)
{
kprintf("\nFehler: %s", buffer);
return size;
}
static int stderr_open(vfs_node_t* node)
{
return 0;
}
static int stderr_close(vfs_node_t* node)
{
return 0;
}
int stderr_init(vfs_node_t* node, const char* name)
{
uint32_t i, j;
vfs_node_t* new_node;
dir_block_t* blockdir;
dirent_t* dirent;
block_list_t* blist;
if (BUILTIN_EXPECT(!node || !name, 0))
return -EINVAL;
if (BUILTIN_EXPECT(node->type != FS_DIRECTORY, 0))
return -EINVAL;
if (finddir_fs(node, name))
return -EINVAL;
new_node = kmalloc(sizeof(vfs_node_t));
if (BUILTIN_EXPECT(!new_node, 0))
return -ENOMEM;
memset(new_node, 0x00, sizeof(vfs_node_t));
new_node->type = FS_CHARDEVICE;
new_node->open = &stderr_open;
new_node->close = &stderr_close;
new_node->read = &stderr_read;
new_node->write = &stderr_write;
spinlock_init(&new_node->lock);
blist= &node->block_list;
do {
for(i=0; i<MAX_DATABLOCKS; i++) {
if (blist->data[i]) {
blockdir = (dir_block_t*) blist->data[i];
for(j=0; j<MAX_DIRENTRIES; j++) {
dirent = &blockdir->entries[j];
if (!dirent->vfs_node) {
dirent->vfs_node = new_node;
strncpy(dirent->name, name, MAX_FNAME);
return 0;
}
}
}
}
if (!blist->next) {
blist->next = (block_list_t*) kmalloc(sizeof(block_list_t));
if (blist->next)
memset(blist->next, 0x00, sizeof(block_list_t));
}
} while(blist);
kfree(new_node, sizeof(vfs_node_t));
return -ENOMEM;
}

5
drivers/stdin/Makefile Normal file
View file

@ -0,0 +1,5 @@
C_source := stdin.c
MODULE := drivers_stdin
include $(TOPDIR)/Makefile.inc

106
drivers/stdin/stdin.c Normal file
View file

@ -0,0 +1,106 @@
/*
* Copyright 2010 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.
*/
#include <metalsvm/stdlib.h>
#include <metalsvm/string.h>
#include <metalsvm/stdio.h>
#include <metalsvm/errno.h>
#include <metalsvm/fs.h>
#include <metalsvm/spinlock.h>
/* Implementation of a simple stdin device */
static ssize_t stdin_read(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset)
{
kprintf("Keine Eingabe implementiert");
return size;
}
static ssize_t stdin_write(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset)
{
return size;
}
static int stdin_open(vfs_node_t* node)
{
return 0;
}
static int stdin_close(vfs_node_t* node)
{
return 0;
}
int stdin_init(vfs_node_t* node, const char* name)
{
uint32_t i, j;
vfs_node_t* new_node;
dir_block_t* blockdir;
dirent_t* dirent;
block_list_t* blist;
if (BUILTIN_EXPECT(!node || !name, 0))
return -EINVAL;
if (BUILTIN_EXPECT(node->type != FS_DIRECTORY, 0))
return -EINVAL;
if (finddir_fs(node, name))
return -EINVAL;
new_node = kmalloc(sizeof(vfs_node_t));
if (BUILTIN_EXPECT(!new_node, 0))
return -ENOMEM;
memset(new_node, 0x00, sizeof(vfs_node_t));
new_node->type = FS_CHARDEVICE;
new_node->open = &stdin_open;
new_node->close = &stdin_close;
new_node->read = &stdin_read;
new_node->write = &stdin_write;
spinlock_init(&new_node->lock);
blist= &node->block_list;
do {
for(i=0; i<MAX_DATABLOCKS; i++) {
if (blist->data[i]) {
blockdir = (dir_block_t*) blist->data[i];
for(j=0; j<MAX_DIRENTRIES; j++) {
dirent = &blockdir->entries[j];
if (!dirent->vfs_node) {
dirent->vfs_node = new_node;
strncpy(dirent->name, name, MAX_FNAME);
return 0;
}
}
}
}
if (!blist->next) {
blist->next = (block_list_t*) kmalloc(sizeof(block_list_t));
if (blist->next)
memset(blist->next, 0x00, sizeof(block_list_t));
}
} while(blist);
kfree(new_node, sizeof(vfs_node_t));
return -ENOMEM;
}

5
drivers/stdout/Makefile Normal file
View file

@ -0,0 +1,5 @@
C_source := stdout.c
MODULE := drivers_stdout
include $(TOPDIR)/Makefile.inc

106
drivers/stdout/stdout.c Normal file
View file

@ -0,0 +1,106 @@
/*
* Copyright 2010 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.
*/
#include <metalsvm/stdlib.h>
#include <metalsvm/string.h>
#include <metalsvm/stdio.h>
#include <metalsvm/errno.h>
#include <metalsvm/fs.h>
#include <metalsvm/spinlock.h>
/* Implementation of a simple stdout device */
static ssize_t stdout_read(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset)
{
return size;
}
static ssize_t stdout_write(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset)
{
kprintf("%s", buffer);
return size;
}
static int stdout_open(vfs_node_t* node)
{
return 0;
}
static int stdout_close(vfs_node_t* node)
{
return 0;
}
int stdout_init(vfs_node_t* node, const char* name)
{
uint32_t i, j;
vfs_node_t* new_node;
dir_block_t* blockdir;
dirent_t* dirent;
block_list_t* blist;
if (BUILTIN_EXPECT(!node || !name, 0))
return -EINVAL;
if (BUILTIN_EXPECT(node->type != FS_DIRECTORY, 0))
return -EINVAL;
if (finddir_fs(node, name))
return -EINVAL;
new_node = kmalloc(sizeof(vfs_node_t));
if (BUILTIN_EXPECT(!new_node, 0))
return -ENOMEM;
memset(new_node, 0x00, sizeof(vfs_node_t));
new_node->type = FS_CHARDEVICE;
new_node->open = &stdout_open;
new_node->close = &stdout_close;
new_node->read = &stdout_read;
new_node->write = &stdout_write;
spinlock_init(&new_node->lock);
blist= &node->block_list;
do {
for(i=0; i<MAX_DATABLOCKS; i++) {
if (blist->data[i]) {
blockdir = (dir_block_t*) blist->data[i];
for(j=0; j<MAX_DIRENTRIES; j++) {
dirent = &blockdir->entries[j];
if (!dirent->vfs_node) {
dirent->vfs_node = new_node;
strncpy(dirent->name, name, MAX_FNAME);
return 0;
}
}
}
}
if (!blist->next) {
blist->next = (block_list_t*) kmalloc(sizeof(block_list_t));
if (blist->next)
memset(blist->next, 0x00, sizeof(block_list_t));
}
} while(blist);
kfree(new_node, sizeof(vfs_node_t));
return -ENOMEM;
}

View file

@ -268,6 +268,9 @@ int initrd_init(void)
tmp = mkdir_fs(fs_root, "dev");
/* create the character device "null" */
null_init(tmp, "null");
stdin_init(tmp, "stdin");
stdout_init(tmp, "stdout");
stderr_init(tmp, "stderr");
/* For every module.. */
#ifdef CONFIG_MULTIBOOT

View file

@ -102,7 +102,7 @@ static int STDCALL join_test(void* arg)
int test_init(void)
{
char* argv[] = {"/bin/tests", NULL};
//char* argv[] = {"/bin/tests", NULL};
//sem_init(&producing, 1);
//sem_init(&consuming, 0);
@ -112,7 +112,7 @@ int test_init(void)
//create_kernel_task(NULL, join_test, NULL);
//create_kernel_task(NULL, producer, NULL);
//create_kernel_task(NULL, consumer, NULL);
create_user_task(NULL, "/bin/hello", argv);
create_user_task(NULL, "/bin/hello", NULL);
//create_user_task(NULL, "/bin/tests", argv);
return 0;