mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-11 07:19:20 +00:00
Restructured and rewritten entire codebase
This commit is contained in:
54
kshell/commands/cat.cpp
Normal file
54
kshell/commands/cat.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include <filesystem.hpp>
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
|
||||
void cmd_cat(const char *args)
|
||||
{
|
||||
if (args[0] == '\0')
|
||||
return;
|
||||
|
||||
Node *thisNode = fs->GetNodeFromPath(args, thisProcess->CurrentWorkingDirectory);
|
||||
if (thisNode == nullptr)
|
||||
{
|
||||
printf("cat: %s: No such file or directory\n", args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (thisNode->Type != NodeType::FILE &&
|
||||
thisNode->Type != NodeType::CHARDEVICE)
|
||||
{
|
||||
printf("cat: %s: Not a file\n", args);
|
||||
return;
|
||||
}
|
||||
|
||||
int fd = fopen(thisNode->FullPath, "r");
|
||||
struct stat st;
|
||||
fstat(fd, &st);
|
||||
|
||||
char *buffer = new char[st.st_size + 1];
|
||||
fread(fd, buffer, st.st_size);
|
||||
printf("%s\n", buffer);
|
||||
delete[] buffer;
|
||||
fclose(fd);
|
||||
}
|
46
kshell/commands/cd.cpp
Normal file
46
kshell/commands/cd.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include <filesystem.hpp>
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
|
||||
void cmd_cd(const char *args)
|
||||
{
|
||||
if (args[0] == '\0')
|
||||
return;
|
||||
|
||||
Node *thisNode = fs->GetNodeFromPath(args, thisProcess->CurrentWorkingDirectory);
|
||||
|
||||
if (thisNode == nullptr)
|
||||
{
|
||||
printf("cd: %s: No such file or directory\n", args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (thisNode->Type != NodeType::DIRECTORY)
|
||||
{
|
||||
printf("cd: %s: Not a directory\n", args);
|
||||
return;
|
||||
}
|
||||
|
||||
thisProcess->CurrentWorkingDirectory = thisNode;
|
||||
}
|
25
kshell/commands/echo.cpp
Normal file
25
kshell/commands/echo.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
void cmd_echo(const char *args)
|
||||
{
|
||||
printf("%s\n", args);
|
||||
}
|
33
kshell/commands/exit.cpp
Normal file
33
kshell/commands/exit.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include <filesystem.hpp>
|
||||
#include <task.hpp>
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
using namespace Tasking;
|
||||
|
||||
void cmd_exit(const char *)
|
||||
{
|
||||
KernelShutdownThread(false);
|
||||
// TaskManager->KillThread(thisThread, KILL_SUCCESS);
|
||||
CPU::Halt(true);
|
||||
}
|
39
kshell/commands/kill.cpp
Normal file
39
kshell/commands/kill.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include <filesystem.hpp>
|
||||
#include <task.hpp>
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
using namespace Tasking;
|
||||
|
||||
void cmd_kill(const char *args)
|
||||
{
|
||||
PID pid = atoi(args);
|
||||
PCB *pcb = TaskManager->GetProcessByID(pid);
|
||||
|
||||
if (pcb == nullptr)
|
||||
{
|
||||
printf("No process with PID %d\n", pid);
|
||||
return;
|
||||
}
|
||||
TaskManager->KillProcess(pcb, KILL_BY_OTHER_PROCESS);
|
||||
}
|
37
kshell/commands/killall.cpp
Normal file
37
kshell/commands/killall.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include <filesystem.hpp>
|
||||
#include <task.hpp>
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
using namespace Tasking;
|
||||
|
||||
void cmd_killall(const char *args)
|
||||
{
|
||||
foreach (auto Proc in TaskManager->GetProcessList())
|
||||
{
|
||||
if (strcmp(Proc->Name, args) == 0)
|
||||
{
|
||||
TaskManager->KillProcess(Proc, KILL_BY_OTHER_PROCESS);
|
||||
}
|
||||
}
|
||||
}
|
57
kshell/commands/ls.cpp
Normal file
57
kshell/commands/ls.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include <filesystem.hpp>
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
|
||||
void cmd_ls(const char *args)
|
||||
{
|
||||
if (args[0] == '\0')
|
||||
{
|
||||
Node *rootNode = thisProcess->CurrentWorkingDirectory;
|
||||
|
||||
if (rootNode == nullptr)
|
||||
rootNode = fs->GetRootNode()->Children[0];
|
||||
|
||||
foreach (auto var in rootNode->Children)
|
||||
printf("%s\n", var->Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Node *thisNode = fs->GetNodeFromPath(args, thisProcess->CurrentWorkingDirectory);
|
||||
|
||||
if (thisNode == nullptr)
|
||||
{
|
||||
printf("ls: %s: No such file or directory\n", args);
|
||||
return;
|
||||
}
|
||||
|
||||
if (thisNode->Type != NodeType::DIRECTORY)
|
||||
{
|
||||
printf("%s\n", thisNode->Name);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (auto var in thisNode->Children)
|
||||
printf("%s\n", var->Name);
|
||||
}
|
||||
}
|
36
kshell/commands/lsof.cpp
Normal file
36
kshell/commands/lsof.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
void cmd_lsof(const char *)
|
||||
{
|
||||
printf("PROCESS FD NAME\n");
|
||||
foreach (auto Proc in TaskManager->GetProcessList())
|
||||
{
|
||||
if (!Proc)
|
||||
continue;
|
||||
|
||||
std::vector<vfs::FileDescriptorTable::Fildes> fds_array =
|
||||
Proc->FileDescriptors->GetFileDescriptors();
|
||||
foreach (auto fd in fds_array)
|
||||
printf("%s %d: %s\n", Proc->Name, fd.Descriptor,
|
||||
fd.Handle->node->FullPath);
|
||||
}
|
||||
}
|
40
kshell/commands/lspci.cpp
Normal file
40
kshell/commands/lspci.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include <filesystem.hpp>
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
|
||||
void cmd_lspci(const char *)
|
||||
{
|
||||
foreach (auto Device in PCIManager->GetDevices())
|
||||
{
|
||||
printf("%02x:%02x.%d: %s: %s %s\n",
|
||||
Device.Bus,
|
||||
Device.Device,
|
||||
Device.Function,
|
||||
PCI::Descriptors::GetSubclassName(Device.Header->Class,
|
||||
Device.Header->Subclass),
|
||||
PCI::Descriptors::GetVendorName(Device.Header->VendorID),
|
||||
PCI::Descriptors::GetDeviceName(Device.Header->VendorID,
|
||||
Device.Header->DeviceID));
|
||||
}
|
||||
}
|
64
kshell/commands/mem.cpp
Normal file
64
kshell/commands/mem.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include <filesystem.hpp>
|
||||
#include <task.hpp>
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
using namespace Tasking;
|
||||
|
||||
void cmd_mem(const char *)
|
||||
{
|
||||
uint64_t total = KernelAllocator.GetTotalMemory();
|
||||
uint64_t used = KernelAllocator.GetUsedMemory();
|
||||
uint64_t free = KernelAllocator.GetFreeMemory();
|
||||
uint64_t reserved = KernelAllocator.GetReservedMemory();
|
||||
|
||||
int usedPercent = (int)((used * 100) / total);
|
||||
int usedBar = (int)(usedPercent / 2);
|
||||
|
||||
int reservedPercent = (int)((reserved * 100) / total);
|
||||
int reservedBar = (int)(reservedPercent / 2);
|
||||
|
||||
printf("[");
|
||||
for (int i = 0; i < usedBar; i++)
|
||||
printf("=");
|
||||
for (int i = 0; i < 50 - usedBar; i++)
|
||||
printf(" ");
|
||||
printf("] %d%% Used\n", usedPercent);
|
||||
|
||||
printf("[");
|
||||
for (int i = 0; i < reservedBar; i++)
|
||||
printf("=");
|
||||
for (int i = 0; i < 50 - reservedBar; i++)
|
||||
printf(" ");
|
||||
printf("] %d%% Reserved\n", reservedPercent);
|
||||
|
||||
// printf("Total: %d MiB\n", (int)(TO_MiB(total)));
|
||||
// printf("Used: %d MiB\n", (int)(TO_MiB(used)));
|
||||
// printf("Free: %d MiB\n", (int)(TO_MiB(free)));
|
||||
// printf("Reserved: %d MiB\n", (int)(TO_MiB(reserved)));
|
||||
|
||||
printf("TOTAL USED FREE RESERVED\n");
|
||||
printf("%d MiB %d MiB %d MiB %d MiB\n",
|
||||
(int)(TO_MiB(total)), (int)(TO_MiB(used)),
|
||||
(int)(TO_MiB(free)), (int)(TO_MiB(reserved)));
|
||||
}
|
33
kshell/commands/ps.cpp
Normal file
33
kshell/commands/ps.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include <filesystem.hpp>
|
||||
#include <task.hpp>
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
using namespace Tasking;
|
||||
|
||||
void cmd_ps(const char *)
|
||||
{
|
||||
printf("PID Name\n");
|
||||
foreach (auto p in TaskManager->GetProcessList())
|
||||
printf("%d %s\n", p->ID, p->Name);
|
||||
}
|
32
kshell/commands/reboot.cpp
Normal file
32
kshell/commands/reboot.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include <filesystem.hpp>
|
||||
#include <task.hpp>
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
using namespace Tasking;
|
||||
|
||||
void cmd_reboot(const char *)
|
||||
{
|
||||
KernelShutdownThread(true);
|
||||
CPU::Halt(true);
|
||||
}
|
32
kshell/commands/shutdown.cpp
Normal file
32
kshell/commands/shutdown.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include <filesystem.hpp>
|
||||
#include <task.hpp>
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
using namespace Tasking;
|
||||
|
||||
void cmd_shutdown(const char *)
|
||||
{
|
||||
KernelShutdownThread(false);
|
||||
CPU::Halt(true);
|
||||
}
|
60
kshell/commands/top.cpp
Normal file
60
kshell/commands/top.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include <filesystem.hpp>
|
||||
#include <task.hpp>
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
using namespace Tasking;
|
||||
|
||||
void cmd_top(const char *)
|
||||
{
|
||||
printf("\e9400A1PID \e9CA100Name \e00A15BState \eCCCCCCPriority Memory Usage CPU Usage\n");
|
||||
foreach (auto Proc in TaskManager->GetProcessList())
|
||||
{
|
||||
#if defined(a64)
|
||||
printf("\e9400A1%-4d \e9CA100%-20s \e00A15B%s \eCCCCCC%d %ld KiB %ld\n",
|
||||
Proc->ID, Proc->Name, Proc->State == Running ? "Running" : "Stopped",
|
||||
Proc->Info.Priority, TO_KiB(Proc->GetSize()),
|
||||
Proc->Info.UserTime + Proc->Info.KernelTime);
|
||||
#elif defined(a32)
|
||||
printf("\e9400A1%-4d \e9CA100%-20s \e00A15B%s \eCCCCCC%d %lld KiB %lld\n",
|
||||
Proc->ID, Proc->Name, Proc->State == Running ? "Running" : "Stopped",
|
||||
Proc->Info.Priority, TO_KiB(Proc->GetSize()),
|
||||
Proc->Info.UserTime + Proc->Info.KernelTime);
|
||||
#endif
|
||||
|
||||
foreach (auto Thrd in Proc->Threads)
|
||||
{
|
||||
#if defined(a64)
|
||||
printf(" \eA80011%-4d \e9CA100%-20s \e00A15B%s \eCCCCCC%d %ld KiB %ld\n",
|
||||
Thrd->ID, Thrd->Name, Thrd->State == Running ? "Running" : "Stopped",
|
||||
Thrd->Info.Priority, TO_KiB(Thrd->GetSize()),
|
||||
Thrd->Info.UserTime + Thrd->Info.KernelTime);
|
||||
#elif defined(a32)
|
||||
printf(" \eA80011%-4d \e9CA100%-20s \e00A15B%s \eCCCCCC%d %lld KiB %lld\n",
|
||||
Thrd->ID, Thrd->Name, Thrd->State == Running ? "Running" : "Stopped",
|
||||
Thrd->Info.Priority, TO_KiB(Thrd->GetSize()),
|
||||
Thrd->Info.UserTime + Thrd->Info.KernelTime);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
65
kshell/commands/uname.cpp
Normal file
65
kshell/commands/uname.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include <filesystem.hpp>
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
|
||||
void cmd_uname(const char *args)
|
||||
{
|
||||
if (args)
|
||||
{
|
||||
if (strcmp(args, "-a") == 0)
|
||||
{
|
||||
printf("Fennix Kernel %s %s %s %s\n",
|
||||
KERNEL_VERSION, KERNEL_NAME, __DATE__,
|
||||
KERNEL_ARCH);
|
||||
}
|
||||
else if (strcmp(args, "-s") == 0)
|
||||
{
|
||||
printf("%s\n", KERNEL_NAME);
|
||||
}
|
||||
else if (strcmp(args, "-v") == 0)
|
||||
{
|
||||
printf("%s\n", KERNEL_VERSION);
|
||||
}
|
||||
else if (strcmp(args, "-n") == 0)
|
||||
{
|
||||
printf("unknown\n");
|
||||
}
|
||||
else if (strcmp(args, "-r") == 0)
|
||||
{
|
||||
printf("%s\n", KERNEL_NAME);
|
||||
}
|
||||
else if (strcmp(args, "-m") == 0)
|
||||
{
|
||||
printf("%s\n", KERNEL_ARCH);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("uname: invalid option: %s\n", args);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Fennix Kernel\n");
|
||||
}
|
||||
}
|
57
kshell/commands/uptime.cpp
Normal file
57
kshell/commands/uptime.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include <filesystem.hpp>
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
|
||||
void cmd_uptime(const char *)
|
||||
{
|
||||
if (TimeManager)
|
||||
{
|
||||
uint64_t Nanoseconds =
|
||||
TimeManager->GetNanosecondsSinceClassCreation();
|
||||
uint64_t Seconds = Nanoseconds / 10000000;
|
||||
uint64_t Minutes = Seconds / 60;
|
||||
uint64_t Hours = Minutes / 60;
|
||||
uint64_t Days = Hours / 24;
|
||||
|
||||
debug("Nanoseconds: %ld", Nanoseconds);
|
||||
|
||||
Seconds %= 60;
|
||||
Minutes %= 60;
|
||||
Hours %= 24;
|
||||
|
||||
#if defined(a64)
|
||||
printf("%ld days, %ld hours, %ld minutes, %ld %s\n",
|
||||
Days, Hours, Minutes, Seconds,
|
||||
Seconds == 1 ? "second" : "seconds");
|
||||
#elif defined(a32)
|
||||
printf("%lld days, %lld hours, %lld minutes, %lld %s\n",
|
||||
Days, Hours, Minutes, Seconds,
|
||||
Seconds == 1 ? "second" : "seconds");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Could not get uptime\n");
|
||||
}
|
||||
}
|
29
kshell/commands/whoami.cpp
Normal file
29
kshell/commands/whoami.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../cmds.hpp"
|
||||
|
||||
#include <filesystem.hpp>
|
||||
|
||||
#include "../../kernel.h"
|
||||
|
||||
using namespace vfs;
|
||||
|
||||
void cmd_whoami(const char *)
|
||||
{
|
||||
printf("kernel\n");
|
||||
}
|
Reference in New Issue
Block a user