mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-15 09:19:19 +00:00
.github
.vscode
arch
core
exec
files
include
include_std
kshell
library
network
profiling
storage
devices
fs
README.md
file_descriptor.cpp
filesystem.cpp
kernel_io.cpp
node.cpp
ref_node.cpp
syscalls
tasking
tests
virtualization
.gdbinit
.gitignore
CREDITS.md
Doxyfile
ISSUES.md
LICENSE.md
LICENSES.md
Makefile
README.md
TODO.md
driver.h
dump.sh
kernel.cpp
kernel.h
kernel_config.cpp
kernel_thread.cpp
kernel_vfs.cpp
syscalls.h
131 lines
2.9 KiB
C++
131 lines
2.9 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 <filesystem.hpp>
|
|
#include <errno.h>
|
|
|
|
#include "../kernel.h"
|
|
|
|
using Tasking::PCB;
|
|
using vfs::FileDescriptorTable;
|
|
|
|
static bool CheckForScheduler()
|
|
{
|
|
if (TaskManager == nullptr)
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
int fopen(const char *pathname, const char *mode)
|
|
{
|
|
if (!CheckForScheduler())
|
|
return -ENOSYS;
|
|
|
|
PCB *pcb = thisProcess;
|
|
FileDescriptorTable *fdt = pcb->FileDescriptors;
|
|
int fd = fdt->_open(pathname, ConvertFileFlags(mode), 0666);
|
|
return fd;
|
|
}
|
|
|
|
int creat(const char *pathname, mode_t mode)
|
|
{
|
|
if (!CheckForScheduler())
|
|
return -ENOSYS;
|
|
|
|
PCB *pcb = thisProcess;
|
|
FileDescriptorTable *fdt = pcb->FileDescriptors;
|
|
int fd = fdt->_creat(pathname, mode);
|
|
return fd;
|
|
}
|
|
|
|
ssize_t fread(int fd, void *buf, size_t count)
|
|
{
|
|
if (!CheckForScheduler())
|
|
return -ENOSYS;
|
|
|
|
PCB *pcb = thisProcess;
|
|
FileDescriptorTable *fdt = pcb->FileDescriptors;
|
|
ssize_t ret = fdt->_read(fd, buf, count);
|
|
return ret;
|
|
}
|
|
|
|
ssize_t fwrite(int fd, const void *buf, size_t count)
|
|
{
|
|
if (!CheckForScheduler())
|
|
return -ENOSYS;
|
|
|
|
PCB *pcb = thisProcess;
|
|
FileDescriptorTable *fdt = pcb->FileDescriptors;
|
|
ssize_t ret = fdt->_write(fd, buf, count);
|
|
return ret;
|
|
}
|
|
|
|
int fclose(int fd)
|
|
{
|
|
if (!CheckForScheduler())
|
|
return -ENOSYS;
|
|
|
|
PCB *pcb = thisProcess;
|
|
FileDescriptorTable *fdt = pcb->FileDescriptors;
|
|
int ret = fdt->_close(fd);
|
|
return ret;
|
|
}
|
|
|
|
off_t lseek(int fd, off_t offset, int whence)
|
|
{
|
|
if (!CheckForScheduler())
|
|
return -ENOSYS;
|
|
|
|
PCB *pcb = thisProcess;
|
|
FileDescriptorTable *fdt = pcb->FileDescriptors;
|
|
off_t ret = fdt->_lseek(fd, offset, whence);
|
|
return ret;
|
|
}
|
|
|
|
int stat(const char *pathname, struct stat *statbuf)
|
|
{
|
|
if (!CheckForScheduler())
|
|
return -ENOSYS;
|
|
|
|
PCB *pcb = thisProcess;
|
|
FileDescriptorTable *fdt = pcb->FileDescriptors;
|
|
int ret = fdt->_stat(pathname, statbuf);
|
|
return ret;
|
|
}
|
|
|
|
int fstat(int fd, struct stat *statbuf)
|
|
{
|
|
if (!CheckForScheduler())
|
|
return -ENOSYS;
|
|
|
|
PCB *pcb = thisProcess;
|
|
FileDescriptorTable *fdt = pcb->FileDescriptors;
|
|
int ret = fdt->_fstat(fd, statbuf);
|
|
return ret;
|
|
}
|
|
|
|
int lstat(const char *pathname, struct stat *statbuf)
|
|
{
|
|
if (!CheckForScheduler())
|
|
return -ENOSYS;
|
|
|
|
PCB *pcb = thisProcess;
|
|
FileDescriptorTable *fdt = pcb->FileDescriptors;
|
|
int ret = fdt->_lstat(pathname, statbuf);
|
|
return ret;
|
|
}
|