Skip to content

Commit

Permalink
procfs: refactored and implemented open()
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Oct 6, 2024
1 parent 53ab15c commit 8a4f836
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
14 changes: 8 additions & 6 deletions fs/procfs/src/include/procfs/procfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
#define RESOLVE_PID_CHILDREN (9 | RESOLVE_PID) /* /proc/pid/children */
#define RESOLVE_PID_STAT (10 | RESOLVE_PID) /* /proc/pid/stat */

void procfsMount(MountCommand *, MountCommand *);
void procfsStat(StatCommand *, StatCommand *);
void procfsOpen(OpenCommand *, OpenCommand *);
void procfsRead(RWCommand *, RWCommand *);
void procfsWrite(RWCommand *, RWCommand *);
#define RESOLVE_DIRECTORY 0x10000

int procfsResolve(const char *, pid_t *);
void procfsMount(MountCommand *);
void procfsStat(StatCommand *);
void procfsOpen(OpenCommand *);
void procfsRead(RWCommand *);
void procfsWrite(RWCommand *);

int resolve(const char *, pid_t *);
40 changes: 40 additions & 0 deletions fs/procfs/src/io.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* luxOS - a unix-like operating system
* Omar Elghoul, 2024
*
* procfs: Microkernel server implementing the /proc file system
*/

#include <procfs/procfs.h>
#include <liblux/liblux.h>
#include <string.h>
#include <stdlib.h>
#include <fnctl.h>
#include <errno.h>

void procfsOpen(OpenCommand *ocmd) {
pid_t pid;

ocmd->header.header.response = 1;
ocmd->header.header.length = sizeof(OpenCommand);

int res = resolve(ocmd->path, &pid);
if(res < 0) {
ocmd->header.header.status = -ENOENT;
luxSendDependency(ocmd);
return;
}

if(res & RESOLVE_DIRECTORY) {
ocmd->header.header.status = -EISDIR;
luxSendDependency(ocmd);
return;
}

if(ocmd->flags & O_WRONLY)
ocmd->header.header.status = -EPERM;
else
ocmd->header.header.status = 0;

luxSendDependency(ocmd);
}
3 changes: 2 additions & 1 deletion fs/procfs/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ int main() {
luxRecvDependency(req, req->header.length, false, false);

switch(req->header.command) {
case COMMAND_MOUNT: procfsMount((MountCommand *) req, (MountCommand *) res); break;
case COMMAND_MOUNT: procfsMount((MountCommand *) req); break;
case COMMAND_OPEN: procfsOpen((OpenCommand *) req); break;
default:
luxLogf(KPRINT_LEVEL_WARNING, "unimplemented command 0x%X, dropping message...\n", req->header.command);
}
Expand Down
12 changes: 5 additions & 7 deletions fs/procfs/src/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@

/* procfsMount(): mounts the /proc file system
* params: req - request buffer
* params: res - response buffer
* returns: nothing
*/

void procfsMount(MountCommand *req, MountCommand *res) {
memcpy(res, req, sizeof(MountCommand));
res->header.header.response = 1;
res->header.header.length = sizeof(MountCommand);
res->header.header.status = 0; // success
void procfsMount(MountCommand *req) {
req->header.header.response = 1;
req->header.header.length = sizeof(MountCommand);
req->header.header.status = 0; // success

luxSendDependency(res);
luxSendDependency(req);
}

0 comments on commit 8a4f836

Please sign in to comment.