kobako 0.30.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.githooks/linux-tests.sh +29 -0
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +460 -0
- data/Cargo.lock +868 -447
- data/README.md +43 -4
- data/ROADMAP.md +1 -2
- data/crates/kobako-runtime/CHANGELOG.md +309 -0
- data/crates/kobako-runtime/Cargo.toml +58 -11
- data/crates/kobako-runtime/README.md +7 -4
- data/crates/kobako-runtime/src/cred.rs +136 -0
- data/crates/kobako-runtime/src/dispatch.rs +4 -5
- data/crates/kobako-runtime/src/endpoint/buffer.rs +153 -44
- data/crates/kobako-runtime/src/endpoint/dispatch.rs +80 -41
- data/crates/kobako-runtime/src/endpoint/invoke.rs +23 -36
- data/crates/kobako-runtime/src/endpoint.rs +137 -36
- data/crates/kobako-runtime/src/errno.rs +391 -0
- data/crates/kobako-runtime/src/error.rs +31 -10
- data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
- data/crates/kobako-runtime/src/filesystem/bind/fid.rs +300 -22
- data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +101 -29
- data/crates/kobako-runtime/src/filesystem/bind/unicode.rs +109 -0
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +52 -34
- data/crates/kobako-runtime/src/filesystem/bind.rs +812 -447
- data/crates/kobako-runtime/src/filesystem/overlay/file.rs +6 -6
- data/crates/kobako-runtime/src/filesystem/overlay/path.rs +43 -65
- data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +11 -16
- data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +47 -72
- data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +12 -12
- data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +4 -7
- data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +120 -37
- data/crates/kobako-runtime/src/filesystem/overlay.rs +578 -388
- data/crates/kobako-runtime/src/filesystem/pipe.rs +12 -9
- data/crates/kobako-runtime/src/filesystem/rdir.rs +14 -50
- data/crates/kobako-runtime/src/filesystem/testing.rs +31 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +3 -3
- data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +57 -35
- data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +2 -2
- data/crates/kobako-runtime/src/filesystem/tmpfs.rs +219 -173
- data/crates/kobako-runtime/src/filesystem/wrap.rs +36 -52
- data/crates/kobako-runtime/src/filesystem.rs +8 -3
- data/crates/kobako-runtime/src/fork.rs +319 -0
- data/crates/kobako-runtime/src/grant.rs +3 -0
- data/crates/kobako-runtime/src/hashtable.rs +4 -2
- data/crates/kobako-runtime/src/lib.rs +18 -7
- data/crates/kobako-runtime/src/limits.rs +171 -0
- data/crates/kobako-runtime/src/locking/seqlock.rs +29 -3
- data/crates/kobako-runtime/src/locking.rs +518 -113
- data/crates/kobako-runtime/src/memcg.rs +306 -0
- data/crates/kobako-runtime/src/mount.rs +37 -9
- data/crates/kobako-runtime/src/net/backends.rs +43 -0
- data/crates/kobako-runtime/src/net/connections.rs +219 -0
- data/crates/kobako-runtime/src/net/credential.rs +125 -0
- data/crates/kobako-runtime/src/net/egress.rs +180 -0
- data/crates/kobako-runtime/src/net/family.rs +181 -0
- data/crates/kobako-runtime/src/net/http.rs +3165 -0
- data/crates/kobako-runtime/src/net/lookup.rs +385 -0
- data/crates/kobako-runtime/src/net/mock.rs +251 -0
- data/crates/kobako-runtime/src/net/namespace.rs +1368 -0
- data/crates/kobako-runtime/src/net/reactor.rs +626 -0
- data/crates/kobako-runtime/src/net/resolv/darwin.rs +280 -0
- data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +519 -0
- data/crates/kobako-runtime/src/net/resolv/stub.rs +542 -0
- data/crates/kobako-runtime/src/net/resolv/windows.rs +218 -0
- data/crates/kobako-runtime/src/net/resolv.rs +251 -0
- data/crates/kobako-runtime/src/net/skbuff.rs +109 -0
- data/crates/kobako-runtime/src/net/socket.rs +869 -0
- data/crates/kobako-runtime/src/net/task.rs +223 -0
- data/crates/kobako-runtime/src/net/tcp.rs +1840 -0
- data/crates/kobako-runtime/src/net/tls.rs +120 -0
- data/crates/kobako-runtime/src/net/transport.rs +304 -0
- data/crates/kobako-runtime/src/net/udp.rs +1105 -0
- data/crates/kobako-runtime/src/net.rs +45 -0
- data/crates/kobako-runtime/src/network/builder.rs +177 -0
- data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
- data/crates/kobako-runtime/src/network.rs +551 -0
- data/crates/kobako-runtime/src/policy.rs +16 -0
- data/crates/kobako-runtime/src/profile.rs +29 -144
- data/crates/kobako-runtime/src/runtime.rs +3 -5
- data/crates/kobako-runtime/src/sched.rs +338 -51
- data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
- data/crates/kobako-runtime/src/{vfs/cred.rs → security/hooks.rs} +52 -144
- data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
- data/crates/kobako-runtime/src/security.rs +125 -209
- data/crates/kobako-runtime/src/snapshot.rs +121 -2
- data/crates/kobako-runtime/src/vfs/attr.rs +5 -5
- data/crates/kobako-runtime/src/vfs/dentry.rs +210 -117
- data/crates/kobako-runtime/src/vfs/file.rs +243 -248
- data/crates/kobako-runtime/src/vfs/inode.rs +41 -45
- data/crates/kobako-runtime/src/vfs/kern_path.rs +62 -53
- data/crates/kobako-runtime/src/vfs/mount.rs +10 -9
- data/crates/kobako-runtime/src/vfs/namei.rs +1162 -818
- data/crates/kobako-runtime/src/vfs/namespace.rs +245 -0
- data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
- data/crates/kobako-runtime/src/vfs/openat2.rs +3 -3
- data/crates/kobako-runtime/src/vfs/path.rs +6 -6
- data/crates/kobako-runtime/src/vfs/readdir.rs +6 -6
- data/crates/kobako-runtime/src/vfs/stat.rs +248 -23
- data/crates/kobako-runtime/src/vfs/super_block.rs +18 -14
- data/crates/kobako-runtime/src/vfs/utimes.rs +37 -27
- data/crates/kobako-runtime/src/vfs.rs +10 -6
- data/crates/kobako-runtime/src/wait.rs +381 -0
- data/crates/kobako-transport/CHANGELOG.md +38 -0
- data/crates/kobako-transport/Cargo.toml +1 -1
- data/crates/kobako-transport/README.md +3 -4
- data/crates/kobako-transport/src/abi.rs +78 -72
- data/crates/kobako-transport/src/envelope/bytes.rs +17 -6
- data/crates/kobako-transport/src/envelope/call.rs +32 -4
- data/crates/kobako-transport/src/envelope/error_record.rs +21 -0
- data/crates/kobako-transport/src/envelope/name.rs +99 -0
- data/crates/kobako-transport/src/envelope/outcome.rs +9 -9
- data/crates/kobako-transport/src/envelope/preamble.rs +24 -21
- data/crates/kobako-transport/src/envelope/reply.rs +27 -27
- data/crates/kobako-transport/src/envelope/unsupported.rs +10 -10
- data/crates/kobako-transport/src/envelope.rs +13 -8
- data/crates/kobako-wasmtime/CHANGELOG.md +208 -0
- data/crates/kobako-wasmtime/Cargo.toml +47 -7
- data/crates/kobako-wasmtime/README.md +4 -3
- data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
- data/crates/kobako-wasmtime/build.rs +16 -0
- data/crates/kobako-wasmtime/src/abi.rs +18 -37
- data/crates/kobako-wasmtime/src/ambient.rs +43 -19
- data/crates/kobako-wasmtime/src/cache/unix.rs +95 -0
- data/crates/kobako-wasmtime/src/cache/windows.rs +359 -0
- data/crates/kobako-wasmtime/src/cache.rs +106 -113
- data/crates/kobako-wasmtime/src/config.rs +52 -68
- data/crates/kobako-wasmtime/src/driver.rs +80 -82
- data/crates/kobako-wasmtime/src/exports.rs +143 -17
- data/crates/kobako-wasmtime/src/guest.rs +12 -6
- data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
- data/crates/kobako-wasmtime/src/imports.rs +42 -18
- data/crates/kobako-wasmtime/src/instance_pre.rs +4 -4
- data/crates/kobako-wasmtime/src/invocation.rs +91 -15
- data/crates/kobako-wasmtime/src/lib.rs +7 -3
- data/crates/kobako-wasmtime/src/limiter.rs +130 -12
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +305 -0
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +9 -20
- data/crates/kobako-wasmtime/src/preview1/differential.rs +27 -31
- data/crates/kobako-wasmtime/src/preview1/errno.rs +55 -66
- data/crates/kobako-wasmtime/src/preview1/fd.rs +347 -312
- data/crates/kobako-wasmtime/src/preview1/memory.rs +21 -12
- data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +34 -53
- data/crates/kobako-wasmtime/src/preview1/mount_view.rs +335 -388
- data/crates/kobako-wasmtime/src/preview1/path.rs +56 -121
- data/crates/kobako-wasmtime/src/preview1/poll.rs +255 -125
- data/crates/kobako-wasmtime/src/preview1/random.rs +125 -0
- data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -8
- data/crates/kobako-wasmtime/src/preview1/testing.rs +31 -0
- data/crates/kobako-wasmtime/src/preview1/testsuite.rs +5 -15
- data/crates/kobako-wasmtime/src/preview1.rs +131 -51
- data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
- data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
- data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
- data/crates/kobako-wasmtime/src/preview2/host.rs +4319 -0
- data/crates/kobako-wasmtime/src/preview2/http.rs +1587 -0
- data/crates/kobako-wasmtime/src/preview2/io.rs +328 -0
- data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
- data/crates/kobako-wasmtime/src/preview2/table.rs +257 -0
- data/crates/kobako-wasmtime/src/preview2.rs +57 -0
- data/crates/kobako-wasmtime/src/trap.rs +88 -28
- data/crates/kobako-wasmtime/src/waits.rs +59 -0
- data/crates/kobako-wasmtime/src/wasi.rs +291 -81
- data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
- data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
- data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
- data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
- data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
- data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
- data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
- data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +13 -0
- data/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +6 -2
- data/ext/kobako/src/{runtime/errors.rs → errors.rs} +34 -26
- data/ext/kobako/src/escape.rs +404 -0
- data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +34 -32
- data/ext/kobako/src/{runtime/filesystem → filesystem}/ruby.rs +158 -170
- data/ext/kobako/src/{runtime/filesystem.rs → filesystem.rs} +71 -23
- data/ext/kobako/src/fork.rs +72 -0
- data/ext/kobako/src/gvl.rs +729 -0
- data/ext/kobako/src/handoff.rs +490 -0
- data/ext/kobako/src/lib.rs +74 -3
- data/ext/kobako/src/network/mock.rs +187 -0
- data/ext/kobako/src/network.rs +593 -0
- data/ext/kobako/src/pinned_value.rs +44 -0
- data/ext/kobako/src/runtime/bridge.rs +58 -50
- data/ext/kobako/src/runtime/snapshot.rs +4 -4
- data/ext/kobako/src/runtime.rs +272 -163
- data/ext/kobako/src/wire.rs +42 -0
- data/lib/kobako/catalog/extensions.rb +14 -2
- data/lib/kobako/catalog/flags.rb +3 -5
- data/lib/kobako/catalog/grants.rb +5 -4
- data/lib/kobako/catalog/handles.rb +14 -32
- data/lib/kobako/catalog/mount.rb +11 -3
- data/lib/kobako/catalog/network.rb +35 -0
- data/lib/kobako/catalog/replacements.rb +28 -0
- data/lib/kobako/catalog/services.rb +5 -19
- data/lib/kobako/catalog/snippets.rb +3 -18
- data/lib/kobako/catalog.rb +3 -0
- data/lib/kobako/codec/{utils.rb → boundary.rb} +4 -2
- data/lib/kobako/codec/decoder.rb +5 -5
- data/lib/kobako/codec/ext_types.rb +3 -3
- data/lib/kobako/codec/handle_walk.rb +3 -43
- data/lib/kobako/codec/state.rb +2 -18
- data/lib/kobako/codec/value_budget.rb +133 -41
- data/lib/kobako/codec.rb +6 -7
- data/lib/kobako/context.rb +24 -11
- data/lib/kobako/errors.rb +18 -18
- data/lib/kobako/extension.rb +3 -2
- data/lib/kobako/filesystem.rb +10 -3
- data/lib/kobako/fork.rb +42 -0
- data/lib/kobako/handle.rb +2 -3
- data/lib/kobako/names.rb +28 -0
- data/lib/kobako/network.rb +210 -0
- data/lib/kobako/outcome.rb +7 -7
- data/lib/kobako/runtime.rb +3 -2
- data/lib/kobako/sandbox.rb +73 -35
- data/lib/kobako/sandbox_options.rb +42 -109
- data/lib/kobako/transport/argument_wrap.rb +64 -0
- data/lib/kobako/transport/block_failure.rb +1 -1
- data/lib/kobako/transport/dispatcher.rb +6 -6
- data/lib/kobako/transport/exposure.rb +26 -15
- data/lib/kobako/transport/reflection.rb +21 -4
- data/lib/kobako/transport/run.rb +8 -23
- data/lib/kobako/transport/yielder.rb +2 -9
- data/lib/kobako/transport.rb +1 -0
- data/lib/kobako/usage.rb +4 -2
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +8 -4
- data/release-please-config.json +15 -0
- data/sig/kobako/catalog/extensions.rbs +2 -0
- data/sig/kobako/catalog/grants.rbs +7 -4
- data/sig/kobako/catalog/handles.rbs +2 -2
- data/sig/kobako/catalog/mount.rbs +3 -1
- data/sig/kobako/catalog/network.rbs +20 -0
- data/sig/kobako/catalog/replacements.rbs +14 -0
- data/sig/kobako/catalog/services.rbs +0 -4
- data/sig/kobako/catalog/snippets.rbs +0 -2
- data/sig/kobako/codec/{utils.rbs → boundary.rbs} +2 -2
- data/sig/kobako/codec/handle_walk.rbs +0 -6
- data/sig/kobako/codec/state.rbs +0 -4
- data/sig/kobako/codec/value_budget.rbs +48 -5
- data/sig/kobako/codec.rbs +2 -2
- data/sig/kobako/context.rbs +3 -1
- data/sig/kobako/errors.rbs +4 -7
- data/sig/kobako/filesystem.rbs +21 -3
- data/sig/kobako/fork.rbs +17 -0
- data/sig/kobako/network.rbs +115 -0
- data/sig/kobako/outcome.rbs +1 -1
- data/sig/kobako/runtime.rbs +32 -3
- data/sig/kobako/sandbox.rbs +10 -2
- data/sig/kobako/sandbox_options.rbs +29 -40
- data/sig/kobako/transport/argument_wrap.rbs +15 -0
- data/sig/kobako/transport/error.rbs +1 -1
- data/sig/kobako/transport/exposure.rbs +2 -4
- data/sig/kobako/transport/reflection.rbs +10 -0
- data/sig/kobako/transport/run.rbs +0 -2
- data/sig/kobako/transport/yielder.rbs +0 -3
- data/sig/kobako/transport.rbs +1 -1
- data/sig/kobako.rbs +13 -0
- metadata +97 -37
- data/crates/kobako-runtime/src/endpoint/capture.rs +0 -115
- data/crates/kobako-runtime/src/endpoint/memory_cap.rs +0 -238
- data/crates/kobako-runtime/src/filesystem/path.rs +0 -21
- data/crates/kobako-runtime/src/vfs/errno.rs +0 -153
- data/crates/kobako-runtime/tests/linux_baseline/calls.rs +0 -171
- data/crates/kobako-runtime/tests/linux_baseline/concurrent.rs +0 -276
- data/crates/kobako-runtime/tests/linux_baseline/kobako.rs +0 -323
- data/crates/kobako-runtime/tests/linux_baseline/linux-baseline-expected.txt +0 -16
- data/crates/kobako-runtime/tests/linux_baseline/linux.rs +0 -449
- data/crates/kobako-runtime/tests/linux_baseline/main.rs +0 -611
- data/crates/kobako-runtime/tests/linux_baseline/permissions.rs +0 -236
- data/crates/kobako-wasmtime/src/descriptors.rs +0 -200
- data/crates/kobako-wasmtime/tests/integration/compile_posture.rs +0 -43
- data/crates/kobako-wasmtime/tests/integration/guest_file.rs +0 -1085
- data/crates/kobako-wasmtime/tests/integration/main.rs +0 -29
- data/crates/kobako-wasmtime/tests/integration/preamble_flags.rs +0 -70
- data/crates/kobako-wasmtime/tests/integration/snippet_compile.rs +0 -95
- data/crates/kobako-wasmtime/tests/integration/support/mod.rs +0 -30
- data/crates/kobako-wasmtime/tests/integration/unanswered_call.rs +0 -86
- data/crates/kobako-wasmtime/tests/integration/unsupported_call.rs +0 -51
- data/ext/kobako/src/runtime/escape.rs +0 -67
- data/ext/kobako/src/runtime/gvl.rs +0 -147
- data/ext/kobako/src/runtime/pinned_value.rs +0 -31
- data/lib/kobako/constant_name.rb +0 -8
- data/lib/kobako/pool.rb +0 -140
- data/sig/kobako/constant_name.rbs +0 -3
- data/sig/kobako/pool.rbs +0 -42
|
@@ -16,16 +16,18 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
|
|
16
16
|
|
|
17
17
|
use kobako_runtime::filesystem::Rdir;
|
|
18
18
|
use kobako_runtime::filesystem::{
|
|
19
|
-
DentryOperations, DirEntry, FileOperations, FileSystemType, FileType, Filesystem,
|
|
20
|
-
|
|
19
|
+
DentryOperations, DirEntry, FileOperations, FileSystemType, FileType, Filesystem, Finish,
|
|
20
|
+
Iattr, InodeOperations, Kiocb, Kstat, Lookup, OpenHow, RenameFlag,
|
|
21
21
|
};
|
|
22
22
|
use kobako_runtime::vfs::{
|
|
23
|
-
generic_file_llseek, generic_read_dir, generic_write_sync,
|
|
24
|
-
DirContext, Identity, Inode, Whence, NAME_MAX,
|
|
23
|
+
generic_file_llseek, generic_read_dir, generic_write_sync, get_anon_bdev, verify_dirent_name,
|
|
24
|
+
Dentry, DirContext, Identity, Inode, Whence, NAME_MAX,
|
|
25
25
|
};
|
|
26
|
+
use kobako_runtime::Errno;
|
|
26
27
|
|
|
27
|
-
use crate::
|
|
28
|
-
use crate::
|
|
28
|
+
use crate::errors::errno_of;
|
|
29
|
+
use crate::pinned_value::PinnedValue;
|
|
30
|
+
use crate::{escape, gvl};
|
|
29
31
|
|
|
30
32
|
/// The Ruby object behind a Mount or a Layer. Whatever holds it on the
|
|
31
33
|
/// Ruby side keeps it alive and in place: the invocation pinning its
|
|
@@ -39,39 +41,43 @@ pub(crate) struct RubyFilesystem {
|
|
|
39
41
|
/// The device a stat without a `dev` names, the object's own, shared by
|
|
40
42
|
/// every directory opened beneath it.
|
|
41
43
|
dev: u64,
|
|
44
|
+
/// Whether the object's `exclusive?` answers true.
|
|
45
|
+
exclusive: bool,
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
impl RubyFilesystem {
|
|
45
|
-
/// The object as a Filesystem, when it answers `open` and `stat
|
|
46
|
-
|
|
49
|
+
/// The object as a Filesystem, when it answers `open` and `stat`; what
|
|
50
|
+
/// its `exclusive?` raises comes back to the mount.
|
|
51
|
+
pub(crate) fn from_value(value: Value) -> Result<Option<Self>, magnus::Error> {
|
|
47
52
|
let answers = |name| value.respond_to(name, false).unwrap_or(false);
|
|
48
|
-
(answers("open") && answers("stat"))
|
|
53
|
+
if !(answers("open") && answers("stat")) {
|
|
54
|
+
return Ok(None);
|
|
55
|
+
}
|
|
56
|
+
let exclusive =
|
|
57
|
+
answers("exclusive?") && value.funcall::<_, _, Value>("exclusive?", ())?.to_bool();
|
|
58
|
+
Ok(Some(Self {
|
|
49
59
|
object: Opaque::from(value),
|
|
50
|
-
dev:
|
|
51
|
-
|
|
60
|
+
dev: get_anon_bdev(),
|
|
61
|
+
exclusive,
|
|
62
|
+
}))
|
|
52
63
|
}
|
|
53
64
|
|
|
54
65
|
/// What the object's `stat` answers for `path`.
|
|
55
|
-
fn stat(&self, path: String) -> Result<Kstat,
|
|
66
|
+
fn stat(&self, path: String) -> Result<Kstat, Errno> {
|
|
56
67
|
let own_dev = self.dev;
|
|
57
|
-
ask(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
own_dev
|
|
71
|
-
};
|
|
72
|
-
with_stat_record(stat, kstat.with_identity(dev, stat.funcall("ino", ())?))
|
|
73
|
-
},
|
|
74
|
-
)
|
|
68
|
+
ask(self.object, "stat", Errno::Unsupported, |_, fs| {
|
|
69
|
+
let stat: Value = fs.funcall("stat", (path,))?;
|
|
70
|
+
let kstat = Kstat::new(kind_of(stat)?, stat.funcall("size", ())?);
|
|
71
|
+
// A stat names its identity as `File::Stat` does; without a
|
|
72
|
+
// `dev` the Filesystem stands for a device of its own, so it
|
|
73
|
+
// shares an identity with no other Filesystem.
|
|
74
|
+
let dev = if stat.respond_to("dev", false)? {
|
|
75
|
+
stat.funcall("dev", ())?
|
|
76
|
+
} else {
|
|
77
|
+
own_dev
|
|
78
|
+
};
|
|
79
|
+
with_stat_record(stat, kstat.with_identity(dev, stat.funcall("ino", ())?))
|
|
80
|
+
})
|
|
75
81
|
}
|
|
76
82
|
}
|
|
77
83
|
|
|
@@ -115,9 +121,9 @@ fn with_stat_record(stat: Value, kstat: Kstat) -> Result<Kstat, MagnusError> {
|
|
|
115
121
|
fn ask<T>(
|
|
116
122
|
object: Opaque<Value>,
|
|
117
123
|
name: &str,
|
|
118
|
-
missing:
|
|
124
|
+
missing: Errno,
|
|
119
125
|
answer: impl FnOnce(&Ruby, Value) -> Result<T, MagnusError>,
|
|
120
|
-
) -> Result<T,
|
|
126
|
+
) -> Result<T, Errno> {
|
|
121
127
|
ask_or(object, name, Err(missing), answer)
|
|
122
128
|
}
|
|
123
129
|
|
|
@@ -125,9 +131,9 @@ fn ask<T>(
|
|
|
125
131
|
fn ask_or<T>(
|
|
126
132
|
object: Opaque<Value>,
|
|
127
133
|
name: &str,
|
|
128
|
-
missing: Result<T,
|
|
134
|
+
missing: Result<T, Errno>,
|
|
129
135
|
answer: impl FnOnce(&Ruby, Value) -> Result<T, MagnusError>,
|
|
130
|
-
) -> Result<T,
|
|
136
|
+
) -> Result<T, Errno> {
|
|
131
137
|
gvl::reenter(|| {
|
|
132
138
|
let ruby = Ruby::get().expect("Ruby handle unavailable in a Filesystem call");
|
|
133
139
|
let object: Value = ruby.get_inner(object);
|
|
@@ -137,9 +143,11 @@ fn ask_or<T>(
|
|
|
137
143
|
answer(&ruby, object).map_err(|err| match escape::hold(&ruby, err) {
|
|
138
144
|
Err(err) => to_error(err),
|
|
139
145
|
// The invocation ends before the guest reads this.
|
|
140
|
-
Ok(()) =>
|
|
146
|
+
Ok(()) => Errno::Other(String::new()),
|
|
141
147
|
})
|
|
142
148
|
})
|
|
149
|
+
// Nothing of the run's caller is left to ask.
|
|
150
|
+
.unwrap_or_else(|| Err(Errno::Other(String::new())))
|
|
143
151
|
}
|
|
144
152
|
|
|
145
153
|
/// Ask `object` a change, answering nothing more than whether it was made.
|
|
@@ -147,8 +155,8 @@ fn change(
|
|
|
147
155
|
object: Opaque<Value>,
|
|
148
156
|
name: &str,
|
|
149
157
|
args: impl magnus::ArgList,
|
|
150
|
-
missing:
|
|
151
|
-
) -> Result<(),
|
|
158
|
+
missing: Errno,
|
|
159
|
+
) -> Result<(), Errno> {
|
|
152
160
|
ask(object, name, missing, |_, object| {
|
|
153
161
|
object.funcall::<_, _, Value>(name, args).map(drop)
|
|
154
162
|
})
|
|
@@ -157,27 +165,18 @@ fn change(
|
|
|
157
165
|
/// Ask `object` a change it may lack, an object lacking `name` having
|
|
158
166
|
/// nothing of its own to change, while one that answers and refuses still
|
|
159
167
|
/// fails, whatever `Errno` it raises.
|
|
160
|
-
fn change_if_answered(object: Opaque<Value>, name: &str) -> Result<(),
|
|
168
|
+
fn change_if_answered(object: Opaque<Value>, name: &str) -> Result<(), Errno> {
|
|
161
169
|
ask_or(object, name, Ok(()), |_, object| {
|
|
162
170
|
object.funcall::<_, _, Value>(name, ()).map(drop)
|
|
163
171
|
})
|
|
164
172
|
}
|
|
165
173
|
|
|
166
|
-
///
|
|
167
|
-
///
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
.class()
|
|
173
|
-
.ancestors()
|
|
174
|
-
.into_iter()
|
|
175
|
-
.find_map(|module| {
|
|
176
|
-
let name: Option<String> = module.funcall("name", ()).ok()?;
|
|
177
|
-
FilesystemError::from_posix_name(name?.strip_prefix("Errno::")?)
|
|
178
|
-
})
|
|
179
|
-
});
|
|
180
|
-
named.unwrap_or_else(|| FilesystemError::Other(err.to_string()))
|
|
174
|
+
/// What the nearest Ruby `Errno` class of `err` stands for; anything else is
|
|
175
|
+
/// `Other`, which reaches the guest as `EIO`.
|
|
176
|
+
fn to_error(err: MagnusError) -> Errno {
|
|
177
|
+
err.value()
|
|
178
|
+
.and_then(|exception| errno_of(exception.class()))
|
|
179
|
+
.unwrap_or_else(|| Errno::Other(err.to_string()))
|
|
181
180
|
}
|
|
182
181
|
|
|
183
182
|
/// `File::Constants` flags for `how`, read from Ruby since their
|
|
@@ -245,17 +244,12 @@ impl RubyFilesystem {
|
|
|
245
244
|
dentry: &Dentry,
|
|
246
245
|
how: &OpenHow,
|
|
247
246
|
create: bool,
|
|
248
|
-
) -> Result<Box<dyn FileOperations>,
|
|
247
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
249
248
|
let path = path_of(dentry);
|
|
250
|
-
let file = ask(
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|ruby, fs| {
|
|
255
|
-
let file: Value = fs.funcall("open", (path, to_flags(ruby, how, create)?))?;
|
|
256
|
-
Ok(RubyFile::pin(ruby, file))
|
|
257
|
-
},
|
|
258
|
-
)?;
|
|
249
|
+
let file = ask(self.object, "open", Errno::Unsupported, |ruby, fs| {
|
|
250
|
+
let file: Value = fs.funcall("open", (path, to_flags(ruby, how, create)?))?;
|
|
251
|
+
Ok(RubyFile::pin(file))
|
|
252
|
+
})?;
|
|
259
253
|
match dentry.inode().map(|inode| inode.identity()) {
|
|
260
254
|
None => {
|
|
261
255
|
let made = self.stat(path_of(dentry))?;
|
|
@@ -265,12 +259,12 @@ impl RubyFilesystem {
|
|
|
265
259
|
// another entry than the one judged, as `Bind::open_file` finds.
|
|
266
260
|
Some(Some(identity)) => {
|
|
267
261
|
if Identity::of(&self.stat(path_of(dentry))?) != Some(identity) {
|
|
268
|
-
return Err(
|
|
262
|
+
return Err(Errno::NotFound);
|
|
269
263
|
}
|
|
270
264
|
}
|
|
271
265
|
Some(None) => {}
|
|
272
266
|
}
|
|
273
|
-
let inode = dentry.inode().ok_or(
|
|
267
|
+
let inode = dentry.inode().ok_or(Errno::NotFound)?;
|
|
274
268
|
let kept = inode
|
|
275
269
|
.private()
|
|
276
270
|
.get_or_init(|| Arc::new(OpenRubyFile::default()))
|
|
@@ -285,21 +279,19 @@ impl RubyFilesystem {
|
|
|
285
279
|
/// about, as it could name a path the object would answer for, and a name
|
|
286
280
|
/// gone by the time it is asked about is one the listing no longer holds, as
|
|
287
281
|
/// any listing is a moment that may have passed.
|
|
288
|
-
fn entries_at(&self, dentry: &Dentry) -> Result<Vec<DirEntry>,
|
|
282
|
+
fn entries_at(&self, dentry: &Dentry) -> Result<Vec<DirEntry>, Errno> {
|
|
289
283
|
let at = path_of(dentry);
|
|
290
|
-
let names: Vec<String> = ask(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
FilesystemError::Unsupported,
|
|
294
|
-
|_, fs| fs.funcall("children", (at.as_str(),)),
|
|
295
|
-
)?;
|
|
284
|
+
let names: Vec<String> = ask(self.object, "children", Errno::Unsupported, |_, fs| {
|
|
285
|
+
fs.funcall("children", (at.as_str(),))
|
|
286
|
+
})?;
|
|
296
287
|
names.iter().try_for_each(|name| verify_dirent_name(name))?;
|
|
297
288
|
let mut entries = Vec::with_capacity(names.len());
|
|
298
289
|
for name in names {
|
|
290
|
+
kobako_runtime::sched::stop_if_fatal()?;
|
|
299
291
|
match self.stat(join(&at, &name)) {
|
|
300
292
|
Ok(stat) => entries
|
|
301
293
|
.push(DirEntry::new(name, stat.file_type).with_identity(stat.dev, stat.ino)),
|
|
302
|
-
Err(
|
|
294
|
+
Err(Errno::NotFound) => {}
|
|
303
295
|
Err(err) => return Err(err),
|
|
304
296
|
}
|
|
305
297
|
}
|
|
@@ -312,12 +304,12 @@ impl RubyFilesystem {
|
|
|
312
304
|
struct RubyLink(RubyFilesystem);
|
|
313
305
|
|
|
314
306
|
impl InodeOperations for RubyLink {
|
|
315
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
307
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
316
308
|
self.0.stat(path_of(dentry))
|
|
317
309
|
}
|
|
318
310
|
|
|
319
|
-
fn get_link(&self, _dentry: &Dentry) -> Result<String,
|
|
320
|
-
Err(
|
|
311
|
+
fn get_link(&self, _dentry: &Dentry) -> Result<String, Errno> {
|
|
312
|
+
Err(Errno::FilesystemLoop)
|
|
321
313
|
}
|
|
322
314
|
}
|
|
323
315
|
|
|
@@ -328,23 +320,18 @@ impl InodeOperations for RubyRegular {
|
|
|
328
320
|
/// A file open here answers for itself even once its name is gone, as 9p
|
|
329
321
|
/// asks an open fid: its `size`, and its `stat` where it has one. It stays
|
|
330
322
|
/// the entry its lookup recorded; anything else is asked by its path.
|
|
331
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
323
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
332
324
|
let Some(file) = find_open_file(dentry) else {
|
|
333
325
|
return self.0.stat(path_of(dentry));
|
|
334
326
|
};
|
|
335
|
-
let metadata = ask(
|
|
336
|
-
file.
|
|
337
|
-
"
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
} else {
|
|
344
|
-
Ok(metadata)
|
|
345
|
-
}
|
|
346
|
-
},
|
|
347
|
-
)?;
|
|
327
|
+
let metadata = ask(file.get(), "size", Errno::Unsupported, |_, file| {
|
|
328
|
+
let metadata = Kstat::new(FileType::RegFile, file.funcall("size", ())?);
|
|
329
|
+
if file.respond_to("stat", false)? {
|
|
330
|
+
with_stat_record(file.funcall("stat", ())?, metadata)
|
|
331
|
+
} else {
|
|
332
|
+
Ok(metadata)
|
|
333
|
+
}
|
|
334
|
+
})?;
|
|
348
335
|
Ok(match dentry.inode().and_then(|inode| inode.identity()) {
|
|
349
336
|
Some(identity) => identity.onto(metadata),
|
|
350
337
|
None => metadata,
|
|
@@ -354,27 +341,18 @@ impl InodeOperations for RubyRegular {
|
|
|
354
341
|
/// A Ruby object was handed `TRUNC` as it opened the file, so an open asking
|
|
355
342
|
/// to truncate has nothing left to ask, as `fuse_do_setattr` finds with
|
|
356
343
|
/// `atomic_o_trunc`.
|
|
357
|
-
fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(),
|
|
344
|
+
fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(), Errno> {
|
|
358
345
|
let Some(len) = attr.size else {
|
|
359
|
-
return Err(
|
|
346
|
+
return Err(Errno::Unsupported);
|
|
360
347
|
};
|
|
361
348
|
if attr.open {
|
|
362
349
|
return Ok(());
|
|
363
350
|
}
|
|
364
|
-
let file = find_open_file(dentry).ok_or(
|
|
365
|
-
change(
|
|
366
|
-
file.get(),
|
|
367
|
-
"truncate",
|
|
368
|
-
(len,),
|
|
369
|
-
FilesystemError::ReadOnlyFilesystem,
|
|
370
|
-
)
|
|
351
|
+
let file = find_open_file(dentry).ok_or(Errno::InvalidInput)?;
|
|
352
|
+
change(file.get(), "truncate", (len,), Errno::ReadOnlyFilesystem)
|
|
371
353
|
}
|
|
372
354
|
|
|
373
|
-
fn open(
|
|
374
|
-
&self,
|
|
375
|
-
dentry: &Dentry,
|
|
376
|
-
how: &OpenHow,
|
|
377
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
355
|
+
fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
378
356
|
self.0.open_at(dentry, how, false)
|
|
379
357
|
}
|
|
380
358
|
}
|
|
@@ -382,7 +360,7 @@ impl InodeOperations for RubyRegular {
|
|
|
382
360
|
/// Its root reports no identity without asking the Ruby object, as FUSE makes its
|
|
383
361
|
/// root from fixed attributes rather than ask the server.
|
|
384
362
|
impl FileSystemType for RubyFilesystem {
|
|
385
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
363
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
386
364
|
sb.set_default_d_op(self.clone());
|
|
387
365
|
sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
|
|
388
366
|
Ok(())
|
|
@@ -392,15 +370,15 @@ impl FileSystemType for RubyFilesystem {
|
|
|
392
370
|
/// A directory of a Ruby Filesystem, asked by the path a dentry stands at, the
|
|
393
371
|
/// path a Policy judges.
|
|
394
372
|
impl InodeOperations for RubyFilesystem {
|
|
395
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
373
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
396
374
|
self.stat(path_of(dentry))
|
|
397
375
|
}
|
|
398
376
|
|
|
399
377
|
/// A Ruby object matches names exactly, as its contract asks. A lookup
|
|
400
378
|
/// asks its `stat` what stands at the name, as FUSE asks its daemon.
|
|
401
|
-
fn lookup(&self, dentry: &Dentry) -> Result<Lookup,
|
|
379
|
+
fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
402
380
|
if dentry.name().len() > NAME_MAX {
|
|
403
|
-
return Err(
|
|
381
|
+
return Err(Errno::InvalidFilename);
|
|
404
382
|
}
|
|
405
383
|
match self.stat(path_of(dentry)) {
|
|
406
384
|
Ok(found) => {
|
|
@@ -411,18 +389,14 @@ impl InodeOperations for RubyFilesystem {
|
|
|
411
389
|
};
|
|
412
390
|
Ok(Lookup::Found(Inode::new(&found, ops)))
|
|
413
391
|
}
|
|
414
|
-
Err(
|
|
392
|
+
Err(Errno::NotFound) => Ok(Lookup::Absent),
|
|
415
393
|
Err(err) => Err(err),
|
|
416
394
|
}
|
|
417
395
|
}
|
|
418
396
|
|
|
419
397
|
/// A directory opens without asking the object anything; it is asked
|
|
420
398
|
/// for the names only when the guest lists them.
|
|
421
|
-
fn open(
|
|
422
|
-
&self,
|
|
423
|
-
_dentry: &Dentry,
|
|
424
|
-
_how: &OpenHow,
|
|
425
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
399
|
+
fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
426
400
|
Ok(Box::new(RubyDir(*self, Rdir::default())))
|
|
427
401
|
}
|
|
428
402
|
|
|
@@ -430,7 +404,7 @@ impl InodeOperations for RubyFilesystem {
|
|
|
430
404
|
/// name is left to the runtime unless the open may make it and nothing
|
|
431
405
|
/// stands there, as FUSE's `fuse_atomic_open` looks the name up before it
|
|
432
406
|
/// creates.
|
|
433
|
-
fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish,
|
|
407
|
+
fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, Errno> {
|
|
434
408
|
if dentry.in_lookup() {
|
|
435
409
|
let found = self.lookup(dentry)?;
|
|
436
410
|
if !how.create || !matches!(found, Lookup::Absent) {
|
|
@@ -447,30 +421,30 @@ impl InodeOperations for RubyFilesystem {
|
|
|
447
421
|
})
|
|
448
422
|
}
|
|
449
423
|
|
|
450
|
-
fn mkdir(&self, dentry: &Dentry) -> Result<(),
|
|
424
|
+
fn mkdir(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
451
425
|
change(
|
|
452
426
|
self.object,
|
|
453
427
|
"mkdir",
|
|
454
428
|
(path_of(dentry),),
|
|
455
|
-
|
|
429
|
+
Errno::ReadOnlyFilesystem,
|
|
456
430
|
)
|
|
457
431
|
}
|
|
458
432
|
|
|
459
|
-
fn rmdir(&self, dentry: &Dentry) -> Result<(),
|
|
433
|
+
fn rmdir(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
460
434
|
change(
|
|
461
435
|
self.object,
|
|
462
436
|
"rmdir",
|
|
463
437
|
(path_of(dentry),),
|
|
464
|
-
|
|
438
|
+
Errno::ReadOnlyFilesystem,
|
|
465
439
|
)
|
|
466
440
|
}
|
|
467
441
|
|
|
468
|
-
fn unlink(&self, dentry: &Dentry) -> Result<(),
|
|
442
|
+
fn unlink(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
469
443
|
change(
|
|
470
444
|
self.object,
|
|
471
445
|
"unlink",
|
|
472
446
|
(path_of(dentry),),
|
|
473
|
-
|
|
447
|
+
Errno::ReadOnlyFilesystem,
|
|
474
448
|
)
|
|
475
449
|
}
|
|
476
450
|
|
|
@@ -479,19 +453,19 @@ impl InodeOperations for RubyFilesystem {
|
|
|
479
453
|
/// directories are of one object, which their shared device names.
|
|
480
454
|
fn rename(
|
|
481
455
|
&self,
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
) -> Result<(),
|
|
487
|
-
if
|
|
488
|
-
return Err(
|
|
456
|
+
old: &Dentry,
|
|
457
|
+
_new_dir: &dyn InodeOperations,
|
|
458
|
+
new: &Dentry,
|
|
459
|
+
flags: Option<RenameFlag>,
|
|
460
|
+
) -> Result<(), Errno> {
|
|
461
|
+
if flags.is_some() {
|
|
462
|
+
return Err(Errno::InvalidInput);
|
|
489
463
|
}
|
|
490
464
|
change(
|
|
491
465
|
self.object,
|
|
492
466
|
"rename",
|
|
493
|
-
(path_of(
|
|
494
|
-
|
|
467
|
+
(path_of(old), path_of(new)),
|
|
468
|
+
Errno::ReadOnlyFilesystem,
|
|
495
469
|
)
|
|
496
470
|
}
|
|
497
471
|
}
|
|
@@ -507,30 +481,30 @@ impl FileOperations for RubyDir {
|
|
|
507
481
|
pos: u64,
|
|
508
482
|
offset: i64,
|
|
509
483
|
whence: Whence,
|
|
510
|
-
) -> Result<u64,
|
|
484
|
+
) -> Result<u64, Errno> {
|
|
511
485
|
generic_file_llseek(dentry, pos, offset, whence)
|
|
512
486
|
}
|
|
513
487
|
|
|
514
|
-
fn read_iter(&mut self, _iocb: &mut Kiocb, _buf: &mut [u8]) -> Result<usize,
|
|
488
|
+
fn read_iter(&mut self, _iocb: &mut Kiocb, _buf: &mut [u8]) -> Result<usize, Errno> {
|
|
515
489
|
generic_read_dir()
|
|
516
490
|
}
|
|
517
491
|
|
|
492
|
+
fn has_iterate_shared(&self) -> bool {
|
|
493
|
+
true
|
|
494
|
+
}
|
|
495
|
+
|
|
518
496
|
/// What a listing began with stays on the open directory until it ends, so
|
|
519
497
|
/// a caller reading in small steps asks the object once, as FUSE's readdir
|
|
520
498
|
/// cache spares asking the server each time.
|
|
521
|
-
fn iterate_shared(
|
|
522
|
-
&mut self,
|
|
523
|
-
dentry: &Dentry,
|
|
524
|
-
ctx: &mut DirContext<'_>,
|
|
525
|
-
) -> Result<(), FilesystemError> {
|
|
499
|
+
fn iterate_shared(&mut self, dentry: &Dentry, ctx: &mut DirContext<'_>) -> Result<(), Errno> {
|
|
526
500
|
let filesystem = self.0;
|
|
527
501
|
self.1
|
|
528
|
-
.
|
|
502
|
+
.iterate_shared(dentry, ctx, || filesystem.entries_at(dentry))
|
|
529
503
|
}
|
|
530
504
|
|
|
531
505
|
/// The object has nothing of a directory's own to flush, as FUSE's
|
|
532
506
|
/// `fuse_dir_fsync` answers for a server without `fsyncdir`.
|
|
533
|
-
fn fsync(&mut self, _datasync: bool) -> Result<(),
|
|
507
|
+
fn fsync(&mut self, _datasync: bool) -> Result<(), Errno> {
|
|
534
508
|
Ok(())
|
|
535
509
|
}
|
|
536
510
|
}
|
|
@@ -562,37 +536,42 @@ fn find_open_file(dentry: &Dentry) -> Option<Arc<PinnedValue>> {
|
|
|
562
536
|
|
|
563
537
|
/// The backend changes outside the runtime, so a dentry someone holds is
|
|
564
538
|
/// asked again, as FUSE compares what a fresh lookup finds, and one no longer
|
|
565
|
-
/// naming what it recorded gets a new one. An
|
|
566
|
-
///
|
|
539
|
+
/// naming what it recorded gets a new one. An object whose `exclusive?` answers
|
|
540
|
+
/// true vouches that only the guest changes it, so what was found stands, as
|
|
541
|
+
/// gVisor's exclusive mount skips revalidation. An open file answers for
|
|
542
|
+
/// itself, so a walk finding a dentry one is open on takes one of its own.
|
|
567
543
|
impl DentryOperations for RubyFilesystem {
|
|
568
|
-
fn revalidate(
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
544
|
+
fn revalidate(&self, _dir: &dyn InodeOperations, dentry: &Dentry) -> Result<bool, Errno> {
|
|
545
|
+
if find_open_file(dentry).is_some() {
|
|
546
|
+
return Ok(false);
|
|
547
|
+
}
|
|
548
|
+
if self.exclusive {
|
|
549
|
+
return Ok(true);
|
|
550
|
+
}
|
|
551
|
+
let Some(inode) = dentry.inode() else {
|
|
574
552
|
return Ok(false);
|
|
575
553
|
};
|
|
576
554
|
match self.stat(path_of(dentry)) {
|
|
577
|
-
Ok(found) =>
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
Err(
|
|
555
|
+
Ok(found) => Ok(
|
|
556
|
+
Identity::of(&found) == inode.identity() && found.file_type == inode.file_type()
|
|
557
|
+
),
|
|
558
|
+
Err(Errno::NotFound | Errno::NotADirectory) => Ok(false),
|
|
581
559
|
Err(err) => Err(err),
|
|
582
560
|
}
|
|
583
561
|
}
|
|
584
562
|
|
|
585
563
|
/// Answering whether a name holds costs a `stat`, as finding it does, so
|
|
586
|
-
/// nothing is gained by keeping it, as FUSE's `entry_timeout=0` keeps none
|
|
564
|
+
/// nothing is gained by keeping it, as FUSE's `entry_timeout=0` keeps none;
|
|
565
|
+
/// an exclusive one keeps every name, as nothing asks again.
|
|
587
566
|
fn delete(&self, _dentry: &Dentry) -> bool {
|
|
588
|
-
|
|
567
|
+
!self.exclusive
|
|
589
568
|
}
|
|
590
569
|
}
|
|
591
570
|
|
|
592
571
|
impl RubyFile {
|
|
593
|
-
fn pin(
|
|
572
|
+
fn pin(file: Value) -> Self {
|
|
594
573
|
Self {
|
|
595
|
-
file: Arc::new(PinnedValue::new(
|
|
574
|
+
file: Arc::new(PinnedValue::new(file)),
|
|
596
575
|
closed: false,
|
|
597
576
|
}
|
|
598
577
|
}
|
|
@@ -601,17 +580,17 @@ impl RubyFile {
|
|
|
601
580
|
/// answers where the file then ends, as `IO#pos` does after a write to
|
|
602
581
|
/// a file opened to append. A file lacking it cannot append, since its
|
|
603
582
|
/// `size` and `pwrite` are two steps another writer can land between.
|
|
604
|
-
fn pwrite(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize,
|
|
583
|
+
fn pwrite(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
|
|
605
584
|
let pos = iocb.pos;
|
|
606
585
|
let written = ask(
|
|
607
586
|
self.file.get(),
|
|
608
587
|
"pwrite",
|
|
609
|
-
|
|
588
|
+
Errno::ReadOnlyFilesystem,
|
|
610
589
|
|ruby, file| file.funcall("pwrite", (ruby.str_from_slice(buf), pos)),
|
|
611
590
|
)
|
|
612
591
|
.and_then(|written: usize| match written {
|
|
613
592
|
written if written <= buf.len() => Ok(written),
|
|
614
|
-
written => Err(
|
|
593
|
+
written => Err(Errno::Other(format!(
|
|
615
594
|
"pwrite answered {written} bytes written of the {} it was handed",
|
|
616
595
|
buf.len()
|
|
617
596
|
))),
|
|
@@ -620,15 +599,15 @@ impl RubyFile {
|
|
|
620
599
|
Ok(written)
|
|
621
600
|
}
|
|
622
601
|
|
|
623
|
-
fn append(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize,
|
|
602
|
+
fn append(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
|
|
624
603
|
let end: u64 = ask(
|
|
625
604
|
self.file.get(),
|
|
626
605
|
"append",
|
|
627
|
-
|
|
606
|
+
Errno::Unsupported,
|
|
628
607
|
|ruby, file| file.funcall("append", (ruby.str_from_slice(buf),)),
|
|
629
608
|
)?;
|
|
630
609
|
if end < buf.len() as u64 {
|
|
631
|
-
return Err(
|
|
610
|
+
return Err(Errno::Other(format!(
|
|
632
611
|
"append answered the file ending at {end}, before the {} bytes it wrote",
|
|
633
612
|
buf.len()
|
|
634
613
|
)));
|
|
@@ -639,7 +618,7 @@ impl RubyFile {
|
|
|
639
618
|
|
|
640
619
|
/// Ask the file to close, a file lacking `close` having nothing to
|
|
641
620
|
/// release.
|
|
642
|
-
fn close(&mut self) -> Result<(),
|
|
621
|
+
fn close(&mut self) -> Result<(), Errno> {
|
|
643
622
|
self.closed = true;
|
|
644
623
|
change_if_answered(self.file.get(), "close")
|
|
645
624
|
}
|
|
@@ -652,16 +631,16 @@ impl FileOperations for RubyFile {
|
|
|
652
631
|
pos: u64,
|
|
653
632
|
offset: i64,
|
|
654
633
|
whence: Whence,
|
|
655
|
-
) -> Result<u64,
|
|
634
|
+
) -> Result<u64, Errno> {
|
|
656
635
|
generic_file_llseek(dentry, pos, offset, whence)
|
|
657
636
|
}
|
|
658
637
|
|
|
659
|
-
fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize,
|
|
638
|
+
fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize, Errno> {
|
|
660
639
|
let pos = iocb.pos;
|
|
661
640
|
let read = ask(
|
|
662
641
|
self.file.get(),
|
|
663
642
|
"pread",
|
|
664
|
-
|
|
643
|
+
Errno::Unsupported,
|
|
665
644
|
|ruby, file| {
|
|
666
645
|
// `IO#pread` raises `EOFError` at the end of a file, which reads as nothing.
|
|
667
646
|
let read: Option<RString> = match file.funcall("pread", (buf.len(), pos)) {
|
|
@@ -673,14 +652,23 @@ impl FileOperations for RubyFile {
|
|
|
673
652
|
let bytes = unsafe { read.as_slice() };
|
|
674
653
|
let len = bytes.len().min(buf.len());
|
|
675
654
|
buf[..len].copy_from_slice(&bytes[..len]);
|
|
676
|
-
Ok(len)
|
|
655
|
+
Ok(bytes.len())
|
|
677
656
|
},
|
|
678
|
-
)
|
|
657
|
+
)
|
|
658
|
+
// A reply longer than its request fails the read, as FUSE's
|
|
659
|
+
// `fuse_copy_out_args` does, rather than cut to fit.
|
|
660
|
+
.and_then(|read| match read {
|
|
661
|
+
read if read <= buf.len() => Ok(read),
|
|
662
|
+
read => Err(Errno::Other(format!(
|
|
663
|
+
"pread answered {read} bytes of the {} it was asked for",
|
|
664
|
+
buf.len()
|
|
665
|
+
))),
|
|
666
|
+
})?;
|
|
679
667
|
iocb.pos += read as u64;
|
|
680
668
|
Ok(read)
|
|
681
669
|
}
|
|
682
670
|
|
|
683
|
-
fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize,
|
|
671
|
+
fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
|
|
684
672
|
let written = match iocb.append {
|
|
685
673
|
true => self.append(iocb, buf)?,
|
|
686
674
|
false => self.pwrite(iocb, buf)?,
|
|
@@ -689,11 +677,11 @@ impl FileOperations for RubyFile {
|
|
|
689
677
|
}
|
|
690
678
|
|
|
691
679
|
/// A file lacking `fsync` has nothing of its own to flush.
|
|
692
|
-
fn fsync(&mut self, _datasync: bool) -> Result<(),
|
|
680
|
+
fn fsync(&mut self, _datasync: bool) -> Result<(), Errno> {
|
|
693
681
|
change_if_answered(self.file.get(), "fsync")
|
|
694
682
|
}
|
|
695
683
|
|
|
696
|
-
fn flush(&mut self) -> Result<(),
|
|
684
|
+
fn flush(&mut self) -> Result<(), Errno> {
|
|
697
685
|
self.close()
|
|
698
686
|
}
|
|
699
687
|
}
|