파일 입력 사본의 제한과 검증 경계를 추가함
- 작성자
- 시로사키 하나
- 작성 시각
- 커밋
b7c3d5575943f8caab8bbdcf465c278c3e7059d1- 부모
- 23b8d1c
변경된 파일 9개
+935-0| @@ -0,0 +1,94 @@ | ||
| 1 | 추가: # This file is automatically @generated by Cargo. | |
| 2 | 추가: # It is not intended for manual editing. | |
| 3 | 추가: version = 4 | |
| 4 | 추가: | |
| 5 | 추가: [[package]] | |
| 6 | 추가: name = "block-buffer" | |
| 7 | 추가: version = "0.10.4" | |
| 8 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 9 | 추가: checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" | |
| 10 | 추가: dependencies = [ | |
| 11 | 추가: "generic-array", | |
| 12 | 추가: ] | |
| 13 | 추가: | |
| 14 | 추가: [[package]] | |
| 15 | 추가: name = "cfg-if" | |
| 16 | 추가: version = "1.0.5" | |
| 17 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 18 | 추가: checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" | |
| 19 | 추가: | |
| 20 | 추가: [[package]] | |
| 21 | 추가: name = "cpufeatures" | |
| 22 | 추가: version = "0.2.17" | |
| 23 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 24 | 추가: checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" | |
| 25 | 추가: dependencies = [ | |
| 26 | 추가: "libc", | |
| 27 | 추가: ] | |
| 28 | 추가: | |
| 29 | 추가: [[package]] | |
| 30 | 추가: name = "crypto-common" | |
| 31 | 추가: version = "0.1.7" | |
| 32 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 33 | 추가: checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" | |
| 34 | 추가: dependencies = [ | |
| 35 | 추가: "generic-array", | |
| 36 | 추가: "typenum", | |
| 37 | 추가: ] | |
| 38 | 추가: | |
| 39 | 추가: [[package]] | |
| 40 | 추가: name = "digest" | |
| 41 | 추가: version = "0.10.7" | |
| 42 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 43 | 추가: checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" | |
| 44 | 추가: dependencies = [ | |
| 45 | 추가: "block-buffer", | |
| 46 | 추가: "crypto-common", | |
| 47 | 추가: ] | |
| 48 | 추가: | |
| 49 | 추가: [[package]] | |
| 50 | 추가: name = "generic-array" | |
| 51 | 추가: version = "0.14.7" | |
| 52 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 53 | 추가: checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" | |
| 54 | 추가: dependencies = [ | |
| 55 | 추가: "typenum", | |
| 56 | 추가: "version_check", | |
| 57 | 추가: ] | |
| 58 | 추가: | |
| 59 | 추가: [[package]] | |
| 60 | 추가: name = "libc" | |
| 61 | 추가: version = "0.2.191" | |
| 62 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 63 | 추가: checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" | |
| 64 | 추가: | |
| 65 | 추가: [[package]] | |
| 66 | 추가: name = "sha2" | |
| 67 | 추가: version = "0.10.9" | |
| 68 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 69 | 추가: checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" | |
| 70 | 추가: dependencies = [ | |
| 71 | 추가: "cfg-if", | |
| 72 | 추가: "cpufeatures", | |
| 73 | 추가: "digest", | |
| 74 | 추가: ] | |
| 75 | 추가: | |
| 76 | 추가: [[package]] | |
| 77 | 추가: name = "typenum" | |
| 78 | 추가: version = "1.20.1" | |
| 79 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 80 | 추가: checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" | |
| 81 | 추가: | |
| 82 | 추가: [[package]] | |
| 83 | 추가: name = "version_check" | |
| 84 | 추가: version = "0.9.5" | |
| 85 | 추가: source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 86 | 추가: checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" | |
| 87 | 추가: | |
| 88 | 추가: [[package]] | |
| 89 | 추가: name = "zipelo-file-snapshot" | |
| 90 | 추가: version = "0.1.0" | |
| 91 | 추가: dependencies = [ | |
| 92 | 추가: "libc", | |
| 93 | 추가: "sha2", | |
| 94 | 추가: ] |
| @@ -0,0 +1,21 @@ | ||
| 1 | 추가: [package] | |
| 2 | 추가: name = "zipelo-file-snapshot" | |
| 3 | 추가: version = "0.1.0" | |
| 4 | 추가: edition = "2024" | |
| 5 | 추가: rust-version = "1.99" | |
| 6 | 추가: license = "MIT" | |
| 7 | 추가: publish = false | |
| 8 | 추가: autotests = false | |
| 9 | 추가: autoexamples = false | |
| 10 | 추가: autobenches = false | |
| 11 | 추가: | |
| 12 | 추가: [lib] | |
| 13 | 추가: doctest = false | |
| 14 | 추가: | |
| 15 | 추가: [dependencies] | |
| 16 | 추가: sha2 = { version = "=0.10.9", default-features = false, features = ["std", "force-soft"] } | |
| 17 | 추가: | |
| 18 | 추가: [target.'cfg(target_os = "linux")'.dependencies] | |
| 19 | 추가: libc = { version = "=0.2.191", default-features = false, features = ["std"] } | |
| 20 | 추가: | |
| 21 | 추가: [workspace] |
| @@ -0,0 +1,21 @@ | ||
| 1 | 추가: MIT License | |
| 2 | 추가: | |
| 3 | 추가: Copyright (c) 2026 Team-LJY contributors | |
| 4 | 추가: | |
| 5 | 추가: Permission is hereby granted, free of charge, to any person obtaining a copy | |
| 6 | 추가: of this software and associated documentation files (the "Software"), to deal | |
| 7 | 추가: in the Software without restriction, including without limitation the rights | |
| 8 | 추가: to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| 9 | 추가: copies of the Software, and to permit persons to whom the Software is | |
| 10 | 추가: furnished to do so, subject to the following conditions: | |
| 11 | 추가: | |
| 12 | 추가: The above copyright notice and this permission notice shall be included in all | |
| 13 | 추가: copies or substantial portions of the Software. | |
| 14 | 추가: | |
| 15 | 추가: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| 16 | 추가: IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| 17 | 추가: FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| 18 | 추가: AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| 19 | 추가: LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| 20 | 추가: OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
| 21 | 추가: SOFTWARE. |
| @@ -0,0 +1,8 @@ | ||
| 1 | 추가: ba55ac17dc748d1f91d7a6e5d5ebb4c6b9c84d09173a17d4cac31cf149fb771b experiments/rust-file-snapshot/Cargo.lock | |
| 2 | 추가: e641f091c0acabd3e6fbfa3ed6bf53e05be3ca6c2fc90d67980721b378840f0f experiments/rust-file-snapshot/Cargo.toml | |
| 3 | 추가: 0714945e52a4d5b560c02c9a18478519f8c4e2572cbf87bd6d52adcfb2b63c62 experiments/rust-file-snapshot/LICENSE | |
| 4 | 추가: 066b8c0623b870c0c3998a0499b0323f3cfe8d3cfd60bf6bbc833be0e523a06e experiments/rust-file-snapshot/THIRD-PARTY-NOTICES.txt | |
| 5 | 추가: 8b54705382c3af1168b684fbcf3e25efd256eb145c636972fe6e26b8cb898ff2 experiments/rust-file-snapshot/contract.json | |
| 6 | 추가: ea113f15ec27f9903eed985e1e55f49114b9867b0c7c707e2cd15009fa02c6c0 experiments/rust-file-snapshot/dependencies.json | |
| 7 | 추가: e087714fc3e30b8efdd1cf16e1d8944ebc3518c757b8917d6e32d3b3dc3936c9 experiments/rust-file-snapshot/src/lib.rs | |
| 8 | 추가: 88aa71907bfd07ef61697eb2c71e8ffbdc178c68ea9fcae8d26957be4751fa21 experiments/rust-file-snapshot/src/linux.rs |
Diff가 표시 한도를 넘어서 생략했어요.
Raw로 열기| @@ -0,0 +1,109 @@ | ||
| 1 | 추가: { | |
| 2 | 추가: "schema": "zipelo.file-snapshot.candidate.v1", | |
| 3 | 추가: "base_head": "23b8d1c615f24f42469138fcc63e7fce7cda4f24", | |
| 4 | 추가: "branch": "features/rust-file-snapshot", | |
| 5 | 추가: "status": "source-only; not compiled or executed", | |
| 6 | 추가: "api": { | |
| 7 | 추가: "capture": "capture<E>(Request { path: &Path, limits: Limits }, FnMut(Checkpoint) -> Result<(), Stop<E>>) -> Result<FileSnapshot, Failure<E>>", | |
| 8 | 추가: "ownership": "FileSnapshot and Identity fields are private, with no public constructors, Default, deserialization, from-bytes or from-fd hooks. bytes() only borrows; into_bytes consumes the snapshot and returns the original Vec. No worker/publication/atomic-snapshot proof type exists.", | |
| 9 | 추가: "output": "Owned bytes, SHA256 of those bytes, observed device/inode/length/nlink/mode/mtime/ctime, and per-attempt Usage. No source path retained. Debug for FileSnapshot omits bytes, identity and digest.", | |
| 10 | 추가: "failure": "Failure preserves Error<E> plus all accumulated Usage and never returns partial payload. Io preserves operation and std::io::Error including raw errno. Callback(E) preserves the original E without conversion.", | |
| 11 | 추가: "threading": "Synchronous API; no thread, queue, process, join or forced interrupt. E need not implement Send; sending Failure<E> across a thread requires E: Send and spawn-owned captures/results require 'static. No compile-time Send assertions have run." | |
| 12 | 추가: }, | |
| 13 | 추가: "scope": { | |
| 14 | 추가: "platform": "Linux source path uses openat2 and verified procfs. Non-Linux returns Unsupported(Platform) without touching the supplied path. x86_64 Linux is the initial metadata target; no OS runtime support is claimed.", | |
| 15 | 추가: "input": "Absolute OS-byte path, 2..4096 bytes, nonempty components <=255 bytes, no dot/dotdot/NUL/trailing or repeated slash. UTF-8 is not required. Backslash remains a Linux name byte. This is a host input path policy, not a replacement archive entry name policy.", | |
| 16 | 추가: "pinning": "openat2 with O_PATH|O_CLOEXEC and RESOLVE_NO_SYMLINKS pins the inode without opening FIFO/device data I/O. fstat must report regular file with exactly one hard link before any data open. FIFO/directory/socket/device and multiple hard links are rejected.", | |
| 17 | 추가: "reopen": "Open /proc using O_PATH|O_DIRECTORY|O_CLOEXEC and RESOLVE_NO_SYMLINKS, check fstatfs PROC_SUPER_MAGIC, then numeric PID/fd using BENEATH|NO_SYMLINKS|NO_XDEV. openat follows only the held numeric fd link with O_RDONLY|O_NONBLOCK|O_NOCTTY|O_CLOEXEC. Recheck identity before reading. No supplied source pathname reopen; no normal pathname fallback.", | |
| 18 | 추가: "trust": "Kernel/procfs, process fd table and process-local ownership are trusted. Does not defend against malicious code in the same process or a privileged actor controlling mounts/ptrace. Descriptor close is RAII, not measured OS cleanup proof. No temporary data file is created.", | |
| 19 | 추가: "copy": "Read from offset zero into one bounded Vec, accumulating positive short reads. Probe one byte at initial length for EOF after each pass. Compare reread bytes exactly with the retained first pass; compare metadata after copy and after the final callback. SHA256 covers owned bytes only.", | |
| 20 | 추가: "stability": "This is a two-pass observational copy, not an atomic source snapshot, coherent point-in-time guarantee, exclusion of concurrent writes, full ABA detection, archive integrity validation or pathname persistence guarantee. Rename/replacement can leave the held inode readable; observed metadata/link changes may reject it, but unchanged pathname association is not proved.", | |
| 21 | 추가: "preservation": "No write/unlink/rename/chmod/launch syscalls. Reading can update source atime. Source contents and existing outputs are never intentionally modified. No app-core/UI integration yet." | |
| 22 | 추가: }, | |
| 23 | 추가: "limits": { | |
| 24 | 추가: "memory_bytes": 16777216, | |
| 25 | 추가: "scratch_bytes": 65536, | |
| 26 | 추가: "max_io_reservations": 134217728, | |
| 27 | 추가: "max_read_calls": 131072, | |
| 28 | 추가: "max_duration_seconds": 300, | |
| 29 | 추가: "default_duration_seconds": 30, | |
| 30 | 추가: "empty": "Empty regular input is supported with two one-byte EOF reservations; max_bytes=0 permits it, max_io_bytes=0 cannot complete those probes. max_read_calls=0 is InvalidLimits.", | |
| 31 | 추가: "allocation": "try_reserve_exact before Vec resize. Bounds logical payload length, not allocator overhead/capacity rounding, total process RSS, callback allocations or infallible small path allocations. OOM abort is not covered.", | |
| 32 | 추가: "io": "Before every read_at attempt reserve the full requested buffer length and one read call. No refund on short read, EOF, native error or mismatch. actual_read_bytes records successful returned bytes, compared_bytes records all second-pass bytes including a mismatching chunk. Earlier usage survives failures.", | |
| 33 | 추가: "formula": "Normal full-chunk success for N bytes reserves 2*N+2 bytes, reads 2*N actual bytes, compares N bytes and takes 2*ceil(N/65536)+2 read calls. Positive short reads may consume more reservations and calls. Fixed acquisition path uses at most 4 open calls and 5 metadata calls, excluding automatic close.", | |
| 34 | 추가: "attempts": "Limits and time are per capture invocation; no hidden retry. A caller retry creates a new attempt and must aggregate Failure/Success Usage if it needs a job-wide budget. Native archive library Budgets are untouched.", | |
| 35 | 추가: "time": "Instant elapsed checks at checkpoints and after final metadata; cooperative only. Callback, open/stat/read/hash/allocator calls cannot be forcibly interrupted. No hard syscall timeout or worker isolation claim." | |
| 36 | 추가: }, | |
| 37 | 추가: "control": { | |
| 38 | 추가: "stages": [ | |
| 39 | 추가: "Opening", | |
| 40 | 추가: "Pinned", | |
| 41 | 추가: "Copying", | |
| 42 | 추가: "Comparing", | |
| 43 | 추가: "Finalizing" | |
| 44 | 추가: ], | |
| 45 | 추가: "checkpoint": "Opening before path validation/syscalls, Pinned after first metadata, Copying before allocation and each read plus EOF probe, Comparing before each read plus EOF probe, Finalizing after digest before final metadata. offset is stage-local; Usage is cumulative.", | |
| 46 | 추가: "priority": "InvalidLimits first. At a checkpoint callback Cancelled/Callback(E) precedes Deadline. Native operation failures, read reservation failures and observed mismatch return directly before a later callback; errors are never rewritten by a later cancellation. Final metadata failure precedes the post-metadata deadline check.", | |
| 47 | 추가: "late_cancel": "Finalizing is the final cancellation checkpoint. A request arriving after it can coexist with successful return; caller must not rewrite a returned snapshot. No public hook covers this narrow interval.", | |
| 48 | 추가: "observers": "Callbacks run synchronously and can block/panic; panic propagates and RAII drops local handles, without synthesizing a completion. No transport policy is implemented. A callback is not allowed to supply bytes/identity as evidence." | |
| 49 | 추가: }, | |
| 50 | 추가: "validation": { | |
| 51 | 추가: "performed": [ | |
| 52 | 추가: "rustfmt 1.99.1 syntax/format", | |
| 53 | 추가: "Cargo 1.99.1 offline lock generation", | |
| 54 | 추가: "locked/offline metadata x86_64-unknown-linux-gnu", | |
| 55 | 추가: "static API/bounds/manifest review", | |
| 56 | 추가: "dependency archive checksum and cached source equality" | |
| 57 | 추가: ], | |
| 58 | 추가: "not_performed": [ | |
| 59 | 추가: "Rust compile/type-check", | |
| 60 | 추가: "unit/integration tests", | |
| 61 | 추가: "capture syscall invocation", | |
| 62 | 추가: "synthetic or user file capture", | |
| 63 | 추가: "Send compilation checks", | |
| 64 | 추가: "Windows or other OS validation" | |
| 65 | 추가: ], | |
| 66 | 추가: "test_owner": "Independent regression source belongs to Kanon under root tests/rust-file-snapshot; none added here.", | |
| 67 | 추가: "future_cases": [ | |
| 68 | 추가: "empty and chunk/limit boundaries", | |
| 69 | 추가: "each path-component symlink and FIFO nonblocking rejection", | |
| 70 | 추가: "hard link and special-file rejection", | |
| 71 | 추가: "positive short reads and premature EOF", | |
| 72 | 추가: "native errno and callback E preservation", | |
| 73 | 추가: "append/truncate/same-size overwrite at checkpoints", | |
| 74 | 추가: "path replacement with pinned inode semantics", | |
| 75 | 추가: "cancel and deadline priority", | |
| 76 | 추가: "failed attempt usage", | |
| 77 | 추가: "opaque result and Send compile checks" | |
| 78 | 추가: ], | |
| 79 | 추가: "excluded": [ | |
| 80 | 추가: "publication", | |
| 81 | 추가: "worker launch", | |
| 82 | 추가: "execveat retry/bypass", | |
| 83 | 추가: "new installation or network restore", | |
| 84 | 추가: "held ZIP/Huffman probes", | |
| 85 | 추가: "C# edits", | |
| 86 | 추가: "main merge" | |
| 87 | 추가: ] | |
| 88 | 추가: }, | |
| 89 | 추가: "references": [ | |
| 90 | 추가: { | |
| 91 | 추가: "head": "018e7593ecb2b3a7ae0bc17a440ecf2c0de8b4dd", | |
| 92 | 추가: "path": "src/Zipelo.Core/OutputPathPolicy.cs", | |
| 93 | 추가: "use": "Host path vs archive name policy distinction" | |
| 94 | 추가: }, | |
| 95 | 추가: { | |
| 96 | 추가: "head": "06e5d6c17318349ea96efef81a9e7d8f54c1e1a1", | |
| 97 | 추가: "path": "src/Zipelo.Runtime/Streaming/StreamingZipWorkerClient.cs", | |
| 98 | 추가: "use": "SnapshotAsync two-pass comparison and non-atomic limitation; no C# code copied" | |
| 99 | 추가: }, | |
| 100 | 추가: { | |
| 101 | 추가: "url": "https://man7.org/linux/man-pages/man2/open.2.html", | |
| 102 | 추가: "use": "O_PATH type inspection, procfs held fd reopening, O_NONBLOCK" | |
| 103 | 추가: }, | |
| 104 | 추가: { | |
| 105 | 추가: "url": "https://man7.org/linux/man-pages/man2/openat2.2.html", | |
| 106 | 추가: "use": "Kernel path resolution restrictions; no fallback" | |
| 107 | 추가: } | |
| 108 | 추가: ] | |
| 109 | 추가: } |
| @@ -0,0 +1,118 @@ | ||
| 1 | 추가: { | |
| 2 | 추가: "target": "x86_64-unknown-linux-gnu", | |
| 3 | 추가: "registry_packages": [ | |
| 4 | 추가: { | |
| 5 | 추가: "name": "block-buffer", | |
| 6 | 추가: "version": "0.10.4", | |
| 7 | 추가: "checksum": "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71", | |
| 8 | 추가: "license": "MIT OR Apache-2.0", | |
| 9 | 추가: "archive_source_files_compared": 10, | |
| 10 | 추가: "license_files": [ | |
| 11 | 추가: "LICENSE-APACHE", | |
| 12 | 추가: "LICENSE-MIT" | |
| 13 | 추가: ] | |
| 14 | 추가: }, | |
| 15 | 추가: { | |
| 16 | 추가: "name": "cfg-if", | |
| 17 | 추가: "version": "1.0.5", | |
| 18 | 추가: "checksum": "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600", | |
| 19 | 추가: "license": "MIT OR Apache-2.0", | |
| 20 | 추가: "archive_source_files_compared": 14, | |
| 21 | 추가: "license_files": [ | |
| 22 | 추가: "LICENSE-APACHE", | |
| 23 | 추가: "LICENSE-MIT" | |
| 24 | 추가: ] | |
| 25 | 추가: }, | |
| 26 | 추가: { | |
| 27 | 추가: "name": "cpufeatures", | |
| 28 | 추가: "version": "0.2.17", | |
| 29 | 추가: "checksum": "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280", | |
| 30 | 추가: "license": "MIT OR Apache-2.0", | |
| 31 | 추가: "archive_source_files_compared": 16, | |
| 32 | 추가: "license_files": [ | |
| 33 | 추가: "LICENSE-APACHE", | |
| 34 | 추가: "LICENSE-MIT" | |
| 35 | 추가: ] | |
| 36 | 추가: }, | |
| 37 | 추가: { | |
| 38 | 추가: "name": "crypto-common", | |
| 39 | 추가: "version": "0.1.7", | |
| 40 | 추가: "checksum": "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a", | |
| 41 | 추가: "license": "MIT OR Apache-2.0", | |
| 42 | 추가: "archive_source_files_compared": 9, | |
| 43 | 추가: "license_files": [ | |
| 44 | 추가: "LICENSE-APACHE", | |
| 45 | 추가: "LICENSE-MIT" | |
| 46 | 추가: ] | |
| 47 | 추가: }, | |
| 48 | 추가: { | |
| 49 | 추가: "name": "digest", | |
| 50 | 추가: "version": "0.10.7", | |
| 51 | 추가: "checksum": "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292", | |
| 52 | 추가: "license": "MIT OR Apache-2.0", | |
| 53 | 추가: "archive_source_files_compared": 21, | |
| 54 | 추가: "license_files": [ | |
| 55 | 추가: "LICENSE-APACHE", | |
| 56 | 추가: "LICENSE-MIT" | |
| 57 | 추가: ] | |
| 58 | 추가: }, | |
| 59 | 추가: { | |
| 60 | 추가: "name": "generic-array", | |
| 61 | 추가: "version": "0.14.7", | |
| 62 | 추가: "checksum": "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a", | |
| 63 | 추가: "license": "MIT", | |
| 64 | 추가: "archive_source_files_compared": 16, | |
| 65 | 추가: "license_files": [ | |
| 66 | 추가: "LICENSE" | |
| 67 | 추가: ] | |
| 68 | 추가: }, | |
| 69 | 추가: { | |
| 70 | 추가: "name": "libc", | |
| 71 | 추가: "version": "0.2.191", | |
| 72 | 추가: "checksum": "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a", | |
| 73 | 추가: "license": "MIT OR Apache-2.0", | |
| 74 | 추가: "archive_source_files_compared": 452, | |
| 75 | 추가: "license_files": [ | |
| 76 | 추가: "LICENSE-APACHE", | |
| 77 | 추가: "LICENSE-MIT" | |
| 78 | 추가: ] | |
| 79 | 추가: }, | |
| 80 | 추가: { | |
| 81 | 추가: "name": "sha2", | |
| 82 | 추가: "version": "0.10.9", | |
| 83 | 추가: "checksum": "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283", | |
| 84 | 추가: "license": "MIT OR Apache-2.0", | |
| 85 | 추가: "archive_source_files_compared": 31, | |
| 86 | 추가: "license_files": [ | |
| 87 | 추가: "LICENSE-APACHE", | |
| 88 | 추가: "LICENSE-MIT" | |
| 89 | 추가: ] | |
| 90 | 추가: }, | |
| 91 | 추가: { | |
| 92 | 추가: "name": "typenum", | |
| 93 | 추가: "version": "1.20.1", | |
| 94 | 추가: "checksum": "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20", | |
| 95 | 추가: "license": "MIT OR Apache-2.0", | |
| 96 | 추가: "archive_source_files_compared": 26, | |
| 97 | 추가: "license_files": [ | |
| 98 | 추가: "LICENSE", | |
| 99 | 추가: "LICENSE-APACHE", | |
| 100 | 추가: "LICENSE-MIT" | |
| 101 | 추가: ] | |
| 102 | 추가: }, | |
| 103 | 추가: { | |
| 104 | 추가: "name": "version_check", | |
| 105 | 추가: "version": "0.9.5", | |
| 106 | 추가: "checksum": "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a", | |
| 107 | 추가: "license": "MIT/Apache-2.0", | |
| 108 | 추가: "archive_source_files_compared": 13, | |
| 109 | 추가: "license_files": [ | |
| 110 | 추가: "LICENSE-APACHE", | |
| 111 | 추가: "LICENSE-MIT" | |
| 112 | 추가: ] | |
| 113 | 추가: } | |
| 114 | 추가: ], | |
| 115 | 추가: "comparison": "10 registry records exactly match existing rust-live-supervisor lock; root package is new; no download/build", | |
| 116 | 추가: "direct": "libc 0.2.191 std Linux-only; sha2 0.10.9 std+force-soft; defaults disabled", | |
| 117 | 추가: "advisories": "No current vulnerability audit performed; source/hash/license verification only" | |
| 118 | 추가: } |
| @@ -0,0 +1,286 @@ | ||
| 1 | 추가: #![deny(unsafe_op_in_unsafe_fn)] | |
| 2 | 추가: | |
| 3 | 추가: use sha2::{Digest, Sha256}; | |
| 4 | 추가: use std::{ | |
| 5 | 추가: collections::TryReserveError, | |
| 6 | 추가: io, | |
| 7 | 추가: path::Path, | |
| 8 | 추가: time::{Duration, Instant}, | |
| 9 | 추가: }; | |
| 10 | 추가: | |
| 11 | 추가: #[cfg(target_os = "linux")] | |
| 12 | 추가: mod linux; | |
| 13 | 추가: | |
| 14 | 추가: pub const MAX_BYTES: u64 = 16 * 1024 * 1024; | |
| 15 | 추가: pub const MAX_IO_BYTES: u64 = 128 * 1024 * 1024; | |
| 16 | 추가: pub const MAX_READ_CALLS: u64 = 131_072; | |
| 17 | 추가: pub const CHUNK_BYTES: usize = 65_536; | |
| 18 | 추가: | |
| 19 | 추가: #[derive(Clone, Copy, Debug)] | |
| 20 | 추가: pub struct Limits { | |
| 21 | 추가: pub max_bytes: u64, | |
| 22 | 추가: pub max_io_bytes: u64, | |
| 23 | 추가: pub max_read_calls: u64, | |
| 24 | 추가: pub max_duration: Duration, | |
| 25 | 추가: } | |
| 26 | 추가: | |
| 27 | 추가: impl Default for Limits { | |
| 28 | 추가: fn default() -> Self { | |
| 29 | 추가: Self { | |
| 30 | 추가: max_bytes: MAX_BYTES, | |
| 31 | 추가: max_io_bytes: MAX_IO_BYTES, | |
| 32 | 추가: max_read_calls: MAX_READ_CALLS, | |
| 33 | 추가: max_duration: Duration::from_secs(30), | |
| 34 | 추가: } | |
| 35 | 추가: } | |
| 36 | 추가: } | |
| 37 | 추가: | |
| 38 | 추가: #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] | |
| 39 | 추가: pub struct Usage { | |
| 40 | 추가: pub open_calls: u64, | |
| 41 | 추가: pub metadata_calls: u64, | |
| 42 | 추가: pub read_calls: u64, | |
| 43 | 추가: pub reserved_read_bytes: u64, | |
| 44 | 추가: pub actual_read_bytes: u64, | |
| 45 | 추가: pub compared_bytes: u64, | |
| 46 | 추가: } | |
| 47 | 추가: | |
| 48 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 49 | 추가: pub enum Stage { | |
| 50 | 추가: Opening, | |
| 51 | 추가: Pinned, | |
| 52 | 추가: Copying, | |
| 53 | 추가: Comparing, | |
| 54 | 추가: Finalizing, | |
| 55 | 추가: } | |
| 56 | 추가: | |
| 57 | 추가: #[derive(Clone, Copy, Debug)] | |
| 58 | 추가: pub struct Checkpoint { | |
| 59 | 추가: pub stage: Stage, | |
| 60 | 추가: pub offset: u64, | |
| 61 | 추가: pub length: Option<u64>, | |
| 62 | 추가: pub usage: Usage, | |
| 63 | 추가: } | |
| 64 | 추가: | |
| 65 | 추가: #[derive(Debug)] | |
| 66 | 추가: pub enum Stop<E> { | |
| 67 | 추가: Cancelled, | |
| 68 | 추가: Callback(E), | |
| 69 | 추가: } | |
| 70 | 추가: | |
| 71 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 72 | 추가: pub enum LimitKind { | |
| 73 | 추가: Bytes, | |
| 74 | 추가: IoBytes, | |
| 75 | 추가: ReadCalls, | |
| 76 | 추가: Deadline, | |
| 77 | 추가: } | |
| 78 | 추가: | |
| 79 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 80 | 추가: pub enum Changed { | |
| 81 | 추가: Metadata, | |
| 82 | 추가: Contents, | |
| 83 | 추가: Length, | |
| 84 | 추가: Identity, | |
| 85 | 추가: } | |
| 86 | 추가: | |
| 87 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 88 | 추가: pub enum Unsupported { | |
| 89 | 추가: Platform, | |
| 90 | 추가: Procfs, | |
| 91 | 추가: FileType, | |
| 92 | 추가: MultipleLinks, | |
| 93 | 추가: } | |
| 94 | 추가: | |
| 95 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 96 | 추가: pub enum IoOperation { | |
| 97 | 추가: PinPath, | |
| 98 | 추가: Inspect, | |
| 99 | 추가: OpenProc, | |
| 100 | 추가: InspectProc, | |
| 101 | 추가: OpenProcDescriptors, | |
| 102 | 추가: ReopenPinned, | |
| 103 | 추가: Read, | |
| 104 | 추가: } | |
| 105 | 추가: | |
| 106 | 추가: #[derive(Debug)] | |
| 107 | 추가: pub enum Error<E> { | |
| 108 | 추가: InvalidLimits, | |
| 109 | 추가: InvalidPath, | |
| 110 | 추가: Unsupported(Unsupported), | |
| 111 | 추가: Limit(LimitKind), | |
| 112 | 추가: Changed(Changed), | |
| 113 | 추가: Cancelled, | |
| 114 | 추가: Callback(E), | |
| 115 | 추가: Allocation(TryReserveError), | |
| 116 | 추가: Io { | |
| 117 | 추가: operation: IoOperation, | |
| 118 | 추가: source: io::Error, | |
| 119 | 추가: }, | |
| 120 | 추가: } | |
| 121 | 추가: | |
| 122 | 추가: #[derive(Debug)] | |
| 123 | 추가: pub struct Failure<E> { | |
| 124 | 추가: pub cause: Error<E>, | |
| 125 | 추가: pub usage: Usage, | |
| 126 | 추가: } | |
| 127 | 추가: | |
| 128 | 추가: /// 열린 파일의 관측값임. 경로 지속성이나 원자적 snapshot 증거가 아님. | |
| 129 | 추가: #[derive(Clone, Copy, Debug, Eq, PartialEq)] | |
| 130 | 추가: pub struct Identity { | |
| 131 | 추가: device: u64, | |
| 132 | 추가: inode: u64, | |
| 133 | 추가: length: u64, | |
| 134 | 추가: links: u64, | |
| 135 | 추가: mode: u32, | |
| 136 | 추가: modified: (i64, i64), | |
| 137 | 추가: changed: (i64, i64), | |
| 138 | 추가: } | |
| 139 | 추가: | |
| 140 | 추가: impl Identity { | |
| 141 | 추가: pub fn device(&self) -> u64 { | |
| 142 | 추가: self.device | |
| 143 | 추가: } | |
| 144 | 추가: pub fn inode(&self) -> u64 { | |
| 145 | 추가: self.inode | |
| 146 | 추가: } | |
| 147 | 추가: pub fn length(&self) -> u64 { | |
| 148 | 추가: self.length | |
| 149 | 추가: } | |
| 150 | 추가: pub fn links(&self) -> u64 { | |
| 151 | 추가: self.links | |
| 152 | 추가: } | |
| 153 | 추가: pub fn mode(&self) -> u32 { | |
| 154 | 추가: self.mode | |
| 155 | 추가: } | |
| 156 | 추가: pub fn modified(&self) -> (i64, i64) { | |
| 157 | 추가: self.modified | |
| 158 | 추가: } | |
| 159 | 추가: pub fn changed(&self) -> (i64, i64) { | |
| 160 | 추가: self.changed | |
| 161 | 추가: } | |
| 162 | 추가: } | |
| 163 | 추가: | |
| 164 | 추가: /// 두 번 읽어 일치한 메모리 사본임. 동시 변경 전체 탐지나 게시 증거가 아님. | |
| 165 | 추가: pub struct FileSnapshot { | |
| 166 | 추가: bytes: Vec<u8>, | |
| 167 | 추가: identity: Identity, | |
| 168 | 추가: sha256: [u8; 32], | |
| 169 | 추가: usage: Usage, | |
| 170 | 추가: } | |
| 171 | 추가: | |
| 172 | 추가: impl FileSnapshot { | |
| 173 | 추가: pub fn bytes(&self) -> &[u8] { | |
| 174 | 추가: &self.bytes | |
| 175 | 추가: } | |
| 176 | 추가: pub fn identity(&self) -> Identity { | |
| 177 | 추가: self.identity | |
| 178 | 추가: } | |
| 179 | 추가: pub fn sha256(&self) -> [u8; 32] { | |
| 180 | 추가: self.sha256 | |
| 181 | 추가: } | |
| 182 | 추가: pub fn usage(&self) -> Usage { | |
| 183 | 추가: self.usage | |
| 184 | 추가: } | |
| 185 | 추가: /// 원본 bytes를 이동하며 snapshot 증명 객체는 소비함. | |
| 186 | 추가: pub fn into_bytes(self) -> Vec<u8> { | |
| 187 | 추가: self.bytes | |
| 188 | 추가: } | |
| 189 | 추가: } | |
| 190 | 추가: | |
| 191 | 추가: impl std::fmt::Debug for FileSnapshot { | |
| 192 | 추가: fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | |
| 193 | 추가: f.debug_struct("FileSnapshot") | |
| 194 | 추가: .field("length", &self.bytes.len()) | |
| 195 | 추가: .field("usage", &self.usage) | |
| 196 | 추가: .finish_non_exhaustive() | |
| 197 | 추가: } | |
| 198 | 추가: } | |
| 199 | 추가: | |
| 200 | 추가: pub struct Request<'a> { | |
| 201 | 추가: pub path: &'a Path, | |
| 202 | 추가: pub limits: Limits, | |
| 203 | 추가: } | |
| 204 | 추가: | |
| 205 | 추가: struct Run { | |
| 206 | 추가: limits: Limits, | |
| 207 | 추가: usage: Usage, | |
| 208 | 추가: started: Instant, | |
| 209 | 추가: } | |
| 210 | 추가: | |
| 211 | 추가: impl Run { | |
| 212 | 추가: fn checkpoint<E>( | |
| 213 | 추가: &self, | |
| 214 | 추가: stage: Stage, | |
| 215 | 추가: offset: u64, | |
| 216 | 추가: length: Option<u64>, | |
| 217 | 추가: callback: &mut impl FnMut(Checkpoint) -> Result<(), Stop<E>>, | |
| 218 | 추가: ) -> Result<(), Error<E>> { | |
| 219 | 추가: callback(Checkpoint { | |
| 220 | 추가: stage, | |
| 221 | 추가: offset, | |
| 222 | 추가: length, | |
| 223 | 추가: usage: self.usage, | |
| 224 | 추가: }) | |
| 225 | 추가: .map_err(|stop| match stop { | |
| 226 | 추가: Stop::Cancelled => Error::Cancelled, | |
| 227 | 추가: Stop::Callback(error) => Error::Callback(error), | |
| 228 | 추가: })?; | |
| 229 | 추가: if self.started.elapsed() >= self.limits.max_duration { | |
| 230 | 추가: return Err(Error::Limit(LimitKind::Deadline)); | |
| 231 | 추가: } | |
| 232 | 추가: Ok(()) | |
| 233 | 추가: } | |
| 234 | 추가: | |
| 235 | 추가: fn reserve_read<E>(&mut self, count: usize) -> Result<(), Error<E>> { | |
| 236 | 추가: if self.usage.read_calls >= self.limits.max_read_calls { | |
| 237 | 추가: return Err(Error::Limit(LimitKind::ReadCalls)); | |
| 238 | 추가: } | |
| 239 | 추가: if count as u64 > self.limits.max_io_bytes - self.usage.reserved_read_bytes { | |
| 240 | 추가: return Err(Error::Limit(LimitKind::IoBytes)); | |
| 241 | 추가: } | |
| 242 | 추가: self.usage.read_calls += 1; | |
| 243 | 추가: self.usage.reserved_read_bytes += count as u64; | |
| 244 | 추가: Ok(()) | |
| 245 | 추가: } | |
| 246 | 추가: } | |
| 247 | 추가: | |
| 248 | 추가: /// 일반 파일을 처음부터 캡처함. callback과 파일 I/O의 강제 종료 시간은 보장하지 않음. | |
| 249 | 추가: pub fn capture<E>( | |
| 250 | 추가: request: Request<'_>, | |
| 251 | 추가: mut checkpoint: impl FnMut(Checkpoint) -> Result<(), Stop<E>>, | |
| 252 | 추가: ) -> Result<FileSnapshot, Failure<E>> { | |
| 253 | 추가: let mut run = Run { | |
| 254 | 추가: limits: request.limits, | |
| 255 | 추가: usage: Usage::default(), | |
| 256 | 추가: started: Instant::now(), | |
| 257 | 추가: }; | |
| 258 | 추가: let limits = request.limits; | |
| 259 | 추가: if limits.max_bytes > MAX_BYTES | |
| 260 | 추가: || limits.max_io_bytes > MAX_IO_BYTES | |
| 261 | 추가: || limits.max_read_calls == 0 | |
| 262 | 추가: || limits.max_read_calls > MAX_READ_CALLS | |
| 263 | 추가: || limits.max_duration.is_zero() | |
| 264 | 추가: || limits.max_duration > Duration::from_secs(300) | |
| 265 | 추가: { | |
| 266 | 추가: return Err(Failure { | |
| 267 | 추가: cause: Error::InvalidLimits, | |
| 268 | 추가: usage: run.usage, | |
| 269 | 추가: }); | |
| 270 | 추가: } | |
| 271 | 추가: #[cfg(target_os = "linux")] | |
| 272 | 추가: let result = linux::capture(request.path, &mut run, &mut checkpoint); | |
| 273 | 추가: #[cfg(not(target_os = "linux"))] | |
| 274 | 추가: let result: Result<FileSnapshot, Error<E>> = { | |
| 275 | 추가: let _ = (&request.path, &mut checkpoint); | |
| 276 | 추가: Err(Error::Unsupported(Unsupported::Platform)) | |
| 277 | 추가: }; | |
| 278 | 추가: result.map_err(|cause| Failure { | |
| 279 | 추가: cause, | |
| 280 | 추가: usage: run.usage, | |
| 281 | 추가: }) | |
| 282 | 추가: } | |
| 283 | 추가: | |
| 284 | 추가: fn digest(bytes: &[u8]) -> [u8; 32] { | |
| 285 | 추가: Sha256::digest(bytes).into() | |
| 286 | 추가: } |
| @@ -0,0 +1,278 @@ | ||
| 1 | 추가: use super::*; | |
| 2 | 추가: use std::{ | |
| 3 | 추가: ffi::CString, | |
| 4 | 추가: fs::{File, Metadata}, | |
| 5 | 추가: os::{ | |
| 6 | 추가: fd::{AsRawFd, FromRawFd}, | |
| 7 | 추가: unix::{ | |
| 8 | 추가: ffi::OsStrExt, | |
| 9 | 추가: fs::{FileExt, MetadataExt}, | |
| 10 | 추가: }, | |
| 11 | 추가: }, | |
| 12 | 추가: }; | |
| 13 | 추가: | |
| 14 | 추가: #[repr(C)] | |
| 15 | 추가: struct OpenHow { | |
| 16 | 추가: flags: u64, | |
| 17 | 추가: mode: u64, | |
| 18 | 추가: resolve: u64, | |
| 19 | 추가: } | |
| 20 | 추가: | |
| 21 | 추가: fn io_error<E>(operation: IoOperation, source: io::Error) -> Error<E> { | |
| 22 | 추가: Error::Io { operation, source } | |
| 23 | 추가: } | |
| 24 | 추가: | |
| 25 | 추가: fn open<E>( | |
| 26 | 추가: directory: i32, | |
| 27 | 추가: path: &std::ffi::CStr, | |
| 28 | 추가: flags: i32, | |
| 29 | 추가: resolve: u64, | |
| 30 | 추가: operation: IoOperation, | |
| 31 | 추가: run: &mut Run, | |
| 32 | 추가: ) -> Result<File, Error<E>> { | |
| 33 | 추가: let how = OpenHow { | |
| 34 | 추가: flags: flags as u64, | |
| 35 | 추가: mode: 0, | |
| 36 | 추가: resolve, | |
| 37 | 추가: }; | |
| 38 | 추가: run.usage.open_calls += 1; | |
| 39 | 추가: // 초기화된 구조체와 NUL 종료 문자열을 호출 동안 유지함. | |
| 40 | 추가: let fd = unsafe { | |
| 41 | 추가: libc::syscall( | |
| 42 | 추가: libc::SYS_openat2, | |
| 43 | 추가: directory, | |
| 44 | 추가: path.as_ptr(), | |
| 45 | 추가: &how as *const OpenHow, | |
| 46 | 추가: std::mem::size_of::<OpenHow>(), | |
| 47 | 추가: ) | |
| 48 | 추가: }; | |
| 49 | 추가: if fd < 0 { | |
| 50 | 추가: let source = io::Error::last_os_error(); | |
| 51 | 추가: return Err(io_error(operation, source)); | |
| 52 | 추가: } | |
| 53 | 추가: // 성공한 syscall의 새 fd 소유권을 한 번만 이전함. | |
| 54 | 추가: Ok(unsafe { File::from_raw_fd(fd as i32) }) | |
| 55 | 추가: } | |
| 56 | 추가: | |
| 57 | 추가: fn inspect<E>(file: &File, run: &mut Run) -> Result<Identity, Error<E>> { | |
| 58 | 추가: run.usage.metadata_calls += 1; | |
| 59 | 추가: let metadata = file | |
| 60 | 추가: .metadata() | |
| 61 | 추가: .map_err(|e| io_error(IoOperation::Inspect, e))?; | |
| 62 | 추가: regular(&metadata)?; | |
| 63 | 추가: Ok(Identity { | |
| 64 | 추가: device: metadata.dev(), | |
| 65 | 추가: inode: metadata.ino(), | |
| 66 | 추가: length: metadata.len(), | |
| 67 | 추가: links: metadata.nlink(), | |
| 68 | 추가: mode: metadata.mode(), | |
| 69 | 추가: modified: (metadata.mtime(), metadata.mtime_nsec()), | |
| 70 | 추가: changed: (metadata.ctime(), metadata.ctime_nsec()), | |
| 71 | 추가: }) | |
| 72 | 추가: } | |
| 73 | 추가: | |
| 74 | 추가: fn regular<E>(metadata: &Metadata) -> Result<(), Error<E>> { | |
| 75 | 추가: if !metadata.is_file() { | |
| 76 | 추가: return Err(Error::Unsupported(Unsupported::FileType)); | |
| 77 | 추가: } | |
| 78 | 추가: if metadata.nlink() != 1 { | |
| 79 | 추가: return Err(Error::Unsupported(Unsupported::MultipleLinks)); | |
| 80 | 추가: } | |
| 81 | 추가: Ok(()) | |
| 82 | 추가: } | |
| 83 | 추가: | |
| 84 | 추가: fn same<E>(before: Identity, after: Identity) -> Result<(), Error<E>> { | |
| 85 | 추가: if before.device != after.device || before.inode != after.inode { | |
| 86 | 추가: return Err(Error::Changed(Changed::Identity)); | |
| 87 | 추가: } | |
| 88 | 추가: if before.length != after.length { | |
| 89 | 추가: return Err(Error::Changed(Changed::Length)); | |
| 90 | 추가: } | |
| 91 | 추가: if before != after { | |
| 92 | 추가: return Err(Error::Changed(Changed::Metadata)); | |
| 93 | 추가: } | |
| 94 | 추가: Ok(()) | |
| 95 | 추가: } | |
| 96 | 추가: | |
| 97 | 추가: fn read<E>(file: &File, output: &mut [u8], offset: u64, run: &mut Run) -> Result<usize, Error<E>> { | |
| 98 | 추가: run.reserve_read(output.len())?; | |
| 99 | 추가: // EINTR도 원래 오류로 반환하며 자동 재시도로 계수를 숨기지 않음. | |
| 100 | 추가: let count = file | |
| 101 | 추가: .read_at(output, offset) | |
| 102 | 추가: .map_err(|e| io_error(IoOperation::Read, e))?; | |
| 103 | 추가: run.usage.actual_read_bytes += count as u64; | |
| 104 | 추가: Ok(count) | |
| 105 | 추가: } | |
| 106 | 추가: | |
| 107 | 추가: fn eof<E>(file: &File, length: u64, run: &mut Run) -> Result<(), Error<E>> { | |
| 108 | 추가: if read(file, &mut [0; 1], length, run)? != 0 { | |
| 109 | 추가: return Err(Error::Changed(Changed::Length)); | |
| 110 | 추가: } | |
| 111 | 추가: Ok(()) | |
| 112 | 추가: } | |
| 113 | 추가: | |
| 114 | 추가: pub(super) fn capture<E>( | |
| 115 | 추가: path: &Path, | |
| 116 | 추가: run: &mut Run, | |
| 117 | 추가: callback: &mut impl FnMut(Checkpoint) -> Result<(), Stop<E>>, | |
| 118 | 추가: ) -> Result<FileSnapshot, Error<E>> { | |
| 119 | 추가: run.checkpoint(Stage::Opening, 0, None, callback)?; | |
| 120 | 추가: let raw = path.as_os_str().as_bytes(); | |
| 121 | 추가: if raw.len() < 2 | |
| 122 | 추가: || raw.len() > 4096 | |
| 123 | 추가: || raw[0] != b'/' | |
| 124 | 추가: || raw[1..] | |
| 125 | 추가: .split(|b| *b == b'/') | |
| 126 | 추가: .any(|part| part.is_empty() || part == b"." || part == b".." || part.len() > 255) | |
| 127 | 추가: { | |
| 128 | 추가: return Err(Error::InvalidPath); | |
| 129 | 추가: } | |
| 130 | 추가: let name = CString::new(raw).map_err(|_| Error::InvalidPath)?; | |
| 131 | 추가: let pinned = open( | |
| 132 | 추가: libc::AT_FDCWD, | |
| 133 | 추가: &name, | |
| 134 | 추가: libc::O_PATH | libc::O_CLOEXEC, | |
| 135 | 추가: 0x04, | |
| 136 | 추가: IoOperation::PinPath, | |
| 137 | 추가: run, | |
| 138 | 추가: )?; | |
| 139 | 추가: let identity = inspect(&pinned, run)?; | |
| 140 | 추가: if identity.length > run.limits.max_bytes { | |
| 141 | 추가: return Err(Error::Limit(LimitKind::Bytes)); | |
| 142 | 추가: } | |
| 143 | 추가: run.checkpoint(Stage::Pinned, 0, Some(identity.length), callback)?; | |
| 144 | 추가: | |
| 145 | 추가: // 검증한 procfs 디렉터리에서 보유 regular-file fd만 읽기 모드로 다시 엶. | |
| 146 | 추가: let proc = open( | |
| 147 | 추가: libc::AT_FDCWD, | |
| 148 | 추가: c"/proc", | |
| 149 | 추가: libc::O_PATH | libc::O_DIRECTORY | libc::O_CLOEXEC, | |
| 150 | 추가: 0x04, | |
| 151 | 추가: IoOperation::OpenProc, | |
| 152 | 추가: run, | |
| 153 | 추가: )?; | |
| 154 | 추가: let mut status = std::mem::MaybeUninit::<libc::statfs>::uninit(); | |
| 155 | 추가: run.usage.metadata_calls += 1; | |
| 156 | 추가: // 성공 반환일 때만 커널이 초기화한 statfs 값을 읽음. | |
| 157 | 추가: if unsafe { libc::fstatfs(proc.as_raw_fd(), status.as_mut_ptr()) } != 0 { | |
| 158 | 추가: return Err(io_error( | |
| 159 | 추가: IoOperation::InspectProc, | |
| 160 | 추가: io::Error::last_os_error(), | |
| 161 | 추가: )); | |
| 162 | 추가: } | |
| 163 | 추가: if unsafe { status.assume_init() }.f_type != libc::PROC_SUPER_MAGIC { | |
| 164 | 추가: return Err(Error::Unsupported(Unsupported::Procfs)); | |
| 165 | 추가: } | |
| 166 | 추가: let directory_name = | |
| 167 | 추가: CString::new(format!("{}/fd", std::process::id())).map_err(|_| Error::InvalidPath)?; | |
| 168 | 추가: let descriptors = open( | |
| 169 | 추가: proc.as_raw_fd(), | |
| 170 | 추가: &directory_name, | |
| 171 | 추가: libc::O_PATH | libc::O_DIRECTORY | libc::O_CLOEXEC, | |
| 172 | 추가: 0x0d, | |
| 173 | 추가: IoOperation::OpenProcDescriptors, | |
| 174 | 추가: run, | |
| 175 | 추가: )?; | |
| 176 | 추가: let descriptor_name = | |
| 177 | 추가: CString::new(pinned.as_raw_fd().to_string()).map_err(|_| Error::InvalidPath)?; | |
| 178 | 추가: run.usage.open_calls += 1; | |
| 179 | 추가: // 검증한 procfs fd 디렉터리의 보유 fd 링크만 의도적으로 따라감. | |
| 180 | 추가: let descriptor = unsafe { | |
| 181 | 추가: libc::openat( | |
| 182 | 추가: descriptors.as_raw_fd(), | |
| 183 | 추가: descriptor_name.as_ptr(), | |
| 184 | 추가: libc::O_RDONLY | libc::O_NONBLOCK | libc::O_CLOEXEC | libc::O_NOCTTY, | |
| 185 | 추가: ) | |
| 186 | 추가: }; | |
| 187 | 추가: if descriptor < 0 { | |
| 188 | 추가: return Err(io_error( | |
| 189 | 추가: IoOperation::ReopenPinned, | |
| 190 | 추가: io::Error::last_os_error(), | |
| 191 | 추가: )); | |
| 192 | 추가: } | |
| 193 | 추가: // 새 읽기 fd만 소유하며 원래 경로를 다시 열지 않음. | |
| 194 | 추가: let file = unsafe { File::from_raw_fd(descriptor) }; | |
| 195 | 추가: same(identity, inspect(&file, run)?)?; | |
| 196 | 추가: drop(descriptors); | |
| 197 | 추가: drop(proc); | |
| 198 | 추가: drop(pinned); | |
| 199 | 추가: | |
| 200 | 추가: let length = identity.length as usize; | |
| 201 | 추가: run.checkpoint(Stage::Copying, 0, Some(identity.length), callback)?; | |
| 202 | 추가: let mut bytes = Vec::new(); | |
| 203 | 추가: bytes.try_reserve_exact(length).map_err(Error::Allocation)?; | |
| 204 | 추가: bytes.resize(length, 0); | |
| 205 | 추가: let mut offset = 0; | |
| 206 | 추가: while offset < length { | |
| 207 | 추가: run.checkpoint( | |
| 208 | 추가: Stage::Copying, | |
| 209 | 추가: offset as u64, | |
| 210 | 추가: Some(identity.length), | |
| 211 | 추가: callback, | |
| 212 | 추가: )?; | |
| 213 | 추가: let end = (offset + CHUNK_BYTES).min(length); | |
| 214 | 추가: let count = read(&file, &mut bytes[offset..end], offset as u64, run)?; | |
| 215 | 추가: if count == 0 { | |
| 216 | 추가: return Err(Error::Changed(Changed::Length)); | |
| 217 | 추가: } | |
| 218 | 추가: offset += count; | |
| 219 | 추가: } | |
| 220 | 추가: run.checkpoint( | |
| 221 | 추가: Stage::Copying, | |
| 222 | 추가: offset as u64, | |
| 223 | 추가: Some(identity.length), | |
| 224 | 추가: callback, | |
| 225 | 추가: )?; | |
| 226 | 추가: eof(&file, identity.length, run)?; | |
| 227 | 추가: same(identity, inspect(&file, run)?)?; | |
| 228 | 추가: | |
| 229 | 추가: let mut check = [0; CHUNK_BYTES]; | |
| 230 | 추가: offset = 0; | |
| 231 | 추가: while offset < length { | |
| 232 | 추가: run.checkpoint( | |
| 233 | 추가: Stage::Comparing, | |
| 234 | 추가: offset as u64, | |
| 235 | 추가: Some(identity.length), | |
| 236 | 추가: callback, | |
| 237 | 추가: )?; | |
| 238 | 추가: let count = read( | |
| 239 | 추가: &file, | |
| 240 | 추가: &mut check[..(length - offset).min(CHUNK_BYTES)], | |
| 241 | 추가: offset as u64, | |
| 242 | 추가: run, | |
| 243 | 추가: )?; | |
| 244 | 추가: if count == 0 { | |
| 245 | 추가: return Err(Error::Changed(Changed::Length)); | |
| 246 | 추가: } | |
| 247 | 추가: run.usage.compared_bytes += count as u64; | |
| 248 | 추가: if bytes[offset..offset + count] != check[..count] { | |
| 249 | 추가: return Err(Error::Changed(Changed::Contents)); | |
| 250 | 추가: } | |
| 251 | 추가: offset += count; | |
| 252 | 추가: } | |
| 253 | 추가: run.checkpoint( | |
| 254 | 추가: Stage::Comparing, | |
| 255 | 추가: offset as u64, | |
| 256 | 추가: Some(identity.length), | |
| 257 | 추가: callback, | |
| 258 | 추가: )?; | |
| 259 | 추가: eof(&file, identity.length, run)?; | |
| 260 | 추가: let sha256 = digest(&bytes); | |
| 261 | 추가: run.checkpoint( | |
| 262 | 추가: Stage::Finalizing, | |
| 263 | 추가: offset as u64, | |
| 264 | 추가: Some(identity.length), | |
| 265 | 추가: callback, | |
| 266 | 추가: )?; | |
| 267 | 추가: same(identity, inspect(&file, run)?)?; | |
| 268 | 추가: // 마지막 syscall 동안 지난 기한도 확인하며 취소 callback을 재호출하지 않음. | |
| 269 | 추가: if run.started.elapsed() >= run.limits.max_duration { | |
| 270 | 추가: return Err(Error::Limit(LimitKind::Deadline)); | |
| 271 | 추가: } | |
| 272 | 추가: Ok(FileSnapshot { | |
| 273 | 추가: bytes, | |
| 274 | 추가: identity, | |
| 275 | 추가: sha256, | |
| 276 | 추가: usage: run.usage, | |
| 277 | 추가: }) | |
| 278 | 추가: } |