Skip to content

Commit

Permalink
servers: allocate directory descriptor after opendir() response
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Sep 26, 2024
1 parent 30b081b commit 0a70c45
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/servers/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void handleSyscallResponse(const SyscallHeader *hdr) {

// some syscalls will require special handling
ssize_t status;
IODescriptor *iod;
FileDescriptor *file;

switch(hdr->header.command) {
Expand All @@ -58,7 +59,7 @@ void handleSyscallResponse(const SyscallHeader *hdr) {
OpenCommand *opencmd = (OpenCommand *) hdr;

// set up a file descriptor for the process
IODescriptor *iod = NULL;
iod = NULL;
int fd = openIO(p, (void **) &iod);
if(fd < 0 || !iod) req->ret = fd;

Expand Down Expand Up @@ -144,6 +145,32 @@ void handleSyscallResponse(const SyscallHeader *hdr) {
}

break;

case COMMAND_OPENDIR:
if(hdr->header.status) break;
OpendirCommand *opendircmd = (OpendirCommand *) hdr;

// set up a file descriptor for the process
IODescriptor *iod = NULL;
int dd = openIO(p, (void **) &iod);
if(dd < 0 || !iod) req->ret = dd;

iod->type = IO_DIRECTORY;
iod->data = calloc(1, sizeof(DirectoryDescriptor));
if(!iod->data) {
closeIO(p, iod);
req->ret = -ENOMEM;
break;
}

DirectoryDescriptor *dir = (DirectoryDescriptor *) iod->data;
dir->process = p;
strcpy(dir->path, opendircmd->path);
strcpy(dir->device, opendircmd->device);

// and return the directory descriptor to the thread
req->ret = dd | DIRECTORY_DESCRIPTOR_FLAG;
break;
}

platformSetContextStatus(req->thread->context, req->ret);
Expand Down

0 comments on commit 0a70c45

Please sign in to comment.