Skip to content

Commit

Permalink
servers: handle readdir() message response
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Sep 26, 2024
1 parent 1f286fb commit 7c78e67
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/servers/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void handleSyscallResponse(const SyscallHeader *hdr) {
ssize_t status;
IODescriptor *iod;
FileDescriptor *file;
DirectoryDescriptor *dir;
int dd;

switch(hdr->header.command) {
case COMMAND_STAT:
Expand Down Expand Up @@ -151,8 +153,8 @@ void handleSyscallResponse(const SyscallHeader *hdr) {
OpendirCommand *opendircmd = (OpendirCommand *) hdr;

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

iod->type = IO_DIRECTORY;
Expand All @@ -163,14 +165,35 @@ void handleSyscallResponse(const SyscallHeader *hdr) {
break;
}

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

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

case COMMAND_READDIR:
if(hdr->header.status) break;
ReaddirCommand *readdircmd = (ReaddirCommand *) hdr;

// update the directory descriptor's internal position
dd = (int) req->params[0] & ~(DIRECTORY_DESCRIPTOR_FLAG);
dir = (DirectoryDescriptor *) p->io[dd].data;
dir->position = readdircmd->position;

// and copy the descriptor and write its pointer into the buffer
threadUseContext(req->thread->tid);
struct dirent **direntptr = (struct dirent **) req->params[2];
if(!readdircmd->end) {
memcpy((void *)req->params[1], &readdircmd->entry, sizeof(struct dirent) + strlen(readdircmd->entry.d_name) + 1);
*direntptr = (struct dirent *) req->params[1];
} else {
*direntptr = NULL;
}

break;
}

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

0 comments on commit 7c78e67

Please sign in to comment.