44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
|
#include "fs/VFS.h"
|
||
|
#include "interrupts/Context.h"
|
||
|
#include "std/errno.h"
|
||
|
#include "sys/UserMemory.h"
|
||
|
#include "thread/Scheduler.h"
|
||
|
|
||
|
typedef unsigned long off_t;
|
||
|
typedef unsigned short mode_t;
|
||
|
typedef unsigned long ino_t;
|
||
|
|
||
|
struct stat // FIXME: This struct is quite stubbed out.
|
||
|
{
|
||
|
ino_t st_ino;
|
||
|
mode_t st_mode;
|
||
|
off_t st_size;
|
||
|
};
|
||
|
|
||
|
void sys_fstat(Context* context, int fd, struct stat* buf)
|
||
|
{
|
||
|
Task* current_task = Scheduler::current_task();
|
||
|
if (fd < 0 || fd >= TASK_MAX_FDS)
|
||
|
{
|
||
|
context->rax = -EBADF;
|
||
|
return;
|
||
|
}
|
||
|
Descriptor& file = current_task->files[fd];
|
||
|
if (!file.is_open())
|
||
|
{
|
||
|
context->rax = -EBADF;
|
||
|
return;
|
||
|
}
|
||
|
struct stat* kstat = obtain_user_ref(buf);
|
||
|
if (!kstat)
|
||
|
{
|
||
|
context->rax = -EFAULT; // FIXME: The manual doesn't say fstat can return EFAULT, but it seems logical here...
|
||
|
return;
|
||
|
}
|
||
|
VFS::Node* node = file.node();
|
||
|
kstat->st_ino = node->inode;
|
||
|
kstat->st_mode = (mode_t)node->type;
|
||
|
kstat->st_size = node->length;
|
||
|
release_user_ref(kstat);
|
||
|
context->rax = 0;
|
||
|
}
|