kobako 0.30.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.githooks/linux-tests.sh +29 -0
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +460 -0
- data/Cargo.lock +868 -447
- data/README.md +43 -4
- data/ROADMAP.md +1 -2
- data/crates/kobako-runtime/CHANGELOG.md +309 -0
- data/crates/kobako-runtime/Cargo.toml +58 -11
- data/crates/kobako-runtime/README.md +7 -4
- data/crates/kobako-runtime/src/cred.rs +136 -0
- data/crates/kobako-runtime/src/dispatch.rs +4 -5
- data/crates/kobako-runtime/src/endpoint/buffer.rs +153 -44
- data/crates/kobako-runtime/src/endpoint/dispatch.rs +80 -41
- data/crates/kobako-runtime/src/endpoint/invoke.rs +23 -36
- data/crates/kobako-runtime/src/endpoint.rs +137 -36
- data/crates/kobako-runtime/src/errno.rs +391 -0
- data/crates/kobako-runtime/src/error.rs +31 -10
- data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
- data/crates/kobako-runtime/src/filesystem/bind/fid.rs +300 -22
- data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +101 -29
- data/crates/kobako-runtime/src/filesystem/bind/unicode.rs +109 -0
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +52 -34
- data/crates/kobako-runtime/src/filesystem/bind.rs +812 -447
- data/crates/kobako-runtime/src/filesystem/overlay/file.rs +6 -6
- data/crates/kobako-runtime/src/filesystem/overlay/path.rs +43 -65
- data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +11 -16
- data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +47 -72
- data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +12 -12
- data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +4 -7
- data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +120 -37
- data/crates/kobako-runtime/src/filesystem/overlay.rs +578 -388
- data/crates/kobako-runtime/src/filesystem/pipe.rs +12 -9
- data/crates/kobako-runtime/src/filesystem/rdir.rs +14 -50
- data/crates/kobako-runtime/src/filesystem/testing.rs +31 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +3 -3
- data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +57 -35
- data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +2 -2
- data/crates/kobako-runtime/src/filesystem/tmpfs.rs +219 -173
- data/crates/kobako-runtime/src/filesystem/wrap.rs +36 -52
- data/crates/kobako-runtime/src/filesystem.rs +8 -3
- data/crates/kobako-runtime/src/fork.rs +319 -0
- data/crates/kobako-runtime/src/grant.rs +3 -0
- data/crates/kobako-runtime/src/hashtable.rs +4 -2
- data/crates/kobako-runtime/src/lib.rs +18 -7
- data/crates/kobako-runtime/src/limits.rs +171 -0
- data/crates/kobako-runtime/src/locking/seqlock.rs +29 -3
- data/crates/kobako-runtime/src/locking.rs +518 -113
- data/crates/kobako-runtime/src/memcg.rs +306 -0
- data/crates/kobako-runtime/src/mount.rs +37 -9
- data/crates/kobako-runtime/src/net/backends.rs +43 -0
- data/crates/kobako-runtime/src/net/connections.rs +219 -0
- data/crates/kobako-runtime/src/net/credential.rs +125 -0
- data/crates/kobako-runtime/src/net/egress.rs +180 -0
- data/crates/kobako-runtime/src/net/family.rs +181 -0
- data/crates/kobako-runtime/src/net/http.rs +3165 -0
- data/crates/kobako-runtime/src/net/lookup.rs +385 -0
- data/crates/kobako-runtime/src/net/mock.rs +251 -0
- data/crates/kobako-runtime/src/net/namespace.rs +1368 -0
- data/crates/kobako-runtime/src/net/reactor.rs +626 -0
- data/crates/kobako-runtime/src/net/resolv/darwin.rs +280 -0
- data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +519 -0
- data/crates/kobako-runtime/src/net/resolv/stub.rs +542 -0
- data/crates/kobako-runtime/src/net/resolv/windows.rs +218 -0
- data/crates/kobako-runtime/src/net/resolv.rs +251 -0
- data/crates/kobako-runtime/src/net/skbuff.rs +109 -0
- data/crates/kobako-runtime/src/net/socket.rs +869 -0
- data/crates/kobako-runtime/src/net/task.rs +223 -0
- data/crates/kobako-runtime/src/net/tcp.rs +1840 -0
- data/crates/kobako-runtime/src/net/tls.rs +120 -0
- data/crates/kobako-runtime/src/net/transport.rs +304 -0
- data/crates/kobako-runtime/src/net/udp.rs +1105 -0
- data/crates/kobako-runtime/src/net.rs +45 -0
- data/crates/kobako-runtime/src/network/builder.rs +177 -0
- data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
- data/crates/kobako-runtime/src/network.rs +551 -0
- data/crates/kobako-runtime/src/policy.rs +16 -0
- data/crates/kobako-runtime/src/profile.rs +29 -144
- data/crates/kobako-runtime/src/runtime.rs +3 -5
- data/crates/kobako-runtime/src/sched.rs +338 -51
- data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
- data/crates/kobako-runtime/src/{vfs/cred.rs → security/hooks.rs} +52 -144
- data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
- data/crates/kobako-runtime/src/security.rs +125 -209
- data/crates/kobako-runtime/src/snapshot.rs +121 -2
- data/crates/kobako-runtime/src/vfs/attr.rs +5 -5
- data/crates/kobako-runtime/src/vfs/dentry.rs +210 -117
- data/crates/kobako-runtime/src/vfs/file.rs +243 -248
- data/crates/kobako-runtime/src/vfs/inode.rs +41 -45
- data/crates/kobako-runtime/src/vfs/kern_path.rs +62 -53
- data/crates/kobako-runtime/src/vfs/mount.rs +10 -9
- data/crates/kobako-runtime/src/vfs/namei.rs +1162 -818
- data/crates/kobako-runtime/src/vfs/namespace.rs +245 -0
- data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
- data/crates/kobako-runtime/src/vfs/openat2.rs +3 -3
- data/crates/kobako-runtime/src/vfs/path.rs +6 -6
- data/crates/kobako-runtime/src/vfs/readdir.rs +6 -6
- data/crates/kobako-runtime/src/vfs/stat.rs +248 -23
- data/crates/kobako-runtime/src/vfs/super_block.rs +18 -14
- data/crates/kobako-runtime/src/vfs/utimes.rs +37 -27
- data/crates/kobako-runtime/src/vfs.rs +10 -6
- data/crates/kobako-runtime/src/wait.rs +381 -0
- data/crates/kobako-transport/CHANGELOG.md +38 -0
- data/crates/kobako-transport/Cargo.toml +1 -1
- data/crates/kobako-transport/README.md +3 -4
- data/crates/kobako-transport/src/abi.rs +78 -72
- data/crates/kobako-transport/src/envelope/bytes.rs +17 -6
- data/crates/kobako-transport/src/envelope/call.rs +32 -4
- data/crates/kobako-transport/src/envelope/error_record.rs +21 -0
- data/crates/kobako-transport/src/envelope/name.rs +99 -0
- data/crates/kobako-transport/src/envelope/outcome.rs +9 -9
- data/crates/kobako-transport/src/envelope/preamble.rs +24 -21
- data/crates/kobako-transport/src/envelope/reply.rs +27 -27
- data/crates/kobako-transport/src/envelope/unsupported.rs +10 -10
- data/crates/kobako-transport/src/envelope.rs +13 -8
- data/crates/kobako-wasmtime/CHANGELOG.md +208 -0
- data/crates/kobako-wasmtime/Cargo.toml +47 -7
- data/crates/kobako-wasmtime/README.md +4 -3
- data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
- data/crates/kobako-wasmtime/build.rs +16 -0
- data/crates/kobako-wasmtime/src/abi.rs +18 -37
- data/crates/kobako-wasmtime/src/ambient.rs +43 -19
- data/crates/kobako-wasmtime/src/cache/unix.rs +95 -0
- data/crates/kobako-wasmtime/src/cache/windows.rs +359 -0
- data/crates/kobako-wasmtime/src/cache.rs +106 -113
- data/crates/kobako-wasmtime/src/config.rs +52 -68
- data/crates/kobako-wasmtime/src/driver.rs +80 -82
- data/crates/kobako-wasmtime/src/exports.rs +143 -17
- data/crates/kobako-wasmtime/src/guest.rs +12 -6
- data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
- data/crates/kobako-wasmtime/src/imports.rs +42 -18
- data/crates/kobako-wasmtime/src/instance_pre.rs +4 -4
- data/crates/kobako-wasmtime/src/invocation.rs +91 -15
- data/crates/kobako-wasmtime/src/lib.rs +7 -3
- data/crates/kobako-wasmtime/src/limiter.rs +130 -12
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +305 -0
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +9 -20
- data/crates/kobako-wasmtime/src/preview1/differential.rs +27 -31
- data/crates/kobako-wasmtime/src/preview1/errno.rs +55 -66
- data/crates/kobako-wasmtime/src/preview1/fd.rs +347 -312
- data/crates/kobako-wasmtime/src/preview1/memory.rs +21 -12
- data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +34 -53
- data/crates/kobako-wasmtime/src/preview1/mount_view.rs +335 -388
- data/crates/kobako-wasmtime/src/preview1/path.rs +56 -121
- data/crates/kobako-wasmtime/src/preview1/poll.rs +255 -125
- data/crates/kobako-wasmtime/src/preview1/random.rs +125 -0
- data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -8
- data/crates/kobako-wasmtime/src/preview1/testing.rs +31 -0
- data/crates/kobako-wasmtime/src/preview1/testsuite.rs +5 -15
- data/crates/kobako-wasmtime/src/preview1.rs +131 -51
- data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
- data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
- data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
- data/crates/kobako-wasmtime/src/preview2/host.rs +4319 -0
- data/crates/kobako-wasmtime/src/preview2/http.rs +1587 -0
- data/crates/kobako-wasmtime/src/preview2/io.rs +328 -0
- data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
- data/crates/kobako-wasmtime/src/preview2/table.rs +257 -0
- data/crates/kobako-wasmtime/src/preview2.rs +57 -0
- data/crates/kobako-wasmtime/src/trap.rs +88 -28
- data/crates/kobako-wasmtime/src/waits.rs +59 -0
- data/crates/kobako-wasmtime/src/wasi.rs +291 -81
- data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
- data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
- data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
- data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
- data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
- data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
- data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
- data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +13 -0
- data/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +6 -2
- data/ext/kobako/src/{runtime/errors.rs → errors.rs} +34 -26
- data/ext/kobako/src/escape.rs +404 -0
- data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +34 -32
- data/ext/kobako/src/{runtime/filesystem → filesystem}/ruby.rs +158 -170
- data/ext/kobako/src/{runtime/filesystem.rs → filesystem.rs} +71 -23
- data/ext/kobako/src/fork.rs +72 -0
- data/ext/kobako/src/gvl.rs +729 -0
- data/ext/kobako/src/handoff.rs +490 -0
- data/ext/kobako/src/lib.rs +74 -3
- data/ext/kobako/src/network/mock.rs +187 -0
- data/ext/kobako/src/network.rs +593 -0
- data/ext/kobako/src/pinned_value.rs +44 -0
- data/ext/kobako/src/runtime/bridge.rs +58 -50
- data/ext/kobako/src/runtime/snapshot.rs +4 -4
- data/ext/kobako/src/runtime.rs +272 -163
- data/ext/kobako/src/wire.rs +42 -0
- data/lib/kobako/catalog/extensions.rb +14 -2
- data/lib/kobako/catalog/flags.rb +3 -5
- data/lib/kobako/catalog/grants.rb +5 -4
- data/lib/kobako/catalog/handles.rb +14 -32
- data/lib/kobako/catalog/mount.rb +11 -3
- data/lib/kobako/catalog/network.rb +35 -0
- data/lib/kobako/catalog/replacements.rb +28 -0
- data/lib/kobako/catalog/services.rb +5 -19
- data/lib/kobako/catalog/snippets.rb +3 -18
- data/lib/kobako/catalog.rb +3 -0
- data/lib/kobako/codec/{utils.rb → boundary.rb} +4 -2
- data/lib/kobako/codec/decoder.rb +5 -5
- data/lib/kobako/codec/ext_types.rb +3 -3
- data/lib/kobako/codec/handle_walk.rb +3 -43
- data/lib/kobako/codec/state.rb +2 -18
- data/lib/kobako/codec/value_budget.rb +133 -41
- data/lib/kobako/codec.rb +6 -7
- data/lib/kobako/context.rb +24 -11
- data/lib/kobako/errors.rb +18 -18
- data/lib/kobako/extension.rb +3 -2
- data/lib/kobako/filesystem.rb +10 -3
- data/lib/kobako/fork.rb +42 -0
- data/lib/kobako/handle.rb +2 -3
- data/lib/kobako/names.rb +28 -0
- data/lib/kobako/network.rb +210 -0
- data/lib/kobako/outcome.rb +7 -7
- data/lib/kobako/runtime.rb +3 -2
- data/lib/kobako/sandbox.rb +73 -35
- data/lib/kobako/sandbox_options.rb +42 -109
- data/lib/kobako/transport/argument_wrap.rb +64 -0
- data/lib/kobako/transport/block_failure.rb +1 -1
- data/lib/kobako/transport/dispatcher.rb +6 -6
- data/lib/kobako/transport/exposure.rb +26 -15
- data/lib/kobako/transport/reflection.rb +21 -4
- data/lib/kobako/transport/run.rb +8 -23
- data/lib/kobako/transport/yielder.rb +2 -9
- data/lib/kobako/transport.rb +1 -0
- data/lib/kobako/usage.rb +4 -2
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +8 -4
- data/release-please-config.json +15 -0
- data/sig/kobako/catalog/extensions.rbs +2 -0
- data/sig/kobako/catalog/grants.rbs +7 -4
- data/sig/kobako/catalog/handles.rbs +2 -2
- data/sig/kobako/catalog/mount.rbs +3 -1
- data/sig/kobako/catalog/network.rbs +20 -0
- data/sig/kobako/catalog/replacements.rbs +14 -0
- data/sig/kobako/catalog/services.rbs +0 -4
- data/sig/kobako/catalog/snippets.rbs +0 -2
- data/sig/kobako/codec/{utils.rbs → boundary.rbs} +2 -2
- data/sig/kobako/codec/handle_walk.rbs +0 -6
- data/sig/kobako/codec/state.rbs +0 -4
- data/sig/kobako/codec/value_budget.rbs +48 -5
- data/sig/kobako/codec.rbs +2 -2
- data/sig/kobako/context.rbs +3 -1
- data/sig/kobako/errors.rbs +4 -7
- data/sig/kobako/filesystem.rbs +21 -3
- data/sig/kobako/fork.rbs +17 -0
- data/sig/kobako/network.rbs +115 -0
- data/sig/kobako/outcome.rbs +1 -1
- data/sig/kobako/runtime.rbs +32 -3
- data/sig/kobako/sandbox.rbs +10 -2
- data/sig/kobako/sandbox_options.rbs +29 -40
- data/sig/kobako/transport/argument_wrap.rbs +15 -0
- data/sig/kobako/transport/error.rbs +1 -1
- data/sig/kobako/transport/exposure.rbs +2 -4
- data/sig/kobako/transport/reflection.rbs +10 -0
- data/sig/kobako/transport/run.rbs +0 -2
- data/sig/kobako/transport/yielder.rbs +0 -3
- data/sig/kobako/transport.rbs +1 -1
- data/sig/kobako.rbs +13 -0
- metadata +97 -37
- data/crates/kobako-runtime/src/endpoint/capture.rs +0 -115
- data/crates/kobako-runtime/src/endpoint/memory_cap.rs +0 -238
- data/crates/kobako-runtime/src/filesystem/path.rs +0 -21
- data/crates/kobako-runtime/src/vfs/errno.rs +0 -153
- data/crates/kobako-runtime/tests/linux_baseline/calls.rs +0 -171
- data/crates/kobako-runtime/tests/linux_baseline/concurrent.rs +0 -276
- data/crates/kobako-runtime/tests/linux_baseline/kobako.rs +0 -323
- data/crates/kobako-runtime/tests/linux_baseline/linux-baseline-expected.txt +0 -16
- data/crates/kobako-runtime/tests/linux_baseline/linux.rs +0 -449
- data/crates/kobako-runtime/tests/linux_baseline/main.rs +0 -611
- data/crates/kobako-runtime/tests/linux_baseline/permissions.rs +0 -236
- data/crates/kobako-wasmtime/src/descriptors.rs +0 -200
- data/crates/kobako-wasmtime/tests/integration/compile_posture.rs +0 -43
- data/crates/kobako-wasmtime/tests/integration/guest_file.rs +0 -1085
- data/crates/kobako-wasmtime/tests/integration/main.rs +0 -29
- data/crates/kobako-wasmtime/tests/integration/preamble_flags.rs +0 -70
- data/crates/kobako-wasmtime/tests/integration/snippet_compile.rs +0 -95
- data/crates/kobako-wasmtime/tests/integration/support/mod.rs +0 -30
- data/crates/kobako-wasmtime/tests/integration/unanswered_call.rs +0 -86
- data/crates/kobako-wasmtime/tests/integration/unsupported_call.rs +0 -51
- data/ext/kobako/src/runtime/escape.rs +0 -67
- data/ext/kobako/src/runtime/gvl.rs +0 -147
- data/ext/kobako/src/runtime/pinned_value.rs +0 -31
- data/lib/kobako/constant_name.rb +0 -8
- data/lib/kobako/pool.rb +0 -140
- data/sig/kobako/constant_name.rbs +0 -3
- data/sig/kobako/pool.rbs +0 -42
|
@@ -7,19 +7,21 @@ use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering};
|
|
|
7
7
|
use std::sync::{Arc, Mutex, MutexGuard};
|
|
8
8
|
use std::time::SystemTime;
|
|
9
9
|
|
|
10
|
-
use super::path::{ancestors, name, normalize_seed};
|
|
11
10
|
use super::{
|
|
12
|
-
DentryOperations, DirEntry, FileOperations, FileSystemType, FileType, Filesystem,
|
|
13
|
-
|
|
11
|
+
DentryOperations, DirEntry, Errno, FileOperations, FileSystemType, FileType, Filesystem, Iattr,
|
|
12
|
+
InodeOperations, Kiocb, Kstat, Lookup, OpenHow, RenameFlag, SetTime,
|
|
14
13
|
};
|
|
15
14
|
use crate::vfs::{dir_emit_dots, generic_file_llseek, generic_read_dir, DirContext, Whence};
|
|
16
|
-
use crate::vfs::{Dentry, Identity, Inode, NAME_MAX};
|
|
15
|
+
use crate::vfs::{get_anon_bdev, Dentry, Identity, Inode, NAME_MAX};
|
|
17
16
|
use whiteout::Whiteout;
|
|
18
17
|
|
|
18
|
+
mod seed;
|
|
19
19
|
mod tmpfile;
|
|
20
20
|
mod whiteout;
|
|
21
21
|
mod xattr;
|
|
22
22
|
|
|
23
|
+
use seed::{ancestors, name};
|
|
24
|
+
|
|
23
25
|
/// Files and directories held in tmpfs. Every Invocation it is handed to
|
|
24
26
|
/// shares it, so what one writes the next reads. What its files hold
|
|
25
27
|
/// together, and how many entries it holds, are bounded as a tmpfs mount
|
|
@@ -52,9 +54,7 @@ enum Node {
|
|
|
52
54
|
File(Arc<Mutex<Content>>),
|
|
53
55
|
Directory(Arc<Dir>),
|
|
54
56
|
/// An Overlay's whiteout, as tmpfs holds a character device 0:0.
|
|
55
|
-
Whiteout
|
|
56
|
-
_inode: Arc<Whiteout>,
|
|
57
|
-
},
|
|
57
|
+
Whiteout(Arc<Whiteout>),
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
impl Node {
|
|
@@ -64,7 +64,7 @@ impl Node {
|
|
|
64
64
|
match self {
|
|
65
65
|
Self::File(data) => lock(data).names = 0,
|
|
66
66
|
Self::Directory(dir) => dir.state().removed = true,
|
|
67
|
-
Self::Whiteout
|
|
67
|
+
Self::Whiteout(_) => {}
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -75,7 +75,18 @@ impl Node {
|
|
|
75
75
|
match self {
|
|
76
76
|
Self::File(data) => lock(data).times.ctime = now,
|
|
77
77
|
Self::Directory(dir) => dir.state().times.ctime = now,
|
|
78
|
-
Self::Whiteout
|
|
78
|
+
Self::Whiteout(whiteout) => whiteout.times().ctime = now,
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/// Refuse a directory holding anything, whiteouts among them, as
|
|
83
|
+
/// `simple_empty` answers before a removal or a replacement takes it.
|
|
84
|
+
fn ensure_empty(&self) -> Result<(), Errno> {
|
|
85
|
+
match self {
|
|
86
|
+
Self::Directory(dir) if !dir.state().entries.is_empty() => {
|
|
87
|
+
Err(Errno::DirectoryNotEmpty)
|
|
88
|
+
}
|
|
89
|
+
_ => Ok(()),
|
|
79
90
|
}
|
|
80
91
|
}
|
|
81
92
|
|
|
@@ -83,7 +94,7 @@ impl Node {
|
|
|
83
94
|
match self {
|
|
84
95
|
Self::File(_) => FileType::RegFile,
|
|
85
96
|
Self::Directory(_) => FileType::Dir,
|
|
86
|
-
Self::Whiteout
|
|
97
|
+
Self::Whiteout(_) => FileType::Chrdev,
|
|
87
98
|
}
|
|
88
99
|
}
|
|
89
100
|
|
|
@@ -96,7 +107,7 @@ impl Node {
|
|
|
96
107
|
entry.with_identity(content.dev, content.ino)
|
|
97
108
|
}
|
|
98
109
|
Self::Directory(dir) => entry.with_identity(dev, dir.ino),
|
|
99
|
-
Self::Whiteout
|
|
110
|
+
Self::Whiteout(whiteout) => entry.with_identity(dev, whiteout.ino()),
|
|
100
111
|
}
|
|
101
112
|
}
|
|
102
113
|
}
|
|
@@ -287,12 +298,12 @@ impl Dir {
|
|
|
287
298
|
}
|
|
288
299
|
|
|
289
300
|
/// What stands at `name` in this directory.
|
|
290
|
-
fn get(&self, name: &str) -> Result<Node,
|
|
301
|
+
fn get(&self, name: &str) -> Result<Node, Errno> {
|
|
291
302
|
self.state()
|
|
292
303
|
.entries
|
|
293
304
|
.get(name)
|
|
294
305
|
.cloned()
|
|
295
|
-
.ok_or(
|
|
306
|
+
.ok_or(Errno::NotFound)
|
|
296
307
|
}
|
|
297
308
|
|
|
298
309
|
/// Hand `nested` every directory this one holds, leaving it holding
|
|
@@ -329,17 +340,18 @@ impl Drop for Dir {
|
|
|
329
340
|
/// What a Tmpfs holds: the bytes of its files, and its entries, each
|
|
330
341
|
/// file and directory and the root counting one as an inode does.
|
|
331
342
|
struct Space {
|
|
332
|
-
bytes:
|
|
333
|
-
inodes:
|
|
343
|
+
bytes: Counter,
|
|
344
|
+
inodes: Counter,
|
|
334
345
|
}
|
|
335
346
|
|
|
336
|
-
/// How much of one thing is used,
|
|
337
|
-
|
|
347
|
+
/// How much of one thing is used, counted against the limit the Host App
|
|
348
|
+
/// set, as shmem counts `used_blocks` against `max_blocks`.
|
|
349
|
+
struct Counter {
|
|
338
350
|
limit: AtomicUsize,
|
|
339
351
|
used: AtomicUsize,
|
|
340
352
|
}
|
|
341
353
|
|
|
342
|
-
impl
|
|
354
|
+
impl Counter {
|
|
343
355
|
fn new(limit: Option<usize>) -> Self {
|
|
344
356
|
Self {
|
|
345
357
|
limit: AtomicUsize::new(limit.unwrap_or(usize::MAX)),
|
|
@@ -353,14 +365,14 @@ impl Budget {
|
|
|
353
365
|
}
|
|
354
366
|
|
|
355
367
|
/// Count `amount` more, refusing when it would pass the limit.
|
|
356
|
-
fn take(&self, amount: usize) -> Result<(),
|
|
368
|
+
fn take(&self, amount: usize) -> Result<(), Errno> {
|
|
357
369
|
let limit = self.limit.load(Ordering::Relaxed);
|
|
358
370
|
self.used
|
|
359
371
|
.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |used| {
|
|
360
372
|
used.checked_add(amount).filter(|&total| total <= limit)
|
|
361
373
|
})
|
|
362
374
|
.map(drop)
|
|
363
|
-
.map_err(|_|
|
|
375
|
+
.map_err(|_| Errno::StorageFull)
|
|
364
376
|
}
|
|
365
377
|
|
|
366
378
|
/// Count `amount` more without refusing, for what the Host App seeds.
|
|
@@ -395,7 +407,7 @@ impl Content {
|
|
|
395
407
|
}
|
|
396
408
|
|
|
397
409
|
/// An empty file the guest creates, refused once no inode is left.
|
|
398
|
-
fn create(tree: &Tree) -> Result<Arc<Mutex<Self>>,
|
|
410
|
+
fn create(tree: &Tree) -> Result<Arc<Mutex<Self>>, Errno> {
|
|
399
411
|
tree.space.inodes.take(1)?;
|
|
400
412
|
Ok(Self::new(Vec::new(), tree))
|
|
401
413
|
}
|
|
@@ -421,13 +433,13 @@ impl Content {
|
|
|
421
433
|
|
|
422
434
|
/// Resize to `len`, refusing a growth past the space left or past what
|
|
423
435
|
/// can be allocated, rather than aborting the host process.
|
|
424
|
-
fn resize(&mut self, len: usize) -> Result<(),
|
|
436
|
+
fn resize(&mut self, len: usize) -> Result<(), Errno> {
|
|
425
437
|
let growth = len.saturating_sub(self.bytes.len());
|
|
426
438
|
if growth > 0 {
|
|
427
439
|
self.space.bytes.take(growth)?;
|
|
428
440
|
if self.bytes.try_reserve_exact(growth).is_err() {
|
|
429
441
|
self.space.bytes.give(growth);
|
|
430
|
-
return Err(
|
|
442
|
+
return Err(Errno::StorageFull);
|
|
431
443
|
}
|
|
432
444
|
}
|
|
433
445
|
self.space.bytes.give(self.bytes.len().saturating_sub(len));
|
|
@@ -458,13 +470,14 @@ const BOGO_DIRENT_SIZE: u64 = 20;
|
|
|
458
470
|
|
|
459
471
|
impl Tmpfs {
|
|
460
472
|
/// The most bytes a Tmpfs's files hold unless given a limit of their
|
|
461
|
-
/// own:
|
|
462
|
-
|
|
473
|
+
/// own: room for a script's scratch files, as most scripts need far
|
|
474
|
+
/// less, while a Host App that needs more says so.
|
|
475
|
+
pub const DEFAULT_SIZE: usize = 4 * 1024 * 1024;
|
|
463
476
|
|
|
464
477
|
pub fn new() -> Self {
|
|
465
478
|
let space = Space {
|
|
466
|
-
bytes:
|
|
467
|
-
inodes:
|
|
479
|
+
bytes: Counter::new(Some(Self::DEFAULT_SIZE)),
|
|
480
|
+
inodes: Counter::new(inodes_for(Some(Self::DEFAULT_SIZE))),
|
|
468
481
|
};
|
|
469
482
|
space.inodes.add(1);
|
|
470
483
|
let space = Arc::new(space);
|
|
@@ -472,7 +485,7 @@ impl Tmpfs {
|
|
|
472
485
|
tree: Arc::new(Tree {
|
|
473
486
|
space: space.clone(),
|
|
474
487
|
inodes_follow_limit: AtomicBool::new(true),
|
|
475
|
-
dev:
|
|
488
|
+
dev: get_anon_bdev(),
|
|
476
489
|
next_ino: AtomicU64::new(2),
|
|
477
490
|
}),
|
|
478
491
|
dir: Dir::new(1, space),
|
|
@@ -567,13 +580,7 @@ impl Tmpfs {
|
|
|
567
580
|
{
|
|
568
581
|
let tmpfs = Self::new();
|
|
569
582
|
for (path, contents) in files {
|
|
570
|
-
let path =
|
|
571
|
-
if path.is_empty() {
|
|
572
|
-
return Err(SeedError::Root);
|
|
573
|
-
}
|
|
574
|
-
if path.split('/').any(|name| name == "..") {
|
|
575
|
-
return Err(SeedError::DotDot(path));
|
|
576
|
-
}
|
|
583
|
+
let path = seed::normalize(path.as_ref())?;
|
|
577
584
|
let mut dir = tmpfs.dir.clone();
|
|
578
585
|
for above in ancestors(&path) {
|
|
579
586
|
let standing = dir.state().entries.get(name(above)).cloned();
|
|
@@ -585,7 +592,7 @@ impl Tmpfs {
|
|
|
585
592
|
});
|
|
586
593
|
dir = match next {
|
|
587
594
|
Node::Directory(inner) => inner,
|
|
588
|
-
Node::File(_) | Node::Whiteout
|
|
595
|
+
Node::File(_) | Node::Whiteout(_) => {
|
|
589
596
|
return Err(SeedError::FileAndDirectory(above.to_string()))
|
|
590
597
|
}
|
|
591
598
|
};
|
|
@@ -593,7 +600,7 @@ impl Tmpfs {
|
|
|
593
600
|
let mut state = dir.state();
|
|
594
601
|
match state.entries.get(name(&path)) {
|
|
595
602
|
Some(Node::Directory(_)) => return Err(SeedError::FileAndDirectory(path)),
|
|
596
|
-
Some(Node::File(_) | Node::Whiteout
|
|
603
|
+
Some(Node::File(_) | Node::Whiteout(_)) => return Err(SeedError::Twice(path)),
|
|
597
604
|
None => {}
|
|
598
605
|
}
|
|
599
606
|
state.hold(
|
|
@@ -620,12 +627,12 @@ impl<P: AsRef<str>, C: Into<Vec<u8>>> FromIterator<(P, C)> for Tmpfs {
|
|
|
620
627
|
|
|
621
628
|
impl Tmpfs {
|
|
622
629
|
/// What `node`, an entry of this Tmpfs, reports of itself. A whiteout is
|
|
623
|
-
/// a character device 0:0, as tmpfs makes one.
|
|
630
|
+
/// a character device 0:0 with an inode of its own, as tmpfs makes one.
|
|
624
631
|
fn node_getattr(&self, node: &Node) -> Kstat {
|
|
625
632
|
match node {
|
|
626
633
|
Node::File(data) => lock(data).getattr(),
|
|
627
634
|
Node::Directory(dir) => dir.getattr(self.tree.dev),
|
|
628
|
-
Node::Whiteout
|
|
635
|
+
Node::Whiteout(whiteout) => whiteout.getattr(),
|
|
629
636
|
}
|
|
630
637
|
}
|
|
631
638
|
|
|
@@ -635,14 +642,14 @@ impl Tmpfs {
|
|
|
635
642
|
let ops: Arc<dyn InodeOperations> = match node {
|
|
636
643
|
Node::Directory(dir) => Arc::new(self.beneath(dir)),
|
|
637
644
|
Node::File(data) => Arc::new(TmpfsRegular { data }),
|
|
638
|
-
Node::Whiteout
|
|
645
|
+
Node::Whiteout(whiteout) => Arc::new(TmpfsWhiteout(whiteout)),
|
|
639
646
|
};
|
|
640
647
|
Inode::new(&stat, ops)
|
|
641
648
|
}
|
|
642
649
|
|
|
643
650
|
/// Put `node` at the name `dentry` carries and record it there, as
|
|
644
651
|
/// `shmem_mknod` calls `d_make_persistent`.
|
|
645
|
-
fn make(&self, dentry: &Dentry, node: Node) -> Result<(),
|
|
652
|
+
fn make(&self, dentry: &Dentry, node: Node) -> Result<(), Errno> {
|
|
646
653
|
self.dir.state().insert(&dentry.name(), node.clone());
|
|
647
654
|
dentry.add(Some(self.inode_of(node)));
|
|
648
655
|
Ok(())
|
|
@@ -650,7 +657,7 @@ impl Tmpfs {
|
|
|
650
657
|
}
|
|
651
658
|
|
|
652
659
|
impl FileSystemType for Tmpfs {
|
|
653
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
660
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
654
661
|
sb.set_default_d_op(Arc::new(TmpfsDentry));
|
|
655
662
|
sb.set_dontcache();
|
|
656
663
|
sb.d_make_root(Inode::new(&self.dir.getattr(self.tree.dev), self));
|
|
@@ -662,82 +669,76 @@ impl FileSystemType for Tmpfs {
|
|
|
662
669
|
/// through `TmpfsRegular`, and a whiteout, a character device 0:0 with no
|
|
663
670
|
/// driver to open it, through `TmpfsWhiteout`.
|
|
664
671
|
impl InodeOperations for Tmpfs {
|
|
665
|
-
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat,
|
|
672
|
+
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
666
673
|
Ok(self.dir.getattr(self.tree.dev))
|
|
667
674
|
}
|
|
668
675
|
|
|
669
|
-
fn setattr(&self, _dentry: &Dentry, attr: &Iattr) -> Result<(),
|
|
676
|
+
fn setattr(&self, _dentry: &Dentry, attr: &Iattr) -> Result<(), Errno> {
|
|
670
677
|
self.dir.state().times.apply(attr);
|
|
671
678
|
Ok(())
|
|
672
679
|
}
|
|
673
680
|
|
|
674
681
|
/// A Tmpfs matches names byte for byte and holds no links, and refuses a
|
|
675
682
|
/// name past `NAME_MAX`, as `simple_lookup` does.
|
|
676
|
-
fn lookup(&self, dentry: &Dentry) -> Result<Lookup,
|
|
683
|
+
fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
677
684
|
let name = dentry.name();
|
|
678
685
|
if name.len() > NAME_MAX {
|
|
679
|
-
return Err(
|
|
686
|
+
return Err(Errno::InvalidFilename);
|
|
680
687
|
}
|
|
681
688
|
let node = match self.dir.get(&name) {
|
|
682
689
|
Ok(node) => node,
|
|
683
|
-
Err(
|
|
690
|
+
Err(Errno::NotFound) => return Ok(Lookup::Absent),
|
|
684
691
|
Err(err) => return Err(err),
|
|
685
692
|
};
|
|
686
693
|
Ok(Lookup::Found(self.inode_of(node)))
|
|
687
694
|
}
|
|
688
695
|
|
|
689
|
-
fn create(&self, dentry: &Dentry) -> Result<(),
|
|
696
|
+
fn create(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
690
697
|
let data = Content::create(&self.tree)?;
|
|
691
698
|
self.make(dentry, Node::File(data))
|
|
692
699
|
}
|
|
693
700
|
|
|
694
|
-
fn open(
|
|
695
|
-
&self,
|
|
696
|
-
_dentry: &Dentry,
|
|
697
|
-
_how: &OpenHow,
|
|
698
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
701
|
+
fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
699
702
|
Ok(Box::new(TmpfsDir {
|
|
700
703
|
dir: self.dir.clone(),
|
|
701
704
|
dev: self.tree.dev,
|
|
702
705
|
}))
|
|
703
706
|
}
|
|
704
707
|
|
|
705
|
-
fn mkdir(&self, dentry: &Dentry) -> Result<(),
|
|
708
|
+
fn mkdir(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
706
709
|
self.tree.space.inodes.take(1)?;
|
|
707
710
|
self.make(dentry, Node::Directory(self.new_directory()))
|
|
708
711
|
}
|
|
709
712
|
|
|
710
713
|
/// The VFS found a directory at the name, as `shmem_rmdir` leaves it to,
|
|
711
714
|
/// so only whether it holds anything is left to answer.
|
|
712
|
-
fn rmdir(&self, dentry: &Dentry) -> Result<(),
|
|
715
|
+
fn rmdir(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
713
716
|
let name = dentry.name();
|
|
714
717
|
let mut state = self.dir.state();
|
|
715
|
-
if let Some(
|
|
716
|
-
|
|
717
|
-
return Err(FilesystemError::DirectoryNotEmpty);
|
|
718
|
-
}
|
|
718
|
+
if let Some(removed) = state.entries.get(&name) {
|
|
719
|
+
removed.ensure_empty()?;
|
|
719
720
|
}
|
|
720
721
|
state.remove(&name);
|
|
721
722
|
Ok(())
|
|
722
723
|
}
|
|
723
724
|
|
|
724
725
|
/// The VFS found no directory at the name, as `shmem_unlink` leaves it to.
|
|
725
|
-
fn unlink(&self, dentry: &Dentry) -> Result<(),
|
|
726
|
+
fn unlink(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
726
727
|
self.dir.state().remove(&dentry.name());
|
|
727
728
|
Ok(())
|
|
728
729
|
}
|
|
729
730
|
|
|
730
731
|
fn rename(
|
|
731
732
|
&self,
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
) -> Result<(),
|
|
737
|
-
let target = (
|
|
733
|
+
old: &Dentry,
|
|
734
|
+
new_dir: &dyn InodeOperations,
|
|
735
|
+
new: &Dentry,
|
|
736
|
+
flags: Option<RenameFlag>,
|
|
737
|
+
) -> Result<(), Errno> {
|
|
738
|
+
let target = (new_dir as &dyn Any)
|
|
738
739
|
.downcast_ref::<Self>()
|
|
739
|
-
.ok_or(
|
|
740
|
-
self.rename_at(&
|
|
740
|
+
.ok_or(Errno::CrossesDevices)?;
|
|
741
|
+
self.rename_at(&old.name(), target, &new.name(), flags)
|
|
741
742
|
}
|
|
742
743
|
}
|
|
743
744
|
|
|
@@ -754,25 +755,26 @@ impl FileOperations for TmpfsDir {
|
|
|
754
755
|
pos: u64,
|
|
755
756
|
offset: i64,
|
|
756
757
|
whence: Whence,
|
|
757
|
-
) -> Result<u64,
|
|
758
|
+
) -> Result<u64, Errno> {
|
|
758
759
|
generic_file_llseek(dentry, pos, offset, whence)
|
|
759
760
|
}
|
|
760
761
|
|
|
761
|
-
fn read_iter(&mut self, _iocb: &mut Kiocb, _buf: &mut [u8]) -> Result<usize,
|
|
762
|
+
fn read_iter(&mut self, _iocb: &mut Kiocb, _buf: &mut [u8]) -> Result<usize, Errno> {
|
|
762
763
|
generic_read_dir()
|
|
763
764
|
}
|
|
764
765
|
|
|
766
|
+
fn has_iterate_shared(&self) -> bool {
|
|
767
|
+
true
|
|
768
|
+
}
|
|
769
|
+
|
|
765
770
|
/// Reads on from each name's stable position, as `offset_readdir` does, so
|
|
766
771
|
/// nothing is held between two calls.
|
|
767
|
-
fn iterate_shared(
|
|
768
|
-
&mut self,
|
|
769
|
-
dentry: &Dentry,
|
|
770
|
-
ctx: &mut DirContext<'_>,
|
|
771
|
-
) -> Result<(), FilesystemError> {
|
|
772
|
+
fn iterate_shared(&mut self, dentry: &Dentry, ctx: &mut DirContext<'_>) -> Result<(), Errno> {
|
|
772
773
|
if !dir_emit_dots(dentry, ctx) {
|
|
773
774
|
return Ok(());
|
|
774
775
|
}
|
|
775
776
|
loop {
|
|
777
|
+
crate::sched::stop_if_fatal()?;
|
|
776
778
|
let found = {
|
|
777
779
|
let state = self.dir.state();
|
|
778
780
|
state
|
|
@@ -792,7 +794,7 @@ impl FileOperations for TmpfsDir {
|
|
|
792
794
|
|
|
793
795
|
/// A Tmpfs holds nothing to make durable, as tmpfs names `noop_fsync` for
|
|
794
796
|
/// its directories too.
|
|
795
|
-
fn fsync(&mut self, _datasync: bool) -> Result<(),
|
|
797
|
+
fn fsync(&mut self, _datasync: bool) -> Result<(), Errno> {
|
|
796
798
|
Ok(())
|
|
797
799
|
}
|
|
798
800
|
}
|
|
@@ -805,11 +807,7 @@ impl FileOperations for TmpfsDir {
|
|
|
805
807
|
pub(super) struct TmpfsDentry;
|
|
806
808
|
|
|
807
809
|
impl DentryOperations for TmpfsDentry {
|
|
808
|
-
fn revalidate(
|
|
809
|
-
&self,
|
|
810
|
-
dir: &dyn InodeOperations,
|
|
811
|
-
dentry: &Dentry,
|
|
812
|
-
) -> Result<bool, FilesystemError> {
|
|
810
|
+
fn revalidate(&self, dir: &dyn InodeOperations, dentry: &Dentry) -> Result<bool, Errno> {
|
|
813
811
|
let Some(dir) = (dir as &dyn Any).downcast_ref::<Tmpfs>() else {
|
|
814
812
|
return Ok(true);
|
|
815
813
|
};
|
|
@@ -830,25 +828,21 @@ struct TmpfsRegular {
|
|
|
830
828
|
}
|
|
831
829
|
|
|
832
830
|
impl InodeOperations for TmpfsRegular {
|
|
833
|
-
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat,
|
|
831
|
+
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
834
832
|
Ok(lock(&self.data).getattr())
|
|
835
833
|
}
|
|
836
834
|
|
|
837
|
-
fn setattr(&self, _dentry: &Dentry, attr: &Iattr) -> Result<(),
|
|
835
|
+
fn setattr(&self, _dentry: &Dentry, attr: &Iattr) -> Result<(), Errno> {
|
|
838
836
|
let mut data = lock(&self.data);
|
|
839
837
|
if let Some(len) = attr.size {
|
|
840
|
-
let len = usize::try_from(len).map_err(|_|
|
|
838
|
+
let len = usize::try_from(len).map_err(|_| Errno::InvalidInput)?;
|
|
841
839
|
data.resize(len)?;
|
|
842
840
|
}
|
|
843
841
|
data.times.apply(attr);
|
|
844
842
|
Ok(())
|
|
845
843
|
}
|
|
846
844
|
|
|
847
|
-
fn open(
|
|
848
|
-
&self,
|
|
849
|
-
_dentry: &Dentry,
|
|
850
|
-
_how: &OpenHow,
|
|
851
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
845
|
+
fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
852
846
|
Ok(Box::new(TmpfsFile {
|
|
853
847
|
data: self.data.clone(),
|
|
854
848
|
}))
|
|
@@ -856,11 +850,17 @@ impl InodeOperations for TmpfsRegular {
|
|
|
856
850
|
}
|
|
857
851
|
|
|
858
852
|
/// A whiteout a Tmpfs holds for an Overlay above it.
|
|
859
|
-
struct TmpfsWhiteout;
|
|
853
|
+
struct TmpfsWhiteout(Arc<Whiteout>);
|
|
860
854
|
|
|
861
855
|
impl InodeOperations for TmpfsWhiteout {
|
|
862
|
-
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat,
|
|
863
|
-
Ok(
|
|
856
|
+
fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
857
|
+
Ok(self.0.getattr())
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/// Its times, as `shmem_setattr` sets a device's; it holds no size.
|
|
861
|
+
fn setattr(&self, _dentry: &Dentry, attr: &Iattr) -> Result<(), Errno> {
|
|
862
|
+
self.0.times().apply(attr);
|
|
863
|
+
Ok(())
|
|
864
864
|
}
|
|
865
865
|
}
|
|
866
866
|
|
|
@@ -868,13 +868,11 @@ fn lock(data: &Mutex<Content>) -> MutexGuard<'_, Content> {
|
|
|
868
868
|
data.lock().unwrap_or_else(|poisoned| poisoned.into_inner())
|
|
869
869
|
}
|
|
870
870
|
|
|
871
|
-
fn write(data: &mut Content, buf: &[u8], start: usize) -> Result<usize,
|
|
871
|
+
fn write(data: &mut Content, buf: &[u8], start: usize) -> Result<usize, Errno> {
|
|
872
872
|
if buf.is_empty() {
|
|
873
873
|
return Ok(0);
|
|
874
874
|
}
|
|
875
|
-
let end = start
|
|
876
|
-
.checked_add(buf.len())
|
|
877
|
-
.ok_or(FilesystemError::InvalidInput)?;
|
|
875
|
+
let end = start.checked_add(buf.len()).ok_or(Errno::InvalidInput)?;
|
|
878
876
|
if data.bytes.len() < end {
|
|
879
877
|
data.resize(end)?;
|
|
880
878
|
}
|
|
@@ -896,11 +894,11 @@ impl FileOperations for TmpfsFile {
|
|
|
896
894
|
pos: u64,
|
|
897
895
|
offset: i64,
|
|
898
896
|
whence: Whence,
|
|
899
|
-
) -> Result<u64,
|
|
897
|
+
) -> Result<u64, Errno> {
|
|
900
898
|
generic_file_llseek(dentry, pos, offset, whence)
|
|
901
899
|
}
|
|
902
900
|
|
|
903
|
-
fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize,
|
|
901
|
+
fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize, Errno> {
|
|
904
902
|
let data = &lock(&self.data).bytes;
|
|
905
903
|
let start = usize::try_from(iocb.pos)
|
|
906
904
|
.unwrap_or(usize::MAX)
|
|
@@ -913,11 +911,11 @@ impl FileOperations for TmpfsFile {
|
|
|
913
911
|
|
|
914
912
|
/// The end is read and written under one lock, so another handle's
|
|
915
913
|
/// append lands before or after this one, never over it.
|
|
916
|
-
fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize,
|
|
914
|
+
fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
|
|
917
915
|
let mut data = lock(&self.data);
|
|
918
916
|
let start = match iocb.append {
|
|
919
917
|
true => data.bytes.len(),
|
|
920
|
-
false => usize::try_from(iocb.pos).map_err(|_|
|
|
918
|
+
false => usize::try_from(iocb.pos).map_err(|_| Errno::InvalidInput)?,
|
|
921
919
|
};
|
|
922
920
|
let written = write(&mut data, buf, start)?;
|
|
923
921
|
iocb.pos = (start + written) as u64;
|
|
@@ -927,15 +925,15 @@ impl FileOperations for TmpfsFile {
|
|
|
927
925
|
|
|
928
926
|
/// Nothing outlives the Tmpfs, so there is nothing to flush, as shmem's
|
|
929
927
|
/// `noop_fsync`.
|
|
930
|
-
fn fsync(&mut self, _datasync: bool) -> Result<(),
|
|
928
|
+
fn fsync(&mut self, _datasync: bool) -> Result<(), Errno> {
|
|
931
929
|
Ok(())
|
|
932
930
|
}
|
|
933
931
|
|
|
934
932
|
/// Grow the file to where the room ends, as `shmem_fallocate` moves `i_size`
|
|
935
933
|
/// past it. A Tmpfs holds every byte up to its end, so the room is taken from
|
|
936
934
|
/// its size or refused as out of space.
|
|
937
|
-
fn fallocate(&mut self, offset: u64, len: u64) -> Result<(),
|
|
938
|
-
let end = usize::try_from(offset + len).map_err(|_|
|
|
935
|
+
fn fallocate(&mut self, offset: u64, len: u64) -> Result<(), Errno> {
|
|
936
|
+
let end = usize::try_from(offset + len).map_err(|_| Errno::StorageFull)?;
|
|
939
937
|
let mut data = lock(&self.data);
|
|
940
938
|
if data.bytes.len() < end {
|
|
941
939
|
data.resize(end)?;
|
|
@@ -954,11 +952,7 @@ mod tests {
|
|
|
954
952
|
struct CountsLookups(std::sync::atomic::AtomicUsize);
|
|
955
953
|
|
|
956
954
|
impl crate::filesystem::wrap::Hook for CountsLookups {
|
|
957
|
-
fn lookup(
|
|
958
|
-
&self,
|
|
959
|
-
inner: &dyn InodeOperations,
|
|
960
|
-
dentry: &Dentry,
|
|
961
|
-
) -> Result<Lookup, FilesystemError> {
|
|
955
|
+
fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
962
956
|
self.0.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
|
963
957
|
inner.lookup(dentry)
|
|
964
958
|
}
|
|
@@ -971,7 +965,7 @@ mod tests {
|
|
|
971
965
|
let tmpfs: Tmpfs = [("a", ""), ("b", ""), ("c", "")].into_iter().collect();
|
|
972
966
|
let mount = crate::mount::Mount::new(
|
|
973
967
|
"/data",
|
|
974
|
-
Filesystem::new(
|
|
968
|
+
Filesystem::new(tmpfs).expect("the instance must stand"),
|
|
975
969
|
crate::mount::Access::ReadWrite,
|
|
976
970
|
)
|
|
977
971
|
.expect("/data is a guest path");
|
|
@@ -1024,7 +1018,7 @@ mod tests {
|
|
|
1024
1018
|
let wrapped = crate::filesystem::wrap::Wrap::new(Arc::new(tmpfs), counts.clone());
|
|
1025
1019
|
let mount = crate::mount::Mount::new(
|
|
1026
1020
|
"/data",
|
|
1027
|
-
Filesystem::new(
|
|
1021
|
+
Filesystem::new(wrapped).expect("the instance must stand"),
|
|
1028
1022
|
crate::mount::Access::ReadWrite,
|
|
1029
1023
|
)
|
|
1030
1024
|
.expect("/data is a guest path");
|
|
@@ -1046,14 +1040,14 @@ mod tests {
|
|
|
1046
1040
|
// @behavior FS-168
|
|
1047
1041
|
#[test]
|
|
1048
1042
|
fn an_exchange_leaves_both_files_named() {
|
|
1049
|
-
let filesystem = crate::filesystem::Filesystem::new(
|
|
1043
|
+
let filesystem = crate::filesystem::Filesystem::new(
|
|
1050
1044
|
[("a", "first"), ("b", "second")]
|
|
1051
1045
|
.into_iter()
|
|
1052
1046
|
.collect::<Tmpfs>(),
|
|
1053
|
-
)
|
|
1047
|
+
)
|
|
1054
1048
|
.expect("the instance must stand");
|
|
1055
1049
|
let dentries = filesystem.dentries();
|
|
1056
|
-
let root = filesystem.
|
|
1050
|
+
let root = filesystem.root().expect(crate::vfs::MADE_ROOT).clone();
|
|
1057
1051
|
let at = |name| {
|
|
1058
1052
|
dentries
|
|
1059
1053
|
.alloc_parallel(&root, name)
|
|
@@ -1091,7 +1085,7 @@ mod tests {
|
|
|
1091
1085
|
fs.create(&"x".repeat(NAME_MAX), &how).is_ok()
|
|
1092
1086
|
&& matches!(
|
|
1093
1087
|
fs.vfs_lstat(&"x".repeat(NAME_MAX + 1)),
|
|
1094
|
-
Err(
|
|
1088
|
+
Err(Errno::InvalidFilename)
|
|
1095
1089
|
),
|
|
1096
1090
|
"a name of NAME_MAX bytes must land in a Tmpfs, and one past it answer ENAMETOOLONG"
|
|
1097
1091
|
);
|
|
@@ -1157,6 +1151,50 @@ mod tests {
|
|
|
1157
1151
|
);
|
|
1158
1152
|
}
|
|
1159
1153
|
|
|
1154
|
+
// A whiteout made where the upper of an Overlay is mounted on its own
|
|
1155
|
+
// shows there, so it answers as the inode `shmem_mknod` makes for it.
|
|
1156
|
+
// @behavior FS-216
|
|
1157
|
+
#[test]
|
|
1158
|
+
fn a_whiteout_reports_an_inode_and_times_of_its_own() {
|
|
1159
|
+
let tmpfs = Tmpfs::new();
|
|
1160
|
+
tmpfs.whiteout("w").expect("the whiteout must be made");
|
|
1161
|
+
let fs = at(tmpfs);
|
|
1162
|
+
let set = SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(1_000);
|
|
1163
|
+
fs.setattr("w", &Iattr::for_times(None, Some(SetTime::At(set))))
|
|
1164
|
+
.expect("the whiteout's times must be set");
|
|
1165
|
+
let stat = fs.vfs_lstat("w").expect("the whiteout must stat");
|
|
1166
|
+
let listed = fs.iterate_dir().expect("the directory must list");
|
|
1167
|
+
let entry = listed
|
|
1168
|
+
.iter()
|
|
1169
|
+
.find(|entry| entry.name == "w")
|
|
1170
|
+
.expect("the whiteout is listed");
|
|
1171
|
+
assert_eq!(
|
|
1172
|
+
(
|
|
1173
|
+
stat.file_type,
|
|
1174
|
+
stat.ino != 0,
|
|
1175
|
+
entry.ino == stat.ino,
|
|
1176
|
+
stat.nlink,
|
|
1177
|
+
stat.mtime
|
|
1178
|
+
),
|
|
1179
|
+
(FileType::Chrdev, true, true, 1, Some(set)),
|
|
1180
|
+
"a whiteout in a Tmpfs through KernPath must stat as a character device with an \
|
|
1181
|
+
inode number its listing shares, one link, and the times set on it"
|
|
1182
|
+
);
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
/// Set every time of what stands at `path` to a moment long past, so a
|
|
1186
|
+
/// time a later change sets differs from it whatever the clock's
|
|
1187
|
+
/// resolution.
|
|
1188
|
+
fn set_long_ago(fs: &KernPath, path: &str) {
|
|
1189
|
+
let long_ago = SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(1);
|
|
1190
|
+
let at = Some(SetTime::At(long_ago));
|
|
1191
|
+
let attr = Iattr {
|
|
1192
|
+
ctime: Some(long_ago),
|
|
1193
|
+
..Iattr::for_times(at, at)
|
|
1194
|
+
};
|
|
1195
|
+
fs.setattr(path, &attr).expect("the times must be set");
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1160
1198
|
fn at(tmpfs: Tmpfs) -> KernPath {
|
|
1161
1199
|
kern_path(Arc::new(tmpfs))
|
|
1162
1200
|
}
|
|
@@ -1173,7 +1211,7 @@ mod tests {
|
|
|
1173
1211
|
.expect("the file must open");
|
|
1174
1212
|
let mut buf = vec![0; 64];
|
|
1175
1213
|
let read = file
|
|
1176
|
-
.read_iter(&mut Kiocb::
|
|
1214
|
+
.read_iter(&mut Kiocb::new(0), &mut buf)
|
|
1177
1215
|
.expect("the file must read");
|
|
1178
1216
|
buf.truncate(read);
|
|
1179
1217
|
buf
|
|
@@ -1265,7 +1303,7 @@ mod tests {
|
|
|
1265
1303
|
},
|
|
1266
1304
|
)
|
|
1267
1305
|
.expect("a new file must be created");
|
|
1268
|
-
file.write_iter(&mut Kiocb::
|
|
1306
|
+
file.write_iter(&mut Kiocb::new(0), b"kept")
|
|
1269
1307
|
.expect("the write must land");
|
|
1270
1308
|
drop(file);
|
|
1271
1309
|
assert_eq!(
|
|
@@ -1278,13 +1316,10 @@ mod tests {
|
|
|
1278
1316
|
#[test]
|
|
1279
1317
|
fn a_directory_with_entries_is_not_removed() {
|
|
1280
1318
|
let tmpfs = at([("dir/file", "x")].into_iter().collect());
|
|
1281
|
-
assert_eq!(
|
|
1282
|
-
tmpfs.vfs_rmdir("dir"),
|
|
1283
|
-
Err(FilesystemError::DirectoryNotEmpty)
|
|
1284
|
-
);
|
|
1319
|
+
assert_eq!(tmpfs.vfs_rmdir("dir"), Err(Errno::DirectoryNotEmpty));
|
|
1285
1320
|
assert_eq!(tmpfs.vfs_unlink("dir/file"), Ok(()));
|
|
1286
1321
|
assert_eq!(tmpfs.vfs_rmdir("dir"), Ok(()));
|
|
1287
|
-
assert_eq!(tmpfs.vfs_lstat("dir"), Err(
|
|
1322
|
+
assert_eq!(tmpfs.vfs_lstat("dir"), Err(Errno::NotFound));
|
|
1288
1323
|
}
|
|
1289
1324
|
|
|
1290
1325
|
#[test]
|
|
@@ -1294,7 +1329,7 @@ mod tests {
|
|
|
1294
1329
|
.rename("old", &tmpfs, "new")
|
|
1295
1330
|
.expect("the rename must succeed");
|
|
1296
1331
|
assert_eq!(read_all(&tmpfs, "new/inner/file"), b"x");
|
|
1297
|
-
assert_eq!(tmpfs.vfs_lstat("old"), Err(
|
|
1332
|
+
assert_eq!(tmpfs.vfs_lstat("old"), Err(Errno::NotFound));
|
|
1298
1333
|
}
|
|
1299
1334
|
|
|
1300
1335
|
fn writable(fs: &KernPath, path: &str) -> Box<dyn FileOperations> {
|
|
@@ -1315,10 +1350,10 @@ mod tests {
|
|
|
1315
1350
|
let tmpfs = at(tmpfs.with_size(Some(4)));
|
|
1316
1351
|
assert_eq!(
|
|
1317
1352
|
(
|
|
1318
|
-
writable(&tmpfs, "file").write_iter(&mut Kiocb::
|
|
1353
|
+
writable(&tmpfs, "file").write_iter(&mut Kiocb::new(1), b"four"),
|
|
1319
1354
|
read_all(&tmpfs, "file")
|
|
1320
1355
|
),
|
|
1321
|
-
(Err(
|
|
1356
|
+
(Err(Errno::StorageFull), b"x".to_vec()),
|
|
1322
1357
|
"a write growing a Tmpfs's files past its limit through TmpfsFile::write_iter must \
|
|
1323
1358
|
answer StorageFull and leave the file as it was"
|
|
1324
1359
|
);
|
|
@@ -1330,7 +1365,7 @@ mod tests {
|
|
|
1330
1365
|
let tmpfs = at([("file", "")].into_iter().collect());
|
|
1331
1366
|
assert_eq!(
|
|
1332
1367
|
(
|
|
1333
|
-
writable(&tmpfs, "file").write_iter(&mut Kiocb::
|
|
1368
|
+
writable(&tmpfs, "file").write_iter(&mut Kiocb::new(1000), b""),
|
|
1334
1369
|
read_all(&tmpfs, "file")
|
|
1335
1370
|
),
|
|
1336
1371
|
(Ok(0), Vec::new()),
|
|
@@ -1344,14 +1379,14 @@ mod tests {
|
|
|
1344
1379
|
fn a_tmpfs_holds_its_default_size() {
|
|
1345
1380
|
let tmpfs = at(Tmpfs::new());
|
|
1346
1381
|
let _file = writable(&tmpfs, "file");
|
|
1347
|
-
let
|
|
1382
|
+
let mib_4 = 4 * 1024 * 1024;
|
|
1348
1383
|
assert_eq!(
|
|
1349
1384
|
(
|
|
1350
|
-
tmpfs.truncate("file",
|
|
1351
|
-
tmpfs.truncate("file",
|
|
1385
|
+
tmpfs.truncate("file", mib_4),
|
|
1386
|
+
tmpfs.truncate("file", mib_4 + 1)
|
|
1352
1387
|
),
|
|
1353
|
-
(Ok(()), Err(
|
|
1354
|
-
"a Tmpfs given no limit through Tmpfs::new must hold
|
|
1388
|
+
(Ok(()), Err(Errno::StorageFull)),
|
|
1389
|
+
"a Tmpfs given no limit through Tmpfs::new must hold 4 MiB and refuse a byte more"
|
|
1355
1390
|
);
|
|
1356
1391
|
}
|
|
1357
1392
|
|
|
@@ -1363,7 +1398,7 @@ mod tests {
|
|
|
1363
1398
|
assert_eq!(
|
|
1364
1399
|
tmpfs.truncate("file", Tmpfs::DEFAULT_SIZE as u64 + 1),
|
|
1365
1400
|
Ok(()),
|
|
1366
|
-
"a Tmpfs given no limit through Tmpfs::with_size(None) must grow past
|
|
1401
|
+
"a Tmpfs given no limit through Tmpfs::with_size(None) must grow past 4 MiB"
|
|
1367
1402
|
);
|
|
1368
1403
|
}
|
|
1369
1404
|
|
|
@@ -1372,11 +1407,11 @@ mod tests {
|
|
|
1372
1407
|
fn a_removed_file_returns_its_space() {
|
|
1373
1408
|
let tmpfs = at(Tmpfs::new().with_size(Some(4)));
|
|
1374
1409
|
writable(&tmpfs, "first")
|
|
1375
|
-
.write_iter(&mut Kiocb::
|
|
1410
|
+
.write_iter(&mut Kiocb::new(0), b"four")
|
|
1376
1411
|
.expect("the first file must fit");
|
|
1377
1412
|
tmpfs.vfs_unlink("first").expect("the file must remove");
|
|
1378
1413
|
assert_eq!(
|
|
1379
|
-
writable(&tmpfs, "second").write_iter(&mut Kiocb::
|
|
1414
|
+
writable(&tmpfs, "second").write_iter(&mut Kiocb::new(0), b"four"),
|
|
1380
1415
|
Ok(4),
|
|
1381
1416
|
"the space a file removed through vfs_unlink held must be free for the next"
|
|
1382
1417
|
);
|
|
@@ -1394,12 +1429,12 @@ mod tests {
|
|
|
1394
1429
|
assert_eq!(
|
|
1395
1430
|
(
|
|
1396
1431
|
tmpfs.truncate("file", unallocatable),
|
|
1397
|
-
file.write_iter(&mut Kiocb::
|
|
1432
|
+
file.write_iter(&mut Kiocb::new(unallocatable), b"x"),
|
|
1398
1433
|
read_all(&tmpfs, "file")
|
|
1399
1434
|
),
|
|
1400
1435
|
(
|
|
1401
|
-
Err(
|
|
1402
|
-
Err(
|
|
1436
|
+
Err(Errno::StorageFull),
|
|
1437
|
+
Err(Errno::StorageFull),
|
|
1403
1438
|
b"x".to_vec()
|
|
1404
1439
|
),
|
|
1405
1440
|
"a length no allocator can hand out through TmpfsRegular::setattr and TmpfsFile::write_iter must \
|
|
@@ -1410,13 +1445,10 @@ mod tests {
|
|
|
1410
1445
|
#[test]
|
|
1411
1446
|
fn a_path_beneath_a_file_is_not_a_directory() {
|
|
1412
1447
|
let tmpfs = at([("file", "x")].into_iter().collect());
|
|
1413
|
-
assert_eq!(
|
|
1414
|
-
tmpfs.vfs_lstat("file/inner"),
|
|
1415
|
-
Err(FilesystemError::NotADirectory)
|
|
1416
|
-
);
|
|
1448
|
+
assert_eq!(tmpfs.vfs_lstat("file/inner"), Err(Errno::NotADirectory));
|
|
1417
1449
|
}
|
|
1418
1450
|
|
|
1419
|
-
fn create(fs: &KernPath, path: &str) -> Result<(),
|
|
1451
|
+
fn create(fs: &KernPath, path: &str) -> Result<(), Errno> {
|
|
1420
1452
|
fs.open_or_create(
|
|
1421
1453
|
path,
|
|
1422
1454
|
&OpenHow {
|
|
@@ -1443,8 +1475,8 @@ mod tests {
|
|
|
1443
1475
|
(
|
|
1444
1476
|
Ok(()),
|
|
1445
1477
|
Ok(()),
|
|
1446
|
-
Err(
|
|
1447
|
-
Err(
|
|
1478
|
+
Err(Errno::StorageFull),
|
|
1479
|
+
Err(Errno::StorageFull)
|
|
1448
1480
|
),
|
|
1449
1481
|
"a Tmpfs given inodes through Tmpfs::with_nr_inodes must refuse a file or directory \
|
|
1450
1482
|
past them, the root counted, as out of space"
|
|
@@ -1461,12 +1493,27 @@ mod tests {
|
|
|
1461
1493
|
create(&tmpfs, "b"),
|
|
1462
1494
|
create(&tmpfs, "c")
|
|
1463
1495
|
),
|
|
1464
|
-
(Ok(()), Ok(()), Err(
|
|
1496
|
+
(Ok(()), Ok(()), Err(Errno::StorageFull)),
|
|
1465
1497
|
"a Tmpfs given only a limit through Tmpfs::with_size must hold one entry for each \
|
|
1466
1498
|
4 KiB of it and the root"
|
|
1467
1499
|
);
|
|
1468
1500
|
}
|
|
1469
1501
|
|
|
1502
|
+
// @behavior FS-238
|
|
1503
|
+
#[test]
|
|
1504
|
+
fn a_tmpfs_holds_its_default_entries() {
|
|
1505
|
+
let tmpfs = at(Tmpfs::new());
|
|
1506
|
+
let created: Vec<_> = (0..1025)
|
|
1507
|
+
.map(|index| create(&tmpfs, &format!("{index}")))
|
|
1508
|
+
.collect();
|
|
1509
|
+
assert_eq!(
|
|
1510
|
+
(created[..1024].iter().all(Result::is_ok), &created[1024]),
|
|
1511
|
+
(true, &Err(Errno::StorageFull)),
|
|
1512
|
+
"a Tmpfs given neither a size nor inodes through Tmpfs::new must hold 1024 files \
|
|
1513
|
+
beside its root and refuse the next as out of space"
|
|
1514
|
+
);
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1470
1517
|
// The second handle opened before the first appended, so only an end
|
|
1471
1518
|
// read as the append lands puts its bytes after the first's.
|
|
1472
1519
|
// @behavior FS-036
|
|
@@ -1476,7 +1523,7 @@ mod tests {
|
|
|
1476
1523
|
let mut first = writable(&tmpfs, "log");
|
|
1477
1524
|
let mut second = writable(&tmpfs, "log");
|
|
1478
1525
|
let (mut from_first, mut from_second) =
|
|
1479
|
-
(Kiocb::
|
|
1526
|
+
(Kiocb::new(0).with_append(), Kiocb::new(0).with_append());
|
|
1480
1527
|
assert_eq!(
|
|
1481
1528
|
(
|
|
1482
1529
|
first.write_iter(&mut from_first, b"bb"),
|
|
@@ -1520,10 +1567,10 @@ mod tests {
|
|
|
1520
1567
|
(moves, standing),
|
|
1521
1568
|
(
|
|
1522
1569
|
[
|
|
1523
|
-
Some(
|
|
1524
|
-
Some(
|
|
1525
|
-
Some(
|
|
1526
|
-
Some(
|
|
1570
|
+
Some(Errno::IsADirectory),
|
|
1571
|
+
Some(Errno::IsADirectory),
|
|
1572
|
+
Some(Errno::NotADirectory),
|
|
1573
|
+
Some(Errno::DirectoryNotEmpty),
|
|
1527
1574
|
],
|
|
1528
1575
|
vec!["empty".to_string(), "file".to_string(), "full".to_string()]
|
|
1529
1576
|
),
|
|
@@ -1565,7 +1612,7 @@ mod tests {
|
|
|
1565
1612
|
drop(handle);
|
|
1566
1613
|
assert_eq!(
|
|
1567
1614
|
(while_open, create(&tmpfs, "second")),
|
|
1568
|
-
(Err(
|
|
1615
|
+
(Err(Errno::StorageFull), Ok(())),
|
|
1569
1616
|
"the inode of a file removed through vfs_unlink must stay taken while a \
|
|
1570
1617
|
handle holds it, and be free once it closes"
|
|
1571
1618
|
);
|
|
@@ -1576,7 +1623,7 @@ mod tests {
|
|
|
1576
1623
|
// @behavior FS-085
|
|
1577
1624
|
#[test]
|
|
1578
1625
|
fn a_device_of_its_own_stands_apart_from_every_other_device() {
|
|
1579
|
-
let (first, second) = (
|
|
1626
|
+
let (first, second) = (get_anon_bdev(), get_anon_bdev());
|
|
1580
1627
|
let tmpfs = at(Tmpfs::new())
|
|
1581
1628
|
.vfs_getattr()
|
|
1582
1629
|
.expect("the root must stand")
|
|
@@ -1586,7 +1633,7 @@ mod tests {
|
|
|
1586
1633
|
&& first != second
|
|
1587
1634
|
&& tmpfs != first
|
|
1588
1635
|
&& tmpfs != second,
|
|
1589
|
-
"devices from
|
|
1636
|
+
"devices from get_anon_bdev and a Tmpfs's root must each set the top bit \
|
|
1590
1637
|
and differ from one another"
|
|
1591
1638
|
);
|
|
1592
1639
|
}
|
|
@@ -1598,7 +1645,7 @@ mod tests {
|
|
|
1598
1645
|
.flat_map(|(name, node)| {
|
|
1599
1646
|
let beneath = match node {
|
|
1600
1647
|
Node::Directory(inner) => names(inner),
|
|
1601
|
-
Node::File(_) | Node::Whiteout
|
|
1648
|
+
Node::File(_) | Node::Whiteout(_) => Vec::new(),
|
|
1602
1649
|
};
|
|
1603
1650
|
std::iter::once(name.clone()).chain(beneath)
|
|
1604
1651
|
})
|
|
@@ -1652,7 +1699,7 @@ mod tests {
|
|
|
1652
1699
|
tmpfs.vfs_lstat("moved/made").map(|m| m.file_type),
|
|
1653
1700
|
tmpfs.vfs_lstat("dir/made").map(|m| m.file_type)
|
|
1654
1701
|
),
|
|
1655
|
-
(Ok(FileType::RegFile), Err(
|
|
1702
|
+
(Ok(FileType::RegFile), Err(Errno::NotFound)),
|
|
1656
1703
|
"a file made through a directory Tmpfs::open_dir opened before Tmpfs::rename moved \
|
|
1657
1704
|
it must stand beneath the directory's new path"
|
|
1658
1705
|
);
|
|
@@ -1673,8 +1720,8 @@ mod tests {
|
|
|
1673
1720
|
dir.vfs_lstat("").map(|m| m.file_type)
|
|
1674
1721
|
),
|
|
1675
1722
|
(
|
|
1676
|
-
Err(
|
|
1677
|
-
Err(
|
|
1723
|
+
Err(Errno::NotFound),
|
|
1724
|
+
Err(Errno::NotFound),
|
|
1678
1725
|
Ok(0),
|
|
1679
1726
|
Ok(FileType::Dir)
|
|
1680
1727
|
),
|
|
@@ -1697,21 +1744,21 @@ mod tests {
|
|
|
1697
1744
|
tmpfs.rename("a", &inner, "a"),
|
|
1698
1745
|
tmpfs.vfs_lstat("a/b").map(|m| m.file_type)
|
|
1699
1746
|
),
|
|
1700
|
-
(Err(
|
|
1747
|
+
(Err(Errno::InvalidInput), Ok(FileType::Dir)),
|
|
1701
1748
|
"Tmpfs::rename of a directory into one opened beneath it must answer InvalidInput \
|
|
1702
1749
|
and move nothing"
|
|
1703
1750
|
);
|
|
1704
1751
|
}
|
|
1705
1752
|
|
|
1706
1753
|
// The content stands as it was, so only `st_ctime` tells the name moved, as
|
|
1707
|
-
// `simple_rename_timestamp` moves it alone. The
|
|
1708
|
-
//
|
|
1754
|
+
// `simple_rename_timestamp` moves it alone. The times start long past, so
|
|
1755
|
+
// the two cannot pass for one whatever the clock's resolution.
|
|
1709
1756
|
// @behavior FS-177
|
|
1710
1757
|
#[test]
|
|
1711
1758
|
fn a_moved_file_moves_only_its_changed_time() {
|
|
1712
1759
|
let tmpfs = at([("file", "x")].into_iter().collect());
|
|
1760
|
+
set_long_ago(&tmpfs, "file");
|
|
1713
1761
|
let before = tmpfs.vfs_lstat("file").expect("the file must stand");
|
|
1714
|
-
std::thread::sleep(std::time::Duration::from_millis(20));
|
|
1715
1762
|
tmpfs
|
|
1716
1763
|
.rename("file", &tmpfs, "moved")
|
|
1717
1764
|
.expect("the move must land");
|
|
@@ -1736,7 +1783,7 @@ mod tests {
|
|
|
1736
1783
|
"file",
|
|
1737
1784
|
&Iattr {
|
|
1738
1785
|
ctime: Some(landed),
|
|
1739
|
-
..Iattr::
|
|
1786
|
+
..Iattr::for_times(now, now)
|
|
1740
1787
|
},
|
|
1741
1788
|
)
|
|
1742
1789
|
.expect("the times must be set");
|
|
@@ -1756,8 +1803,7 @@ mod tests {
|
|
|
1756
1803
|
fn a_removed_directory_something_holds_keeps_its_inode() {
|
|
1757
1804
|
let mount = crate::mount::Mount::new(
|
|
1758
1805
|
"/data",
|
|
1759
|
-
Filesystem::new(
|
|
1760
|
-
.expect("the instance must stand"),
|
|
1806
|
+
Filesystem::new(Tmpfs::new().with_nr_inodes(Some(2))).expect("the instance must stand"),
|
|
1761
1807
|
crate::mount::Access::ReadWrite,
|
|
1762
1808
|
)
|
|
1763
1809
|
.expect("/data is a guest path");
|
|
@@ -1779,7 +1825,7 @@ mod tests {
|
|
|
1779
1825
|
while_open,
|
|
1780
1826
|
crate::vfs::filename_mkdirat(&cred, &root, "next")
|
|
1781
1827
|
),
|
|
1782
|
-
(Err(
|
|
1828
|
+
(Err(Errno::StorageFull), Ok(())),
|
|
1783
1829
|
"vfs::filename_mkdirat in a Tmpfs out of inodes must answer ENOSPC while a removed \
|
|
1784
1830
|
directory stays open, and succeed once it closes"
|
|
1785
1831
|
);
|
|
@@ -1791,7 +1837,7 @@ mod tests {
|
|
|
1791
1837
|
let mount = |tmpfs: Tmpfs| {
|
|
1792
1838
|
crate::mount::Mount::new(
|
|
1793
1839
|
"/data",
|
|
1794
|
-
Filesystem::new(
|
|
1840
|
+
Filesystem::new(tmpfs).expect("the instance must stand"),
|
|
1795
1841
|
crate::mount::Access::ReadWrite,
|
|
1796
1842
|
)
|
|
1797
1843
|
.expect("/data is a guest path")
|
|
@@ -1807,14 +1853,14 @@ mod tests {
|
|
|
1807
1853
|
crate::vfs::filename_renameat2(&cred, &root(&from), "file", &root(&to), "file"),
|
|
1808
1854
|
crate::vfs::vfs_fstatat(&cred, &root(&from), "file", false).map(|found| found.size),
|
|
1809
1855
|
),
|
|
1810
|
-
(Err(
|
|
1856
|
+
(Err(Errno::CrossesDevices), Ok(1)),
|
|
1811
1857
|
"vfs::filename_renameat2 into a directory of another Tmpfs must answer EXDEV and \
|
|
1812
1858
|
leave the file"
|
|
1813
1859
|
);
|
|
1814
1860
|
}
|
|
1815
1861
|
|
|
1816
|
-
// The
|
|
1817
|
-
//
|
|
1862
|
+
// The file's times are set long past before it is read, so a time left
|
|
1863
|
+
// where it was cannot pass for one the write moved.
|
|
1818
1864
|
// @behavior FS-115
|
|
1819
1865
|
#[test]
|
|
1820
1866
|
fn a_tmpfs_keeps_a_files_times_as_a_tmpfs_mounted_noatime_does() {
|
|
@@ -1827,13 +1873,13 @@ mod tests {
|
|
|
1827
1873
|
let mut file = tmpfs
|
|
1828
1874
|
.open_or_create("file", &how)
|
|
1829
1875
|
.expect("the file must be made");
|
|
1830
|
-
file.write_iter(&mut Kiocb::
|
|
1876
|
+
file.write_iter(&mut Kiocb::new(0), b"ab")
|
|
1831
1877
|
.expect("the file must take a write");
|
|
1878
|
+
set_long_ago(&tmpfs, "file");
|
|
1832
1879
|
let made = tmpfs.vfs_lstat("file").expect("the file must report");
|
|
1833
|
-
file.read_iter(&mut Kiocb::
|
|
1880
|
+
file.read_iter(&mut Kiocb::new(0), &mut [0; 1])
|
|
1834
1881
|
.expect("the file must read");
|
|
1835
|
-
|
|
1836
|
-
file.write_iter(&mut Kiocb::at(0), b"c")
|
|
1882
|
+
file.write_iter(&mut Kiocb::new(0), b"c")
|
|
1837
1883
|
.expect("the file must take a write within its length");
|
|
1838
1884
|
let written = tmpfs.vfs_lstat("file").expect("the file must stand");
|
|
1839
1885
|
assert_eq!(
|
|
@@ -1947,7 +1993,7 @@ mod tests {
|
|
|
1947
1993
|
fn a_moved_file_keeps_its_names_through_the_move() {
|
|
1948
1994
|
let mount = crate::mount::Mount::new(
|
|
1949
1995
|
"/data",
|
|
1950
|
-
Filesystem::new(
|
|
1996
|
+
Filesystem::new([("a", "x")].into_iter().collect::<Tmpfs>())
|
|
1951
1997
|
.expect("the instance must stand"),
|
|
1952
1998
|
crate::mount::Access::ReadWrite,
|
|
1953
1999
|
)
|