Initial RetroNFS95 Win9x VxD prototype

This commit is contained in:
2026-10-12 12:59:15 +00:00
commit 908ece2cc8
51 changed files with 3266 additions and 0 deletions

24
include/compat.hpp Normal file
View File

@@ -0,0 +1,24 @@
#ifndef RETRONFS95_COMPAT_HPP
#define RETRONFS95_COMPAT_HPP
#include <string>
#include <vector>
#include <stdexcept>
#include <stdint.h>
namespace retronfs {
typedef unsigned char byte;
typedef std::vector<byte> Bytes;
class Error : public std::runtime_error {
public:
explicit Error(const std::string& msg) : std::runtime_error(msg) {}
};
std::string format_error(const std::string& what, int code);
}
#endif

17
include/mount.hpp Normal file
View File

@@ -0,0 +1,17 @@
#ifndef RETRONFS95_MOUNT_HPP
#define RETRONFS95_MOUNT_HPP
#include "rpc.hpp"
namespace retronfs {
struct FileHandle {
Bytes data;
};
FileHandle mount_export(const std::string& host, const std::string& export_path, const RpcIdentity& identity);
}
#endif

33
include/nfs.hpp Normal file
View File

@@ -0,0 +1,33 @@
#ifndef RETRONFS95_NFS_HPP
#define RETRONFS95_NFS_HPP
#include "mount.hpp"
namespace retronfs {
struct DirEntry {
uint64_t fileid;
std::string name;
uint64_t cookie;
};
class NfsClient {
public:
NfsClient(const std::string& host, unsigned short port, const RpcIdentity& identity);
FileHandle lookup(const FileHandle& dir, const std::string& name);
std::vector<DirEntry> readdir(const FileHandle& dir);
Bytes read(const FileHandle& file, uint64_t offset, uint32_t count, bool* eof);
Bytes read_all(const FileHandle& file);
private:
RpcClient rpc_;
RpcIdentity identity_;
};
FileHandle resolve_path(NfsClient& nfs, const FileHandle& root, const std::string& path);
}
#endif

13
include/path.hpp Normal file
View File

@@ -0,0 +1,13 @@
#ifndef RETRONFS95_PATH_HPP
#define RETRONFS95_PATH_HPP
#include "compat.hpp"
namespace retronfs {
std::vector<std::string> split_nfs_path(const std::string& path);
}
#endif

13
include/portmap.hpp Normal file
View File

@@ -0,0 +1,13 @@
#ifndef RETRONFS95_PORTMAP_HPP
#define RETRONFS95_PORTMAP_HPP
#include "rpc.hpp"
namespace retronfs {
unsigned short portmap_get_tcp_port(const std::string& host, uint32_t program, uint32_t version);
}
#endif

51
include/retro_ioctl.h Normal file
View File

@@ -0,0 +1,51 @@
#ifndef RETRO_IOCTL_H
#define RETRO_IOCTL_H
#define RETRO_IOCTL_MAP 0x800
#define RETRO_IOCTL_UNMAP 0x801
#define RETRO_IOCTL_QUERY 0x802
#define RETRO_IOCTL_ENUM 0x803
#define RETRO_IOCTL_STATUS 0x804
#define RETRO_MAX_MAPPINGS 26
#define RETRO_STATUS_OK 0
#define RETRO_STATUS_BAD_ARGUMENT 1
#define RETRO_STATUS_NO_MAPPING 2
#define RETRO_STATUS_TABLE_FULL 3
#define RETRO_STATUS_BAD_REMOTE 4
#define RETRO_DRIVER_FLAG_IFS_STUB 0x00000001UL
#define RETRO_DRIVER_FLAG_IFS_REGISTERED 0x00000002UL
typedef struct RETRO_MAP_REQUEST {
char local[64];
char remote[448];
} RETRO_MAP_REQUEST;
typedef struct RETRO_QUERY_REQUEST {
char local[64];
} RETRO_QUERY_REQUEST;
typedef struct RETRO_ENUM_REQUEST {
unsigned long index;
} RETRO_ENUM_REQUEST;
typedef struct RETRO_MAPPING_INFO {
unsigned long status;
unsigned long index;
char local[64];
char remote[448];
char server[128];
char export_path[256];
unsigned long flags;
} RETRO_MAPPING_INFO;
typedef struct RETRO_STATUS_INFO {
unsigned long status;
unsigned long mapping_count;
unsigned long max_mappings;
unsigned long driver_flags;
} RETRO_STATUS_INFO;
#endif

43
include/rpc.hpp Normal file
View File

@@ -0,0 +1,43 @@
#ifndef RETRONFS95_RPC_HPP
#define RETRONFS95_RPC_HPP
#include "socket.hpp"
#include "xdr.hpp"
namespace retronfs {
enum RpcAuthFlavor {
AUTH_NONE = 0,
AUTH_SYS = 1
};
struct RpcIdentity {
std::string machine;
uint32_t uid;
uint32_t gid;
std::vector<uint32_t> groups;
RpcIdentity() : machine("retronfs95"), uid(65534), gid(65534) {}
};
class RpcClient {
public:
RpcClient(const std::string& host, unsigned short port, uint32_t program, uint32_t version);
Bytes call(uint32_t procedure, const Bytes& args, const RpcIdentity& identity);
private:
std::string host_;
unsigned short port_;
uint32_t program_;
uint32_t version_;
uint32_t xid_;
Bytes make_call(uint32_t procedure, const Bytes& args, const RpcIdentity& identity, uint32_t xid);
Bytes read_record(TcpSocket& sock);
};
}
#endif

38
include/socket.hpp Normal file
View File

@@ -0,0 +1,38 @@
#ifndef RETRONFS95_SOCKET_HPP
#define RETRONFS95_SOCKET_HPP
#include "compat.hpp"
namespace retronfs {
class SocketSystem {
public:
SocketSystem();
~SocketSystem();
};
class TcpSocket {
public:
TcpSocket();
~TcpSocket();
void connect_to(const std::string& host, unsigned short port, unsigned timeout_ms);
void send_all(const Bytes& data);
Bytes recv_exact(unsigned count);
void close();
private:
TcpSocket(const TcpSocket&);
TcpSocket& operator=(const TcpSocket&);
#ifdef _WIN32
unsigned int fd_;
#else
int fd_;
#endif
};
}
#endif

44
include/xdr.hpp Normal file
View File

@@ -0,0 +1,44 @@
#ifndef RETRONFS95_XDR_HPP
#define RETRONFS95_XDR_HPP
#include "compat.hpp"
namespace retronfs {
class XdrWriter {
public:
void u32(uint32_t v);
void u64(uint64_t v);
void opaque(const Bytes& data);
void fixed_opaque(const byte* data, unsigned len);
void str(const std::string& value);
const Bytes& data() const;
private:
Bytes out_;
void pad(unsigned len);
};
class XdrReader {
public:
explicit XdrReader(const Bytes& data);
uint32_t u32();
uint64_t u64();
Bytes opaque();
Bytes fixed_opaque(unsigned len);
std::string str();
bool eof() const;
unsigned remaining() const;
private:
const Bytes& in_;
unsigned pos_;
void require(unsigned n);
void skip_pad(unsigned len);
};
}
#endif