commit 548181245409811ed56bff19def827b87236f5c0
parent 86f0ac2912865ff0c3956e4bf2e60f605c231668
Author: Drew DeVault <sir@cmpwn.com>
Date: Fri, 22 Oct 2021 10:31:04 +0200
os: add dirfile, refactor dirfdfs somewhat
We don't use this io::mode when opening an io::file.
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
1 file changed, 9 insertions(+), 21 deletions(-)
diff --git a/os/+linux/dirfdfs.ha b/os/+linux/dirfdfs.ha
@@ -111,6 +111,13 @@ export fn dirfdfs_set_getdents_bufsz(fs: *fs::fs, sz: size) void = {
fs.getdents_bufsz = sz;
};
+// Returns an [[io::file]] for this filesystem. This function is not portable.
+export fn dirfile(fs: *fs::fs) io::file = {
+ assert(fs.open == &fs_open);
+ let fs = fs: *os_filesystem;
+ return fs.dirfd;
+};
+
fn errno_to_fs(err: rt::errno) fs::error = switch (err) {
case rt::ENOENT =>
yield errors::noentry;
@@ -133,7 +140,6 @@ case =>
fn _fs_open(
fs: *fs::fs,
path: str,
- mode: io::mode,
oh: *rt::open_how,
) (io::file | fs::error) = {
let fs = fs: *os_filesystem;
@@ -168,7 +174,6 @@ fn fs_open_file(
flags: fs::flags...
) (io::file | fs::error) = {
let oflags = 0;
- let iomode = io::mode::NONE;
if (len(flags) == 0z) {
oflags |= (fs::flags::NOCTTY
| fs::flags::CLOEXEC
@@ -184,19 +189,11 @@ fn fs_open_file(
oflags |= rt::O_DIRECTORY: int;
};
- if ((oflags: fs::flags & fs::flags::RDWR) == fs::flags::RDWR) {
- iomode = io::mode::RDWR;
- } else if ((oflags: fs::flags & fs::flags::WRONLY) == fs::flags::WRONLY) {
- iomode = io::mode::WRITE;
- } else if ((oflags: fs::flags & fs::flags::PATH) != fs::flags::PATH) {
- iomode = io::mode::READ;
- };
-
let oh = rt::open_how {
flags = oflags: u64,
...
};
- return _fs_open(fs, path, iomode, &oh);
+ return _fs_open(fs, path, &oh);
};
fn fs_open(
@@ -212,7 +209,6 @@ fn fs_create_file(
flags: fs::flags...
) (io::file | fs::error) = {
let oflags = 0;
- let iomode = io::mode::NONE;
if (len(flags) == 0z) {
oflags |= (fs::flags::NOCTTY
| fs::flags::CLOEXEC
@@ -223,20 +219,12 @@ fn fs_create_file(
};
oflags |= fs::flags::CREATE: int;
- if ((oflags: fs::flags & fs::flags::RDWR) == fs::flags::RDWR) {
- iomode = io::mode::RDWR;
- } else if ((oflags: fs::flags & fs::flags::WRONLY) == fs::flags::WRONLY) {
- iomode = io::mode::WRITE;
- } else if ((oflags: fs::flags & fs::flags::PATH) != fs::flags::PATH) {
- iomode = io::mode::READ;
- };
-
let oh = rt::open_how {
flags = oflags: u64,
mode = mode: u64,
...
};
- return _fs_open(fs, path, iomode, &oh)?;
+ return _fs_open(fs, path, &oh)?;
};
fn fs_create(