Compare commits
No commits in common. "32db3667811b4d89181db87e09513334a0c1625f" and "19ee21ae5a11762dcb10727c3ba742bf1b6a5b16" have entirely different histories.
32db366781
...
19ee21ae5a
@ -1,4 +1,4 @@
|
|||||||
APPS := init sym sh crash uname uptime hello ps ls
|
APPS := init sym sh crash uname uptime hello ps
|
||||||
|
|
||||||
APPS_DIR := $(LUNA_ROOT)/apps
|
APPS_DIR := $(LUNA_ROOT)/apps
|
||||||
APPS_SRC := $(APPS_DIR)/src
|
APPS_SRC := $(APPS_DIR)/src
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
#include <fcntl.h>
|
|
||||||
#include <luna/dirent.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
int dirfd = open("/bin", O_RDONLY);
|
|
||||||
if (dirfd < 0)
|
|
||||||
{
|
|
||||||
perror("open");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
struct luna_dirent dirent[5];
|
|
||||||
ssize_t nread;
|
|
||||||
do {
|
|
||||||
nread = getdents(dirfd, dirent, 5);
|
|
||||||
if (nread < 0)
|
|
||||||
{
|
|
||||||
perror("getdents");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < nread; i++) { printf("%s\n", dirent[i].name); }
|
|
||||||
} while (nread == 5);
|
|
||||||
|
|
||||||
close(dirfd);
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -19,7 +19,6 @@ namespace VFS
|
|||||||
typedef Node* (*node_finddir)(Node*, const char*);
|
typedef Node* (*node_finddir)(Node*, const char*);
|
||||||
typedef int (*node_mkdir)(Node*, const char*);
|
typedef int (*node_mkdir)(Node*, const char*);
|
||||||
typedef int (*node_block)(Node*);
|
typedef int (*node_block)(Node*);
|
||||||
typedef Node* (*node_readdir)(Node*, long);
|
|
||||||
|
|
||||||
struct Node
|
struct Node
|
||||||
{
|
{
|
||||||
@ -30,7 +29,6 @@ namespace VFS
|
|||||||
int flags;
|
int flags;
|
||||||
node_read read_func;
|
node_read read_func;
|
||||||
node_finddir find_func;
|
node_finddir find_func;
|
||||||
node_readdir readdir_func;
|
|
||||||
node_mkdir mkdir_func;
|
node_mkdir mkdir_func;
|
||||||
node_write write_func;
|
node_write write_func;
|
||||||
node_block block_func;
|
node_block block_func;
|
||||||
@ -57,6 +55,4 @@ namespace VFS
|
|||||||
void unmount(Node* mountpoint);
|
void unmount(Node* mountpoint);
|
||||||
|
|
||||||
Node* root();
|
Node* root();
|
||||||
|
|
||||||
Node* readdir(Node* dir, long offset);
|
|
||||||
}
|
}
|
@ -6,5 +6,4 @@ namespace DeviceFS
|
|||||||
VFS::Node* get();
|
VFS::Node* get();
|
||||||
|
|
||||||
VFS::Node* finddir(VFS::Node* node, const char* filename);
|
VFS::Node* finddir(VFS::Node* node, const char* filename);
|
||||||
VFS::Node* readdir(VFS::Node* node, long offset);
|
|
||||||
}
|
}
|
@ -24,11 +24,9 @@
|
|||||||
#define SYS_access 19
|
#define SYS_access 19
|
||||||
#define SYS_fstat 20
|
#define SYS_fstat 20
|
||||||
#define SYS_pstat 21
|
#define SYS_pstat 21
|
||||||
#define SYS_getdents 22
|
|
||||||
|
|
||||||
struct stat;
|
struct stat;
|
||||||
struct pstat;
|
struct pstat;
|
||||||
struct luna_dirent;
|
|
||||||
|
|
||||||
namespace Syscall
|
namespace Syscall
|
||||||
{
|
{
|
||||||
@ -57,4 +55,3 @@ void sys_waitpid(Context* context, long pid, int* wstatus, int options);
|
|||||||
void sys_access(Context* context, const char* path, int amode);
|
void sys_access(Context* context, const char* path, int amode);
|
||||||
void sys_fstat(Context* context, int fd, struct stat* buf);
|
void sys_fstat(Context* context, int fd, struct stat* buf);
|
||||||
void sys_pstat(Context* context, long pid, struct pstat* buf);
|
void sys_pstat(Context* context, long pid, struct pstat* buf);
|
||||||
void sys_getdents(Context* context, int fd, struct luna_dirent* buf, size_t count);
|
|
@ -39,7 +39,7 @@ ssize_t Descriptor::write(size_t size, const char* buffer)
|
|||||||
|
|
||||||
int Descriptor::seek(long offset)
|
int Descriptor::seek(long offset)
|
||||||
{
|
{
|
||||||
if (m_node->type == VFS_FILE && (uint64_t)offset > m_node->length)
|
if (m_node->type != VFS_DEVICE && (uint64_t)offset > m_node->length)
|
||||||
return -EINVAL; // FIXME: Support seeking beyond the current file's length.
|
return -EINVAL; // FIXME: Support seeking beyond the current file's length.
|
||||||
m_offset = (uint64_t)offset;
|
m_offset = (uint64_t)offset;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -202,10 +202,3 @@ void VFS::unmount(Node* mountpoint)
|
|||||||
if (!(mountpoint->flags & VFS_MOUNTPOINT)) return;
|
if (!(mountpoint->flags & VFS_MOUNTPOINT)) return;
|
||||||
mountpoint->flags &= ~VFS_MOUNTPOINT;
|
mountpoint->flags &= ~VFS_MOUNTPOINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
VFS::Node* VFS::readdir(VFS::Node* dir, long offset)
|
|
||||||
{
|
|
||||||
if (!dir) return 0;
|
|
||||||
if (!dir->readdir_func) return 0;
|
|
||||||
return dir->readdir_func(dir, offset);
|
|
||||||
}
|
|
@ -23,7 +23,6 @@ VFS::Node* DeviceFS::get()
|
|||||||
devfs_root->inode = 0;
|
devfs_root->inode = 0;
|
||||||
devfs_root->type = VFS_DIRECTORY;
|
devfs_root->type = VFS_DIRECTORY;
|
||||||
devfs_root->find_func = DeviceFS::finddir;
|
devfs_root->find_func = DeviceFS::finddir;
|
||||||
devfs_root->readdir_func = DeviceFS::readdir;
|
|
||||||
strncpy(devfs_root->name, "dev", sizeof(devfs_root->name));
|
strncpy(devfs_root->name, "dev", sizeof(devfs_root->name));
|
||||||
|
|
||||||
devfs_files[devfs_file_count++] = VersionDevice::create_new("version");
|
devfs_files[devfs_file_count++] = VersionDevice::create_new("version");
|
||||||
@ -32,7 +31,6 @@ VFS::Node* DeviceFS::get()
|
|||||||
devfs_files[devfs_file_count++] = RandomDevice::create_new("random");
|
devfs_files[devfs_file_count++] = RandomDevice::create_new("random");
|
||||||
devfs_files[devfs_file_count++] = KeyboardDevice::create_new("kbd");
|
devfs_files[devfs_file_count++] = KeyboardDevice::create_new("kbd");
|
||||||
devfs_files[devfs_file_count++] = UptimeDevice::create_new("uptime");
|
devfs_files[devfs_file_count++] = UptimeDevice::create_new("uptime");
|
||||||
devfs_root->length = devfs_file_count;
|
|
||||||
return devfs_root;
|
return devfs_root;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,10 +43,3 @@ VFS::Node* DeviceFS::finddir(VFS::Node* node, const char* filename)
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
VFS::Node* DeviceFS::readdir(VFS::Node* node, long offset)
|
|
||||||
{
|
|
||||||
if (!node) return 0;
|
|
||||||
if (offset >= devfs_file_count) return 0;
|
|
||||||
return devfs_files[offset];
|
|
||||||
}
|
|
@ -186,15 +186,6 @@ VFS::Node* initrd_scan_dir(VFS::Node* node, const char* filename)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
VFS::Node* initrd_read_dir(VFS::Node* node, long offset)
|
|
||||||
{
|
|
||||||
if (!node) return 0;
|
|
||||||
if (node->inode >= total_dirs) return 0;
|
|
||||||
InitRD::Directory dir = dirs[node->inode];
|
|
||||||
if (offset >= dir.entries) return 0;
|
|
||||||
return dir.files[offset];
|
|
||||||
}
|
|
||||||
|
|
||||||
int initrd_mkdir(VFS::Node* node, const char* name) // FIXME: Return proper error numbers.
|
int initrd_mkdir(VFS::Node* node, const char* name) // FIXME: Return proper error numbers.
|
||||||
{
|
{
|
||||||
if (total_dirs >= 32)
|
if (total_dirs >= 32)
|
||||||
@ -231,7 +222,6 @@ int initrd_mkdir(VFS::Node* node, const char* name) // FIXME: Return proper erro
|
|||||||
dir.entries = 0;
|
dir.entries = 0;
|
||||||
dirs[total_dirs++] = dir; // FIXME: Right now this isn't of worry, but there is a possibility for a TOCTOU bug here.
|
dirs[total_dirs++] = dir; // FIXME: Right now this isn't of worry, but there is a possibility for a TOCTOU bug here.
|
||||||
// Should use a spinlock or something.
|
// Should use a spinlock or something.
|
||||||
node->length++;
|
|
||||||
parent.files[parent.entries++] = &new_node;
|
parent.files[parent.entries++] = &new_node;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -280,13 +270,10 @@ static bool initrd_register_dir(InitRD::Directory& dir, uint64_t inode)
|
|||||||
node.length = 0;
|
node.length = 0;
|
||||||
node.type = VFS_DIRECTORY;
|
node.type = VFS_DIRECTORY;
|
||||||
node.mkdir_func = initrd_mkdir;
|
node.mkdir_func = initrd_mkdir;
|
||||||
node.readdir_func = initrd_read_dir;
|
|
||||||
node.length = 0;
|
|
||||||
strncpy(node.name, buffer, sizeof(node.name));
|
strncpy(node.name, buffer, sizeof(node.name));
|
||||||
strncpy(dir.name, buffer, sizeof(dir.name));
|
strncpy(dir.name, buffer, sizeof(dir.name));
|
||||||
|
|
||||||
parent.files[parent.entries++] = &node;
|
parent.files[parent.entries++] = &node;
|
||||||
current_node->length++;
|
|
||||||
|
|
||||||
kfree(buffer);
|
kfree(buffer);
|
||||||
return true;
|
return true;
|
||||||
@ -345,7 +332,6 @@ static bool initrd_register_file(InitRD::File& f, uint64_t inode)
|
|||||||
strncpy(f.name, buffer, sizeof(f.name));
|
strncpy(f.name, buffer, sizeof(f.name));
|
||||||
|
|
||||||
parent.files[parent.entries++] = &node;
|
parent.files[parent.entries++] = &node;
|
||||||
current_node->length++;
|
|
||||||
kfree(buffer);
|
kfree(buffer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -389,7 +375,6 @@ static void initrd_initialize_root()
|
|||||||
strncpy(root.name, "initrd", sizeof(root.name));
|
strncpy(root.name, "initrd", sizeof(root.name));
|
||||||
initrd_root.find_func = initrd_scan_dir;
|
initrd_root.find_func = initrd_scan_dir;
|
||||||
initrd_root.mkdir_func = initrd_mkdir;
|
initrd_root.mkdir_func = initrd_mkdir;
|
||||||
initrd_root.readdir_func = initrd_read_dir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitRD::init()
|
void InitRD::init()
|
||||||
|
@ -33,9 +33,6 @@ void Syscall::entry(Context* context)
|
|||||||
case SYS_access: sys_access(context, (const char*)context->rdi, (int)context->rsi); break;
|
case SYS_access: sys_access(context, (const char*)context->rdi, (int)context->rsi); break;
|
||||||
case SYS_fstat: sys_fstat(context, (int)context->rdi, (struct stat*)context->rsi); break;
|
case SYS_fstat: sys_fstat(context, (int)context->rdi, (struct stat*)context->rsi); break;
|
||||||
case SYS_pstat: sys_pstat(context, (long)context->rdi, (struct pstat*)context->rsi); break;
|
case SYS_pstat: sys_pstat(context, (long)context->rdi, (struct pstat*)context->rsi); break;
|
||||||
case SYS_getdents:
|
|
||||||
sys_getdents(context, (int)context->rdi, (struct luna_dirent*)context->rsi, (size_t)context->rdx);
|
|
||||||
break;
|
|
||||||
default: context->rax = -ENOSYS; break;
|
default: context->rax = -ENOSYS; break;
|
||||||
}
|
}
|
||||||
VMM::exit_syscall_context();
|
VMM::exit_syscall_context();
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
#define MODULE "dir"
|
|
||||||
|
|
||||||
#include "luna/dirent.h"
|
|
||||||
#include "fs/VFS.h"
|
|
||||||
#include "interrupts/Context.h"
|
|
||||||
#include "std/errno.h"
|
|
||||||
#include "std/string.h"
|
|
||||||
#include "sys/UserMemory.h"
|
|
||||||
#include "thread/Scheduler.h"
|
|
||||||
|
|
||||||
void sys_getdents(Context* context, int fd, struct luna_dirent* buf, size_t count)
|
|
||||||
{
|
|
||||||
if (fd < 0 || fd > TASK_MAX_FDS)
|
|
||||||
{
|
|
||||||
context->rax = -EBADF;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Task* current_task = Scheduler::current_task();
|
|
||||||
if (!current_task->files[fd].is_open())
|
|
||||||
{
|
|
||||||
context->rax = -EBADF;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Descriptor& dir = current_task->files[fd];
|
|
||||||
VFS::Node* node = dir.node();
|
|
||||||
if (node->type != VFS_DIRECTORY)
|
|
||||||
{
|
|
||||||
context->rax = -ENOTDIR;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
size_t nread = 0;
|
|
||||||
while (count)
|
|
||||||
{
|
|
||||||
VFS::Node* entry = VFS::readdir(node, dir.offset());
|
|
||||||
if (!entry)
|
|
||||||
{
|
|
||||||
context->rax = nread;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* kdirent = obtain_user_ref(buf);
|
|
||||||
if (!kdirent)
|
|
||||||
{
|
|
||||||
context->rax = -EFAULT;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
kdirent->total = node->length;
|
|
||||||
kdirent->offset = dir.offset();
|
|
||||||
kdirent->inode = entry->inode;
|
|
||||||
strlcpy(kdirent->name, entry->name, sizeof(kdirent->name));
|
|
||||||
|
|
||||||
release_user_ref(kdirent);
|
|
||||||
|
|
||||||
dir.seek(dir.offset() + 1);
|
|
||||||
buf++;
|
|
||||||
nread++;
|
|
||||||
count--;
|
|
||||||
}
|
|
||||||
context->rax = nread;
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
#ifndef _LUNA_DIRENT_H
|
|
||||||
#define _LUNA_DIRENT_H
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
struct luna_dirent
|
|
||||||
{
|
|
||||||
ino_t inode;
|
|
||||||
char name[64];
|
|
||||||
size_t total;
|
|
||||||
off_t offset;
|
|
||||||
};
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Retrieve directory entries from the kernel. This is the raw interface, use readdir() instead. */
|
|
||||||
ssize_t getdents(int fd, struct luna_dirent* buf, size_t count);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -23,6 +23,5 @@
|
|||||||
#define SYS_access 19
|
#define SYS_access 19
|
||||||
#define SYS_fstat 20
|
#define SYS_fstat 20
|
||||||
#define SYS_pstat 21
|
#define SYS_pstat 21
|
||||||
#define SYS_getdents 22
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,11 +0,0 @@
|
|||||||
#include <luna/dirent.h>
|
|
||||||
#include <sys/syscall.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
ssize_t getdents(int fd, struct luna_dirent* buf, size_t count)
|
|
||||||
{
|
|
||||||
return syscall(SYS_getdents, fd, buf, count);
|
|
||||||
}
|
|
||||||
}
|
|
@ -31,7 +31,6 @@ extern "C" long syscall(long number, ...)
|
|||||||
result = __luna_syscall2(number, arg0, arg1);
|
result = __luna_syscall2(number, arg0, arg1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SYS_getdents:
|
|
||||||
case SYS_fcntl:
|
case SYS_fcntl:
|
||||||
case SYS_seek:
|
case SYS_seek:
|
||||||
case SYS_write:
|
case SYS_write:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user