Skip to content

Commit

Permalink
file: account for relative paths and working dir
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Oct 1, 2024
1 parent afda0f4 commit e5160f6
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,23 @@ int mount(Thread *t, uint64_t id, const char *src, const char *tgt, const char *
}

int stat(Thread *t, uint64_t id, const char *path, struct stat *buffer) {
Process *p = getProcess(t->pid);
if(!p) return -ESRCH;

StatCommand *command = calloc(1, sizeof(StatCommand));
if(!command) return -ENOMEM;

command->header.header.command = COMMAND_STAT;
command->header.header.length = sizeof(StatCommand);
command->header.id = id;
strcpy(command->path, path);

if(path[0] == '/') {
strcpy(command->path, path);
} else {
strcpy(command->path, p->cwd);
command->path[strlen(command->path)] = '/';
strcpy(command->path + strlen(command->path), path);
}

int status = requestServer(t, command);
free(command);
Expand Down Expand Up @@ -77,7 +87,14 @@ int open(Thread *t, uint64_t id, const char *path, int flags, mode_t mode) {
command->mode = mode;
command->uid = p->user;
command->gid = p->group;
strcpy(command->abspath, path);

if(path[0] == '/') {
strcpy(command->abspath, path);
} else {
strcpy(command->abspath, p->cwd);
command->abspath[strlen(command->abspath)] = '/';
strcpy(command->abspath + strlen(command->abspath), path);
}

int status = requestServer(t, command);
free(command);
Expand Down

0 comments on commit e5160f6

Please sign in to comment.