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
|
@@ -7,7 +7,6 @@ use std::ops::BitOr;
|
|
|
7
7
|
use std::sync::Arc;
|
|
8
8
|
|
|
9
9
|
use super::attr::notify_change;
|
|
10
|
-
use super::cred::{on_path, Cred, FileSecurity, SecurityPath};
|
|
11
10
|
use super::dentry::Dentry;
|
|
12
11
|
use super::inode::{EmptyFops, Inode};
|
|
13
12
|
use super::mount::VfsMount;
|
|
@@ -17,11 +16,14 @@ use super::readdir::DirContext;
|
|
|
17
16
|
#[cfg(test)]
|
|
18
17
|
use super::readdir::{DirEmit, DirEntry};
|
|
19
18
|
use super::stat::special_file;
|
|
20
|
-
use super::{
|
|
19
|
+
use super::{Errno, FileType, Iattr, Kstat};
|
|
20
|
+
use crate::cred::Cred;
|
|
21
|
+
use crate::security::{on_path, FileSecurity, SecurityPath};
|
|
22
|
+
use crate::wait::PollTable;
|
|
21
23
|
|
|
22
24
|
/// The largest offset a file holds, as Linux's `OFFSET_MAX` ends its signed
|
|
23
25
|
/// `loff_t`.
|
|
24
|
-
const OFFSET_MAX: u64 = i64::MAX as u64;
|
|
26
|
+
pub const OFFSET_MAX: u64 = i64::MAX as u64;
|
|
25
27
|
|
|
26
28
|
/// The most one read or write takes, as Linux's `MAX_RW_COUNT`, the largest
|
|
27
29
|
/// signed 32-bit count rounded down to a page.
|
|
@@ -47,7 +49,7 @@ pub struct Kiocb {
|
|
|
47
49
|
|
|
48
50
|
impl Kiocb {
|
|
49
51
|
/// A call landing at `pos`.
|
|
50
|
-
pub fn
|
|
52
|
+
pub fn new(pos: u64) -> Self {
|
|
51
53
|
Self {
|
|
52
54
|
pos,
|
|
53
55
|
append: false,
|
|
@@ -73,7 +75,7 @@ pub fn generic_write_sync<F: FileOperations + ?Sized>(
|
|
|
73
75
|
file: &mut F,
|
|
74
76
|
iocb: &Kiocb,
|
|
75
77
|
written: usize,
|
|
76
|
-
) -> Result<usize,
|
|
78
|
+
) -> Result<usize, Errno> {
|
|
77
79
|
if iocb.dsync && written > 0 {
|
|
78
80
|
file.fsync(!iocb.sync)?;
|
|
79
81
|
}
|
|
@@ -95,16 +97,16 @@ pub trait FileOperations: Any + Send + Sync {
|
|
|
95
97
|
_pos: u64,
|
|
96
98
|
_offset: i64,
|
|
97
99
|
_whence: Whence,
|
|
98
|
-
) -> Result<u64,
|
|
99
|
-
Err(
|
|
100
|
+
) -> Result<u64, Errno> {
|
|
101
|
+
Err(Errno::NotSeekable)
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
/// Read into `buf` from where `iocb` lands, moving it past what was read
|
|
103
105
|
/// unless the file has no positions. A file without it refuses as Linux's
|
|
104
106
|
/// `vfs_read` refuses one without `f_op->read_iter`. A directory answers
|
|
105
107
|
/// through `generic_read_dir`, so its read is refused as a directory's.
|
|
106
|
-
fn read_iter(&mut self, _iocb: &mut Kiocb, _buf: &mut [u8]) -> Result<usize,
|
|
107
|
-
Err(
|
|
108
|
+
fn read_iter(&mut self, _iocb: &mut Kiocb, _buf: &mut [u8]) -> Result<usize, Errno> {
|
|
109
|
+
Err(Errno::InvalidInput)
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
/// Write `buf` where `iocb` lands, moving it past what was written unless
|
|
@@ -115,8 +117,8 @@ pub trait FileOperations: Any + Send + Sync {
|
|
|
115
117
|
/// writer's from landing over it, as `generic_file_write_iter` reads the
|
|
116
118
|
/// end under the inode's lock, so a file that cannot read its end and
|
|
117
119
|
/// write there in one step answers `Unsupported`.
|
|
118
|
-
fn write_iter(&mut self, _iocb: &mut Kiocb, _buf: &[u8]) -> Result<usize,
|
|
119
|
-
Err(
|
|
120
|
+
fn write_iter(&mut self, _iocb: &mut Kiocb, _buf: &[u8]) -> Result<usize, Errno> {
|
|
121
|
+
Err(Errno::InvalidInput)
|
|
120
122
|
}
|
|
121
123
|
|
|
122
124
|
/// Hand `ctx` the entries of this directory, which `dentry` names, from
|
|
@@ -124,24 +126,21 @@ pub trait FileOperations: Any + Send + Sync {
|
|
|
124
126
|
/// `dir_emit_dots` and `dir_emit`. One reading the whole directory at once
|
|
125
127
|
/// answers through the `Rdir` that `filesystem` provides. A file without
|
|
126
128
|
/// it answers `NotADirectory`, as Linux's `iterate_dir` does.
|
|
127
|
-
fn iterate_shared(
|
|
128
|
-
|
|
129
|
-
_dentry: &Dentry,
|
|
130
|
-
_ctx: &mut DirContext<'_>,
|
|
131
|
-
) -> Result<(), FilesystemError> {
|
|
132
|
-
Err(FilesystemError::NotADirectory)
|
|
129
|
+
fn iterate_shared(&mut self, _dentry: &Dentry, _ctx: &mut DirContext<'_>) -> Result<(), Errno> {
|
|
130
|
+
Err(Errno::NotADirectory)
|
|
133
131
|
}
|
|
134
132
|
|
|
135
133
|
/// Reserve `len` bytes from `offset`, as `f_op->fallocate` does. A file
|
|
136
134
|
/// without it refuses as Linux's `vfs_fallocate` refuses one without it.
|
|
137
|
-
fn fallocate(&mut self, _offset: u64, _len: u64) -> Result<(),
|
|
138
|
-
Err(
|
|
135
|
+
fn fallocate(&mut self, _offset: u64, _len: u64) -> Result<(), Errno> {
|
|
136
|
+
Err(Errno::Unsupported)
|
|
139
137
|
}
|
|
140
138
|
|
|
141
139
|
/// What a call would find ready on this end, opened for `mode`, as
|
|
142
|
-
/// `f_op->poll` answers
|
|
143
|
-
/// `
|
|
144
|
-
|
|
140
|
+
/// `f_op->poll` answers; a file that can become ready later registers
|
|
141
|
+
/// its wait queue on `table` through `poll_wait`. A file without it is
|
|
142
|
+
/// always ready, as Linux's `vfs_poll` answers `DEFAULT_POLLMASK`.
|
|
143
|
+
fn poll(&self, _mode: FMode, _table: Option<&mut PollTable>) -> PollMask {
|
|
145
144
|
PollMask::IN | PollMask::OUT
|
|
146
145
|
}
|
|
147
146
|
|
|
@@ -149,15 +148,15 @@ pub trait FileOperations: Any + Send + Sync {
|
|
|
149
148
|
/// `datasync` asks, as `f_op->fsync` takes it. A file with nothing to flush
|
|
150
149
|
/// answers success itself, as tmpfs names `noop_fsync`; one without it refuses
|
|
151
150
|
/// as Linux's `vfs_fsync_range` refuses one without `f_op->fsync`.
|
|
152
|
-
fn fsync(&mut self, _datasync: bool) -> Result<(),
|
|
153
|
-
Err(
|
|
151
|
+
fn fsync(&mut self, _datasync: bool) -> Result<(), Errno> {
|
|
152
|
+
Err(Errno::InvalidInput)
|
|
154
153
|
}
|
|
155
154
|
|
|
156
155
|
/// Answer, as the file is closed, whether what it held was kept, as
|
|
157
156
|
/// `f_op->flush` answers `close(2)`. The default has nothing to flush.
|
|
158
157
|
/// What the file holds goes when it is dropped, as `->release` runs and
|
|
159
158
|
/// no caller reads its answer, so a file never closed still lets go of it.
|
|
160
|
-
fn flush(&mut self) -> Result<(),
|
|
159
|
+
fn flush(&mut self) -> Result<(), Errno> {
|
|
161
160
|
Ok(())
|
|
162
161
|
}
|
|
163
162
|
|
|
@@ -177,7 +176,7 @@ pub fn generic_file_llseek(
|
|
|
177
176
|
pos: u64,
|
|
178
177
|
offset: i64,
|
|
179
178
|
whence: Whence,
|
|
180
|
-
) -> Result<u64,
|
|
179
|
+
) -> Result<u64, Errno> {
|
|
181
180
|
let base = match whence {
|
|
182
181
|
Whence::Set => 0,
|
|
183
182
|
Whence::Cur => pos,
|
|
@@ -185,7 +184,7 @@ pub fn generic_file_llseek(
|
|
|
185
184
|
};
|
|
186
185
|
base.checked_add_signed(offset)
|
|
187
186
|
.filter(|pos| *pos <= OFFSET_MAX)
|
|
188
|
-
.ok_or(
|
|
187
|
+
.ok_or(Errno::InvalidInput)
|
|
189
188
|
}
|
|
190
189
|
|
|
191
190
|
/// What an open file was opened for and what it can do, as Linux's `fmode_t`.
|
|
@@ -251,8 +250,9 @@ impl FMode {
|
|
|
251
250
|
}
|
|
252
251
|
}
|
|
253
252
|
|
|
254
|
-
/// What a file would find ready, as Linux's `__poll_t
|
|
255
|
-
|
|
253
|
+
/// What a file would find ready, as Linux's `__poll_t`; the default finds
|
|
254
|
+
/// nothing ready.
|
|
255
|
+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
|
256
256
|
pub struct PollMask(u8);
|
|
257
257
|
|
|
258
258
|
impl PollMask {
|
|
@@ -260,11 +260,22 @@ impl PollMask {
|
|
|
260
260
|
pub const IN: Self = Self(1);
|
|
261
261
|
/// A write would not wait, as `EPOLLOUT`.
|
|
262
262
|
pub const OUT: Self = Self(1 << 1);
|
|
263
|
+
/// The file failed, and a call would answer its error, as `EPOLLERR`.
|
|
264
|
+
pub const ERR: Self = Self(1 << 2);
|
|
265
|
+
/// The peer hung up, and a read would answer the end, as `EPOLLHUP`.
|
|
266
|
+
pub const HUP: Self = Self(1 << 3);
|
|
263
267
|
|
|
264
268
|
/// Whether this holds all of `mask`.
|
|
265
269
|
pub fn contains(self, mask: Self) -> bool {
|
|
266
270
|
self.0 & mask.0 == mask.0
|
|
267
271
|
}
|
|
272
|
+
|
|
273
|
+
/// Whether a poll asking `asked` finds this ready: it holds what was
|
|
274
|
+
/// asked, or an error or a hang-up whatever was asked, as `do_pollfd`
|
|
275
|
+
/// adds `EPOLLERR` and `EPOLLHUP` to every poll's events.
|
|
276
|
+
pub fn is_ready_for(self, asked: Self) -> bool {
|
|
277
|
+
self.contains(asked) || self.contains(Self::ERR) || self.contains(Self::HUP)
|
|
278
|
+
}
|
|
268
279
|
}
|
|
269
280
|
|
|
270
281
|
impl BitOr for PollMask {
|
|
@@ -294,8 +305,8 @@ pub(super) fn do_dentry_open(
|
|
|
294
305
|
kind: FileType,
|
|
295
306
|
mode: FMode,
|
|
296
307
|
how: &OpenHow,
|
|
297
|
-
open: impl FnOnce() -> Result<Box<dyn FileOperations>,
|
|
298
|
-
) -> Result<(Box<dyn FileOperations>, Vec<FileSecurity>),
|
|
308
|
+
open: impl FnOnce() -> Result<Box<dyn FileOperations>, Errno>,
|
|
309
|
+
) -> Result<(Box<dyn FileOperations>, Vec<FileSecurity>), Errno> {
|
|
299
310
|
if mode.contains(FMode::PATH) {
|
|
300
311
|
return Ok((Box::new(EmptyFops), cred.security_file_alloc()));
|
|
301
312
|
}
|
|
@@ -319,7 +330,7 @@ pub struct File {
|
|
|
319
330
|
mode: FMode,
|
|
320
331
|
/// Whether each write lands at the end, as `O_APPEND` in `f_flags`.
|
|
321
332
|
append: bool,
|
|
322
|
-
/// Whether it asked not to wait, as `O_NONBLOCK` in `f_flags`.
|
|
333
|
+
/// Whether it asked not to wait, as `O_NONBLOCK` in `f_flags`. No file
|
|
323
334
|
/// here waits, so it only reports back.
|
|
324
335
|
nonblock: bool,
|
|
325
336
|
/// Whether what each write needs read back is durable before it answers, as
|
|
@@ -416,12 +427,8 @@ impl File {
|
|
|
416
427
|
/// What stands at `path`, opened as `how` asks for `cred`, as Linux's
|
|
417
428
|
/// `dentry_open` asks the security modules before `f_op->open` and walks no
|
|
418
429
|
/// path.
|
|
419
|
-
pub(super) fn dentry_open(
|
|
420
|
-
path
|
|
421
|
-
how: &OpenHow,
|
|
422
|
-
cred: &Arc<Cred>,
|
|
423
|
-
) -> Result<Self, FilesystemError> {
|
|
424
|
-
let kind = path.dentry().kind()?;
|
|
430
|
+
pub(super) fn dentry_open(path: Path, how: &OpenHow, cred: &Arc<Cred>) -> Result<Self, Errno> {
|
|
431
|
+
let kind = path.dentry().file_type()?;
|
|
425
432
|
let mode = FMode::of(how);
|
|
426
433
|
let (ops, security) = on_path(path.mnt(), path.dentry(), |at| {
|
|
427
434
|
do_dentry_open(cred, at, kind, mode, how, || path.dentry().open(how))
|
|
@@ -429,10 +436,10 @@ impl File {
|
|
|
429
436
|
Ok(Self::new(path, ops, mode, how, cred, security))
|
|
430
437
|
}
|
|
431
438
|
|
|
432
|
-
/// The root of `mnt` opened as a directory for `cred`. A Wasm Driver opens
|
|
433
|
-
/// Mount's root with the Cred its Policies are added to afterwards, as a
|
|
439
|
+
/// The root of `mnt` opened as a directory for `cred`. A Wasm Driver opens
|
|
440
|
+
/// each outermost Mount's root with the Cred its Policies are added to afterwards, as a
|
|
434
441
|
/// Linux task opens what it keeps before `landlock_restrict_self`.
|
|
435
|
-
pub fn root(mnt: &Arc<VfsMount>, cred: &Arc<Cred>) -> Result<Self,
|
|
442
|
+
pub fn root(mnt: &Arc<VfsMount>, cred: &Arc<Cred>) -> Result<Self, Errno> {
|
|
436
443
|
let read = OpenHow {
|
|
437
444
|
read: true,
|
|
438
445
|
..OpenHow::default()
|
|
@@ -452,12 +459,12 @@ impl File {
|
|
|
452
459
|
|
|
453
460
|
/// Whether it is a directory, as `S_ISDIR(file_inode(file))`.
|
|
454
461
|
pub fn is_directory(&self) -> bool {
|
|
455
|
-
self.
|
|
462
|
+
self.file_type() == FileType::Dir
|
|
456
463
|
}
|
|
457
464
|
|
|
458
465
|
/// What kind of entry it is, as `file_inode(file)->i_mode` says.
|
|
459
|
-
pub fn
|
|
460
|
-
self.inode.
|
|
466
|
+
pub fn file_type(&self) -> FileType {
|
|
467
|
+
self.inode.file_type()
|
|
461
468
|
}
|
|
462
469
|
|
|
463
470
|
/// What it was opened for.
|
|
@@ -467,12 +474,12 @@ impl File {
|
|
|
467
474
|
}
|
|
468
475
|
|
|
469
476
|
/// Whether it was opened to read.
|
|
470
|
-
pub fn
|
|
477
|
+
pub fn is_readable(&self) -> bool {
|
|
471
478
|
self.mode.contains(FMode::READ)
|
|
472
479
|
}
|
|
473
480
|
|
|
474
481
|
/// Whether it was opened to write.
|
|
475
|
-
pub fn
|
|
482
|
+
pub fn is_writable(&self) -> bool {
|
|
476
483
|
self.mode.contains(FMode::WRITE)
|
|
477
484
|
}
|
|
478
485
|
|
|
@@ -484,22 +491,22 @@ impl File {
|
|
|
484
491
|
}
|
|
485
492
|
|
|
486
493
|
/// Whether each write lands at the end.
|
|
487
|
-
pub fn
|
|
494
|
+
pub fn is_append(&self) -> bool {
|
|
488
495
|
self.append
|
|
489
496
|
}
|
|
490
497
|
|
|
491
498
|
/// Whether it asked not to wait.
|
|
492
|
-
pub fn
|
|
499
|
+
pub fn is_nonblock(&self) -> bool {
|
|
493
500
|
self.nonblock
|
|
494
501
|
}
|
|
495
502
|
|
|
496
503
|
/// Whether what each write needs read back is durable before it answers.
|
|
497
|
-
pub fn
|
|
504
|
+
pub fn is_dsync(&self) -> bool {
|
|
498
505
|
self.dsync
|
|
499
506
|
}
|
|
500
507
|
|
|
501
508
|
/// Whether everything each write changed is durable before it answers.
|
|
502
|
-
pub fn
|
|
509
|
+
pub fn is_sync(&self) -> bool {
|
|
503
510
|
self.sync
|
|
504
511
|
}
|
|
505
512
|
|
|
@@ -512,9 +519,9 @@ impl File {
|
|
|
512
519
|
|
|
513
520
|
/// Move its position, answering where it now stands, as `vfs_llseek` refuses
|
|
514
521
|
/// a file with no position and asks `f_op->llseek` of the rest.
|
|
515
|
-
pub fn llseek(&mut self, offset: i64, whence: Whence) -> Result<u64,
|
|
522
|
+
pub fn llseek(&mut self, offset: i64, whence: Whence) -> Result<u64, Errno> {
|
|
516
523
|
if !self.mode.contains(FMode::LSEEK) {
|
|
517
|
-
return Err(
|
|
524
|
+
return Err(Errno::NotSeekable);
|
|
518
525
|
}
|
|
519
526
|
let dentry = self.path.dentry().clone();
|
|
520
527
|
self.pos = self.ops.llseek(&dentry, self.pos, offset, whence)?;
|
|
@@ -524,12 +531,12 @@ impl File {
|
|
|
524
531
|
/// Take a hint about `len` bytes from `offset`, as `generic_fadvise`
|
|
525
532
|
/// refuses a FIFO, then a negative offset or length, and ignores the rest.
|
|
526
533
|
/// Every Filesystem is still correct without one.
|
|
527
|
-
pub fn fadvise(&self, offset: u64, len: u64) -> Result<(),
|
|
528
|
-
if self.
|
|
529
|
-
return Err(
|
|
534
|
+
pub fn fadvise(&self, offset: u64, len: u64) -> Result<(), Errno> {
|
|
535
|
+
if self.file_type() == FileType::Fifo {
|
|
536
|
+
return Err(Errno::NotSeekable);
|
|
530
537
|
}
|
|
531
538
|
match offset > OFFSET_MAX || len > OFFSET_MAX {
|
|
532
|
-
true => Err(
|
|
539
|
+
true => Err(Errno::InvalidInput),
|
|
533
540
|
false => Ok(()),
|
|
534
541
|
}
|
|
535
542
|
}
|
|
@@ -538,26 +545,27 @@ impl File {
|
|
|
538
545
|
/// order before it asks `f_op->fallocate`: what the call asks, the open's
|
|
539
546
|
/// mode, a FIFO, a directory, and then anything but a regular file or a
|
|
540
547
|
/// block device.
|
|
541
|
-
pub fn fallocate(&mut self, offset: u64, len: u64) -> Result<(),
|
|
548
|
+
pub fn fallocate(&mut self, offset: u64, len: u64) -> Result<(), Errno> {
|
|
542
549
|
if offset > OFFSET_MAX || len == 0 || len > OFFSET_MAX {
|
|
543
|
-
return Err(
|
|
550
|
+
return Err(Errno::InvalidInput);
|
|
544
551
|
}
|
|
545
552
|
self.may_write()?;
|
|
546
|
-
match self.
|
|
547
|
-
FileType::Fifo => return Err(
|
|
548
|
-
FileType::Dir => return Err(
|
|
553
|
+
match self.file_type() {
|
|
554
|
+
FileType::Fifo => return Err(Errno::NotSeekable),
|
|
555
|
+
FileType::Dir => return Err(Errno::IsADirectory),
|
|
549
556
|
FileType::RegFile | FileType::Blkdev => {}
|
|
550
|
-
_ => return Err(
|
|
557
|
+
_ => return Err(Errno::NoSuchDevice),
|
|
551
558
|
}
|
|
552
559
|
if offset + len > OFFSET_MAX {
|
|
553
|
-
return Err(
|
|
560
|
+
return Err(Errno::FileTooLarge);
|
|
554
561
|
}
|
|
555
562
|
self.ops.fallocate(offset, len)
|
|
556
563
|
}
|
|
557
564
|
|
|
558
|
-
/// What a call would find ready, as `vfs_poll` asks `f_op->poll
|
|
559
|
-
|
|
560
|
-
|
|
565
|
+
/// What a call would find ready, as `vfs_poll` asks `f_op->poll`,
|
|
566
|
+
/// registering on `table` for a poll that will sleep.
|
|
567
|
+
pub fn poll(&self, table: Option<&mut PollTable>) -> PollMask {
|
|
568
|
+
self.ops.poll(self.mode, table)
|
|
561
569
|
}
|
|
562
570
|
|
|
563
571
|
/// Whether it reads and writes what comes next, with no position.
|
|
@@ -572,7 +580,7 @@ impl File {
|
|
|
572
580
|
let iocb = Kiocb {
|
|
573
581
|
dsync: self.dsync,
|
|
574
582
|
sync: self.sync,
|
|
575
|
-
..Kiocb::
|
|
583
|
+
..Kiocb::new(pos)
|
|
576
584
|
};
|
|
577
585
|
match self.append {
|
|
578
586
|
true => iocb.with_append(),
|
|
@@ -582,43 +590,43 @@ impl File {
|
|
|
582
590
|
|
|
583
591
|
/// Whether a read may reach it, as `vfs_read` asks of `f_mode` before it
|
|
584
592
|
/// touches the caller's buffer.
|
|
585
|
-
pub fn may_read(&self) -> Result<(),
|
|
586
|
-
match self.
|
|
593
|
+
pub fn may_read(&self) -> Result<(), Errno> {
|
|
594
|
+
match self.is_readable() {
|
|
587
595
|
true => Ok(()),
|
|
588
|
-
false => Err(
|
|
596
|
+
false => Err(Errno::BadDescriptor),
|
|
589
597
|
}
|
|
590
598
|
}
|
|
591
599
|
|
|
592
600
|
/// Whether a write may reach it, as `vfs_write` asks of `f_mode` before
|
|
593
601
|
/// it touches the caller's buffer.
|
|
594
|
-
pub fn may_write(&self) -> Result<(),
|
|
595
|
-
match self.
|
|
602
|
+
pub fn may_write(&self) -> Result<(), Errno> {
|
|
603
|
+
match self.is_writable() {
|
|
596
604
|
true => Ok(()),
|
|
597
|
-
false => Err(
|
|
605
|
+
false => Err(Errno::BadDescriptor),
|
|
598
606
|
}
|
|
599
607
|
}
|
|
600
608
|
|
|
601
609
|
/// Whether a read from `pos` may reach it, as `pread` refuses a negative
|
|
602
610
|
/// offset, then a file without one.
|
|
603
|
-
pub fn may_pread(&self, pos: u64) -> Result<(),
|
|
611
|
+
pub fn may_pread(&self, pos: u64) -> Result<(), Errno> {
|
|
604
612
|
self.may_at(pos, FMode::PREAD)?;
|
|
605
613
|
self.may_read()
|
|
606
614
|
}
|
|
607
615
|
|
|
608
616
|
/// Whether a write at `pos` may reach it, as `pwrite` refuses a negative
|
|
609
617
|
/// offset, then a file without one.
|
|
610
|
-
pub fn may_pwrite(&self, pos: u64) -> Result<(),
|
|
618
|
+
pub fn may_pwrite(&self, pos: u64) -> Result<(), Errno> {
|
|
611
619
|
self.may_at(pos, FMode::PWRITE)?;
|
|
612
620
|
self.may_write()
|
|
613
621
|
}
|
|
614
622
|
|
|
615
|
-
fn may_at(&self, pos: u64, mode: FMode) -> Result<(),
|
|
623
|
+
fn may_at(&self, pos: u64, mode: FMode) -> Result<(), Errno> {
|
|
616
624
|
if pos > OFFSET_MAX {
|
|
617
|
-
return Err(
|
|
625
|
+
return Err(Errno::InvalidInput);
|
|
618
626
|
}
|
|
619
627
|
match self.mode.contains(mode) {
|
|
620
628
|
true => Ok(()),
|
|
621
|
-
false => Err(
|
|
629
|
+
false => Err(Errno::NotSeekable),
|
|
622
630
|
}
|
|
623
631
|
}
|
|
624
632
|
|
|
@@ -630,20 +638,20 @@ impl File {
|
|
|
630
638
|
|
|
631
639
|
/// Refuse a call of `count` bytes from `ppos` if it would end past the
|
|
632
640
|
/// largest offset, as `rw_verify_area` does; a call landing nowhere passes.
|
|
633
|
-
fn rw_verify_area(&self, ppos: Option<u64>, count: usize) -> Result<(),
|
|
641
|
+
fn rw_verify_area(&self, ppos: Option<u64>, count: usize) -> Result<(), Errno> {
|
|
634
642
|
let Some(pos) = ppos else {
|
|
635
643
|
return Ok(());
|
|
636
644
|
};
|
|
637
645
|
match pos.checked_add(count as u64) {
|
|
638
646
|
Some(end) if end <= OFFSET_MAX => Ok(()),
|
|
639
|
-
_ => Err(
|
|
647
|
+
_ => Err(Errno::InvalidInput),
|
|
640
648
|
}
|
|
641
649
|
}
|
|
642
650
|
|
|
643
651
|
/// Read from its position, moving it past what was read, as `vfs_read`
|
|
644
652
|
/// does; a stream starts from no position and keeps none, as
|
|
645
653
|
/// `new_sync_read` hands it `ki_pos` 0.
|
|
646
|
-
pub fn read(&mut self, buf: &mut [u8]) -> Result<usize,
|
|
654
|
+
pub fn read(&mut self, buf: &mut [u8]) -> Result<usize, Errno> {
|
|
647
655
|
self.may_read()?;
|
|
648
656
|
let ppos = self.file_ppos();
|
|
649
657
|
self.rw_verify_area(ppos, buf.len())?;
|
|
@@ -657,7 +665,7 @@ impl File {
|
|
|
657
665
|
}
|
|
658
666
|
|
|
659
667
|
/// Read from `pos`, leaving its position, as `pread` does.
|
|
660
|
-
pub fn pread(&mut self, buf: &mut [u8], pos: u64) -> Result<usize,
|
|
668
|
+
pub fn pread(&mut self, buf: &mut [u8], pos: u64) -> Result<usize, Errno> {
|
|
661
669
|
self.may_pread(pos)?;
|
|
662
670
|
self.rw_verify_area(Some(pos), buf.len())?;
|
|
663
671
|
let count = buf.len().min(MAX_RW_COUNT);
|
|
@@ -667,7 +675,7 @@ impl File {
|
|
|
667
675
|
/// Write at its position, moving it past what was written, as `vfs_write`
|
|
668
676
|
/// does; a stream starts from no position and keeps none, as
|
|
669
677
|
/// `new_sync_write` hands it `ki_pos` 0.
|
|
670
|
-
pub fn write(&mut self, buf: &[u8]) -> Result<usize,
|
|
678
|
+
pub fn write(&mut self, buf: &[u8]) -> Result<usize, Errno> {
|
|
671
679
|
self.may_write()?;
|
|
672
680
|
let ppos = self.file_ppos();
|
|
673
681
|
self.rw_verify_area(ppos, buf.len())?;
|
|
@@ -683,7 +691,7 @@ impl File {
|
|
|
683
691
|
|
|
684
692
|
/// Write at `pos`, leaving its position, as `pwrite` does. Opened to
|
|
685
693
|
/// append, it lands at the end whatever `pos` says.
|
|
686
|
-
pub fn pwrite(&mut self, buf: &[u8], pos: u64) -> Result<usize,
|
|
694
|
+
pub fn pwrite(&mut self, buf: &[u8], pos: u64) -> Result<usize, Errno> {
|
|
687
695
|
self.may_pwrite(pos)?;
|
|
688
696
|
self.rw_verify_area(Some(pos), buf.len())?;
|
|
689
697
|
self.ops
|
|
@@ -692,25 +700,29 @@ impl File {
|
|
|
692
700
|
|
|
693
701
|
/// Make what was written durable, as `vfs_fsync` does, and `vfs_fsync_range`
|
|
694
702
|
/// passes `datasync` through.
|
|
695
|
-
pub fn fsync(&mut self, datasync: bool) -> Result<(),
|
|
703
|
+
pub fn fsync(&mut self, datasync: bool) -> Result<(), Errno> {
|
|
696
704
|
self.ops.fsync(datasync)
|
|
697
705
|
}
|
|
698
706
|
|
|
699
707
|
/// What it reports of itself, as `vfs_getattr` answers.
|
|
700
|
-
pub fn getattr(&self) -> Result<Kstat,
|
|
708
|
+
pub fn getattr(&self) -> Result<Kstat, Errno> {
|
|
701
709
|
self.path.dentry().getattr()
|
|
702
710
|
}
|
|
703
711
|
|
|
704
712
|
/// Truncate or extend it through what it was opened on, as `do_ftruncate`
|
|
705
713
|
/// refuses anything but a file open to write, and reaches `->setattr`.
|
|
706
|
-
pub fn truncate(&mut self, len: u64) -> Result<(),
|
|
707
|
-
if self.
|
|
708
|
-
return Err(
|
|
714
|
+
pub fn truncate(&mut self, len: u64) -> Result<(), Errno> {
|
|
715
|
+
if self.file_type() != FileType::RegFile || !self.is_writable() || len > OFFSET_MAX {
|
|
716
|
+
return Err(Errno::InvalidInput);
|
|
709
717
|
}
|
|
710
718
|
self.cred.security_file_truncate(&self.security)?;
|
|
711
719
|
let dentry = self.path.dentry();
|
|
712
720
|
let held = dentry.inode_lock()?;
|
|
713
|
-
notify_change(
|
|
721
|
+
notify_change(
|
|
722
|
+
dentry,
|
|
723
|
+
&held,
|
|
724
|
+
&Iattr::for_size(len).through(self.ops.as_ref()),
|
|
725
|
+
)
|
|
714
726
|
}
|
|
715
727
|
|
|
716
728
|
/// Hand `ctx` the entries of the directory from where it stands until the
|
|
@@ -718,11 +730,11 @@ impl File {
|
|
|
718
730
|
/// holds the directory's lock shared, so a removal through the VFS lands
|
|
719
731
|
/// before or after, and a removed directory answers not found, as it asks
|
|
720
732
|
/// `IS_DEADDIR`.
|
|
721
|
-
pub fn iterate_dir(&mut self, ctx: &mut DirContext<'_>) -> Result<(),
|
|
733
|
+
pub fn iterate_dir(&mut self, ctx: &mut DirContext<'_>) -> Result<(), Errno> {
|
|
722
734
|
let dentry = self.path.dentry().clone();
|
|
723
735
|
let _held = dentry.inode_lock_shared()?;
|
|
724
736
|
if dentry.is_deaddir() {
|
|
725
|
-
return Err(
|
|
737
|
+
return Err(Errno::NotFound);
|
|
726
738
|
}
|
|
727
739
|
ctx.pos = self.pos;
|
|
728
740
|
ctx.cred = self.cred.clone();
|
|
@@ -734,7 +746,7 @@ impl File {
|
|
|
734
746
|
/// What its Filesystem lists past `.` and `..`, for a test of what the
|
|
735
747
|
/// Filesystem answers beneath the VFS.
|
|
736
748
|
#[cfg(test)]
|
|
737
|
-
pub(crate) fn iterate_shared(&mut self) -> Result<Vec<DirEntry>,
|
|
749
|
+
pub(crate) fn iterate_shared(&mut self) -> Result<Vec<DirEntry>, Errno> {
|
|
738
750
|
let dentry = self.path.dentry().clone();
|
|
739
751
|
let mut entries = Vec::new();
|
|
740
752
|
let mut actor = |emit: &DirEmit<'_>| {
|
|
@@ -748,7 +760,7 @@ impl File {
|
|
|
748
760
|
|
|
749
761
|
/// Close it once the last descriptor goes, answering what its flush
|
|
750
762
|
/// answers, as `filp_close` does; dropping it is what `->release` does.
|
|
751
|
-
pub fn close(mut self) -> Result<(),
|
|
763
|
+
pub fn close(mut self) -> Result<(), Errno> {
|
|
752
764
|
self.ops.flush()
|
|
753
765
|
}
|
|
754
766
|
}
|
|
@@ -775,7 +787,7 @@ mod tests {
|
|
|
775
787
|
_pos: u64,
|
|
776
788
|
_offset: i64,
|
|
777
789
|
_whence: Whence,
|
|
778
|
-
) -> Result<u64,
|
|
790
|
+
) -> Result<u64, Errno> {
|
|
779
791
|
Ok(9)
|
|
780
792
|
}
|
|
781
793
|
}
|
|
@@ -785,18 +797,18 @@ mod tests {
|
|
|
785
797
|
struct Opens(fn() -> Box<dyn FileOperations>);
|
|
786
798
|
|
|
787
799
|
impl crate::vfs::FileSystemType for Opens {
|
|
788
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
800
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
789
801
|
sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
|
|
790
802
|
Ok(())
|
|
791
803
|
}
|
|
792
804
|
}
|
|
793
805
|
|
|
794
806
|
impl InodeOperations for Opens {
|
|
795
|
-
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat,
|
|
807
|
+
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
796
808
|
Ok(Kstat::new(FileType::RegFile, 0))
|
|
797
809
|
}
|
|
798
810
|
|
|
799
|
-
fn lookup(&self, _dentry: &Dentry) -> Result<Lookup,
|
|
811
|
+
fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
800
812
|
let found = Kstat::new(FileType::RegFile, 0);
|
|
801
813
|
Ok(Lookup::Found(Inode::new(&found, Arc::new(Self(self.0)))))
|
|
802
814
|
}
|
|
@@ -805,7 +817,7 @@ mod tests {
|
|
|
805
817
|
&self,
|
|
806
818
|
_dentry: &Dentry,
|
|
807
819
|
_options: &OpenHow,
|
|
808
|
-
) -> Result<Box<dyn FileOperations>,
|
|
820
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
809
821
|
Ok((self.0)())
|
|
810
822
|
}
|
|
811
823
|
}
|
|
@@ -815,7 +827,7 @@ mod tests {
|
|
|
815
827
|
fn open_one(opens: fn() -> Box<dyn FileOperations>) -> File {
|
|
816
828
|
let mount = Mount::new(
|
|
817
829
|
"/data",
|
|
818
|
-
Filesystem::new(
|
|
830
|
+
Filesystem::new(Opens(opens)).expect("the instance must stand"),
|
|
819
831
|
Access::Read,
|
|
820
832
|
)
|
|
821
833
|
.expect("/data is a guest path");
|
|
@@ -835,11 +847,7 @@ mod tests {
|
|
|
835
847
|
true
|
|
836
848
|
}
|
|
837
849
|
|
|
838
|
-
fn read_iter(
|
|
839
|
-
&mut self,
|
|
840
|
-
iocb: &mut Kiocb,
|
|
841
|
-
buf: &mut [u8],
|
|
842
|
-
) -> Result<usize, FilesystemError> {
|
|
850
|
+
fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize, Errno> {
|
|
843
851
|
buf[0] = iocb.pos as u8;
|
|
844
852
|
iocb.pos += buf.len() as u64;
|
|
845
853
|
Ok(buf.len())
|
|
@@ -878,11 +886,7 @@ mod tests {
|
|
|
878
886
|
file.pread(&mut [0], 0),
|
|
879
887
|
file.is_stream()
|
|
880
888
|
),
|
|
881
|
-
(
|
|
882
|
-
Err(FilesystemError::NotSeekable),
|
|
883
|
-
Err(FilesystemError::NotSeekable),
|
|
884
|
-
true
|
|
885
|
-
),
|
|
889
|
+
(Err(Errno::NotSeekable), Err(Errno::NotSeekable), true),
|
|
886
890
|
"File::llseek and File::pread on a file its Filesystem's open marks a stream must \
|
|
887
891
|
answer ESPIPE, as stream_open clears FMODE_LSEEK and FMODE_PREAD"
|
|
888
892
|
);
|
|
@@ -915,7 +919,7 @@ mod tests {
|
|
|
915
919
|
let mut file = open_one(|| Box::new(NoSeek));
|
|
916
920
|
assert_eq!(
|
|
917
921
|
(file.llseek(0, Whence::Set), file.pos()),
|
|
918
|
-
(Err(
|
|
922
|
+
(Err(Errno::NotSeekable), 0),
|
|
919
923
|
"File::llseek of a file whose Filesystem answers no llseek must answer ESPIPE and \
|
|
920
924
|
leave its position, as Linux clears FMODE_LSEEK for one"
|
|
921
925
|
);
|
|
@@ -937,21 +941,21 @@ mod tests {
|
|
|
937
941
|
struct OpensNothing;
|
|
938
942
|
|
|
939
943
|
impl crate::vfs::FileSystemType for OpensNothing {
|
|
940
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
944
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
941
945
|
sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
|
|
942
946
|
Ok(())
|
|
943
947
|
}
|
|
944
948
|
}
|
|
945
949
|
|
|
946
950
|
impl InodeOperations for OpensNothing {
|
|
947
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
951
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
948
952
|
Ok(match dentry.is_root() {
|
|
949
953
|
false => Kstat::new(FileType::RegFile, 0),
|
|
950
954
|
true => Kstat::new(FileType::Dir, 0),
|
|
951
955
|
})
|
|
952
956
|
}
|
|
953
957
|
|
|
954
|
-
fn lookup(&self, _dentry: &Dentry) -> Result<Lookup,
|
|
958
|
+
fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
955
959
|
let found = Kstat::new(FileType::RegFile, 0);
|
|
956
960
|
Ok(Lookup::Found(Inode::new(&found, Arc::new(Self))))
|
|
957
961
|
}
|
|
@@ -965,7 +969,7 @@ mod tests {
|
|
|
965
969
|
let tmpfs: Tmpfs = [("d/f", "x")].into_iter().collect();
|
|
966
970
|
let mount = Mount::new(
|
|
967
971
|
"/data",
|
|
968
|
-
Filesystem::new(
|
|
972
|
+
Filesystem::new(tmpfs).expect("the instance must stand"),
|
|
969
973
|
Access::Read,
|
|
970
974
|
)
|
|
971
975
|
.expect("/data is a guest path");
|
|
@@ -978,7 +982,7 @@ mod tests {
|
|
|
978
982
|
};
|
|
979
983
|
assert_eq!(
|
|
980
984
|
dir.read(&mut [0; 1]),
|
|
981
|
-
Err(
|
|
985
|
+
Err(Errno::BadDescriptor),
|
|
982
986
|
"File::read of a directory opened for neither reading nor writing must answer EBADF"
|
|
983
987
|
);
|
|
984
988
|
}
|
|
@@ -991,7 +995,7 @@ mod tests {
|
|
|
991
995
|
fn a_write_of_nothing_leaves_an_appending_file_where_it_stands() {
|
|
992
996
|
let mount = Mount::new(
|
|
993
997
|
"/data",
|
|
994
|
-
Filesystem::new(
|
|
998
|
+
Filesystem::new(Tmpfs::new()).expect("the instance must stand"),
|
|
995
999
|
Access::ReadWrite,
|
|
996
1000
|
)
|
|
997
1001
|
.expect("/data is a guest path");
|
|
@@ -1021,7 +1025,7 @@ mod tests {
|
|
|
1021
1025
|
fn an_entry_without_open_opens_with_no_operations() {
|
|
1022
1026
|
let mount = Mount::new(
|
|
1023
1027
|
"/data",
|
|
1024
|
-
Filesystem::new(
|
|
1028
|
+
Filesystem::new(OpensNothing).expect("the instance must stand"),
|
|
1025
1029
|
Access::Read,
|
|
1026
1030
|
)
|
|
1027
1031
|
.expect("/data is a guest path");
|
|
@@ -1035,7 +1039,7 @@ mod tests {
|
|
|
1035
1039
|
.map(|mut file| file.read(&mut [0; 1]));
|
|
1036
1040
|
assert_eq!(
|
|
1037
1041
|
read,
|
|
1038
|
-
Ok(Err(
|
|
1042
|
+
Ok(Err(Errno::InvalidInput)),
|
|
1039
1043
|
"vfs::do_file_open of a file whose Filesystem has no open must succeed, and File::read \
|
|
1040
1044
|
of it must answer EINVAL, as Linux's opens with no f_op->open"
|
|
1041
1045
|
);
|
|
@@ -1046,7 +1050,7 @@ mod tests {
|
|
|
1046
1050
|
let tmpfs = Tmpfs::try_from_iter([("file.txt", "granted")]).expect("the seed must fit");
|
|
1047
1051
|
let mount = Mount::new(
|
|
1048
1052
|
"/data",
|
|
1049
|
-
Filesystem::new(
|
|
1053
|
+
Filesystem::new(tmpfs).expect("the instance must stand"),
|
|
1050
1054
|
Access::ReadWrite,
|
|
1051
1055
|
)
|
|
1052
1056
|
.expect("/data is a guest path");
|
|
@@ -1067,7 +1071,7 @@ mod tests {
|
|
|
1067
1071
|
let tmpfs = Tmpfs::try_from_iter([("file.txt", "granted")]).expect("the seed must fit");
|
|
1068
1072
|
let mount = Mount::new(
|
|
1069
1073
|
"/data",
|
|
1070
|
-
Filesystem::new(
|
|
1074
|
+
Filesystem::new(tmpfs).expect("the instance must stand"),
|
|
1071
1075
|
Access::Read,
|
|
1072
1076
|
)
|
|
1073
1077
|
.expect("/data is a guest path");
|
|
@@ -1085,7 +1089,7 @@ mod tests {
|
|
|
1085
1089
|
.clone();
|
|
1086
1090
|
assert_eq!(
|
|
1087
1091
|
File::dentry_open(path, &write, &Arc::default()).err(),
|
|
1088
|
-
Some(
|
|
1092
|
+
Some(Errno::ReadOnlyFilesystem),
|
|
1089
1093
|
"File::dentry_open to write a file beneath a read-only Mount must answer EROFS"
|
|
1090
1094
|
);
|
|
1091
1095
|
}
|
|
@@ -1104,10 +1108,10 @@ mod tests {
|
|
|
1104
1108
|
open(false, true).pread(&mut buf, 0),
|
|
1105
1109
|
),
|
|
1106
1110
|
(
|
|
1107
|
-
Err(
|
|
1108
|
-
Err(
|
|
1109
|
-
Err(
|
|
1110
|
-
Err(
|
|
1111
|
+
Err(Errno::BadDescriptor),
|
|
1112
|
+
Err(Errno::BadDescriptor),
|
|
1113
|
+
Err(Errno::BadDescriptor),
|
|
1114
|
+
Err(Errno::BadDescriptor),
|
|
1111
1115
|
),
|
|
1112
1116
|
"File::write and pwrite on a file opened to read, and File::read and pread on one \
|
|
1113
1117
|
opened to write, must answer EBADF, as vfs_read and vfs_write do"
|
|
@@ -1145,7 +1149,7 @@ mod tests {
|
|
|
1145
1149
|
pos: u64,
|
|
1146
1150
|
offset: i64,
|
|
1147
1151
|
whence: Whence,
|
|
1148
|
-
) -> Result<u64,
|
|
1152
|
+
) -> Result<u64, Errno> {
|
|
1149
1153
|
generic_file_llseek(dentry, pos, offset, whence)
|
|
1150
1154
|
}
|
|
1151
1155
|
|
|
@@ -1153,8 +1157,8 @@ mod tests {
|
|
|
1153
1157
|
&mut self,
|
|
1154
1158
|
dentry: &Dentry,
|
|
1155
1159
|
ctx: &mut DirContext<'_>,
|
|
1156
|
-
) -> Result<(),
|
|
1157
|
-
self.0.
|
|
1160
|
+
) -> Result<(), Errno> {
|
|
1161
|
+
self.0.iterate_shared(dentry, ctx, || {
|
|
1158
1162
|
Ok(vec![
|
|
1159
1163
|
DirEntry::new("a", FileType::RegFile),
|
|
1160
1164
|
DirEntry::new("b", FileType::RegFile),
|
|
@@ -1164,14 +1168,14 @@ mod tests {
|
|
|
1164
1168
|
}
|
|
1165
1169
|
|
|
1166
1170
|
impl crate::vfs::FileSystemType for ReadsWhole {
|
|
1167
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
1171
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
1168
1172
|
sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
|
|
1169
1173
|
Ok(())
|
|
1170
1174
|
}
|
|
1171
1175
|
}
|
|
1172
1176
|
|
|
1173
1177
|
impl InodeOperations for ReadsWhole {
|
|
1174
|
-
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat,
|
|
1178
|
+
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
1175
1179
|
Ok(Kstat::new(FileType::Dir, 0))
|
|
1176
1180
|
}
|
|
1177
1181
|
|
|
@@ -1179,7 +1183,7 @@ mod tests {
|
|
|
1179
1183
|
&self,
|
|
1180
1184
|
_dentry: &Dentry,
|
|
1181
1185
|
_options: &OpenHow,
|
|
1182
|
-
) -> Result<Box<dyn FileOperations>,
|
|
1186
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
1183
1187
|
Ok(Box::new(ReadsWholeDir(crate::filesystem::Rdir::default())))
|
|
1184
1188
|
}
|
|
1185
1189
|
}
|
|
@@ -1188,22 +1192,22 @@ mod tests {
|
|
|
1188
1192
|
struct CannotStat;
|
|
1189
1193
|
|
|
1190
1194
|
impl crate::vfs::FileSystemType for CannotStat {
|
|
1191
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
1195
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
1192
1196
|
sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
|
|
1193
1197
|
Ok(())
|
|
1194
1198
|
}
|
|
1195
1199
|
}
|
|
1196
1200
|
|
|
1197
1201
|
impl InodeOperations for CannotStat {
|
|
1198
|
-
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat,
|
|
1199
|
-
Err(
|
|
1202
|
+
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
1203
|
+
Err(Errno::Other("no stat".into()))
|
|
1200
1204
|
}
|
|
1201
1205
|
|
|
1202
1206
|
fn open(
|
|
1203
1207
|
&self,
|
|
1204
1208
|
_dentry: &Dentry,
|
|
1205
1209
|
_options: &OpenHow,
|
|
1206
|
-
) -> Result<Box<dyn FileOperations>,
|
|
1210
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
1207
1211
|
Ok(Box::new(ReadsWholeDir(crate::filesystem::Rdir::default())))
|
|
1208
1212
|
}
|
|
1209
1213
|
}
|
|
@@ -1212,14 +1216,14 @@ mod tests {
|
|
|
1212
1216
|
struct StatsAsOne;
|
|
1213
1217
|
|
|
1214
1218
|
impl crate::vfs::FileSystemType for StatsAsOne {
|
|
1215
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
1219
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
1216
1220
|
sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
|
|
1217
1221
|
Ok(())
|
|
1218
1222
|
}
|
|
1219
1223
|
}
|
|
1220
1224
|
|
|
1221
1225
|
impl InodeOperations for StatsAsOne {
|
|
1222
|
-
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat,
|
|
1226
|
+
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
1223
1227
|
Ok(Kstat::new(FileType::Dir, 0).with_identity(7, 9))
|
|
1224
1228
|
}
|
|
1225
1229
|
|
|
@@ -1227,7 +1231,7 @@ mod tests {
|
|
|
1227
1231
|
&self,
|
|
1228
1232
|
_dentry: &Dentry,
|
|
1229
1233
|
_options: &OpenHow,
|
|
1230
|
-
) -> Result<Box<dyn FileOperations>,
|
|
1234
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
1231
1235
|
Ok(Box::new(ReadsWholeDir(crate::filesystem::Rdir::default())))
|
|
1232
1236
|
}
|
|
1233
1237
|
}
|
|
@@ -1252,7 +1256,7 @@ mod tests {
|
|
|
1252
1256
|
fn a_listing_read_whole_names_its_dots_as_a_stat_does() {
|
|
1253
1257
|
let mount = Mount::new(
|
|
1254
1258
|
"/data",
|
|
1255
|
-
Filesystem::new(
|
|
1259
|
+
Filesystem::new(StatsAsOne).expect("the instance must stand"),
|
|
1256
1260
|
Access::Read,
|
|
1257
1261
|
)
|
|
1258
1262
|
.expect("/data is a guest path");
|
|
@@ -1274,7 +1278,7 @@ mod tests {
|
|
|
1274
1278
|
let tmpfs: Tmpfs = [("d/f", "x")].into_iter().collect();
|
|
1275
1279
|
let mount = Mount::new(
|
|
1276
1280
|
"/data",
|
|
1277
|
-
Filesystem::new(
|
|
1281
|
+
Filesystem::new(tmpfs).expect("the instance must stand"),
|
|
1278
1282
|
Access::Read,
|
|
1279
1283
|
)
|
|
1280
1284
|
.expect("/data is a guest path");
|
|
@@ -1307,7 +1311,7 @@ mod tests {
|
|
|
1307
1311
|
fn a_listing_whose_directory_cannot_be_stated_hands_nothing() {
|
|
1308
1312
|
let mount = Mount::new(
|
|
1309
1313
|
"/data",
|
|
1310
|
-
Filesystem::new(
|
|
1314
|
+
Filesystem::new(CannotStat).expect("the instance must stand"),
|
|
1311
1315
|
Access::Read,
|
|
1312
1316
|
)
|
|
1313
1317
|
.expect("/data is a guest path");
|
|
@@ -1321,7 +1325,7 @@ mod tests {
|
|
|
1321
1325
|
}));
|
|
1322
1326
|
assert_eq!(
|
|
1323
1327
|
(answer, seen),
|
|
1324
|
-
(Err(
|
|
1328
|
+
(Err(Errno::Other("no stat".into())), 0),
|
|
1325
1329
|
"File::iterate_dir through Rdir of a directory its Filesystem cannot stat must answer \
|
|
1326
1330
|
that failure and hand no entry, as ovl_cache_update fails the listing"
|
|
1327
1331
|
);
|
|
@@ -1329,7 +1333,7 @@ mod tests {
|
|
|
1329
1333
|
|
|
1330
1334
|
/// A listing of `file` from the start, its actor stopping after `room`
|
|
1331
1335
|
/// entries.
|
|
1332
|
-
fn begin_listing(file: &mut File, room: usize) -> Result<(),
|
|
1336
|
+
fn begin_listing(file: &mut File, room: usize) -> Result<(), Errno> {
|
|
1333
1337
|
let mut seen = 0;
|
|
1334
1338
|
file.iterate_dir(&mut DirContext::new(0, &mut |_| {
|
|
1335
1339
|
seen += 1;
|
|
@@ -1340,16 +1344,16 @@ mod tests {
|
|
|
1340
1344
|
/// A security module refusing to open any directory.
|
|
1341
1345
|
struct RefusesDirectories;
|
|
1342
1346
|
|
|
1343
|
-
impl crate::
|
|
1347
|
+
impl crate::security::SecurityOperations for RefusesDirectories {
|
|
1344
1348
|
fn file_open(
|
|
1345
1349
|
&self,
|
|
1346
|
-
_path: crate::
|
|
1350
|
+
_path: crate::security::SecurityPath<'_>,
|
|
1347
1351
|
kind: FileType,
|
|
1348
1352
|
_mode: FMode,
|
|
1349
1353
|
_how: &OpenHow,
|
|
1350
|
-
) -> Result<FileSecurity,
|
|
1354
|
+
) -> Result<FileSecurity, Errno> {
|
|
1351
1355
|
match kind {
|
|
1352
|
-
FileType::Dir => Err(
|
|
1356
|
+
FileType::Dir => Err(Errno::PermissionDenied),
|
|
1353
1357
|
_ => Ok(None),
|
|
1354
1358
|
}
|
|
1355
1359
|
}
|
|
@@ -1362,14 +1366,14 @@ mod tests {
|
|
|
1362
1366
|
fn opening_a_mounts_root_asks_the_security_modules() {
|
|
1363
1367
|
let mount = Mount::new(
|
|
1364
1368
|
"/data",
|
|
1365
|
-
Filesystem::new(
|
|
1369
|
+
Filesystem::new(Tmpfs::default()).expect("the instance must stand"),
|
|
1366
1370
|
Access::Read,
|
|
1367
1371
|
)
|
|
1368
1372
|
.expect("/data is a guest path");
|
|
1369
1373
|
let cred = Cred::new(vec![Arc::new(RefusesDirectories)]);
|
|
1370
1374
|
assert_eq!(
|
|
1371
1375
|
File::root(mount.mnt(), &cred).err(),
|
|
1372
|
-
Some(
|
|
1376
|
+
Some(Errno::PermissionDenied),
|
|
1373
1377
|
"File::root under a security module refusing to open a directory must answer as \
|
|
1374
1378
|
the module refuses, as dentry_open asks security_file_open"
|
|
1375
1379
|
);
|
|
@@ -1382,16 +1386,18 @@ mod tests {
|
|
|
1382
1386
|
fn listings_held_between_calls_count_against_their_limit() {
|
|
1383
1387
|
let mount = Mount::new(
|
|
1384
1388
|
"/data",
|
|
1385
|
-
Filesystem::new(
|
|
1389
|
+
Filesystem::new(ReadsWhole).expect("the instance must stand"),
|
|
1386
1390
|
Access::Read,
|
|
1387
1391
|
)
|
|
1388
1392
|
.expect("/data is a guest path");
|
|
1389
1393
|
// `.`, `..`, and two one-letter names.
|
|
1390
1394
|
let one_listing = 4 * size_of::<DirEntry>() + 1 + 2 + 2;
|
|
1391
|
-
let cred = crate::security::
|
|
1395
|
+
let cred = crate::security::prepare_creds(&[], Some(one_listing));
|
|
1392
1396
|
// A Wasm Driver opens the root before the Policies apply and lists through
|
|
1393
1397
|
// the Cred they were added to, so both must count against one limit.
|
|
1394
|
-
let restricted =
|
|
1398
|
+
let restricted =
|
|
1399
|
+
crate::security::restrict_self(&cred, [&crate::grant::Grant::Mount(mount.clone())])
|
|
1400
|
+
.expect("every Mount stands");
|
|
1395
1401
|
let open = |cred: &Arc<Cred>| {
|
|
1396
1402
|
File::root(mount.mnt(), cred).unwrap_or_else(|_| panic!("the root must open"))
|
|
1397
1403
|
};
|
|
@@ -1405,8 +1411,8 @@ mod tests {
|
|
|
1405
1411
|
(held, refused, read_whole, after_close),
|
|
1406
1412
|
(
|
|
1407
1413
|
Ok(()),
|
|
1408
|
-
Err(
|
|
1409
|
-
Err(
|
|
1414
|
+
Err(Errno::OutOfMemory),
|
|
1415
|
+
Err(Errno::OutOfMemory),
|
|
1410
1416
|
Ok(())
|
|
1411
1417
|
),
|
|
1412
1418
|
"File::iterate_dir of a second listing past its caller's memory limit, stopped part \
|
|
@@ -1422,7 +1428,7 @@ mod tests {
|
|
|
1422
1428
|
) -> Vec<(String, Option<Identity>, Option<Identity>)> {
|
|
1423
1429
|
let mount = Mount::new(
|
|
1424
1430
|
"/data",
|
|
1425
|
-
Filesystem::new(
|
|
1431
|
+
Filesystem::new(filesystem).expect("the instance must stand"),
|
|
1426
1432
|
Access::ReadWrite,
|
|
1427
1433
|
)
|
|
1428
1434
|
.expect("/data is a guest path");
|
|
@@ -1471,16 +1477,14 @@ mod tests {
|
|
|
1471
1477
|
let lower: Tmpfs = [("a", "x"), ("d/b", "y")].into_iter().collect();
|
|
1472
1478
|
let upper = Tmpfs::new();
|
|
1473
1479
|
let overlay = Overlay::new(
|
|
1474
|
-
vec![Filesystem::new(
|
|
1475
|
-
Some(Filesystem::new(
|
|
1480
|
+
vec![Filesystem::new(lower).expect("the instance must stand")],
|
|
1481
|
+
Some(Filesystem::new(upper).expect("the instance must stand")),
|
|
1476
1482
|
)
|
|
1477
1483
|
.unwrap_or_else(|_| panic!("the Overlay must make"));
|
|
1478
1484
|
assert_named_alike("Overlay", identities(overlay));
|
|
1479
1485
|
}
|
|
1480
1486
|
|
|
1481
|
-
// A host names no identity through a Bind beyond unix.
|
|
1482
1487
|
// @behavior RT-183
|
|
1483
|
-
#[cfg(unix)]
|
|
1484
1488
|
#[test]
|
|
1485
1489
|
fn a_bind_lists_each_entry_as_a_stat_names_it() {
|
|
1486
1490
|
let dir = std::env::temp_dir().join(format!("kobako-listed-{}", std::process::id()));
|
|
@@ -1523,7 +1527,7 @@ mod tests {
|
|
|
1523
1527
|
fn a_listing_read_whole_goes_on_past_the_last_entry_taken() {
|
|
1524
1528
|
let mount = Mount::new(
|
|
1525
1529
|
"/data",
|
|
1526
|
-
Filesystem::new(
|
|
1530
|
+
Filesystem::new(ReadsWhole).expect("the instance must stand"),
|
|
1527
1531
|
Access::Read,
|
|
1528
1532
|
)
|
|
1529
1533
|
.expect("/data is a guest path");
|
|
@@ -1546,11 +1550,11 @@ mod tests {
|
|
|
1546
1550
|
struct CountsSyncs(Arc<AtomicUsize>);
|
|
1547
1551
|
|
|
1548
1552
|
impl FileOperations for CountsSyncs {
|
|
1549
|
-
fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize,
|
|
1553
|
+
fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
|
|
1550
1554
|
generic_write_sync(self, iocb, buf.len())
|
|
1551
1555
|
}
|
|
1552
1556
|
|
|
1553
|
-
fn fsync(&mut self, _datasync: bool) -> Result<(),
|
|
1557
|
+
fn fsync(&mut self, _datasync: bool) -> Result<(), Errno> {
|
|
1554
1558
|
self.0.fetch_add(1, Ordering::SeqCst);
|
|
1555
1559
|
Ok(())
|
|
1556
1560
|
}
|
|
@@ -1564,42 +1568,38 @@ mod tests {
|
|
|
1564
1568
|
}
|
|
1565
1569
|
|
|
1566
1570
|
impl FileOperations for RecordsCalls {
|
|
1567
|
-
fn read_iter(
|
|
1568
|
-
&mut self,
|
|
1569
|
-
_iocb: &mut Kiocb,
|
|
1570
|
-
buf: &mut [u8],
|
|
1571
|
-
) -> Result<usize, FilesystemError> {
|
|
1571
|
+
fn read_iter(&mut self, _iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize, Errno> {
|
|
1572
1572
|
self.taken.store(buf.len(), Ordering::SeqCst);
|
|
1573
1573
|
Ok(0)
|
|
1574
1574
|
}
|
|
1575
1575
|
|
|
1576
|
-
fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize,
|
|
1576
|
+
fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
|
|
1577
1577
|
self.taken.store(buf.len(), Ordering::SeqCst);
|
|
1578
1578
|
generic_write_sync(self, iocb, buf.len())
|
|
1579
1579
|
}
|
|
1580
1580
|
|
|
1581
|
-
fn fsync(&mut self, datasync: bool) -> Result<(),
|
|
1581
|
+
fn fsync(&mut self, datasync: bool) -> Result<(), Errno> {
|
|
1582
1582
|
self.syncs.lock().expect("never poisoned").push(datasync);
|
|
1583
1583
|
Ok(())
|
|
1584
1584
|
}
|
|
1585
1585
|
}
|
|
1586
1586
|
|
|
1587
1587
|
impl crate::vfs::FileSystemType for RecordsCalls {
|
|
1588
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
1588
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
1589
1589
|
sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
|
|
1590
1590
|
Ok(())
|
|
1591
1591
|
}
|
|
1592
1592
|
}
|
|
1593
1593
|
|
|
1594
1594
|
impl InodeOperations for RecordsCalls {
|
|
1595
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
1595
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
1596
1596
|
Ok(match dentry.is_root() {
|
|
1597
1597
|
false => Kstat::new(FileType::RegFile, 0),
|
|
1598
1598
|
true => Kstat::new(FileType::Dir, 0),
|
|
1599
1599
|
})
|
|
1600
1600
|
}
|
|
1601
1601
|
|
|
1602
|
-
fn lookup(&self, _dentry: &Dentry) -> Result<Lookup,
|
|
1602
|
+
fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
1603
1603
|
let found = Kstat::new(FileType::RegFile, 0);
|
|
1604
1604
|
Ok(Lookup::Found(Inode::new(&found, Arc::new(self.clone()))))
|
|
1605
1605
|
}
|
|
@@ -1608,7 +1608,7 @@ mod tests {
|
|
|
1608
1608
|
&self,
|
|
1609
1609
|
_dentry: &Dentry,
|
|
1610
1610
|
_options: &OpenHow,
|
|
1611
|
-
) -> Result<Box<dyn FileOperations>,
|
|
1611
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
1612
1612
|
Ok(Box::new(self.clone()))
|
|
1613
1613
|
}
|
|
1614
1614
|
}
|
|
@@ -1617,7 +1617,7 @@ mod tests {
|
|
|
1617
1617
|
fn open_recording(calls: &RecordsCalls, how: OpenHow) -> File {
|
|
1618
1618
|
let mount = Mount::new(
|
|
1619
1619
|
"/data",
|
|
1620
|
-
Filesystem::new(
|
|
1620
|
+
Filesystem::new(calls.clone()).expect("the instance must stand"),
|
|
1621
1621
|
Access::ReadWrite,
|
|
1622
1622
|
)
|
|
1623
1623
|
.expect("/data is a guest path");
|
|
@@ -1689,18 +1689,18 @@ mod tests {
|
|
|
1689
1689
|
struct HoldsCountsSyncs(Arc<AtomicUsize>);
|
|
1690
1690
|
|
|
1691
1691
|
impl crate::vfs::FileSystemType for HoldsCountsSyncs {
|
|
1692
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
1692
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
1693
1693
|
sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
|
|
1694
1694
|
Ok(())
|
|
1695
1695
|
}
|
|
1696
1696
|
}
|
|
1697
1697
|
|
|
1698
1698
|
impl InodeOperations for HoldsCountsSyncs {
|
|
1699
|
-
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat,
|
|
1699
|
+
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
1700
1700
|
Ok(Kstat::new(FileType::Dir, 0))
|
|
1701
1701
|
}
|
|
1702
1702
|
|
|
1703
|
-
fn lookup(&self, _dentry: &Dentry) -> Result<Lookup,
|
|
1703
|
+
fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
1704
1704
|
let found = Kstat::new(FileType::RegFile, 0);
|
|
1705
1705
|
let ops = Arc::new(Self(self.0.clone()));
|
|
1706
1706
|
Ok(Lookup::Found(Inode::new(&found, ops)))
|
|
@@ -1710,7 +1710,7 @@ mod tests {
|
|
|
1710
1710
|
&self,
|
|
1711
1711
|
_dentry: &Dentry,
|
|
1712
1712
|
_options: &OpenHow,
|
|
1713
|
-
) -> Result<Box<dyn FileOperations>,
|
|
1713
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
1714
1714
|
Ok(Box::new(CountsSyncs(self.0.clone())))
|
|
1715
1715
|
}
|
|
1716
1716
|
}
|
|
@@ -1721,8 +1721,7 @@ mod tests {
|
|
|
1721
1721
|
let syncs = Arc::new(AtomicUsize::new(0));
|
|
1722
1722
|
let mount = Mount::new(
|
|
1723
1723
|
"/data",
|
|
1724
|
-
Filesystem::new(
|
|
1725
|
-
.expect("the instance must stand"),
|
|
1724
|
+
Filesystem::new(HoldsCountsSyncs(syncs.clone())).expect("the instance must stand"),
|
|
1726
1725
|
Access::ReadWrite,
|
|
1727
1726
|
)
|
|
1728
1727
|
.expect("/data is a guest path");
|
|
@@ -1771,7 +1770,7 @@ mod tests {
|
|
|
1771
1770
|
let dir = filp_open(&Arc::default(), &Path::root(mount.mnt()), "dir", &how)
|
|
1772
1771
|
.unwrap_or_else(|_| panic!("the directory must open"));
|
|
1773
1772
|
assert_eq!(
|
|
1774
|
-
(dir.
|
|
1773
|
+
(dir.is_nonblock(), dir.is_sync()),
|
|
1775
1774
|
(true, true),
|
|
1776
1775
|
"File::nonblock and File::sync on a directory do_file_open opened with both must \
|
|
1777
1776
|
report them, as F_GETFL does"
|
|
@@ -1803,12 +1802,12 @@ mod tests {
|
|
|
1803
1802
|
dir.fadvise(0, 0),
|
|
1804
1803
|
),
|
|
1805
1804
|
(
|
|
1806
|
-
Err(
|
|
1807
|
-
Err(
|
|
1808
|
-
Err(
|
|
1809
|
-
Err(
|
|
1810
|
-
Err(
|
|
1811
|
-
Err(
|
|
1805
|
+
Err(Errno::IsADirectory),
|
|
1806
|
+
Err(Errno::IsADirectory),
|
|
1807
|
+
Err(Errno::BadDescriptor),
|
|
1808
|
+
Err(Errno::BadDescriptor),
|
|
1809
|
+
Err(Errno::InvalidInput),
|
|
1810
|
+
Err(Errno::BadDescriptor),
|
|
1812
1811
|
Ok(()),
|
|
1813
1812
|
Ok(()),
|
|
1814
1813
|
),
|
|
@@ -1834,10 +1833,7 @@ mod tests {
|
|
|
1834
1833
|
alloc_file_pseudo(inode, &mnt, &how, Box::new(NoOperations), &Arc::default());
|
|
1835
1834
|
assert_eq!(
|
|
1836
1835
|
(file.pread(&mut [0], 0), file.pwrite(b"x", 0)),
|
|
1837
|
-
(
|
|
1838
|
-
Err(FilesystemError::NotSeekable),
|
|
1839
|
-
Err(FilesystemError::NotSeekable)
|
|
1840
|
-
),
|
|
1836
|
+
(Err(Errno::NotSeekable), Err(Errno::NotSeekable)),
|
|
1841
1837
|
"File::pread and File::pwrite on a file alloc_file_pseudo made must answer ESPIPE, \
|
|
1842
1838
|
as file_init_path gives no FMODE_PREAD or FMODE_PWRITE"
|
|
1843
1839
|
);
|
|
@@ -1870,10 +1866,10 @@ mod tests {
|
|
|
1870
1866
|
pipe.fallocate(0, 1),
|
|
1871
1867
|
),
|
|
1872
1868
|
(
|
|
1873
|
-
Err(
|
|
1874
|
-
Err(
|
|
1875
|
-
Err(
|
|
1876
|
-
Err(
|
|
1869
|
+
Err(Errno::InvalidInput),
|
|
1870
|
+
Err(Errno::BadDescriptor),
|
|
1871
|
+
Err(Errno::Unsupported),
|
|
1872
|
+
Err(Errno::NotSeekable),
|
|
1877
1873
|
),
|
|
1878
1874
|
"File::fallocate must answer an empty range EINVAL, a file not open to write EBADF, \
|
|
1879
1875
|
a file without fallocate ENOTSUP, and a pipe ESPIPE, as vfs_fallocate does"
|
|
@@ -1899,13 +1895,13 @@ mod tests {
|
|
|
1899
1895
|
file.pwrite(b"", OFFSET_MAX),
|
|
1900
1896
|
),
|
|
1901
1897
|
(
|
|
1902
|
-
Err(
|
|
1903
|
-
Err(
|
|
1904
|
-
Err(
|
|
1905
|
-
Err(
|
|
1906
|
-
Err(
|
|
1907
|
-
Err(
|
|
1908
|
-
Err(
|
|
1898
|
+
Err(Errno::InvalidInput),
|
|
1899
|
+
Err(Errno::InvalidInput),
|
|
1900
|
+
Err(Errno::InvalidInput),
|
|
1901
|
+
Err(Errno::InvalidInput),
|
|
1902
|
+
Err(Errno::InvalidInput),
|
|
1903
|
+
Err(Errno::InvalidInput),
|
|
1904
|
+
Err(Errno::InvalidInput),
|
|
1909
1905
|
Ok(0),
|
|
1910
1906
|
),
|
|
1911
1907
|
"File calls ending past the largest signed offset must answer EINVAL, as \
|