Skip to content

Commit

Permalink
dirent: request for opendir()
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Sep 25, 2024
1 parent 52c12fb commit 1c0b2e9
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/dirent.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* lux - a lightweight unix-like operating system
* Omar Elghoul, 2024
*
* Core Microkernel
*/

#include <kernel/dirent.h>
#include <kernel/servers.h>
#include <kernel/io.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

/* Just as with the file system calls, these are just wrappers and do not
* implement any actual functionality at the kernel level */

int opendir(Thread *t, uint64_t id, const char *path) {
if(strlen(path) >= MAX_FILE_PATH) return -ENAMETOOLONG;
Process *p = getProcess(t->pid);
if(!p) return -ESRCH;

OpendirCommand *cmd = calloc(1, sizeof(OpendirCommand));
if(!cmd) return -ENOMEM;

cmd->header.header.command = COMMAND_OPENDIR;
cmd->header.header.length = sizeof(OpendirCommand);
cmd->header.id = id;
cmd->uid = p->user;
cmd->gid = p->group;
strcpy(cmd->path, path);

int status = requestServer(t, cmd);
free(cmd);
return status;
}

0 comments on commit 1c0b2e9

Please sign in to comment.