/* * spnfsc.h — scorpiox-scorpioplayer-nfs-v3-file-client * * SCORPIO PLAYER 2027: a pure C99, zero-dependency, READ-ONLY NFS v3 client * (ONC RPC v2 + XDR + portmapper v2 + MOUNT v3 + NFS v3), written from * RFC 1813 / 5531 / 4506 / 1833. It replaces the vendored C# NFSLibrary * (tplayer bosxixi.Toolkit20/NFSLibrary). See SPEC.md for every decision. * * Read-only by construction: the procedure table has no WRITE, CREATE, * REMOVE, RENAME, SETATTR, MKDIR, RMDIR, LINK, SYMLINK, MKNOD or COMMIT. * spnfsc_proc_table_json() lists what exists; the tests assert it. * * Threading: one global session (fleet style). Not thread-safe; call from * one thread. Strings returned by spnfsc_* are owned by the library and are * valid until the next call that changes the same state. Copy them. */ #ifndef SPNFSC_H #define SPNFSC_H #include "scorpiox-io.h" #ifdef __cplusplus extern "C" { #endif #if defined(SPNFSC_STATIC) # define SPNFSC_API #elif defined(_WIN32) # if defined(SPNFSC_BUILD) # define SPNFSC_API __declspec(dllexport) # else # define SPNFSC_API __declspec(dllimport) # endif #else # define SPNFSC_API __attribute__((visibility("default"))) #endif #define SPNFSC_VERSION "1.0.0" /* ---- error taxonomy (SPEC §9). Values are frozen. ---- */ #define SPNFSC_OK 0 #define SPNFSC_E_NETWORK -1 /* refused, reset, timeout, host not found */ #define SPNFSC_E_PROTOCOL -2 /* malformed / truncated / mismatched reply */ #define SPNFSC_E_AUTH -3 /* RPC AUTH_ERROR (bad cred, too weak) */ #define SPNFSC_E_ACCESS -4 /* NFS3ERR_ACCES/PERM, MNT3ERR_ACCES/PERM */ #define SPNFSC_E_NOENT -5 /* no such file, directory or export */ #define SPNFSC_E_STALE -6 /* NFS3ERR_STALE (after one re-lookup) */ #define SPNFSC_E_NOTDIR -7 #define SPNFSC_E_ISDIR -8 #define SPNFSC_E_UNSUPPORTED -9 /* NFS version / procedure not supported */ #define SPNFSC_E_INVALID_ARG -10 #define SPNFSC_E_NOT_CONNECTED -11 /* no connect / no mount / bad handle */ #define SPNFSC_E_PRIVILEGE -12 /* server wants a source port < 1024 */ #define SPNFSC_E_LIMIT -13 /* a bounded decode limit was exceeded */ #define SPNFSC_E_OOM -14 #define SPNFSC_E_SERVER -15 /* NFS3ERR_IO / SERVERFAULT / JUKEBOX exhausted */ #define SPNFSC_E_NOPROG -16 /* portmapper: MOUNT or NFS v3 not registered */ #define SPNFSC_E_UNSAFE_PATH -17 /* '..' or a control byte in a caller path */ #define SPNFSC_E_CHARSET -18 /* unknown charset name */ /* ---- session ---- */ SPNFSC_API int spnfsc_connect(const char *host, int uid, int gid, int timeout_ms, int secure_port); SPNFSC_API int spnfsc_connect_json(const char *runtime_settings_json); /* legacy RuntimeSettings keys */ SPNFSC_API int spnfsc_set_charset(const char *charset); /* "utf-8" (default) "gbk" "big5" "ascii" "latin1" or a codepage */ SPNFSC_API int spnfsc_set_ports(int mount_port, int nfs_port); /* 0 = ask the portmapper (default) */ SPNFSC_API int spnfsc_set_rsize(int bytes); /* 0 = auto from FSINFO (default) */ SPNFSC_API int spnfsc_set_pipeline(int depth); /* 1..32 outstanding READs, default 8 */ SPNFSC_API int spnfsc_set_hidden_mode(int mode); /* 0 show all, 1 legacy (default), 2 hide files too */ SPNFSC_API int spnfsc_set_cache(int on); /* UseCache: LOOKUP handle cache */ SPNFSC_API void spnfsc_disconnect(void); /* UMNT + close */ SPNFSC_API int spnfsc_is_connected(void); /* ---- MOUNT ---- */ SPNFSC_API int spnfsc_exports(void); /* count, <0 error */ SPNFSC_API const char *spnfsc_export_json(int i); /* {"path":..,"groups":[..]} */ SPNFSC_API int spnfsc_mount(const char *export_path); SPNFSC_API const char *spnfsc_mounted(void); /* "" if none */ /* ---- browse ---- */ SPNFSC_API int spnfsc_list(const char *relpath); /* count after the hidden filter, <0 error */ SPNFSC_API const char *spnfsc_item_json(int i); /* name path folder kind size mtime_ms fileid hidden mode */ SPNFSC_API const char *spnfsc_list_json(void); /* {"path":..,"items":[..]} (#26 shape) */ SPNFSC_API int spnfsc_list_hidden_count(void); /* entries removed by the hidden filter */ SPNFSC_API int spnfsc_list_pages(void); /* READDIR(PLUS) round trips of the last list */ SPNFSC_API int spnfsc_list_used_plus(void); /* 1 READDIRPLUS, 0 fell back to READDIR */ SPNFSC_API const char *spnfsc_stat_json(const char *relpath); SPNFSC_API const char *spnfsc_readlink(const char *relpath);/* display only; never followed */ SPNFSC_API const char *spnfsc_fsinfo_json(void); /* rtmax rtpref ... rsize legacy_block */ /* ---- read ---- */ SPNFSC_API int spnfsc_open(const char *relpath); /* handle >= 1, <0 error */ SPNFSC_API long long spnfsc_size(int h); /* <0 error */ SPNFSC_API int spnfsc_read_at(int h, long long off, void *buf, int count); /* EOF-capped, bytes or <0 */ SPNFSC_API void spnfsc_close(int h); SPNFSC_API long long spnfsc_rpc_count(void); /* RPCs sent since connect */ /* ---- pure, socket-free ---- */ SPNFSC_API int spnfsc_xdr_selftest(void); /* 0 = pass, else the failing case number */ SPNFSC_API const char *spnfsc_decode_filename(const char *bytes, int len, const char *charset); SPNFSC_API int spnfsc_is_hidden_name(const char *name); /* legacy $ . @ rule */ SPNFSC_API const char *spnfsc_proc_table_json(void); /* every procedure the client can send */ SPNFSC_API int spnfsc_proc_is_write(int program, int proc); /* 1 if a write proc (never in table) */ SPNFSC_API int spnfsc_legacy_block_size(int rtpref, int wtpref); /* the C# GetBlockSize formula */ SPNFSC_API const char *spnfsc_strerror(int code); SPNFSC_API const char *spnfsc_last_error(void); SPNFSC_API int spnfsc_last_code(void); SPNFSC_API const char *spnfsc_version(void); /* ---- transports ---- */ SPNFSC_API int spnfsc_use_sockets(void); /* default: real TCP/UDP */ SPNFSC_API int spnfsc_use_io(const scorpiox_io *io); /* RPC tunnelled through scorpiox_io (SPEC D3) */ SPNFSC_API const scorpiox_io *spnfsc_io_socket(void); /* scorpiox_io face of the socket transport */ /* the in-memory fake server (tests, console --test). tree_json: SPEC §11 */ SPNFSC_API int spnfsc_use_fake(const char *tree_json); SPNFSC_API const scorpiox_io *spnfsc_io_fake(void); /* scorpiox_io face of the fake */ SPNFSC_API int spnfsc_fake_set_fault(const char *what, int value); /* SPEC §11 */ SPNFSC_API long long spnfsc_fake_calls(int program, int proc); /* ---- adapters ---- */ SPNFSC_API const void *spnfsc_spffa_backend(void); /* const spffa_backend * (#26), id "nfs" */ #ifdef __cplusplus } #endif #endif /* SPNFSC_H */