C API reference¶
libfsspec is the shared library that contains the process-wide filesystem registry and
the built-in backends. Its interface is fsspec.h. The fsspec_sys crate declares the
same interface for Rust.
Files¶
Item |
Wheel location |
|---|---|
Header |
|
Library |
|
Link name |
|
Symbols |
every exported function and type starts with |
Source |
|
fsspec_rs reports these paths at runtime:
Function |
Returns |
|---|---|
|
the package directory |
|
the directory containing |
|
a list with the directory containing the library |
|
|
The extension module adds two functions:
Function |
Returns |
|---|---|
|
|
|
the protocols registered in the registry the extension uses, sorted |
ABI version¶
FSSPEC_ABI_VERSION is the version the header describes; fsspec_abi_version() returns
the version the loaded library was built with. Both are 1. Every vtable and factory
struct starts with struct_size and abi_version. Registration fails with
FSSPEC_INVALID_ARGUMENT when abi_version differs from the library’s, or when
struct_size is smaller than those two fields or larger than 64 KiB. A struct shorter
than the library’s is accepted; the missing trailing fields are treated as null.
Status codes¶
Most fallible functions return fsspec_status, a 32-bit enum:
Code |
Value |
Rust |
|---|---|---|
|
0 |
|
|
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
Function |
Description |
|---|---|
|
Message for the last failure on the calling thread, or null. Valid until the next failure on that thread. |
|
Sets the thread’s message. Foreign backends call it before returning a failing status. |
|
Clears the thread’s message. |
Panics inside libfsspec are caught at the boundary and returned as FSSPEC_OTHER.
Strings and memory¶
Arguments are UTF-8 pointer and length pairs and need no NUL terminator. Values that
libfsspec returns are owned by the caller and freed with the matching function:
Type |
Fields |
Free with |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
created_ns and modified_ns are nanoseconds since the Unix epoch, or -1 when
unknown. file_type is FSSPEC_FILE_TYPE_FILE, FSSPEC_FILE_TYPE_DIRECTORY, or
FSSPEC_FILE_TYPE_OTHER. extra contains backend-specific fields as alternating key and
value strings.
All of these buffers use the platform allocator: malloc on Unix and
HeapAlloc(GetProcessHeap(), ...) on Windows. Foreign backends allocate the values
they return through vtable callbacks the same way, and libfsspec frees them.
Options¶
fsspec_options is a string-to-string map.
Function |
Description |
|---|---|
|
Creates an empty map. |
|
Sets a key, replacing an earlier value. |
|
Alternating key and value strings, sorted by key. |
|
Frees the map. Null is ignored. |
A null fsspec_options * argument means no options.
Registry¶
Function |
Description |
|---|---|
|
Resolves a URL through the registry. |
|
Registers a factory, replacing an earlier one and dropping its cached instances. The factory struct is copied. |
|
Registered protocols, sorted. |
|
Installs the factory used for protocols nothing registered; null clears it. It is given the whole URL. |
URL resolution, caching, and the built-in protocols (file, local, memory, s3) and their
options are the same as the Rust registry; see
“Filesystem registry” in the Rust reference.
fsspec_fs_factory:
Field |
Description |
|---|---|
|
|
|
|
|
Passed to every callback. |
|
Required. Builds a filesystem for a path and options; returns it in |
|
Optional. Returns the part of the path that needs its own instance, such as a bucket. |
|
Optional. Called with |
Filesystems¶
fsspec_fs * is a reference-counted handle.
Function |
Description |
|---|---|
|
Another handle to the same filesystem. |
|
Frees a handle; the filesystem is dropped with its last handle. |
|
Protocol names of the filesystem. |
|
Root marker and path separator. |
|
The path without its protocol prefix, as the backend normalises it; an empty result is the root marker. |
|
The path with the backend’s protocol prefix. |
|
Lists a directory. With |
|
Metadata for one path. |
|
Whether a path exists. |
|
Reads a file, or |
|
Writes a file, replacing it. |
|
Deletes one file. |
|
Copies one file within the filesystem. |
|
Creates a directory. |
|
Removes an empty directory. |
|
Opens a file with mode |
|
As |
Object I/O and conditions¶
fsspec_fs_read(fs, path, path_len, options, out) returns bytes and their
validator in fsspec_read_result. fsspec_fs_write(fs, path, path_len, bytes, bytes_len, options, out) returns the committed object’s validator in
fsspec_write_result. Free successful outputs with fsspec_read_result_free
and fsspec_write_result_free. On error, output storage is unchanged and must
not be freed as a result.
These two functions return fsspec_operation_status, an int32_t. Values 0–9
retain the meanings above. status & FSSPEC_ERROR_KIND_MASK extracts the category:
FSSPEC_CONFLICT (10), FSSPEC_GAP (11), FSSPEC_UNAVAILABLE (12),
FSSPEC_TIMEOUT (13), FSSPEC_CORRUPT (14), FSSPEC_CANCELLED (15), and
FSSPEC_UNKNOWN_OUTCOME (16) extend the legacy categories. A nonzero typed status
may include FSSPEC_RETRY_SAFE; this bit means repeating the operation is safe.
Unknown outcomes are never retry-safe. Zero still means success. Rust foreign
adapters preserve category and retry metadata in both directions; old callbacks
and legacy fsspec_status functions retain their existing contract.
Existing functions and callbacks continue to return the original fsspec_status
enum. Do not return conflict through a legacy callback.
Read and write option structs begin with struct_size; initialize it to the
struct’s sizeof. Null options mean defaults. Read options include optional
start and end pointers. Both include a condition pointer, with null meaning
unconditional I/O. A condition has a kind and a borrowed validator pointer:
Kind |
Validator |
Meaning |
|---|---|---|
|
Required, both scope and value strings |
Operate only on the matching object. |
|
Must be null |
Create only if absent; invalid for reads. |
Input pointers remain borrowed for the duration of the call. Result validators own both strings; both null means unavailable. Copy or retain the full validator when using it in a later request. Unknown condition kinds, short option structs, null output pointers and null byte pointers with nonzero lengths are invalid arguments. Validation occurs before writes.
fsspec_fs_io_capabilities(fs, out) reports read_match, write_match and
write_missing. The filesystem vtable appends read, write and
io_capabilities callbacks. Old shorter vtables remain valid: missing read/write
callbacks use legacy I/O only for unconditional requests and reject conditions;
a missing capability callback reports all flags false. Clients using the new
symbols require a library that exports them, even though the ABI version remains 1.
Backend support and consistency guarantees match the Rust object I/O contract.
Native S3 object reads¶
fsspec_s3_open(bucket, bucket_len, options, out_fs, out_objects) constructs the
built-in S3 backend and returns two owned handles sharing one client and runtime:
a normal fsspec_fs and an opaque fsspec_object_store. Options use the registered
S3 backend’s names and validation. This constructor bypasses registry lookup,
protocol overrides and instance caching. Both output pointers must be nonnull
and distinct. Failure leaves both outputs unchanged.
The object handle can be retained with fsspec_object_store_retain and released
with fsspec_object_store_release; retain on null returns null and release on null
is ignored. Each retained handle has its own release obligation. Filesystem and
object handles may be released independently. Calls can run concurrently while
their handles remain alive. These handles currently originate only from the
built-in S3 constructor; no foreign object-store vtable is exposed.
Function |
Result |
Free with |
|---|---|---|
|
|
|
|
|
|
Both reads return fsspec_operation_status and preserve structured error and
retry metadata. Failure leaves the output unchanged. Keys are canonical nonempty
bucket-relative paths, without URL or bucket stripping, percent decoding or the
filesystem’s extra key escaping. Leading/trailing slashes,
empty or dot segments, backslashes and control characters are invalid. HEAD never
lists directories. head names its result with the supplied key. Modification
times outside the nonnegative signed 64-bit nanosecond representation use the
existing modified_ns = -1 sentinel.
Range reads reuse fsspec_byte_range, but require both bounds and
0 <= start < end within signed 64-bit limits. Starts at or past EOF fail; ends
past EOF are clipped. Empty arrays perform no I/O. Requests use the built-in S3
coalescing and concurrency limits and verify an ETag across HEAD and all GETs.
A missing ETag is unsupported. The complete output is retained in memory.
These are additive symbols: existing vtables and ABI version 1 are unchanged. Clients using these functions require a library exporting them; checking ABI version 1 alone does not establish their availability.
Range reads¶
fsspec_fs_read_ranges(fs, path, path_len, ranges, ranges_len, options, out) returns
fsspec_operation_status. Its input is a borrowed array of fsspec_byte_range:
start and end point to signed offsets, or are null for unbounded endpoints.
The array may be null only when its length is zero. Input pointers remain valid
for the duration of the call.
fsspec_range_read_options starts with struct_size, initialized to its sizeof,
followed by condition, max_gap, max_request_size and max_concurrency.
Null options use defaults of 65,536 bytes, 8,388,608 bytes and eight requests.
Request size and concurrency must be positive. Conditions use the same representation
as single-object reads.
Successful output is fsspec_range_read_result: an owned data array of
fsspec_bytes, its len, and a shared validator. Call
fsspec_range_read_result_free once to free the array, its buffers and validator.
On failure output storage is unchanged. Null output pointers, invalid input arrays
and short option structs are rejected before backend calls.
The filesystem vtable appends an optional read_ranges callback. Older shorter
vtables retain coalesced sequential reads through their legacy callbacks and reject
conditions. Native S3 retains concurrent pinned reads through both ABI directions.
Existing status values, structs and callbacks retain their layouts. Clients using
the new symbols require an updated library.
Range ordering, consistency and request limits follow the Rust range-read contract.
Files¶
fsspec_file * is an open file, closed with fsspec_file_close.
Function |
Description |
|---|---|
|
Reads up to |
|
Writes bytes; |
|
|
|
Current offset. |
|
Flushes buffered writes. |
|
Size, or |
|
Metadata for the open file. |
|
Commits or discards a transactional write. |
|
Flushes, commits, and frees the handle. After commit or discard, it only frees. Failures discard pending writes before freeing. Null is ignored. |
Async operations and dispatch¶
The async I/O contract documents operation/producer handles, managed
and foreign event-loop dispatch, owned results/errors, cancellation, and deadlines.
fsspec.h also exports read-only async filesystem/file vtables, shared budget
contexts, and close operations that wait for cleanup. Native S3 streaming remains
proposed; its draft constructor is not exported.
Foreign backends¶
fsspec_fs_from_vtable(vtable, data) wraps an implementation written outside
libfsspec as an fsspec_fs *, and fsspec_file_from_vtable(vtable, data) does the
same for an open file. Both copy the vtable, pass data to every callback, and return
null with the error message set on failure.
fsspec_fs_vtable:
Field |
Description |
|---|---|
|
As for factories. |
|
NUL-terminated, comma-separated protocol names, such as |
|
NUL-terminated strings; null uses the defaults. |
|
The |
|
Called with |
|
Optional, after |
fsspec_file_vtable has read, write, seek, flush, size, info, commit,
discard, and release. A null read, write, seek, or info returns
FSSPEC_NOT_SUPPORTED; a null size reports -1; a null flush, commit, or
discard succeeds without doing anything. release is called on close.
Rust bindings¶
The fsspec_sys crate declares the C functions without a #[link] attribute; the
build links libfsspec (hatch-rs links) or compiles fsspec_capi in. It contains no
registry state.
Item |
Description |
|---|---|
|
Resolves a URL through |
|
Registers a |
|
Installs or clears the factory for protocols nothing registered. |
|
Routes |
|
Registered protocols, sorted. |
|
ABI version of the loaded library. |
|
|
|
Wrap Rust implementations as |
|
Conversions between |
|
Raw declarations and |