1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
//! Filesystem intrinsics for `std/fs`.
//!
//! # The boundary this module implements
//!
//! Nova has no out-parameters, so an intrinsic returns exactly one word — but
//! `read_to_string` must convey a `String` *and* a two-field `IoError`. Rather
//! than build a Nova sum and record here, which would put Nova value layout in
//! Rust, **the status code returned by each operation *is* the error kind**, and
//! payloads travel in the slots below. `std/fs`'s Nova wrappers map a status to
//! an `IoErrorKind` and construct every `Result` and `IoError` themselves.
//!
//! # Why `SLOTS` is a `RefCell` guarded with `try_borrow_mut`, not `borrow_mut`
//!
//! **Every function here is called from inside an `async fn`'s generated
//! `$poll`, which has no landing pads** (see `nova_mir::async_lower`'s module
//! doc comment), so nothing here may panic. `RefCell::borrow_mut` panics on an
//! already-outstanding borrow; `try_borrow_mut` cannot, so `with_slot` uses
//! that instead and falls back to `abort_with` -- which terminates without
//! unwinding -- on the contended case. Each slot still holds nothing more
//! than a raw already-allocated pointer as a `usize`, with `0` meaning empty;
//! the per-task table just adds one layer of indirection to reach it, keyed
//! by `slot_index`.
//!
//! `stash` itself is `pub(crate)`: `std/fs` is not its only consumer.
//! `crates/nova-runtime/src/io.rs` stashes the three standard streams'
//! payloads and write byte counts through this identical slot table, and
//! `crates/nova-runtime/src/crypto.rs` stashes digests, HMAC tags and random
//! bytes the same way, rather than either module owning a second one.
//! `take` stays private (final review, M4) -- `io.rs`'s own production code
//! only ever stashes, and its tests reach `take` through the test-only
//! `take_for_test` instead of `take` itself being widened for their sake.
//!
//! # Why the pointer is GC-rooted while it sits in a slot
//!
//! A slot is written by one intrinsic and read by the next, with Nova code in
//! between. A conservative stack scan cannot see a pointer that lives only in a
//! thread-local, so the object is registered with `gc::add_root` while stashed
//! and released on take — the same balance `task::spawn_internal` and
//! `take_output_internal` keep. Without it the payload could be collected
//! between the two calls, which is why this does not merely rely on "no
//! allocation happens in between".
use crate::;
use RefCell;
/// Status codes. `0` is success; every other value is an `IoErrorKind`.
///
/// **This numbering is one half of a wire contract.** The other half is
/// `io_error_kind_of` in `std/io/lib.nova`. The two are independent copies.
///
/// **MEASURED, not "pinned together by a fixture per kind" for all eight —
/// that claim was false and this replaces it (final review, I1).** The Nova
/// half (`io_error_kind_of`'s own arms) is pinned per-code by
/// `fs_io_types.nova`. This Rust half, the one that produces a code from a
/// real `std::io::ErrorKind` below, is pinned by a fixture that provokes the
/// real OS condition for only four of the eight: `NotFound`, `AlreadyExists`,
/// `InvalidData`, and `PermissionDenied` on Windows only.
///
/// **Corrected 2026-08-14 (branch `file-open-openoptions`): naming one
/// fixture per kind, as this comment used to, went stale for three of those
/// four the moment `file.rs`'s `open` began producing this same numbering
/// from a second Rust source.** Per kind, now:
/// - `NotFound`: `fs_not_found.nova` (`read_to_string` on a missing path),
/// and independently `file_errors.nova` (`open` on a path under a missing
/// parent directory).
/// - `AlreadyExists`: `fs_already_exists.nova` (`create_dir` on an existing
/// path, twice), and independently `file_errors.nova` (`open` with
/// `create_new` on an existing path).
/// - `InvalidData`: `fs_invalid_data.nova` only — `File::read` hands back
/// `Bytes` and never decodes UTF-8, so nothing about `File` can provoke
/// this one.
/// - `PermissionDenied`, Windows only: `fs_permission_denied.nova`
/// (`read_to_string` on a directory, `#[cfg(windows)]`), and independently
/// `file_open_dir.nova` (`open` on a directory, `#[cfg(windows)]`).
///
/// `Interrupted`, `TimedOut` and `ConnectionRefused` are not reachable from
/// `std/fs`'s `async fn`s at all, portably or otherwise, so no fixture can pin
/// them. **Reasoned, not measured, for `read`/`write` (`byte-type` branch):**
/// both route through this same `fail` function exactly as
/// `read_to_string`/`write_string` do, over `std::fs::read`/`std::fs::write`
/// rather than `std::fs::read_to_string`/`std::fs::write` — reading or
/// writing raw bytes instead of UTF-8 text opens no path to a network- or
/// signal-flavoured `ErrorKind` that plain-text local I/O did not already
/// have, so the same unreachability is expected to hold, not separately
/// provoked. The `_ => OTHER` fallback *is* reachable (e.g. `read_dir` on a
/// plain file returns it, still unexercised).
///
/// **Corrected 2026-08-14: it is no longer true that nothing exercises this
/// fallback.** `file.rs`'s closed/stale/forged-fd case (`closed_fd_error`)
/// fabricates a `std::io::Error` of `ErrorKind::Other` on every table miss,
/// unconditionally, which falls to this identical `_` arm — and
/// `file_lifetime.nova`'s "read after close" check asserts on the exact
/// message that arm stashes. See `docs/adr/0011-io-error-kinds.md`, which
/// states this split correctly as of the same correction.
///
/// **Corrected 2026-08-16 (branch `io-poller-std-net`): the "not reachable ...
/// so no fixture can pin them" paragraph above is now stale for two of its
/// three kinds, and the per-kind breakdown two paragraphs up goes four
/// fixture-pinned kinds to six.** `TIMED_OUT` and `CONNECTION_REFUSED` have
/// carried this numbering with no producer since increment 1, because no
/// filesystem operation can produce either — `crates/nova-runtime/src/net.rs`'s
/// two-phase `connect` and its `read_timeout` future are their first. A
/// `connect` to a loopback port nothing is listening on is refused either
/// synchronously (an immediate `ECONNREFUSED`/`WSAECONNREFUSED`, routine for
/// a closed loopback port) or via the second poll's `SO_ERROR` check, both
/// paths through this identical `fail` (`net.rs`'s own module doc comment,
/// "`CONNECTION_REFUSED` gets its first producer"), pinned end to end by
/// `tests/runtime/net_refused.nova` (`net_refused_run`,
/// `crates/nova-cli/tests/run_tests.rs`). `read_timeout` reports `TIMED_OUT`
/// when its deadline passes with a read still would-blocking, pinned by
/// `tests/runtime/net_timeout.nova` (`net_timeout_run`), which also pins the
/// opposite direction in the same fixture — a deadline comfortably longer
/// than the peer's own delay must still succeed with the real data, not fire
/// merely because a deadline is in play at all. Six of the eight status
/// codes are therefore fixture-pinned now: the original four two paragraphs
/// up, plus these two. Only `INTERRUPTED` remains genuinely unreachable from
/// either module's `async fn`s, portably or otherwise — the "reasoned, not
/// measured" argument above, made for all three together, now supports
/// `INTERRUPTED` alone.
pub const OK: i64 = 0;
pub const NOT_FOUND: i64 = 1;
pub const PERMISSION_DENIED: i64 = 2;
pub const ALREADY_EXISTS: i64 = 3;
pub const INVALID_DATA: i64 = 4;
pub const INTERRUPTED: i64 = 5;
pub const TIMED_OUT: i64 = 6;
pub const CONNECTION_REFUSED: i64 = 7;
pub const OTHER: i64 = 8;
/// Which payload a `stash`/`take` pair is addressing.
///
/// Replaces the three separate `thread_local!` slots this module used before
/// per-task storage. `Buffer` serves `String` *and* `Bytes` payloads, not one
/// variant each: the two have the identical `{len, ptr}` representation (see
/// `crate::bytes`'s module doc comment), and which one a payload is gets
/// carried entirely by which builtin stashed it and which one reads it back
/// (`nova_rt_fs_read_to_string`/`nova_rt_fs_take_string` treat it as UTF-8;
/// `nova_rt_fs_read`/`nova_rt_fs_take_bytes` do not interpret it at all). A
/// dedicated `Bytes` slot would be a fourth copy of storage for a distinction
/// already carried by which builtin stashed it — exactly the kind of
/// avoidable debt this module's boundary design exists to prevent.
///
/// `pub(crate)`, not private: the [`release_task_slots`] test that seeds all
/// three kinds for one task id lives in `task.rs`, alongside the two
/// Buffer-only ones it completes, and needs to name a variant to call
/// [`stash_for_test`] with (final review, I2). A placement choice, not a
/// forced one -- the same coverage could instead have been written directly
/// in this module's own tests, which already call [`stash`] without needing
/// `Slot` visible outside it at all.
pub
/// One task's three payload slots. Each field is a GC-rooted pointer, or 0.
thread_local!
/// Allocate a GC-managed string for a slot payload.
///
/// A thin name for [`crate::gc_str`], reused rather than reproducing
/// `NovaStr { len, ptr }`'s layout here a second time — precisely the drift
/// class this module's boundary design exists to avoid.
/// Convert a task id into its `SLOTS` index. Shared by [`slot_index`] and
/// [`release_task_slots`] so the `+ 1` offset is written in exactly one place
/// (final review, M3 — it was previously duplicated between them).
///
/// `id + 1`, so index **0 stays the reserved no-task key** and is never a
/// real task's own index. Both of today's callers already validate `id`
/// against `TASKS` before reaching here (`task.rs`'s `release_internal`
/// aborts and `take_output_internal` panics on an id that was never
/// registered), so a negative `id` cannot reach this function today. Guarded
/// anyway, for a future caller that might: `abort_with`, not a check that
/// could panic, since this can run inside a generated poll boundary with no
/// landing pads. Without the guard, `id as usize + 1` on a negative `id`
/// is an overflow -- a debug-only panic, and a silent wrap onto the
/// no-task index in release -- rather than a clean rejection.
/// The `SLOTS` index for the current task.
///
/// `id + 1`, so index **0 is the reserved no-task key**. Task ids are dense
/// from zero (`poll_one` reads `tasks.get(id as usize)`), so a `Vec` gives O(1)
/// access with no hashing and no per-call allocation.
/// Run `f` against one field of the current task's slots, growing the table if
/// this task has not been seen before.
///
/// **Panic-free by construction, because this runs inside a generated poll
/// boundary with no landing pads.** `try_borrow_mut` rather than `borrow_mut`,
/// and `get_mut` rather than `[i]`; both fall back to `abort_with`, which
/// terminates without unwinding. The `get_mut` arm is unreachable — the resize
/// immediately above guarantees `i < len` — and exists so the impossible case
/// still cannot unwind.
/// Register `ptr` as a GC root, then publish it in `slot`.
///
/// Rooting before publishing means a scan running between these two
/// statements still finds the object through the root table — there is no
/// instant where it is reachable by neither the slot nor a root. This now
/// holds for the overwrite case too: releasing whatever `slot` already held
/// happens first, via the same `take` a normal read uses, so a displaced
/// pointer's root is never left dangling.
///
/// **Releases the slot's current occupant first (final review, I2).**
/// Without this, stashing into an already-occupied slot would `add_root` the
/// new pointer while leaving the displaced one's root registered forever —
/// `take` is the only place that releases a *slot's* root (`stash_array`'s own
/// `remove_root` call is a separate, self-contained build-time balance,
/// finished before its block ever reaches a slot), and `take` can only see
/// whichever pointer is *currently* published, so the one just overwritten
/// would never be found and released. Not reachable through today's
/// `std/fs` surface (every wrapper drains a slot before the next `stash`
/// targeting it — see `a_stashed_string_is_rooted_until_it_is_taken`'s doc
/// comment for why that is not itself enough to catch this), so this was
/// latent rather than observed in any fixture; measured with a probe
/// identical in shape to
/// `stash_overwriting_an_occupied_slot_does_not_leak_the_displaced_root`
/// below, minus this fix. `take`'s own contract (return `0` for an empty
/// slot, otherwise the released pointer) makes discarding its result safe
/// here: there is nothing to free by hand either way.
///
/// `pub(crate)`, not private: `std/fs` is not this function's only consumer.
/// `crate::io` also stashes the standard streams' read payloads and write
/// byte counts through it, and `crate::crypto` stashes digests, HMAC tags
/// and random bytes the same way, rather than either module reproducing its
/// root-balancing logic for itself.
pub
/// Read and clear `slot`, releasing its root, and return what was there (`0`
/// if the slot was empty).
///
/// **Ordered exactly as `task::take_output_internal` orders its matching
/// `gc::remove_root`:** the pointer is read out of the slot and the slot is
/// cleared *before* the root is released, so the add/remove stay balanced and
/// the returned pointer is live throughout — rooted by the slot until the
/// instant before this returns, then rooted by the caller's own frame like
/// any other runtime return value.
///
/// **The `gc::remove_root` deliberately happens after the borrow is dropped**,
/// not inside `with_slot`'s closure. Holding a `RefCell` borrow across a call
/// into the collector would be a re-entrancy hazard for no benefit; the
/// pointer is already out of the table and owned by this frame by then.
///
/// Private, not `pub(crate)` (final review, M4): every production caller is
/// in this module -- `stash` below and the `nova_rt_fs_take_*` intrinsics --
/// and `crate::io`'s production code only ever stashes (its payloads are
/// meant for a future Nova caller to take via `nova_rt_fs_take_bytes`, not
/// for `io.rs` itself to take back out). `crate::io`'s own *tests* are the
/// one cross-module consumer, verifying what a stash left behind the same
/// way this function's own tests here do; they reach this through
/// [`take_for_test`] below instead of this function being widened just for
/// them. `take` carries GC-root semantics (`remove_root`), so a
/// broader-than-needed path to it is worth the extra indirection.
/// Test-only cross-module accessor for [`take`], for `crate::io`'s own tests
/// -- the same reason [`stash_for_test`] exists for [`stash`], and a
/// narrower pattern than widening `take` itself would have been: every
/// *production* call to [`take`] is inside this module, so it never needed
/// more than module-private visibility.
pub
/// Release every payload root task `id` still holds, and clear its slots.
///
/// Called from `crate::task::release_internal` and `crate::task::take_output_internal` —
/// the two places that release a task's *state* root. Keyed on `id` rather
/// than [`slot_index`] precisely because those call sites do not run with
/// `CURRENT` set to the task being released.
///
/// Idempotent, and silent for a task that never stashed anything: a task id
/// past the end of the table simply has no slots.
///
/// Roots are released after the borrow is dropped, for the same reason
/// [`take`] does it that way.
pub
/// Test-only: stash `ptr` into task `id`'s `slot`, without requiring
/// `CURRENT` to already equal `id`.
///
/// `task.rs`'s own test module cannot reach `SLOTS` directly -- it is
/// private to this module -- and even now that [`stash`] itself is
/// `pub(crate)`, calling it directly still only ever targets *the current
/// task's* slot (through `slot_index`), never an arbitrary one. This
/// function needs a way to seed a payload for a task it registers through
/// its own internals (`spawn_internal`/`nova_rt_task_spawn`) without
/// driving a real poll, so it can call
/// `release_internal`/`take_output_internal` directly and check whether
/// either one actually drops the payload's root. Delegates
/// to [`stash`] under a temporary [`crate::task::set_current_for_test`]
/// override, restoring whatever `CURRENT` held beforehand rather than
/// assuming it was `None`.
///
/// **Takes `slot` rather than hardcoding [`Slot::Buffer`] (final review,
/// I2).** `release_task_slots` has three fields to release, and until this
/// change every caller of this function seeded only `Buffer` -- widened
/// only as far as pinning all three needed, not into a general-purpose
/// helper.
///
/// `#[cfg(test)]` only: every caller of this function is an ordinary,
/// cross-platform `task.rs` test, the same reasoning
/// `set_current_for_test`'s own doc comment gives for itself.
pub
/// Map an `std::io::Error` to its status code, and stash its message.
///
/// Called on every failure path, so the message is always available to the
/// wrapper that is about to build an `IoError`.
///
/// `pub(crate)`, not private: `crate::io` is a second consumer, mapping the
/// standard streams' I/O errors through this same function rather than a
/// second copy of the kind-to-status table.
pub
/// Build a Nova `[String]` from `names` and stash it, GC-rooted.
///
/// **Reproduces the layout codegen emits for an array**: word 0 is the element
/// count, elements follow at `8 + 8*i`, allocated scanned so the collector
/// traces the `NovaStr` pointers inside. Getting this wrong is a silent
/// miscompile rather than a failure, which is why `mod tests` asserts the
/// tracked `(size, scan)` through `gc::object_info` and not merely the values
/// read back — the same discipline `nova_rt_str_chars` carries.
///
/// Each element is rooted while it is being built, because the allocation of a
/// later element can collect and an earlier one is then named only by a block
/// that is itself not yet reachable from anywhere the collector scans.
///
/// **This is rooting the block, not each element — verified against `gc.rs`'s
/// actual contract rather than assumed.** `block` is allocated with
/// `scan = true` (the same flag `nova_rt_str_chars`'s array block uses), and
/// `collect_with_roots`'s mark phase does not stop at a rooted object: every
/// object it marks — reached directly as a root or transitively — is then
/// traced if `scan` is true, meaning its words are read back and each one is
/// itself passed through the identical range-based `mark_word` check a root
/// gets. So once `block` is a root, every `NovaStr` pointer already written
/// into its element words is found by that trace and kept alive too, the same
/// way a rooted record keeps its fields alive without each field needing its
/// own root. If `add_root`ing a block did NOT cause its contents to be
/// traced, this function would need to root every element individually
/// instead; it does not, because the property above holds.
/// Read `path` as UTF-8. Returns a status; on `OK` the contents are waiting in
/// `nova_rt_fs_take_string`.
///
/// Non-UTF-8 contents are `INVALID_DATA`: `std::fs::read_to_string` reports
/// `ErrorKind::InvalidData` for them, which is exactly the case that motivated
/// adding that kind (see docs/adr/0011-io-error-kinds.md).
///
/// # Safety
/// `path` must point to a live `NovaStr`.
pub unsafe extern "C"
/// Write `content` to `path`, truncating an existing file.
///
/// # Safety
/// Both arguments must point to live `NovaStr`s.
pub unsafe extern "C"
/// Take the pending payload string. Returns an empty string if nothing is
/// pending, which a correct wrapper never asks for.
pub extern "C"
/// Read `path`'s bytes. Returns a status; on `OK` the contents are waiting in
/// `nova_rt_fs_take_bytes`.
///
/// Unlike `nova_rt_fs_read_to_string` this cannot produce `INVALID_DATA`: there
/// is no encoding to violate. Any status other than `OK` is a real I/O failure.
///
/// # Safety
/// `path` must point to a live `NovaStr`.
pub unsafe extern "C"
/// Write `content`'s bytes to `path`, truncating an existing file.
///
/// # Safety
/// Both arguments must point to live `NovaStr`s.
pub unsafe extern "C"
/// Take the pending payload as `Bytes`. Returns an empty `Bytes` if nothing is
/// pending, which a correct wrapper never asks for.
///
/// Mirrors [`nova_rt_fs_take_string`], reading the same
/// [`Slot::Buffer`] -- the payload left there by a successful
/// [`nova_rt_fs_read`], never interpreted as UTF-8.
///
/// **The `fs_` prefix is now historical.** Since increment 3a this reads a
/// general per-task slot, not an fs-specific one, and `crate::io`'s stream
/// intrinsics stash exactly this shape of payload here too -- both a read
/// buffer and, for a write, its byte count encoded as bytes.
/// `std/io/lib.nova`'s `read_stdin`, `write_stdout` and `write_stderr` are
/// that outside-`std/fs` caller now, collecting through this same taker
/// rather than a second one.
pub extern "C"
/// Take the pending error message.
///
/// **The `fs_` prefix is now historical**, for the same reason
/// [`nova_rt_fs_take_bytes`]'s doc comment gives: [`fail`] stashes into the
/// same per-task [`Slot::Message`] regardless of which module's intrinsic
/// called it. Every fallible wrapper in `std/io/lib.nova` --
/// `read_stdin`, `write_stdout`, `write_stderr`, `flush_stdout` and
/// `flush_stderr` -- reads its own error message back through this same
/// taker now, alongside `std/fs`'s own wrappers.
pub extern "C"
/// The OS temporary-directory path, per `std::env::temp_dir()`.
///
/// `to_string_lossy`, not a fallible conversion: a Nova `String` is UTF-8
/// while a Windows path is UTF-16, so a path containing an unpaired
/// surrogate cannot round-trip exactly. There is no `IoError` to report that
/// through here -- nothing failed at the OS level, the path is simply
/// unrepresentable exactly -- and this path is exotic enough in practice
/// that a usable (if occasionally imprecise) string beats an operation with
/// no way to signal the problem.
pub extern "C"
/// Whether `path` exists. Cannot distinguish absent from unreadable, because
/// `nova-spec/20-STDLIB.md` §5 gives `exists` a `Bool` return rather than a
/// `Result`; that is the spec's choice and is left alone.
///
/// # Safety
/// `path` must point to a live `NovaStr`.
pub unsafe extern "C"
/// Create the directory `path`. Its parent must exist; an existing `path` is
/// `ALREADY_EXISTS`.
///
/// # Safety
/// `path` must point to a live `NovaStr`.
pub unsafe extern "C"
/// Create the directory `path`, and any missing parent directories along the
/// way. Unlike `create_dir`, an existing directory at `path` is success, not
/// `ALREADY_EXISTS` -- `std::fs::create_dir_all`'s own behaviour, carried
/// through unchanged rather than papered over.
///
/// # Safety
/// `path` must point to a live `NovaStr`.
pub unsafe extern "C"
/// Remove the file `path`.
///
/// # Safety
/// `path` must point to a live `NovaStr`.
pub unsafe extern "C"
/// Remove the directory `path` and everything under it.
///
/// # Safety
/// `path` must point to a live `NovaStr`.
pub unsafe extern "C"
/// List `path`'s entry names, sorted. On `OK` the names are waiting in
/// `nova_rt_fs_take_string_array`.
///
/// **Sorted in the runtime deliberately.** Directory order is unspecified by
/// every OS, so unsorted output would make each fixture platform-dependent.
///
/// # Safety
/// `path` must point to a live `NovaStr`.
pub unsafe extern "C"
/// Take the array payload staged by a successful `nova_rt_fs_read_dir`.
///
/// Mirrors [`nova_rt_fs_take_string`], with the one difference forced by there
/// being no such thing as a null Nova array: an empty slot (`0`) yields a
/// fresh, well-formed zero-length array here -- the same `{ len: 0 }` shape
/// `nova_rt_str_chars` produces for an empty string -- rather than a null
/// pointer, which a correct wrapper would then have to null-check for no
/// reason (a correct wrapper never asks for this when nothing is pending,
/// exactly as `nova_rt_fs_take_string`'s own doc comment notes).
pub extern "C"
/// What `path` is: 0 = metadata unavailable (absent, or unreadable), 1 file,
/// 2 directory.
///
/// One call rather than separate `is_file`/`is_dir` intrinsics, so a `DirEntry`
/// costs one syscall instead of two and the two answers cannot disagree.
///
/// **The convention for an entry that is neither, stated here because the code
/// below does not spell it out: it is classified `1` (file).** The check is
/// `is_dir()`, with everything else that exists falling to the `else` arm, so
/// a FIFO, Unix domain socket, or device node -- a filesystem entry that is
/// genuinely neither a plain file nor a directory -- is `1`, not some third
/// code. This is a stated convention, not a measurement: nothing in this
/// codebase constructs such an entry to observe it against, and on Windows
/// the class is structurally unreachable through this function's `metadata`
/// call. `tests/runtime/fs_read_dir.nova`'s fixture, the one test that drives
/// this function, contains only a plain file and a subdirectory -- it pins
/// the two-way split, and says nothing about the third case, which is why
/// this paragraph exists instead of a test.
///
/// # Safety
/// `path` must point to a live `NovaStr`.
pub unsafe extern "C"