PathlessDirFs
A modern filesystem, built for humans.
What's a DirFs?
A DirFs is a filesystem where everything is both a file and a dir. So, for example, I can have file src/lib.rs with the following contents:
pub mod hello;And file src/lib.rs/hello.rs with the following contents:
pub fn hello() {
println!("hello world!");
}At the same time.
What's a pathless FS?
A pathless FS is an FS where there are no path separators, but there are still paths, built on arrays and array elements rather than path separators.
["a", "b", "c"] in a pathless FS is equivalent to "a/b/c" in a pathful FS.
APIs
This is how PathlessDirFs uses POSIX APIs.
FILE *fopen(const char *pathname, const char *mode); (and friends)
The pathname may only refer to files in the current directory.
int open(const char *path, int oflag, ...);
As above.
int openat(int fd, const char *path, int oflag, ...);
The pathname may only refer to files relative to fd. It may be ...
These give the basis for a functioning PathlessDirFs.
// path is NULL-terminated
FILE *fopenatpath(int fd, const char *path[], const char *mode) {
int i;
for (i = 0; fd >= 0 && path[i+1]; i++) {
fd = openat(fd, path[i], O_SEARCH | O_DIRECTORY); // O_DIRECTORY is a no-op.
}
if (fd < 0) {
errno = -fd;
return NULL;
}
return fopen(path[i], mode);
}[TODO finish this at some point]