mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 15:29:18 +00:00
Fix driver implementation
This commit is contained in:
@ -28,29 +28,34 @@ void cmd_cat(const char *args)
|
||||
if (args[0] == '\0')
|
||||
return;
|
||||
|
||||
/* FIXME: Reimplement this later */
|
||||
assert(!"Function not implemented");
|
||||
// Node *thisNode = fs->GetByPath(args, thisProcess->CWD, true);
|
||||
// if (thisNode == nullptr)
|
||||
// {
|
||||
// printf("cat: %s: No such file or directory\n", args);
|
||||
// return;
|
||||
// }
|
||||
FileNode *node = fs->GetByPath(args, nullptr);
|
||||
|
||||
// if (!thisNode->Stat.IsType(FILE) && !thisNode->Stat.IsType(CHARDEVICE))
|
||||
// {
|
||||
// printf("cat: %s: Not a file\n", args);
|
||||
// return;
|
||||
// }
|
||||
if (node == nullptr)
|
||||
{
|
||||
printf("cat: %s: No such file or directory\n", args);
|
||||
return;
|
||||
}
|
||||
|
||||
// vfs::FileHandle *fd = fs->Open(thisNode->FilePath, nullptr, true);
|
||||
if (!node->IsRegularFile() && !node->IsCharacterDevice())
|
||||
{
|
||||
printf("cat: %s: Not a regular file or character device\n", args);
|
||||
return;
|
||||
}
|
||||
|
||||
// uint8_t *buffer = new uint8_t[fd->node->Stat.Size + 1];
|
||||
// ssize_t rBytes = fd->read(buffer, fd->node->Stat.Size);
|
||||
// if (rBytes > 0)
|
||||
// printf("%s\n", buffer);
|
||||
// else
|
||||
// printf("cat: %s: Could not read file\n", args);
|
||||
// delete[] buffer;
|
||||
// delete fd;
|
||||
if (node->IsCharacterDevice())
|
||||
{
|
||||
printf("cat: %s: Character devices are not supported yet\n", args);
|
||||
return;
|
||||
}
|
||||
|
||||
kstat stat = {};
|
||||
node->Stat(&stat);
|
||||
|
||||
uint8_t *buffer = new uint8_t[stat.Size + 1];
|
||||
ssize_t rBytes = node->Read(buffer, stat.Size, 0);
|
||||
if (rBytes > 0)
|
||||
printf("%s\n", buffer);
|
||||
else
|
||||
printf("cat: %s: Could not read file\n", args);
|
||||
delete[] buffer;
|
||||
}
|
||||
|
@ -28,24 +28,19 @@ void cmd_cd(const char *args)
|
||||
if (args[0] == '\0')
|
||||
return;
|
||||
|
||||
/* FIXME: Reimplement this later */
|
||||
assert(!"Function not implemented");
|
||||
// Node *thisNode = fs->GetByPath(args, thisProcess->CWD, true);
|
||||
FileNode *node = fs->GetByPath(args, nullptr);
|
||||
|
||||
// if (thisNode == nullptr)
|
||||
// {
|
||||
// printf("cd: %s: No such file or directory\n", args);
|
||||
// return;
|
||||
// }
|
||||
if (node == nullptr)
|
||||
{
|
||||
printf("cd: %s: No such file or directory\n", args);
|
||||
return;
|
||||
}
|
||||
|
||||
// if (thisNode->Stat.IsType(SYMLINK))
|
||||
// thisNode = fs->GetByPath(thisNode->GetSymLink(), nullptr, true);
|
||||
if (!node->IsDirectory())
|
||||
{
|
||||
printf("cd: %s: Not a directory\n", args);
|
||||
return;
|
||||
}
|
||||
|
||||
// if (!thisNode->Stat.IsType(DIRECTORY))
|
||||
// {
|
||||
// printf("cd: %s: Not a directory\n", args);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// thisProcess->CWD = thisNode;
|
||||
thisProcess->CWD = node;
|
||||
}
|
||||
|
@ -23,84 +23,113 @@
|
||||
|
||||
using namespace vfs;
|
||||
|
||||
// const char *ColorNodeType(Node *node)
|
||||
// {
|
||||
// switch (node->Stat.GetFileType())
|
||||
// {
|
||||
// case DIRECTORY:
|
||||
// return "\e3871F5";
|
||||
// case BLOCKDEVICE:
|
||||
// return "\eE8CD1E";
|
||||
// case CHARDEVICE:
|
||||
// return "\e86E01F";
|
||||
// case PIPE:
|
||||
// return "\eE0991F";
|
||||
// case SYMLINK:
|
||||
// return "\e1FB9E0";
|
||||
// case FILE:
|
||||
// return "\eCCCCCC";
|
||||
// default:
|
||||
// return "\eF72020";
|
||||
// }
|
||||
// }
|
||||
const char *ColorNodeType(FileNode *node)
|
||||
{
|
||||
if (node->IsRegularFile())
|
||||
return "\eCCCCCC";
|
||||
else if (node->IsDirectory())
|
||||
return "\e3871F5";
|
||||
else if (node->IsBlockDevice())
|
||||
return "\eE8CD1E";
|
||||
else if (node->IsCharacterDevice())
|
||||
return "\e86E01F";
|
||||
else if (node->IsFIFO())
|
||||
return "\eE0991F";
|
||||
else if (node->IsSymbolicLink())
|
||||
return "\e1FB9E0";
|
||||
else
|
||||
return "\eF72020";
|
||||
}
|
||||
|
||||
// size_t MaxNameLength(Node *nodes)
|
||||
// {
|
||||
// size_t maxLength = 0;
|
||||
// foreach (auto &node in nodes->GetChildren(true))
|
||||
// maxLength = std::max(maxLength, strlen(node->FileName));
|
||||
// return maxLength;
|
||||
// }
|
||||
__no_sanitize("alignment") size_t MaxNameLength(FileNode *nodes)
|
||||
{
|
||||
size_t maxLength = 0;
|
||||
|
||||
// void PrintLS(Node *node)
|
||||
// {
|
||||
// size_t maxNameLength = MaxNameLength(node);
|
||||
// int count = 0;
|
||||
// bool first = true;
|
||||
// foreach (auto &var in node->GetChildren(true))
|
||||
// {
|
||||
// if (count % 5 == 0 && !first)
|
||||
// printf("\n");
|
||||
// printf(" %s%-*s ", ColorNodeType(var), (int)maxNameLength, var->FileName);
|
||||
// count++;
|
||||
// first = false;
|
||||
// }
|
||||
// printf("\eCCCCCC\n");
|
||||
// }
|
||||
kdirent *dirBuffer = new kdirent[16];
|
||||
ssize_t read = 0;
|
||||
off_t offset = 0;
|
||||
while ((read = nodes->ReadDir(dirBuffer, sizeof(kdirent) * 16, offset, LONG_MAX)) > 0)
|
||||
{
|
||||
if (read / sizeof(kdirent) == 0)
|
||||
break;
|
||||
|
||||
off_t bufOffset = 0;
|
||||
debug("There are %ld entries in this directory", read / sizeof(kdirent));
|
||||
for (size_t i = 0; i < read / sizeof(kdirent); i++)
|
||||
{
|
||||
kdirent *dirent = (kdirent *)((uintptr_t)dirBuffer + bufOffset);
|
||||
if (dirent->d_reclen == 0)
|
||||
break;
|
||||
bufOffset += dirent->d_reclen;
|
||||
maxLength = std::max(maxLength, strlen(dirent->d_name));
|
||||
debug("dirent->d_name: %s (max length: %ld)", dirent->d_name, maxLength);
|
||||
}
|
||||
offset += read / sizeof(kdirent);
|
||||
}
|
||||
delete[] dirBuffer;
|
||||
return maxLength;
|
||||
}
|
||||
|
||||
__no_sanitize("alignment") void PrintLS(FileNode *node)
|
||||
{
|
||||
size_t maxNameLength = MaxNameLength(node);
|
||||
int count = 0;
|
||||
bool first = true;
|
||||
|
||||
kdirent *dirBuffer = new kdirent[16];
|
||||
ssize_t read = 0;
|
||||
off_t offset = 0;
|
||||
while ((read = node->ReadDir(dirBuffer, sizeof(kdirent) * 16, offset, LONG_MAX)) > 0)
|
||||
{
|
||||
if (read / sizeof(kdirent) == 0)
|
||||
break;
|
||||
|
||||
off_t bufOffset = 0;
|
||||
for (size_t i = 0; i < read / sizeof(kdirent); i++)
|
||||
{
|
||||
if (count % 5 == 0 && !first)
|
||||
printf("\n");
|
||||
kdirent *dirent = (kdirent *)((uintptr_t)dirBuffer + bufOffset);
|
||||
if (dirent->d_reclen == 0)
|
||||
break;
|
||||
bufOffset += dirent->d_reclen;
|
||||
printf(" %s%-*s ", ColorNodeType(node), (int)maxNameLength, dirent->d_name);
|
||||
count++;
|
||||
first = false;
|
||||
}
|
||||
offset += read / sizeof(kdirent);
|
||||
}
|
||||
|
||||
printf("\eCCCCCC\n");
|
||||
delete[] dirBuffer;
|
||||
}
|
||||
|
||||
void cmd_ls(const char *args)
|
||||
{
|
||||
/* FIXME: Reimplement this later */
|
||||
assert(!"Function not implemented");
|
||||
if (args[0] == '\0')
|
||||
{
|
||||
FileNode *rootNode = thisProcess->CWD;
|
||||
|
||||
// if (args[0] == '\0')
|
||||
// {
|
||||
// Node *rootNode = thisProcess->CWD;
|
||||
if (rootNode == nullptr)
|
||||
rootNode = fs->GetRoot(0);
|
||||
|
||||
// if (rootNode == nullptr)
|
||||
// rootNode = fs->FileSystemRoots->GetChildren(true)[0];
|
||||
PrintLS(rootNode);
|
||||
return;
|
||||
}
|
||||
|
||||
// PrintLS(rootNode);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Node *thisNode = fs->GetByPath(args, thisProcess->CWD, true);
|
||||
FileNode *thisNode = fs->GetByPath(args, nullptr);
|
||||
|
||||
// if (thisNode == nullptr)
|
||||
// {
|
||||
// printf("ls: %s: No such file or directory\n", args);
|
||||
// return;
|
||||
// }
|
||||
if (thisNode == nullptr)
|
||||
{
|
||||
printf("ls: %s: No such file or directory\n", args);
|
||||
return;
|
||||
}
|
||||
|
||||
// if (thisNode->Stat.IsType(SYMLINK))
|
||||
// thisNode = fs->GetByPath(thisNode->GetSymLink(), nullptr, true);
|
||||
if (!thisNode->IsDirectory())
|
||||
{
|
||||
printf("%s%s\n", ColorNodeType(thisNode), thisNode->Path.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// if (!thisNode->Stat.IsType(DIRECTORY))
|
||||
// {
|
||||
// printf("%s%s\n", ColorNodeType(thisNode), thisNode->FileName);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// PrintLS(thisNode);
|
||||
// }
|
||||
PrintLS(thisNode);
|
||||
}
|
||||
|
@ -53,11 +53,16 @@ void cmd_modinfo(const char *args)
|
||||
}
|
||||
|
||||
Driver::DriverObject drv = drivers[id];
|
||||
|
||||
char drvVersion[32];
|
||||
snprintf(drvVersion, sizeof(drvVersion), "%d.%d.%d",
|
||||
drv.Version.Major, drv.Version.Minor, drv.Version.Patch);
|
||||
|
||||
printf("Base Info:\n");
|
||||
printf(" Name: %s\n", drv.Name);
|
||||
printf(" Description: %s\n", drv.Description);
|
||||
printf(" Author: %s\n", drv.Author);
|
||||
printf(" Version: %s\n", drv.Version);
|
||||
printf(" Version: %s\n", drvVersion);
|
||||
printf(" License: %s\n", drv.License);
|
||||
printf("Resource Info:\n");
|
||||
printf(" Initialized: %s\n", drv.Initialized ? "yes" : "no");
|
||||
|
@ -21,57 +21,81 @@
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
void tree_loop(FileNode *rootNode, int depth = 0)
|
||||
{
|
||||
// foreach (auto Child in rootNode->GetChildren(true))
|
||||
// {
|
||||
// Display->UpdateBuffer();
|
||||
// if (Child->Stat.IsType(DIRECTORY) || Child->Stat.IsType(MOUNTPOINT))
|
||||
// {
|
||||
// printf("%*s%*s%*s|- %s\n",
|
||||
// depth, "",
|
||||
// depth, "",
|
||||
// depth, "",
|
||||
// Child->FileName);
|
||||
// tree_loop(Child, depth + 1);
|
||||
// }
|
||||
// else
|
||||
// printf("%*s%*s%*s|- %s\n",
|
||||
// depth, "",
|
||||
// depth, "",
|
||||
// depth, "",
|
||||
// Child->FileName);
|
||||
// }
|
||||
|
||||
// void tree_loop(Node *rootNode, int depth = 0)
|
||||
// {
|
||||
// foreach (auto Child in rootNode->GetChildren(true))
|
||||
// {
|
||||
// Display->UpdateBuffer();
|
||||
// if (Child->Stat.IsType(DIRECTORY) || Child->Stat.IsType(MOUNTPOINT))
|
||||
// {
|
||||
// printf("%*s%*s%*s|- %s\n",
|
||||
// depth, "",
|
||||
// depth, "",
|
||||
// depth, "",
|
||||
// Child->FileName);
|
||||
// tree_loop(Child, depth + 1);
|
||||
// }
|
||||
// else
|
||||
// printf("%*s%*s%*s|- %s\n",
|
||||
// depth, "",
|
||||
// depth, "",
|
||||
// depth, "",
|
||||
// Child->FileName);
|
||||
// }
|
||||
// }
|
||||
kdirent *dirBuffer = new kdirent[16];
|
||||
ssize_t read = 0;
|
||||
off_t offset = 0;
|
||||
while ((read = rootNode->ReadDir(dirBuffer, sizeof(kdirent) * 16, offset, LONG_MAX)) > 0)
|
||||
{
|
||||
if (read / sizeof(kdirent) == 0)
|
||||
break;
|
||||
|
||||
off_t bufOffset = 0;
|
||||
for (size_t i = 0; i < read / sizeof(kdirent); i++)
|
||||
{
|
||||
kdirent *dirent = (kdirent *)((uintptr_t)dirBuffer + bufOffset);
|
||||
if (dirent->d_reclen == 0)
|
||||
break;
|
||||
bufOffset += dirent->d_reclen;
|
||||
|
||||
if (strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0)
|
||||
continue;
|
||||
|
||||
FileNode *node = fs->GetByPath(dirent->d_name, rootNode);
|
||||
if (node == nullptr)
|
||||
continue;
|
||||
|
||||
for (int i = 0; i < depth; i++)
|
||||
printf(" ");
|
||||
printf("|- %s\n", dirent->d_name);
|
||||
|
||||
if (node->IsDirectory())
|
||||
tree_loop(node, depth + 1);
|
||||
}
|
||||
offset += read;
|
||||
}
|
||||
delete[] dirBuffer;
|
||||
}
|
||||
|
||||
void cmd_tree(const char *args)
|
||||
{
|
||||
/* FIXME: Reimplement this later */
|
||||
assert(!"Function not implemented");
|
||||
FileNode *rootNode = thisProcess->CWD;
|
||||
if (args[0] == '\0')
|
||||
{
|
||||
if (rootNode == nullptr)
|
||||
rootNode = fs->GetRoot(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
rootNode = fs->GetByPath(args, nullptr);
|
||||
if (rootNode == nullptr)
|
||||
{
|
||||
printf("ls: %s: No such file or directory\n", args);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Node *rootNode = thisProcess->CWD;
|
||||
// if (args[0] == '\0')
|
||||
// {
|
||||
// if (rootNode == nullptr)
|
||||
// rootNode = fs->FileSystemRoots->GetChildren(true)[0];
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// rootNode = fs->GetByPath(args, thisProcess->CWD, true);
|
||||
// if (rootNode == nullptr)
|
||||
// {
|
||||
// printf("ls: %s: No such file or directory\n", args);
|
||||
// return;
|
||||
// }
|
||||
// if (!rootNode->Stat.IsType(DIRECTORY))
|
||||
// {
|
||||
// printf("%s\n", rootNode->FileName);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
// printf("%s\n", rootNode->FileName);
|
||||
// tree_loop(rootNode);
|
||||
printf("%s\n", rootNode->Name.c_str());
|
||||
tree_loop(rootNode);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <kshell.hpp>
|
||||
|
||||
#include <interface/driver.h>
|
||||
#include <interface/input.h>
|
||||
#include <filesystem.hpp>
|
||||
#include <driver.hpp>
|
||||
#include <lock.hpp>
|
||||
@ -160,14 +161,14 @@ void StartKernelShell()
|
||||
KPrint("Starting kernel shell...");
|
||||
thisThread->SetPriority(Tasking::TaskPriority::High);
|
||||
|
||||
std::string strBuf;
|
||||
std::string strBuf = "";
|
||||
std::vector<std::string *> history;
|
||||
size_t hIdx = 0;
|
||||
bool ctrlDown = false;
|
||||
bool upperCase = false;
|
||||
bool tabDblPress = false;
|
||||
|
||||
FileNode *kfd = fs->GetByPath("/dev/key", nullptr);
|
||||
FileNode *kfd = fs->GetByPath("/dev/input/keyboard", fs->GetRoot(0));
|
||||
if (kfd == nullptr)
|
||||
{
|
||||
KPrint("Failed to open keyboard device!");
|
||||
@ -194,18 +195,17 @@ void StartKernelShell()
|
||||
|
||||
FileNode *cwd = thisProcess->CWD;
|
||||
if (!cwd)
|
||||
cwd = fs->GetByPath("/", nullptr);
|
||||
cwd = fs->GetRoot(0);
|
||||
std::string cwdStr = fs->GetByNode(cwd);
|
||||
|
||||
printf("\e34C6EB%s@%s:%s$ \eCCCCCC",
|
||||
"kernel",
|
||||
"fennix",
|
||||
cwd->Path.c_str());
|
||||
"kernel", "fennix",
|
||||
cwdStr.c_str());
|
||||
Display->UpdateBuffer();
|
||||
|
||||
Display->GetBufferCursor(&homeX, &homeY);
|
||||
|
||||
uint8_t scBuf[2];
|
||||
scBuf[1] = 0x00; /* Request scan code */
|
||||
KeyboardReport scBuf{};
|
||||
ssize_t nBytes;
|
||||
while (true)
|
||||
{
|
||||
@ -215,24 +215,21 @@ void StartKernelShell()
|
||||
CurY.store(__cy);
|
||||
CurHalt.store(false);
|
||||
|
||||
nBytes = kfd->Read(scBuf, 2, 0);
|
||||
nBytes = kfd->Read(&scBuf, sizeof(KeyboardReport), 0);
|
||||
if (nBytes == 0)
|
||||
continue;
|
||||
if (nBytes < 0)
|
||||
if (nBytes < (ssize_t)sizeof(KeyboardReport))
|
||||
{
|
||||
KPrint("Failed to read from keyboard device: %s",
|
||||
strerror((int)nBytes));
|
||||
return;
|
||||
}
|
||||
|
||||
if (scBuf[0] == 0x00)
|
||||
continue;
|
||||
|
||||
BlinkerSleep.store(TimeManager->CalculateTarget(250, Time::Units::Milliseconds));
|
||||
CurHalt.store(true);
|
||||
UpdateBlinker();
|
||||
|
||||
uint8_t sc = scBuf[0];
|
||||
const KeyScanCodes &sc = scBuf.Key;
|
||||
switch (sc & ~KEY_PRESSED)
|
||||
{
|
||||
case KEY_LEFT_CTRL:
|
||||
@ -291,15 +288,15 @@ void StartKernelShell()
|
||||
|
||||
for (size_t i = 0; i < sizeof(commands) / sizeof(commands[0]); i++)
|
||||
{
|
||||
if (strncmp(strBuf.c_str(), commands[i].Name, strBuf.size()) == 0)
|
||||
{
|
||||
strBuf = commands[i].Name;
|
||||
for (size_t i = 0; i < strlen(strBuf.c_str()); i++)
|
||||
Display->Print(strBuf[i]);
|
||||
seekCount = bsCount = strBuf.size();
|
||||
Display->UpdateBuffer();
|
||||
break;
|
||||
}
|
||||
if (strncmp(strBuf.c_str(), commands[i].Name, strBuf.size()) != 0)
|
||||
continue;
|
||||
|
||||
strBuf = commands[i].Name;
|
||||
for (size_t i = 0; i < strlen(strBuf.c_str()); i++)
|
||||
Display->Print(strBuf[i]);
|
||||
seekCount = bsCount = strBuf.size();
|
||||
Display->UpdateBuffer();
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -714,7 +711,7 @@ void StartKernelShell()
|
||||
|
||||
Found = true;
|
||||
|
||||
std::string arg_only;
|
||||
std::string arg_only = "";
|
||||
const char *cmd_name = commands[i].Name;
|
||||
for (size_t i = strlen(cmd_name) + 1; i < strBuf.length(); i++)
|
||||
arg_only += strBuf[i];
|
||||
|
Reference in New Issue
Block a user