kobako 0.30.0 → 0.31.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/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +335 -0
- data/Cargo.lock +469 -11
- data/README.md +43 -3
- data/ROADMAP.md +1 -1
- data/crates/kobako-runtime/CHANGELOG.md +219 -0
- data/crates/kobako-runtime/Cargo.toml +51 -3
- data/crates/kobako-runtime/README.md +7 -4
- data/crates/kobako-runtime/src/cred.rs +124 -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/lookup.rs +52 -14
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +19 -20
- data/crates/kobako-runtime/src/filesystem/bind.rs +437 -245
- 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 +9 -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 +121 -37
- data/crates/kobako-runtime/src/filesystem/overlay.rs +302 -343
- data/crates/kobako-runtime/src/filesystem/pipe.rs +12 -9
- data/crates/kobako-runtime/src/filesystem/rdir.rs +15 -32
- 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 +172 -160
- data/crates/kobako-runtime/src/filesystem/wrap.rs +36 -52
- data/crates/kobako-runtime/src/filesystem.rs +6 -3
- data/crates/kobako-runtime/src/fork.rs +96 -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 +195 -0
- data/crates/kobako-runtime/src/locking.rs +10 -0
- data/crates/kobako-runtime/src/memcg.rs +383 -0
- data/crates/kobako-runtime/src/mount.rs +67 -9
- data/crates/kobako-runtime/src/net/backends.rs +43 -0
- data/crates/kobako-runtime/src/net/connections.rs +179 -0
- data/crates/kobako-runtime/src/net/credential.rs +125 -0
- data/crates/kobako-runtime/src/net/egress.rs +160 -0
- data/crates/kobako-runtime/src/net/family.rs +181 -0
- data/crates/kobako-runtime/src/net/http.rs +2733 -0
- data/crates/kobako-runtime/src/net/lookup.rs +285 -0
- data/crates/kobako-runtime/src/net/mock.rs +251 -0
- data/crates/kobako-runtime/src/net/namespace.rs +1366 -0
- data/crates/kobako-runtime/src/net/reactor.rs +531 -0
- data/crates/kobako-runtime/src/net/resolv/darwin.rs +275 -0
- data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +469 -0
- data/crates/kobako-runtime/src/net/resolv/stub.rs +536 -0
- data/crates/kobako-runtime/src/net/resolv/windows.rs +248 -0
- data/crates/kobako-runtime/src/net/resolv.rs +227 -0
- data/crates/kobako-runtime/src/net/socket.rs +870 -0
- data/crates/kobako-runtime/src/net/tcp.rs +1588 -0
- data/crates/kobako-runtime/src/net/tls.rs +58 -0
- data/crates/kobako-runtime/src/net/transport.rs +279 -0
- data/crates/kobako-runtime/src/net/udp.rs +1003 -0
- data/crates/kobako-runtime/src/net.rs +42 -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 +130 -29
- 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 +101 -196
- 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 +143 -89
- data/crates/kobako-runtime/src/vfs/file.rs +199 -203
- data/crates/kobako-runtime/src/vfs/inode.rs +41 -45
- data/crates/kobako-runtime/src/vfs/kern_path.rs +38 -42
- data/crates/kobako-runtime/src/vfs/mount.rs +10 -9
- data/crates/kobako-runtime/src/vfs/namei.rs +829 -700
- data/crates/kobako-runtime/src/vfs/namespace.rs +162 -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 +159 -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 +9 -6
- data/crates/kobako-runtime/src/wait.rs +356 -0
- data/crates/kobako-transport/CHANGELOG.md +31 -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 +161 -0
- data/crates/kobako-wasmtime/Cargo.toml +26 -7
- data/crates/kobako-wasmtime/README.md +3 -2
- data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
- data/crates/kobako-wasmtime/build.rs +16 -0
- data/crates/kobako-wasmtime/src/abi.rs +17 -37
- data/crates/kobako-wasmtime/src/ambient.rs +33 -18
- data/crates/kobako-wasmtime/src/cache.rs +23 -15
- data/crates/kobako-wasmtime/src/config.rs +52 -68
- data/crates/kobako-wasmtime/src/driver.rs +48 -63
- 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 +74 -12
- data/crates/kobako-wasmtime/src/lib.rs +5 -3
- data/crates/kobako-wasmtime/src/limiter.rs +70 -5
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +309 -0
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +5 -15
- 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 +327 -296
- 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 +231 -217
- data/crates/kobako-wasmtime/src/preview1/path.rs +56 -121
- data/crates/kobako-wasmtime/src/preview1/poll.rs +244 -120
- data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -8
- data/crates/kobako-wasmtime/src/preview1/testsuite.rs +5 -15
- data/crates/kobako-wasmtime/src/preview1.rs +46 -42
- 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 +3959 -0
- data/crates/kobako-wasmtime/src/preview2/http.rs +1503 -0
- data/crates/kobako-wasmtime/src/preview2/io.rs +315 -0
- data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
- data/crates/kobako-wasmtime/src/preview2/table.rs +305 -0
- data/crates/kobako-wasmtime/src/preview2.rs +57 -0
- data/crates/kobako-wasmtime/src/trap.rs +24 -9
- data/crates/kobako-wasmtime/src/wasi.rs +210 -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/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +1 -1
- data/ext/kobako/src/{runtime/errors.rs → errors.rs} +34 -26
- data/ext/kobako/src/{runtime/escape.rs → escape.rs} +42 -11
- data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +30 -26
- data/ext/kobako/src/{runtime/filesystem → filesystem}/ruby.rs +149 -168
- data/ext/kobako/src/{runtime/filesystem.rs → filesystem.rs} +24 -15
- data/ext/kobako/src/gvl.rs +306 -0
- data/ext/kobako/src/lib.rs +64 -3
- data/ext/kobako/src/network/mock.rs +187 -0
- data/ext/kobako/src/network.rs +591 -0
- data/ext/kobako/src/runtime/bridge.rs +30 -29
- data/ext/kobako/src/runtime/snapshot.rs +4 -4
- data/ext/kobako/src/runtime.rs +221 -143
- 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 +5 -27
- 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 +4 -4
- data/lib/kobako/codec/ext_types.rb +3 -3
- data/lib/kobako/codec/handle_walk.rb +3 -43
- data/lib/kobako/codec/value_budget.rb +132 -40
- data/lib/kobako/codec.rb +1 -1
- data/lib/kobako/context.rb +24 -11
- data/lib/kobako/errors.rb +15 -12
- data/lib/kobako/extension.rb +3 -2
- data/lib/kobako/filesystem.rb +9 -2
- data/lib/kobako/handle.rb +2 -2
- data/lib/kobako/names.rb +28 -0
- data/lib/kobako/network.rb +210 -0
- data/lib/kobako/outcome.rb +7 -7
- data/lib/kobako/pool.rb +45 -23
- data/lib/kobako/runtime.rb +3 -2
- data/lib/kobako/sandbox.rb +92 -35
- data/lib/kobako/sandbox_options.rb +41 -106
- 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/version.rb +1 -1
- data/lib/kobako.rb +6 -2
- data/release-please-config.json +15 -0
- data/sig/core/thread.rbs +6 -0
- data/sig/kobako/catalog/extensions.rbs +2 -0
- data/sig/kobako/catalog/grants.rbs +7 -4
- data/sig/kobako/catalog/handles.rbs +0 -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/value_budget.rbs +47 -4
- data/sig/kobako/context.rbs +3 -1
- data/sig/kobako/errors.rbs +4 -4
- data/sig/kobako/filesystem.rbs +21 -3
- data/sig/kobako/network.rbs +115 -0
- data/sig/kobako/outcome.rbs +1 -1
- data/sig/kobako/pool.rbs +7 -3
- data/sig/kobako/runtime.rbs +32 -3
- data/sig/kobako/sandbox.rbs +19 -2
- data/sig/kobako/sandbox_options.rbs +29 -38
- 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 +84 -35
- 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/gvl.rs +0 -147
- data/lib/kobako/constant_name.rb +0 -8
- data/sig/kobako/constant_name.rbs +0 -3
- /data/ext/kobako/src/{runtime/pinned_value.rs → pinned_value.rs} +0 -0
|
@@ -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,7 +143,7 @@ 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
|
})
|
|
143
149
|
}
|
|
@@ -147,8 +153,8 @@ fn change(
|
|
|
147
153
|
object: Opaque<Value>,
|
|
148
154
|
name: &str,
|
|
149
155
|
args: impl magnus::ArgList,
|
|
150
|
-
missing:
|
|
151
|
-
) -> Result<(),
|
|
156
|
+
missing: Errno,
|
|
157
|
+
) -> Result<(), Errno> {
|
|
152
158
|
ask(object, name, missing, |_, object| {
|
|
153
159
|
object.funcall::<_, _, Value>(name, args).map(drop)
|
|
154
160
|
})
|
|
@@ -157,27 +163,18 @@ fn change(
|
|
|
157
163
|
/// Ask `object` a change it may lack, an object lacking `name` having
|
|
158
164
|
/// nothing of its own to change, while one that answers and refuses still
|
|
159
165
|
/// fails, whatever `Errno` it raises.
|
|
160
|
-
fn change_if_answered(object: Opaque<Value>, name: &str) -> Result<(),
|
|
166
|
+
fn change_if_answered(object: Opaque<Value>, name: &str) -> Result<(), Errno> {
|
|
161
167
|
ask_or(object, name, Ok(()), |_, object| {
|
|
162
168
|
object.funcall::<_, _, Value>(name, ()).map(drop)
|
|
163
169
|
})
|
|
164
170
|
}
|
|
165
171
|
|
|
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()))
|
|
172
|
+
/// What the nearest Ruby `Errno` class of `err` stands for; anything else is
|
|
173
|
+
/// `Other`, which reaches the guest as `EIO`.
|
|
174
|
+
fn to_error(err: MagnusError) -> Errno {
|
|
175
|
+
err.value()
|
|
176
|
+
.and_then(|exception| errno_of(exception.class()))
|
|
177
|
+
.unwrap_or_else(|| Errno::Other(err.to_string()))
|
|
181
178
|
}
|
|
182
179
|
|
|
183
180
|
/// `File::Constants` flags for `how`, read from Ruby since their
|
|
@@ -245,17 +242,12 @@ impl RubyFilesystem {
|
|
|
245
242
|
dentry: &Dentry,
|
|
246
243
|
how: &OpenHow,
|
|
247
244
|
create: bool,
|
|
248
|
-
) -> Result<Box<dyn FileOperations>,
|
|
245
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
249
246
|
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
|
-
)?;
|
|
247
|
+
let file = ask(self.object, "open", Errno::Unsupported, |ruby, fs| {
|
|
248
|
+
let file: Value = fs.funcall("open", (path, to_flags(ruby, how, create)?))?;
|
|
249
|
+
Ok(RubyFile::pin(ruby, file))
|
|
250
|
+
})?;
|
|
259
251
|
match dentry.inode().map(|inode| inode.identity()) {
|
|
260
252
|
None => {
|
|
261
253
|
let made = self.stat(path_of(dentry))?;
|
|
@@ -265,12 +257,12 @@ impl RubyFilesystem {
|
|
|
265
257
|
// another entry than the one judged, as `Bind::open_file` finds.
|
|
266
258
|
Some(Some(identity)) => {
|
|
267
259
|
if Identity::of(&self.stat(path_of(dentry))?) != Some(identity) {
|
|
268
|
-
return Err(
|
|
260
|
+
return Err(Errno::NotFound);
|
|
269
261
|
}
|
|
270
262
|
}
|
|
271
263
|
Some(None) => {}
|
|
272
264
|
}
|
|
273
|
-
let inode = dentry.inode().ok_or(
|
|
265
|
+
let inode = dentry.inode().ok_or(Errno::NotFound)?;
|
|
274
266
|
let kept = inode
|
|
275
267
|
.private()
|
|
276
268
|
.get_or_init(|| Arc::new(OpenRubyFile::default()))
|
|
@@ -285,21 +277,18 @@ impl RubyFilesystem {
|
|
|
285
277
|
/// about, as it could name a path the object would answer for, and a name
|
|
286
278
|
/// gone by the time it is asked about is one the listing no longer holds, as
|
|
287
279
|
/// any listing is a moment that may have passed.
|
|
288
|
-
fn entries_at(&self, dentry: &Dentry) -> Result<Vec<DirEntry>,
|
|
280
|
+
fn entries_at(&self, dentry: &Dentry) -> Result<Vec<DirEntry>, Errno> {
|
|
289
281
|
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
|
-
)?;
|
|
282
|
+
let names: Vec<String> = ask(self.object, "children", Errno::Unsupported, |_, fs| {
|
|
283
|
+
fs.funcall("children", (at.as_str(),))
|
|
284
|
+
})?;
|
|
296
285
|
names.iter().try_for_each(|name| verify_dirent_name(name))?;
|
|
297
286
|
let mut entries = Vec::with_capacity(names.len());
|
|
298
287
|
for name in names {
|
|
299
288
|
match self.stat(join(&at, &name)) {
|
|
300
289
|
Ok(stat) => entries
|
|
301
290
|
.push(DirEntry::new(name, stat.file_type).with_identity(stat.dev, stat.ino)),
|
|
302
|
-
Err(
|
|
291
|
+
Err(Errno::NotFound) => {}
|
|
303
292
|
Err(err) => return Err(err),
|
|
304
293
|
}
|
|
305
294
|
}
|
|
@@ -312,12 +301,12 @@ impl RubyFilesystem {
|
|
|
312
301
|
struct RubyLink(RubyFilesystem);
|
|
313
302
|
|
|
314
303
|
impl InodeOperations for RubyLink {
|
|
315
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
304
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
316
305
|
self.0.stat(path_of(dentry))
|
|
317
306
|
}
|
|
318
307
|
|
|
319
|
-
fn get_link(&self, _dentry: &Dentry) -> Result<String,
|
|
320
|
-
Err(
|
|
308
|
+
fn get_link(&self, _dentry: &Dentry) -> Result<String, Errno> {
|
|
309
|
+
Err(Errno::FilesystemLoop)
|
|
321
310
|
}
|
|
322
311
|
}
|
|
323
312
|
|
|
@@ -328,23 +317,18 @@ impl InodeOperations for RubyRegular {
|
|
|
328
317
|
/// A file open here answers for itself even once its name is gone, as 9p
|
|
329
318
|
/// asks an open fid: its `size`, and its `stat` where it has one. It stays
|
|
330
319
|
/// the entry its lookup recorded; anything else is asked by its path.
|
|
331
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
320
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
332
321
|
let Some(file) = find_open_file(dentry) else {
|
|
333
322
|
return self.0.stat(path_of(dentry));
|
|
334
323
|
};
|
|
335
|
-
let metadata = ask(
|
|
336
|
-
file.
|
|
337
|
-
"
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
} else {
|
|
344
|
-
Ok(metadata)
|
|
345
|
-
}
|
|
346
|
-
},
|
|
347
|
-
)?;
|
|
324
|
+
let metadata = ask(file.get(), "size", Errno::Unsupported, |_, file| {
|
|
325
|
+
let metadata = Kstat::new(FileType::RegFile, file.funcall("size", ())?);
|
|
326
|
+
if file.respond_to("stat", false)? {
|
|
327
|
+
with_stat_record(file.funcall("stat", ())?, metadata)
|
|
328
|
+
} else {
|
|
329
|
+
Ok(metadata)
|
|
330
|
+
}
|
|
331
|
+
})?;
|
|
348
332
|
Ok(match dentry.inode().and_then(|inode| inode.identity()) {
|
|
349
333
|
Some(identity) => identity.onto(metadata),
|
|
350
334
|
None => metadata,
|
|
@@ -354,27 +338,18 @@ impl InodeOperations for RubyRegular {
|
|
|
354
338
|
/// A Ruby object was handed `TRUNC` as it opened the file, so an open asking
|
|
355
339
|
/// to truncate has nothing left to ask, as `fuse_do_setattr` finds with
|
|
356
340
|
/// `atomic_o_trunc`.
|
|
357
|
-
fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(),
|
|
341
|
+
fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(), Errno> {
|
|
358
342
|
let Some(len) = attr.size else {
|
|
359
|
-
return Err(
|
|
343
|
+
return Err(Errno::Unsupported);
|
|
360
344
|
};
|
|
361
345
|
if attr.open {
|
|
362
346
|
return Ok(());
|
|
363
347
|
}
|
|
364
|
-
let file = find_open_file(dentry).ok_or(
|
|
365
|
-
change(
|
|
366
|
-
file.get(),
|
|
367
|
-
"truncate",
|
|
368
|
-
(len,),
|
|
369
|
-
FilesystemError::ReadOnlyFilesystem,
|
|
370
|
-
)
|
|
348
|
+
let file = find_open_file(dentry).ok_or(Errno::InvalidInput)?;
|
|
349
|
+
change(file.get(), "truncate", (len,), Errno::ReadOnlyFilesystem)
|
|
371
350
|
}
|
|
372
351
|
|
|
373
|
-
fn open(
|
|
374
|
-
&self,
|
|
375
|
-
dentry: &Dentry,
|
|
376
|
-
how: &OpenHow,
|
|
377
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
352
|
+
fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
378
353
|
self.0.open_at(dentry, how, false)
|
|
379
354
|
}
|
|
380
355
|
}
|
|
@@ -382,7 +357,7 @@ impl InodeOperations for RubyRegular {
|
|
|
382
357
|
/// Its root reports no identity without asking the Ruby object, as FUSE makes its
|
|
383
358
|
/// root from fixed attributes rather than ask the server.
|
|
384
359
|
impl FileSystemType for RubyFilesystem {
|
|
385
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
360
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
386
361
|
sb.set_default_d_op(self.clone());
|
|
387
362
|
sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
|
|
388
363
|
Ok(())
|
|
@@ -392,15 +367,15 @@ impl FileSystemType for RubyFilesystem {
|
|
|
392
367
|
/// A directory of a Ruby Filesystem, asked by the path a dentry stands at, the
|
|
393
368
|
/// path a Policy judges.
|
|
394
369
|
impl InodeOperations for RubyFilesystem {
|
|
395
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
370
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
396
371
|
self.stat(path_of(dentry))
|
|
397
372
|
}
|
|
398
373
|
|
|
399
374
|
/// A Ruby object matches names exactly, as its contract asks. A lookup
|
|
400
375
|
/// asks its `stat` what stands at the name, as FUSE asks its daemon.
|
|
401
|
-
fn lookup(&self, dentry: &Dentry) -> Result<Lookup,
|
|
376
|
+
fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
402
377
|
if dentry.name().len() > NAME_MAX {
|
|
403
|
-
return Err(
|
|
378
|
+
return Err(Errno::InvalidFilename);
|
|
404
379
|
}
|
|
405
380
|
match self.stat(path_of(dentry)) {
|
|
406
381
|
Ok(found) => {
|
|
@@ -411,18 +386,14 @@ impl InodeOperations for RubyFilesystem {
|
|
|
411
386
|
};
|
|
412
387
|
Ok(Lookup::Found(Inode::new(&found, ops)))
|
|
413
388
|
}
|
|
414
|
-
Err(
|
|
389
|
+
Err(Errno::NotFound) => Ok(Lookup::Absent),
|
|
415
390
|
Err(err) => Err(err),
|
|
416
391
|
}
|
|
417
392
|
}
|
|
418
393
|
|
|
419
394
|
/// A directory opens without asking the object anything; it is asked
|
|
420
395
|
/// 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> {
|
|
396
|
+
fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
426
397
|
Ok(Box::new(RubyDir(*self, Rdir::default())))
|
|
427
398
|
}
|
|
428
399
|
|
|
@@ -430,7 +401,7 @@ impl InodeOperations for RubyFilesystem {
|
|
|
430
401
|
/// name is left to the runtime unless the open may make it and nothing
|
|
431
402
|
/// stands there, as FUSE's `fuse_atomic_open` looks the name up before it
|
|
432
403
|
/// creates.
|
|
433
|
-
fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish,
|
|
404
|
+
fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, Errno> {
|
|
434
405
|
if dentry.in_lookup() {
|
|
435
406
|
let found = self.lookup(dentry)?;
|
|
436
407
|
if !how.create || !matches!(found, Lookup::Absent) {
|
|
@@ -447,30 +418,30 @@ impl InodeOperations for RubyFilesystem {
|
|
|
447
418
|
})
|
|
448
419
|
}
|
|
449
420
|
|
|
450
|
-
fn mkdir(&self, dentry: &Dentry) -> Result<(),
|
|
421
|
+
fn mkdir(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
451
422
|
change(
|
|
452
423
|
self.object,
|
|
453
424
|
"mkdir",
|
|
454
425
|
(path_of(dentry),),
|
|
455
|
-
|
|
426
|
+
Errno::ReadOnlyFilesystem,
|
|
456
427
|
)
|
|
457
428
|
}
|
|
458
429
|
|
|
459
|
-
fn rmdir(&self, dentry: &Dentry) -> Result<(),
|
|
430
|
+
fn rmdir(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
460
431
|
change(
|
|
461
432
|
self.object,
|
|
462
433
|
"rmdir",
|
|
463
434
|
(path_of(dentry),),
|
|
464
|
-
|
|
435
|
+
Errno::ReadOnlyFilesystem,
|
|
465
436
|
)
|
|
466
437
|
}
|
|
467
438
|
|
|
468
|
-
fn unlink(&self, dentry: &Dentry) -> Result<(),
|
|
439
|
+
fn unlink(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
469
440
|
change(
|
|
470
441
|
self.object,
|
|
471
442
|
"unlink",
|
|
472
443
|
(path_of(dentry),),
|
|
473
|
-
|
|
444
|
+
Errno::ReadOnlyFilesystem,
|
|
474
445
|
)
|
|
475
446
|
}
|
|
476
447
|
|
|
@@ -479,19 +450,19 @@ impl InodeOperations for RubyFilesystem {
|
|
|
479
450
|
/// directories are of one object, which their shared device names.
|
|
480
451
|
fn rename(
|
|
481
452
|
&self,
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
) -> Result<(),
|
|
487
|
-
if
|
|
488
|
-
return Err(
|
|
453
|
+
old: &Dentry,
|
|
454
|
+
_new_dir: &dyn InodeOperations,
|
|
455
|
+
new: &Dentry,
|
|
456
|
+
flags: Option<RenameFlag>,
|
|
457
|
+
) -> Result<(), Errno> {
|
|
458
|
+
if flags.is_some() {
|
|
459
|
+
return Err(Errno::InvalidInput);
|
|
489
460
|
}
|
|
490
461
|
change(
|
|
491
462
|
self.object,
|
|
492
463
|
"rename",
|
|
493
|
-
(path_of(
|
|
494
|
-
|
|
464
|
+
(path_of(old), path_of(new)),
|
|
465
|
+
Errno::ReadOnlyFilesystem,
|
|
495
466
|
)
|
|
496
467
|
}
|
|
497
468
|
}
|
|
@@ -507,30 +478,26 @@ impl FileOperations for RubyDir {
|
|
|
507
478
|
pos: u64,
|
|
508
479
|
offset: i64,
|
|
509
480
|
whence: Whence,
|
|
510
|
-
) -> Result<u64,
|
|
481
|
+
) -> Result<u64, Errno> {
|
|
511
482
|
generic_file_llseek(dentry, pos, offset, whence)
|
|
512
483
|
}
|
|
513
484
|
|
|
514
|
-
fn read_iter(&mut self, _iocb: &mut Kiocb, _buf: &mut [u8]) -> Result<usize,
|
|
485
|
+
fn read_iter(&mut self, _iocb: &mut Kiocb, _buf: &mut [u8]) -> Result<usize, Errno> {
|
|
515
486
|
generic_read_dir()
|
|
516
487
|
}
|
|
517
488
|
|
|
518
489
|
/// What a listing began with stays on the open directory until it ends, so
|
|
519
490
|
/// a caller reading in small steps asks the object once, as FUSE's readdir
|
|
520
491
|
/// cache spares asking the server each time.
|
|
521
|
-
fn iterate_shared(
|
|
522
|
-
&mut self,
|
|
523
|
-
dentry: &Dentry,
|
|
524
|
-
ctx: &mut DirContext<'_>,
|
|
525
|
-
) -> Result<(), FilesystemError> {
|
|
492
|
+
fn iterate_shared(&mut self, dentry: &Dentry, ctx: &mut DirContext<'_>) -> Result<(), Errno> {
|
|
526
493
|
let filesystem = self.0;
|
|
527
494
|
self.1
|
|
528
|
-
.
|
|
495
|
+
.iterate_shared(dentry, ctx, || filesystem.entries_at(dentry))
|
|
529
496
|
}
|
|
530
497
|
|
|
531
498
|
/// The object has nothing of a directory's own to flush, as FUSE's
|
|
532
499
|
/// `fuse_dir_fsync` answers for a server without `fsyncdir`.
|
|
533
|
-
fn fsync(&mut self, _datasync: bool) -> Result<(),
|
|
500
|
+
fn fsync(&mut self, _datasync: bool) -> Result<(), Errno> {
|
|
534
501
|
Ok(())
|
|
535
502
|
}
|
|
536
503
|
}
|
|
@@ -562,30 +529,35 @@ fn find_open_file(dentry: &Dentry) -> Option<Arc<PinnedValue>> {
|
|
|
562
529
|
|
|
563
530
|
/// The backend changes outside the runtime, so a dentry someone holds is
|
|
564
531
|
/// 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
|
-
///
|
|
532
|
+
/// naming what it recorded gets a new one. An object whose `exclusive?` answers
|
|
533
|
+
/// true vouches that only the guest changes it, so what was found stands, as
|
|
534
|
+
/// gVisor's exclusive mount skips revalidation. An open file answers for
|
|
535
|
+
/// itself, so a walk finding a dentry one is open on takes one of its own.
|
|
567
536
|
impl DentryOperations for RubyFilesystem {
|
|
568
|
-
fn revalidate(
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
537
|
+
fn revalidate(&self, _dir: &dyn InodeOperations, dentry: &Dentry) -> Result<bool, Errno> {
|
|
538
|
+
if find_open_file(dentry).is_some() {
|
|
539
|
+
return Ok(false);
|
|
540
|
+
}
|
|
541
|
+
if self.exclusive {
|
|
542
|
+
return Ok(true);
|
|
543
|
+
}
|
|
544
|
+
let Some(inode) = dentry.inode() else {
|
|
574
545
|
return Ok(false);
|
|
575
546
|
};
|
|
576
547
|
match self.stat(path_of(dentry)) {
|
|
577
|
-
Ok(found) =>
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
Err(
|
|
548
|
+
Ok(found) => Ok(
|
|
549
|
+
Identity::of(&found) == inode.identity() && found.file_type == inode.file_type()
|
|
550
|
+
),
|
|
551
|
+
Err(Errno::NotFound | Errno::NotADirectory) => Ok(false),
|
|
581
552
|
Err(err) => Err(err),
|
|
582
553
|
}
|
|
583
554
|
}
|
|
584
555
|
|
|
585
556
|
/// 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
|
|
557
|
+
/// nothing is gained by keeping it, as FUSE's `entry_timeout=0` keeps none;
|
|
558
|
+
/// an exclusive one keeps every name, as nothing asks again.
|
|
587
559
|
fn delete(&self, _dentry: &Dentry) -> bool {
|
|
588
|
-
|
|
560
|
+
!self.exclusive
|
|
589
561
|
}
|
|
590
562
|
}
|
|
591
563
|
|
|
@@ -601,17 +573,17 @@ impl RubyFile {
|
|
|
601
573
|
/// answers where the file then ends, as `IO#pos` does after a write to
|
|
602
574
|
/// a file opened to append. A file lacking it cannot append, since its
|
|
603
575
|
/// `size` and `pwrite` are two steps another writer can land between.
|
|
604
|
-
fn pwrite(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize,
|
|
576
|
+
fn pwrite(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
|
|
605
577
|
let pos = iocb.pos;
|
|
606
578
|
let written = ask(
|
|
607
579
|
self.file.get(),
|
|
608
580
|
"pwrite",
|
|
609
|
-
|
|
581
|
+
Errno::ReadOnlyFilesystem,
|
|
610
582
|
|ruby, file| file.funcall("pwrite", (ruby.str_from_slice(buf), pos)),
|
|
611
583
|
)
|
|
612
584
|
.and_then(|written: usize| match written {
|
|
613
585
|
written if written <= buf.len() => Ok(written),
|
|
614
|
-
written => Err(
|
|
586
|
+
written => Err(Errno::Other(format!(
|
|
615
587
|
"pwrite answered {written} bytes written of the {} it was handed",
|
|
616
588
|
buf.len()
|
|
617
589
|
))),
|
|
@@ -620,15 +592,15 @@ impl RubyFile {
|
|
|
620
592
|
Ok(written)
|
|
621
593
|
}
|
|
622
594
|
|
|
623
|
-
fn append(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize,
|
|
595
|
+
fn append(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
|
|
624
596
|
let end: u64 = ask(
|
|
625
597
|
self.file.get(),
|
|
626
598
|
"append",
|
|
627
|
-
|
|
599
|
+
Errno::Unsupported,
|
|
628
600
|
|ruby, file| file.funcall("append", (ruby.str_from_slice(buf),)),
|
|
629
601
|
)?;
|
|
630
602
|
if end < buf.len() as u64 {
|
|
631
|
-
return Err(
|
|
603
|
+
return Err(Errno::Other(format!(
|
|
632
604
|
"append answered the file ending at {end}, before the {} bytes it wrote",
|
|
633
605
|
buf.len()
|
|
634
606
|
)));
|
|
@@ -639,7 +611,7 @@ impl RubyFile {
|
|
|
639
611
|
|
|
640
612
|
/// Ask the file to close, a file lacking `close` having nothing to
|
|
641
613
|
/// release.
|
|
642
|
-
fn close(&mut self) -> Result<(),
|
|
614
|
+
fn close(&mut self) -> Result<(), Errno> {
|
|
643
615
|
self.closed = true;
|
|
644
616
|
change_if_answered(self.file.get(), "close")
|
|
645
617
|
}
|
|
@@ -652,16 +624,16 @@ impl FileOperations for RubyFile {
|
|
|
652
624
|
pos: u64,
|
|
653
625
|
offset: i64,
|
|
654
626
|
whence: Whence,
|
|
655
|
-
) -> Result<u64,
|
|
627
|
+
) -> Result<u64, Errno> {
|
|
656
628
|
generic_file_llseek(dentry, pos, offset, whence)
|
|
657
629
|
}
|
|
658
630
|
|
|
659
|
-
fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize,
|
|
631
|
+
fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize, Errno> {
|
|
660
632
|
let pos = iocb.pos;
|
|
661
633
|
let read = ask(
|
|
662
634
|
self.file.get(),
|
|
663
635
|
"pread",
|
|
664
|
-
|
|
636
|
+
Errno::Unsupported,
|
|
665
637
|
|ruby, file| {
|
|
666
638
|
// `IO#pread` raises `EOFError` at the end of a file, which reads as nothing.
|
|
667
639
|
let read: Option<RString> = match file.funcall("pread", (buf.len(), pos)) {
|
|
@@ -673,14 +645,23 @@ impl FileOperations for RubyFile {
|
|
|
673
645
|
let bytes = unsafe { read.as_slice() };
|
|
674
646
|
let len = bytes.len().min(buf.len());
|
|
675
647
|
buf[..len].copy_from_slice(&bytes[..len]);
|
|
676
|
-
Ok(len)
|
|
648
|
+
Ok(bytes.len())
|
|
677
649
|
},
|
|
678
|
-
)
|
|
650
|
+
)
|
|
651
|
+
// A reply longer than its request fails the read, as FUSE's
|
|
652
|
+
// `fuse_copy_out_args` does, rather than cut to fit.
|
|
653
|
+
.and_then(|read| match read {
|
|
654
|
+
read if read <= buf.len() => Ok(read),
|
|
655
|
+
read => Err(Errno::Other(format!(
|
|
656
|
+
"pread answered {read} bytes of the {} it was asked for",
|
|
657
|
+
buf.len()
|
|
658
|
+
))),
|
|
659
|
+
})?;
|
|
679
660
|
iocb.pos += read as u64;
|
|
680
661
|
Ok(read)
|
|
681
662
|
}
|
|
682
663
|
|
|
683
|
-
fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize,
|
|
664
|
+
fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
|
|
684
665
|
let written = match iocb.append {
|
|
685
666
|
true => self.append(iocb, buf)?,
|
|
686
667
|
false => self.pwrite(iocb, buf)?,
|
|
@@ -689,11 +670,11 @@ impl FileOperations for RubyFile {
|
|
|
689
670
|
}
|
|
690
671
|
|
|
691
672
|
/// A file lacking `fsync` has nothing of its own to flush.
|
|
692
|
-
fn fsync(&mut self, _datasync: bool) -> Result<(),
|
|
673
|
+
fn fsync(&mut self, _datasync: bool) -> Result<(), Errno> {
|
|
693
674
|
change_if_answered(self.file.get(), "fsync")
|
|
694
675
|
}
|
|
695
676
|
|
|
696
|
-
fn flush(&mut self) -> Result<(),
|
|
677
|
+
fn flush(&mut self) -> Result<(), Errno> {
|
|
697
678
|
self.close()
|
|
698
679
|
}
|
|
699
680
|
}
|