mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-14 16:59:17 +00:00
.devcontainer
.github
.vscode
Bootloader
Drivers
Kernel
.vscode
arch
core
drivers
exec
files
include
include_std
kshell
commands
cat.cpp
cd.cpp
clear.cpp
dump.cpp
echo.cpp
exit.cpp
kill.cpp
killall.cpp
ls.cpp
lsacpi.cpp
lsmod.cpp
lspci.cpp
mem.cpp
modinfo.cpp
panic.cpp
ps.cpp
reboot.cpp
shutdown.cpp
theme.cpp
top.cpp
tree.cpp
uname.cpp
uptime.cpp
whoami.cpp
cmds.hpp
shell.cpp
library
network
profiling
security
storage
subsystem
syscalls
tasking
tests
tty
virtualization
.editorconfig
.gdbinit
.gitignore
ISSUES.md
Makefile
README.md
TODO.md
dump.sh
kernel.cpp
kernel.h
kernel_config.cpp
kernel_note.cpp
kernel_thread.cpp
kernel_vfs.cpp
Userspace
rootfs
tools
.editorconfig
.gitignore
.gitlab-ci.yml
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
CREDITS.md
Doxyfile
Fennix Bootloader.code-workspace
Fennix Drivers.code-workspace
Fennix Kernel.code-workspace
Fennix Userspace.code-workspace
Fennix Website.code-workspace
Fennix.code-workspace
INSTALL.md
LICENSE.md
LICENSES.md
Makefile
README.md
SECURITY.md
STYLE_GUIDE.md
cliff.toml
config.mk
102 lines
2.4 KiB
C++
102 lines
2.4 KiB
C++
/*
|
|
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"
|
|
|
|
void tree_loop(FileNode *rootNode, int depth = 0)
|
|
{
|
|
// for (auto Child : 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)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
|
|
printf("%s\n", rootNode->Name.c_str());
|
|
tree_loop(rootNode);
|
|
}
|