Skip to content

Commit

Permalink
lxfs: implemented opendir()
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Oct 6, 2024
1 parent 7b151de commit 70d748e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
54 changes: 54 additions & 0 deletions fs/lxfs/src/dirent.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 <string.h>
#include <stdlib.h>
#include <errno.h>

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

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

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;
}

// ensure this is a directory
if(((entry.flags >> LXFS_DIR_TYPE_SHIFT) & LXFS_DIR_TYPE_MASK) != LXFS_DIR_TYPE_DIR) {
ocmd->header.header.status = -EISDIR;
luxSendDependency(ocmd);
return;
}

// and ensure adequate permissions (execute)
ocmd->header.header.status = 0;
if((ocmd->uid == entry.owner) && !(entry.permissions & LXFS_PERMS_OWNER_X))
ocmd->header.header.status = -EPERM;
else if((ocmd->gid == entry.group) && !(entry.permissions & LXFS_PERMS_GROUP_X))
ocmd->header.header.status = -EPERM;
else if(!(entry.permissions & LXFS_PERMS_OTHER_X))
ocmd->header.header.status = -EPERM;

luxSendDependency(ocmd);
}
2 changes: 2 additions & 0 deletions fs/lxfs/src/include/lxfs/lxfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,5 @@ void lxfsOpen(OpenCommand *);
void lxfsStat(StatCommand *);
void lxfsRead(RWCommand *);
void lxfsWrite(RWCommand *);
void lxfsOpendir(OpendirCommand *);
void lxfsReaddir(ReaddirCommand *);
1 change: 1 addition & 0 deletions fs/lxfs/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ int main() {
case COMMAND_OPEN: lxfsOpen((OpenCommand *) msg); break;
case COMMAND_READ: lxfsRead((RWCommand *) msg); break;
case COMMAND_STAT: lxfsStat((StatCommand *) msg); break;
case COMMAND_OPENDIR: lxfsOpendir((OpendirCommand *) msg); break;
default:
luxLogf(KPRINT_LEVEL_WARNING, "unimplemented command 0x%04X, dropping message...\n", msg->header.command);
}
Expand Down

0 comments on commit 70d748e

Please sign in to comment.