Skip to content

Commit

Permalink
lxfs: stub for open()
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Sep 30, 2024
1 parent 88926f9 commit bd3f1c6
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
11 changes: 11 additions & 0 deletions fs/lxfs/src/dirtree.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,15 @@ char *pathComponent(char *dest, const char *path, int n) {
}

return NULL;
}

/* lxfsFind(): finds the directory entry associated with a file
* params: dest - destination buffer to store the directory entry
* params: mp - lxfs mountpoint
* params: path - full qualified path
* returns: pointer to destination on success, NULL on fail
*/

LXFSDirectoryEntry *lxfsFind(LXFSDirectoryEntry *dest, Mountpoint *mp, const char *path) {
return NULL; // stub
}
1 change: 1 addition & 0 deletions fs/lxfs/src/include/lxfs/lxfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ uint64_t lxfsWriteNextBlock(Mountpoint *, uint64_t, const void *);
Mountpoint *findMP(const char *);
int pathDepth(const char *);
char *pathComponent(char *, const char *, int);
LXFSDirectoryEntry *lxfsFind(LXFSDirectoryEntry *, Mountpoint *, const char *);

void lxfsOpen(OpenCommand *);
void lxfsStat(StatCommand *);
Expand Down
1 change: 1 addition & 0 deletions fs/lxfs/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ int main() {

switch(msg->header.command) {
case COMMAND_MOUNT: lxfsMount((MountCommand *) msg); break;
case COMMAND_OPEN: lxfsOpen((OpenCommand *) msg); break;
default:
luxLogf(KPRINT_LEVEL_WARNING, "unimplemented command 0x%04X, dropping message...\n", msg->header.command);
}
Expand Down
12 changes: 12 additions & 0 deletions fs/lxfs/src/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ static Mountpoint *allocateMP() {
return mp;
}

Mountpoint *findMP(const char *dev) {
if(!mps) return NULL;

Mountpoint *list = mps;
while(list) {
if(!strcmp(list->device, dev)) return list;
else list = list->next;
}

return NULL;
}

void lxfsMount(MountCommand *cmd) {
cmd->header.header.response = 1;

Expand Down
41 changes: 41 additions & 0 deletions fs/lxfs/src/open.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* luxOS - a unix-like operating system
* Omar Elghoul, 2024
*
* lxfs: Driver for the lxfs file system
*/

#include <liblux/liblux.h>
#include <lxfs/lxfs.h>
#include <vfs.h>
#include <string.h>
#include <stdlib.h>
#include <fnctl.h>
#include <unistd.h>
#include <errno.h>

/* lxfsOpen(): opens a opened file on an lxfs volume
* params: ocmd - open command message
* returns: nothing, response relayed to vfs
*/

void lxfsOpen(OpenCommand *ocmd) {
ocmd->header.header.response = 1;
ocmd->header.header.length = sizeof(OpenCommand);

luxLogf(KPRINT_LEVEL_DEBUG, "opening %s on %s\n", ocmd->path, ocmd->device);

Mountpoint *mp = findMP(ocmd->device);
if(!mp) {
ocmd->header.header.status = -EIO; // device doesn't exist
luxSendDependency(ocmd);
return;
}

LXFSDirectoryEntry entry;
if(!lxfsFind(&entry, mp, ocmd->path)) {
ocmd->header.header.status = -ENOENT; // file doesn't exist
luxSendDependency(ocmd);
return;
}
}

0 comments on commit bd3f1c6

Please sign in to comment.