forked from ish-app/ish
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move pwd, root, uname out into its own struct
- Loading branch information
Showing
32 changed files
with
303 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#include "kernel/errno.h" | ||
#include "fs/fd.h" | ||
#include "fs/dev.h" | ||
#include "fs/tty.h" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#ifndef FD_H | ||
#define FD_H | ||
#include <dirent.h> | ||
#include "misc.h" | ||
#include "emu/memory.h" | ||
#include "util/list.h" | ||
#include "util/bits.h" | ||
|
||
struct fd { | ||
atomic_uint refcount; | ||
unsigned flags; | ||
const struct fd_ops *ops; | ||
struct list poll_fds; | ||
|
||
// fd data | ||
union { | ||
struct { | ||
DIR *dir; | ||
}; | ||
struct { | ||
struct tty *tty; | ||
// links together fds pointing to the same tty | ||
// locked by the tty | ||
struct list other_fds; | ||
}; | ||
}; | ||
|
||
// fs/inode data | ||
struct mount *mount; | ||
union { | ||
int real_fd; | ||
struct statbuf *stat; | ||
}; | ||
|
||
lock_t lock; | ||
}; | ||
|
||
typedef sdword_t fd_t; | ||
#define FD_CLOEXEC_ 1 | ||
#define AT_FDCWD_ -100 | ||
|
||
struct fd *fd_create(void); | ||
struct fd *fd_retain(struct fd *fd); | ||
int fd_close(struct fd *fd); | ||
|
||
#define NAME_MAX 255 | ||
struct dir_entry { | ||
qword_t inode; | ||
qword_t offset; | ||
char name[NAME_MAX + 1]; | ||
}; | ||
|
||
struct fd_ops { | ||
ssize_t (*read)(struct fd *fd, void *buf, size_t bufsize); | ||
ssize_t (*write)(struct fd *fd, const void *buf, size_t bufsize); | ||
off_t_ (*lseek)(struct fd *fd, off_t_ off, int whence); | ||
|
||
// Reads a directory entry from the stream | ||
int (*readdir)(struct fd *fd, struct dir_entry *entry); | ||
|
||
// map the file | ||
int (*mmap)(struct fd *fd, struct mem *mem, page_t start, pages_t pages, off_t offset, int prot, int flags); | ||
|
||
// returns a bitmask of operations that won't block | ||
int (*poll)(struct fd *fd); | ||
|
||
// returns the size needed for the output of ioctl, 0 if the arg is not a | ||
// pointer, -1 for invalid command | ||
ssize_t (*ioctl_size)(struct fd *fd, int cmd); | ||
// if ioctl_size returns non-zero, arg must point to ioctl_size valid bytes | ||
int (*ioctl)(struct fd *fd, int cmd, void *arg); | ||
|
||
// Returns the path of the file descriptor, buf must be at least MAX_PATH | ||
int (*getpath)(struct fd *fd, char *buf); | ||
|
||
int (*close)(struct fd *fd); | ||
}; | ||
|
||
struct fdtable { | ||
atomic_uint refcount; | ||
unsigned size; | ||
struct fd **files; | ||
bits_t *cloexec; | ||
}; | ||
|
||
struct fdtable *fdtable_new(); | ||
void fdtable_release(struct fdtable *table); | ||
int fdtable_resize(struct fdtable *table, unsigned size); | ||
struct fdtable *fdtable_copy(struct fdtable *table); | ||
void fdtable_free(struct fdtable *table); | ||
|
||
struct fd *f_get(fd_t f); | ||
bool f_is_cloexec(fd_t f); | ||
void f_put(fd_t f, struct fd *fd); | ||
// steals a reference to the fd, gives it to the table on success and destroys it on error | ||
fd_t f_install(struct fd *fd); | ||
int f_close(fd_t f); | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef PATH_H | ||
#define PATH_H | ||
|
||
#define AT_PWD (struct fd *) -2 | ||
|
||
// Normalizes the path specified and writes the result into the out buffer. | ||
// | ||
// Normalization means: | ||
// - prepending the current or root directory | ||
// - converting multiple slashes into one | ||
// - resolving . and .. | ||
// - resolving symlinks, skipping the last path component if the follow_links | ||
// argument is true | ||
// The result will always begin with a slash or be empty. | ||
// | ||
// If the normalized path plus the null terminator would be longer than | ||
// MAX_PATH, _ENAMETOOLONG is returned. The out buffer is expected to be at | ||
// least MAX_PATH in size. | ||
// | ||
// at is the file descriptor to use as a base to interpret relative paths. If | ||
// at is AT_PWD, uses current->pwd (with appropriate locking). | ||
int path_normalize(struct fd *at, const char *path, char *out, bool follow_links); | ||
bool path_is_normalized(const char *path); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.