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

83
src/main.cpp Normal file
View File

@@ -0,0 +1,83 @@
#include "nfs.hpp"
#include "portmap.hpp"
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace retronfs;
static void usage() {
std::cerr
<< "RetroNFS95 v0.1\n"
<< "Usage:\n"
<< " retronfs95 ls <server> <export> <path>\n"
<< " retronfs95 get <server> <export> <remote-path> <local-file>\n"
<< "\n"
<< "Example:\n"
<< " retronfs95 ls 192.168.1.10 /srv/retro /\n"
<< " retronfs95 get 192.168.1.10 /srv/retro /README.TXT README.TXT\n";
}
static NfsClient make_client(const std::string& host, RpcIdentity& id) {
unsigned short nfs_port = portmap_get_tcp_port(host, 100003, 3);
return NfsClient(host, nfs_port, id);
}
int main(int argc, char** argv) {
try {
SocketSystem sockets;
if (argc < 5) {
usage();
return 2;
}
std::string cmd = argv[1];
std::string host = argv[2];
std::string export_path = argv[3];
std::string remote_path = argv[4];
RpcIdentity id;
id.uid = 65534;
id.gid = 65534;
FileHandle root = mount_export(host, export_path, id);
NfsClient nfs = make_client(host, id);
if (cmd == "ls") {
FileHandle dir = resolve_path(nfs, root, remote_path);
std::vector<DirEntry> entries = nfs.readdir(dir);
for (unsigned i = 0; i < entries.size(); ++i) {
std::cout << entries[i].name << "\n";
}
return 0;
}
if (cmd == "get") {
if (argc < 6) {
usage();
return 2;
}
FileHandle file = resolve_path(nfs, root, remote_path);
Bytes data = nfs.read_all(file);
std::ofstream out(argv[5], std::ios::binary);
if (!out) {
throw Error("could not open local output file");
}
if (!data.empty()) {
out.write((const char*)&data[0], (std::streamsize)data.size());
}
std::cout << "wrote " << data.size() << " bytes\n";
return 0;
}
usage();
return 2;
} catch (const std::exception& e) {
std::cerr << "error: " << e.what() << "\n";
return 1;
}
}