Devices: add a new ConsoleDevice
This new device is the userspace interface to the text console/tty.
This commit is contained in:
parent
b1fcfd0d74
commit
e764647133
9
kernel/include/fs/devices/Console.h
Normal file
9
kernel/include/fs/devices/Console.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "fs/VFS.h"
|
||||||
|
|
||||||
|
namespace ConsoleDevice
|
||||||
|
{
|
||||||
|
VFS::Node* create_new();
|
||||||
|
|
||||||
|
ssize_t write(VFS::Node* node, size_t offset, size_t size, const char* buffer);
|
||||||
|
}
|
25
kernel/src/fs/devices/Console.cpp
Normal file
25
kernel/src/fs/devices/Console.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include "fs/devices/Console.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "render/TextRenderer.h"
|
||||||
|
#include "std/stdio.h"
|
||||||
|
#include "std/stdlib.h"
|
||||||
|
#include "std/string.h"
|
||||||
|
|
||||||
|
VFS::Node* ConsoleDevice::create_new()
|
||||||
|
{
|
||||||
|
VFS::Node* dev = new VFS::Node;
|
||||||
|
dev->write_func = ConsoleDevice::write;
|
||||||
|
dev->inode = 0;
|
||||||
|
dev->length = 0;
|
||||||
|
dev->type = VFS_FILE;
|
||||||
|
dev->flags = 0;
|
||||||
|
strncpy(dev->name, "console", sizeof(dev->name));
|
||||||
|
return dev;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t ConsoleDevice::write(VFS::Node* node, size_t, size_t size, const char* buffer)
|
||||||
|
{
|
||||||
|
if (!node) return -1;
|
||||||
|
TextRenderer::write(buffer, size);
|
||||||
|
return (ssize_t)size;
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
#include "fs/devices/DeviceFS.h"
|
#include "fs/devices/DeviceFS.h"
|
||||||
|
#include "fs/devices/Console.h"
|
||||||
#include "fs/devices/Version.h"
|
#include "fs/devices/Version.h"
|
||||||
#include "std/stdlib.h"
|
#include "std/stdlib.h"
|
||||||
#include "std/string.h"
|
#include "std/string.h"
|
||||||
@ -21,6 +22,7 @@ VFS::Node* DeviceFS::get()
|
|||||||
strncpy(devfs_root->name, "dev", sizeof(devfs_root->name));
|
strncpy(devfs_root->name, "dev", sizeof(devfs_root->name));
|
||||||
|
|
||||||
devfs_files[devfs_file_count++] = VersionDevice::create_new();
|
devfs_files[devfs_file_count++] = VersionDevice::create_new();
|
||||||
|
devfs_files[devfs_file_count++] = ConsoleDevice::create_new();
|
||||||
return devfs_root;
|
return devfs_root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user