got some of the pty actually working in userspace
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <lib/memory.h>
|
||||
#include <lib/string.h>
|
||||
#include <lib/print.h>
|
||||
|
||||
#define MAX_INITRD_FILES 64
|
||||
|
||||
@@ -17,9 +18,16 @@ static uint32_t parse_hex_ascii(const char *str, int len) {
|
||||
}
|
||||
|
||||
static vfs_node_t* cpio_find(vfs_node_t* _dir, const char* name) {
|
||||
if (strcmp(name, "tvga") == 0) {
|
||||
kprintf("looking for tvga\n");
|
||||
}
|
||||
if (!(_dir->flags & VFS_DIRECTORY)) return NULL;
|
||||
vfs_node_t* root = _dir;
|
||||
if (_dir->mnt) {
|
||||
root = _dir->mnt;
|
||||
}
|
||||
|
||||
vfs_node_t* child = _dir->first_child;
|
||||
vfs_node_t* child = root->first_child;
|
||||
while (child != NULL) {
|
||||
if (strcmp(child->name, name) == 0) {
|
||||
return child;
|
||||
@@ -39,7 +47,7 @@ static uint32_t cpio_read(struct vfs_node* node, uint32_t offset, uint32_t size,
|
||||
return size;
|
||||
}
|
||||
|
||||
static vfs_node_t* cpio_get_or_create(vfs_node_t* root_node, const char* path) {
|
||||
static vfs_node_t* cpio_find_or_create(vfs_node_t* root_node, const char* path) {
|
||||
vfs_node_t* current = root_node;
|
||||
|
||||
char path_cpy[256];
|
||||
@@ -49,8 +57,6 @@ static vfs_node_t* cpio_get_or_create(vfs_node_t* root_node, const char* path) {
|
||||
char* tkn = strtok_r(path_cpy, "/", &sav);
|
||||
|
||||
while (tkn != NULL) {
|
||||
char* next_tkn = strtok_r(NULL, "/", &sav);
|
||||
|
||||
vfs_node_t* next_node = cpio_find(current, tkn);
|
||||
if (!next_node) {
|
||||
next_node = kalloc(sizeof(vfs_node_t));
|
||||
@@ -65,7 +71,7 @@ static vfs_node_t* cpio_get_or_create(vfs_node_t* root_node, const char* path) {
|
||||
}
|
||||
|
||||
current = next_node;
|
||||
tkn = next_tkn;
|
||||
tkn = strtok_r(NULL, "/", &sav);
|
||||
}
|
||||
|
||||
return current;
|
||||
@@ -99,26 +105,7 @@ vfs_node_t* cpio_read_fs(uint32_t _vaddr) {
|
||||
uint8_t* file_data = (uint8_t*)header + file_data_offset;
|
||||
|
||||
if (strcmp(".", filename) != 0) {
|
||||
vfs_node_t* parent = cpio_get_or_create(cpio_root, filename);
|
||||
|
||||
char* base_name = filename;
|
||||
for (int i = strlen(filename) - 1; i >= 0; i--) {
|
||||
if (filename[i] == '/') {
|
||||
base_name = &filename[i + 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vfs_node_t* current = cpio_find(parent, base_name);
|
||||
if (!current) {
|
||||
current = kalloc(sizeof(vfs_node_t));
|
||||
memset((void*)current, 0, sizeof(vfs_node_t));
|
||||
strcpy(current->name, base_name);
|
||||
|
||||
current->next_sibling = parent->first_child;
|
||||
parent->first_child = current;
|
||||
}
|
||||
|
||||
vfs_node_t* current = cpio_find_or_create(cpio_root, filename);
|
||||
if ((mode & 0xF000) == 0x4000) {
|
||||
current->flags = VFS_DIRECTORY;
|
||||
current->find = cpio_find;
|
||||
|
||||
40
kernel/drivers/devfs/devfs.c
Normal file
40
kernel/drivers/devfs/devfs.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "vfs.h"
|
||||
#include <drivers/devfs/devfs.h>
|
||||
|
||||
#include <lib/memory.h>
|
||||
#include <lib/string.h>
|
||||
#include <lib/print.h>
|
||||
|
||||
static vfs_node_t* devfs_find(vfs_node_t* parent, const char* name) {
|
||||
vfs_node_t* cur = parent->first_child;
|
||||
if (!cur) return NULL;
|
||||
|
||||
while (cur) {
|
||||
if (strcmp(cur->name, name) == 0) break;
|
||||
cur = cur->next_sibling;
|
||||
}
|
||||
|
||||
return cur;
|
||||
}
|
||||
|
||||
static vfs_node_t* devfs_create(vfs_node_t* parent, const char* name) {
|
||||
vfs_node_t* node = kalloc(sizeof(vfs_node_t*));
|
||||
memset((void*)node, 0, sizeof(vfs_node_t));
|
||||
strcpy(node->name, name);
|
||||
node->flags = VFS_CHARDEVICE;
|
||||
if (parent->first_child) {
|
||||
node->next_sibling = parent->first_child;
|
||||
}
|
||||
parent->first_child = node;
|
||||
return node;
|
||||
}
|
||||
|
||||
vfs_node_t* create_devfs() {
|
||||
vfs_node_t* root = kalloc(sizeof(vfs_node_t*));
|
||||
memset((void*)root, 0, sizeof(vfs_node_t));
|
||||
strcpy(root->name, "dev");
|
||||
root->find = devfs_find;
|
||||
root->flags = VFS_DIRECTORY;
|
||||
root->create = devfs_create;
|
||||
return root;
|
||||
}
|
||||
8
kernel/drivers/devfs/devfs.h
Normal file
8
kernel/drivers/devfs/devfs.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef D_DEVFS_H
|
||||
#define D_DEVFS_H
|
||||
|
||||
#include <vfs.h>
|
||||
|
||||
vfs_node_t* create_devfs();
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,9 @@
|
||||
#include "lib/ringbuf.h"
|
||||
|
||||
#include <drivers/pty/pty.h>
|
||||
|
||||
#include <lib/print.h>
|
||||
|
||||
uint32_t pty_master_read(struct vfs_node* node, uint32_t offset, uint32_t size, uint8_t* buffer) {
|
||||
pty_t* pty = (pty_t*)node->data;
|
||||
uint32_t bytes_read = 0;
|
||||
|
||||
@@ -77,4 +77,15 @@ void vga_putchar(char c) {
|
||||
if (++terminal_row == VGA_HEIGHT)
|
||||
terminal_row = 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t vga_write(vfs_node_t* node, uint32_t offset, uint32_t size, uint8_t* buf) {
|
||||
terminal_row = offset / VGA_WIDTH;
|
||||
terminal_column = offset % VGA_WIDTH;
|
||||
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
vga_putchar((char)buf[i]);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
Reference in New Issue
Block a user