/* scorpiox-scorpioplayer-nfs-v3-file-server — the read-only NFS v3 server (spnfss_). * * SCORPIO PLAYER 2027 row 36. Pure C99, zero external deps (vendored yyjson only). * See SPEC.md for every decision (D1..Dn) referenced below. * * A process can run ONE server (fleet style). Exports are added before or after * start; removing an export leaves open connections serving their handles until * they close. All mutating NFS v3 procedures answer NFS3ERR_ROFS (D3). */ #ifndef SPNFSS_H #define SPNFSS_H #ifdef _WIN32 # ifdef SPNFSS_BUILD # define SPNFSS_API __declspec(dllexport) # else # define SPNFSS_API __declspec(dllimport) # endif #else # define SPNFSS_API __attribute__((visibility("default"))) #endif #ifdef __cplusplus extern "C" { #endif #define SPNFSS_VERSION "1.0.0" #define SPNFSS_OK 0 #define SPNFSS_E_ARG (-1) /* bad argument */ #define SPNFSS_E_STATE (-2) /* wrong lifecycle state (already running etc.) */ #define SPNFSS_E_NET (-3) /* socket()/bind()/listen() failed */ #define SPNFSS_E_NOENT (-4) /* local path does not exist / not a file or folder */ #define SPNFSS_E_NOMEM (-5) #define SPNFSS_E_LIMIT (-6) /* a bounded limit was exceeded */ #define SPNFSS_E_EXISTS (-7) /* export path already added */ #define SPNFSS_E_THREAD (-8) /* thread start failed */ /* ---- lifecycle ---- */ SPNFSS_API const char *spnfss_version(void); /* keys: idle_timeout_ms (1000..3600000, default 120000), read_timeout_ms (default 30000), * max_connections (1..1024, default 64), nfs_port (0..65535, default 2049), mount_port * (default 20048), portmap_port (0 = off, default 0), secret (handle MAC key, printed * once; NULL resets). NULL value = reset to default. */ SPNFSS_API int spnfss_config(const char *key, const char *value); /* bind_ip: an IPv4 literal of ONE interface (0.0.0.0 refused, D8). nfs_port/mount_port * 0 = the configured defaults, portmap_port 0 = the portmapper OFF (D2). */ SPNFSS_API int spnfss_start(const char *bind_ip, int nfs_port, int mount_port, int portmap_port); SPNFSS_API void spnfss_stop(void); SPNFSS_API int spnfss_is_running(void); SPNFSS_API int spnfss_nfs_port(void); SPNFSS_API int spnfss_mount_port(void); SPNFSS_API int spnfss_portmap_port(void); /* ---- exports (roots) ---- * export_path an absolute virtual path that starts with '/', e.g. "/movies". No '..' * component, no '\' (D9). A single trailing '/' is stripped. * local_path a folder OR a single file (a file is served as a one-entry directory, D6). * allow_cidrs comma-separated CIDRs ("198.51.100.0/24,127.0.0.0/8") or NULL/"" = loopback * only (D10). Applied per export at MNT time. */ SPNFSS_API int spnfss_add_export(const char *export_path, const char *local_path, const char *allow_cidrs); SPNFSS_API int spnfss_remove_export(const char *export_path); SPNFSS_API int spnfss_export_count(void); SPNFSS_API const char *spnfss_export_json(int i); /* {"path","local","allow_cidrs","is_file"} */ SPNFSS_API int spnfss_client_count(void); SPNFSS_API const char *spnfss_stats_json(void); /* counters, see SPEC §11 */ /* ---- pure / socket-free ---- */ /* the fh for (export_path, relpath): 0 ok, <0 refused. out holds up to outlen bytes. */ SPNFSS_API int spnfss_fh_for(const char *export_path, const char *relpath, unsigned char *out, int outlen); /* 0 ok iff the fh decodes against the live table AND its MAC binds the root path "" * (a 32-byte fh carries no path, D5; relpath_out is set to "" on OK), <0 E_NOENT for an * unknown / stale / non-root fh. */ SPNFSS_API int spnfss_fh_resolve(const unsigned char *fh, int len, char *relpath_out, int rlen); /* a client address (network byte order) against a CIDR list: *out_allowed 1 = allow */ SPNFSS_API int spnfss_cidr_allows(const char *allow_cidrs, unsigned int client_be, int *out_allowed); /* the procs this server answers, and which are read-only; JSON arrays */ SPNFSS_API const char *spnfss_proc_table_json(void); SPNFSS_API int spnfss_proc_is_write(int nfs_proc); SPNFSS_API const char *spnfss_nfsstat_name(int st); SPNFSS_API int spnfss_last_code(void); SPNFSS_API const char *spnfss_last_error(void); #ifdef __cplusplus } #endif #endif /* SPNFSS_H */