Make ttyX not implement a vnode struct for itself
This commit is contained in:
@@ -15,6 +15,8 @@ enum dev_class {
|
||||
#define DEV_BLOCK_PART 127
|
||||
#define DEV_BLOCK_PSEUDO 128
|
||||
|
||||
#define DEV_CHAR_TTY 1
|
||||
|
||||
struct dev_entry {
|
||||
char dev_name[64];
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
#include "sys/fs/node.h"
|
||||
|
||||
extern vnode_t *tty0;
|
||||
|
||||
void tty_buffer_write(int n, char c);
|
||||
void tty_init(void);
|
||||
|
||||
@@ -118,14 +118,16 @@ void init_func(void *arg) {
|
||||
// Free memory
|
||||
kfree(exec_buf);
|
||||
|
||||
// FIXME: this way of opening requires devfs to be mounted at /dev, I guess
|
||||
// I can just have dev_entry have a vnode for each of them (and remove
|
||||
// ones used in devfs mapper)
|
||||
// Set tty0 input
|
||||
init_thread->fds[0].flags = O_RDONLY;
|
||||
init_thread->fds[0].vnode = tty0;
|
||||
init_thread->fds[0].pos = 0;
|
||||
|
||||
init_thread->fds[1].flags = O_WRONLY;
|
||||
init_thread->fds[1].vnode = tty0;
|
||||
init_thread->fds[1].pos = 0;
|
||||
if ((res = vfs_open(&init_thread->ioctx, &init_thread->fds[0], "/dev/tty0", O_RDONLY, 0)) < 0) {
|
||||
panic("Failed to set up tty0 for input: %s\n", kstrerror(res));
|
||||
}
|
||||
if ((res = vfs_open(&init_thread->ioctx, &init_thread->fds[1], "/dev/tty0", O_WRONLY, 0)) < 0) {
|
||||
panic("Failed to set up tty0 for output: %s\n", kstrerror(res));
|
||||
}
|
||||
|
||||
kdebug("Done\n");
|
||||
sched_add_to(0, init_thread);
|
||||
|
||||
@@ -291,13 +291,12 @@ int sys_fork(void) {
|
||||
memset(&thr_dst->ioctx, 0, sizeof(thr_dst->ioctx));
|
||||
memset(thr_dst->fds, 0, sizeof(thr_dst->fds));
|
||||
|
||||
thr_dst->fds[0].flags = O_RDONLY;
|
||||
thr_dst->fds[0].vnode = tty0;
|
||||
thr_dst->fds[0].pos = 0;
|
||||
|
||||
thr_dst->fds[1].flags = O_WRONLY;
|
||||
thr_dst->fds[1].vnode = tty0;
|
||||
thr_dst->fds[1].pos = 0;
|
||||
if ((res = vfs_open(&thr_dst->ioctx, &thr_dst->fds[0], "/dev/tty0", O_RDONLY, 0)) < 0) {
|
||||
panic("Failed to set up tty0 for input: %s\n", kstrerror(res));
|
||||
}
|
||||
if ((res = vfs_open(&thr_dst->ioctx, &thr_dst->fds[1], "/dev/tty0", O_WRONLY, 0)) < 0) {
|
||||
panic("Failed to set up tty0 for output: %s\n", kstrerror(res));
|
||||
}
|
||||
|
||||
sched_add(thr_dst);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "sys/mm.h"
|
||||
#include "sys/amd64/cpu.h"
|
||||
#include "sys/amd64/hw/con.h"
|
||||
#include "sys/dev.h"
|
||||
|
||||
#define DEV_TTY(n) (n ## ULL)
|
||||
#define DEV_DATA_TTY(n) ((void *) n ## ULL)
|
||||
@@ -21,12 +22,12 @@ static struct chrdev _dev_tty0 = {
|
||||
.write = tty_write,
|
||||
.read = tty_read
|
||||
};
|
||||
|
||||
static vnode_t _tty0 = {
|
||||
.type = VN_CHR,
|
||||
.dev = &_dev_tty0
|
||||
static struct dev_entry _ent_tty0 = {
|
||||
.dev = &_dev_tty0,
|
||||
.dev_class = DEV_CLASS_CHAR,
|
||||
.dev_subclass = DEV_CHAR_TTY,
|
||||
.dev_name = "tty0"
|
||||
};
|
||||
vnode_t *tty0 = &_tty0;
|
||||
|
||||
static struct ring tty_ring = {0};
|
||||
|
||||
@@ -37,6 +38,7 @@ void tty_buffer_write(int tty_no, char c) {
|
||||
|
||||
void tty_init(void) {
|
||||
ring_init(&tty_ring, 16);
|
||||
dev_entry_add(&_ent_tty0);
|
||||
}
|
||||
|
||||
// TODO: multiple ttys
|
||||
|
||||
Reference in New Issue
Block a user