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
// SPDX-License-Identifier: Apache-2.0
//! Single source of truth for the FSKit C ABI surface.
//!
//! Every callback typedef, opaque handle, and extern function in the
//! Swift-side bridging header (`swift/HeddleFSKit/HeddleFSKit-Bridging.h`)
//! is derived from the declarations in *this* file. The header is
//! generated by `cbindgen` at build time (see `build.rs`). The Swift
//! source then `#imports` that generated header — so any change here
//! propagates to Swift on the next `cargo build --features fskit`,
//! and a drift between the Rust ABI and the Swift call sites becomes
//! a `swiftc` error rather than runtime UB.
//!
//! Conventions for adding to this surface:
//! * Use `pub type` aliases for callback function pointer types.
//! Wrap them in `Option<unsafe extern "C" fn(...) -> i32>` so the
//! Rust caller can pass `None` and the C side sees `NULL`.
//! * Use `i32` (not `c_int`) for return codes so cbindgen emits
//! `int32_t` rather than `int`. Errno-style: 0 success, libc errno
//! on failure.
//! * Use `u64`/`u32`/`u8` for sized integers (cbindgen emits
//! `uint64_t`/`uint32_t`/`uint8_t`).
//! * Keep the `unsafe extern "C"` block at the bottom — cbindgen
//! emits prototypes for these in declaration order.
use ;
use warn;
// ----------------------------------------------------------------
// Opaque handle
// ----------------------------------------------------------------
/// Opaque pointer to the Swift-side `HeddleFSKitSession`. Treat as
/// untyped on the Rust side; the Swift session walks behind it.
pub type HeddleFSKitSessionHandle = *mut c_void;
// ----------------------------------------------------------------
// Callback typedefs — invoked by Swift, implemented by Rust.
// ----------------------------------------------------------------
/// Resolve `name` inside `parent_inode`. Writes the child's identity
/// into the out-pointers when found; returns 0 on success, `ENOENT`
/// when missing, or another libc errno on failure.
pub type HeddleLookupCallback = ;
/// Fetch attributes for `inode`. Mode includes type bits (S_IFREG /
/// S_IFDIR / etc.). `out_mtime_sec` receives the modification time
/// as seconds-since-UNIX-epoch — zero is a valid value (means
/// "epoch"), so callers should treat the out-pointer as the only
/// signal of success.
pub type HeddleGetattrCallback = ;
/// Read `[offset, offset+buffer_capacity)` from `inode` into `buffer`.
/// Writes actual bytes-read into `out_bytes_read`.
pub type HeddleReadCallback = ;
/// Write `[data, data+data_len)` into `inode` at `offset`. Writes
/// actual bytes-written into `out_bytes_written`.
pub type HeddleWriteCallback = ;
/// Per-entry callback invoked from inside [`HeddleEnumerateCallback`].
/// Return 0 to keep iterating, non-zero to stop early (typically when
/// the FSKit reply buffer is full). `mtime_sec` is the modification
/// time of the entry as seconds-since-UNIX-epoch; for content-addressed
/// mounts every entry currently shares the mount's bootstrap time.
pub type HeddleEnumerateEmit = ;
/// Enumerate the children of `dir_inode`. The Rust side calls
/// `emit(emit_user_data, ...)` once per entry.
pub type HeddleEnumerateCallback = ;
/// Flush any buffered writes for `inode`. Heddle's mount is read-only
/// today so this currently always returns 0.
pub type HeddleFlushCallback =
;
/// Release the `user_data` payload. Called exactly once when the
/// Swift session is freed; reclaims the boxed `PlatformShell`.
pub type HeddleDropCallback = ;
// ----------------------------------------------------------------
// Functions exported by the Swift side, called by Rust.
//
// These are imports for Rust, but cbindgen still emits prototypes
// for them in the generated C header (which is what Swift consumes).
// ----------------------------------------------------------------
unsafe extern "C"
// ----------------------------------------------------------------
// High-level entry point used by the System Extension.
//
// `heddle_fskit_open_thread` is the C ABI Swift-extension code calls
// to bootstrap a mount session: it parses the repo path + thread
// name into Rust types, opens the repository, builds a
// `ContentAddressedMount`, and hands back the same session handle
// shape `FSKitShell::new(mount)` produces in-process. The Swift
// caller dispatches per-syscall through the callbacks held on the
// returned session, and releases the handle via
// [`heddle_fskit_session_free`].
//
// Implementation lives in `super::open_thread` so it has visibility
// into the trampolines + `FSKitShell::into_handle`. This shim is
// only here so cbindgen (which only scans this file) emits the
// prototype in the generated bridging header.
// ----------------------------------------------------------------
/// Open a content-addressed mount for `thread_id_utf8` rooted at
/// `repo_path_utf8`. Returns a session handle suitable for the
/// FSKit `FSVolume` to dispatch through, or NULL if any step
/// fails (bad UTF-8, missing repo, unknown thread).
///
/// The caller owns the returned handle and must release it with
/// [`heddle_fskit_session_free`] when the volume is torn down.
///
/// # Safety
/// Both arguments must be NUL-terminated UTF-8 C strings owned by
/// the caller for the duration of the call.
pub unsafe extern "C"