Skip to content

Commit

Permalink
Implement read parts of tmpfs
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Feb 17, 2020
1 parent 580b3b9 commit 823647b
Show file tree
Hide file tree
Showing 8 changed files with 499 additions and 14 deletions.
7 changes: 6 additions & 1 deletion fs/fd.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct fd {
// length of actual data stored in the buffer
size_t buffer_len;
} clipboard;

// can fit anything in here
void *data;
};
Expand All @@ -86,6 +86,11 @@ struct fd {
struct {
int num;
} devpts;
struct {
struct tmp_dirent *dirent;
struct tmp_dirent *dir_pos;
} tmpfs;
void *fs_data;
};

// fs/inode data
Expand Down
1 change: 1 addition & 0 deletions fs/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const struct fs_ops *filesystems[] = {
&realfs,
&procfs,
&devptsfs,
&tmpfs,
};

struct mount *mount_find(char *path) {
Expand Down
20 changes: 20 additions & 0 deletions fs/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,23 @@ bool path_is_normalized(const char *path) {
}
return true;
}

bool path_next_component(const char **path, char *component, int *err) {
const char *p = *path;
if (*p == '\0')
return false;

assert(*p == '/');
p++;
char *c = component;
while (*p != '/' && *p != '\0') {
*c++ = *p++;
if (c - component >= MAX_NAME) {
*err = _ENAMETOOLONG;
return false;
}
}
*c = '\0';
*path = p;
return true;
}
11 changes: 11 additions & 0 deletions fs/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@
int path_normalize(struct fd *at, const char *path, char *out, int flags);
bool path_is_normalized(const char *path);

// Helper function for iterating through a normalized path.
//
// The *path pointer is advanced to point to the next /, and the next path
// component is copied to component. component must point to a buffer large
// enough to hold a string of MAX_NAME characters.
//
// If the next path component was successfully copied, returns true; otherwise
// returns false. If an error occurred, *err is set to the error code.
// Otherwise, the end of the path has been reached.
bool path_next_component(const char **path, char *component, int *err);

#endif
18 changes: 5 additions & 13 deletions fs/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@
#include "kernel/calls.h"
#include "kernel/fs.h"
#include "fs/proc.h"
#include "fs/path.h"

static int proc_lookup(const char *path, struct proc_entry *entry) {
entry->meta = &proc_root;
char component[MAX_NAME + 1] = {};
while (*path != '\0') {
char component[MAX_NAME + 1];
int err = 0;
while (path_next_component(&path, component, &err)) {
if (!S_ISDIR(proc_entry_mode(entry)))
return _ENOTDIR;

assert(*path == '/');
path++;
char *c = component;
while (*path != '/' && *path != '\0') {
*c++ = *path++;
if (c - component >= MAX_NAME)
return _ENAMETOOLONG;
}
*c = '\0';

unsigned long index = 0;
struct proc_entry next_entry;
char entry_name[MAX_NAME];
Expand All @@ -42,7 +34,7 @@ static int proc_lookup(const char *path, struct proc_entry *entry) {
found:
*entry = next_entry;
}
return 0;
return err;
}

extern const struct fd_ops procfs_fdops;
Expand Down
Loading

0 comments on commit 823647b

Please sign in to comment.