Initial RetroNFS95 Win9x VxD prototype
This commit is contained in:
13
.gitignore
vendored
Normal file
13
.gitignore
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
vxd/build/
|
||||||
|
|
||||||
|
mounter/*.exe
|
||||||
|
provider/*.DLL
|
||||||
|
provider/*.dll
|
||||||
|
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
*.err
|
||||||
|
|
||||||
|
test.err
|
||||||
43
Makefile.mingw
Normal file
43
Makefile.mingw
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
CXX = g++
|
||||||
|
WINDRES = windres
|
||||||
|
OUT = bin/retronfs95.exe
|
||||||
|
OBJS = obj/main.o obj/socket.o obj/xdr.o obj/rpc.o obj/portmap.o obj/mount.o obj/nfs.o obj/path.o
|
||||||
|
CXXFLAGS = -Os -Wall -Wextra -pedantic -std=c++98 -DWIN32_LEAN_AND_MEAN -Iinclude
|
||||||
|
LDFLAGS = -lws2_32
|
||||||
|
|
||||||
|
all: dirs $(OUT)
|
||||||
|
|
||||||
|
dirs:
|
||||||
|
@if not exist bin mkdir bin
|
||||||
|
@if not exist obj mkdir obj
|
||||||
|
|
||||||
|
$(OUT): $(OBJS)
|
||||||
|
$(CXX) -o $@ $(OBJS) $(LDFLAGS)
|
||||||
|
|
||||||
|
obj/main.o: src/main.cpp include/*.hpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c src/main.cpp -o $@
|
||||||
|
|
||||||
|
obj/socket.o: src/socket.cpp include/*.hpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c src/socket.cpp -o $@
|
||||||
|
|
||||||
|
obj/xdr.o: src/xdr.cpp include/*.hpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c src/xdr.cpp -o $@
|
||||||
|
|
||||||
|
obj/rpc.o: src/rpc.cpp include/*.hpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c src/rpc.cpp -o $@
|
||||||
|
|
||||||
|
obj/portmap.o: src/portmap.cpp include/*.hpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c src/portmap.cpp -o $@
|
||||||
|
|
||||||
|
obj/mount.o: src/mount.cpp include/*.hpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c src/mount.cpp -o $@
|
||||||
|
|
||||||
|
obj/nfs.o: src/nfs.cpp include/*.hpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c src/nfs.cpp -o $@
|
||||||
|
|
||||||
|
obj/path.o: src/path.cpp include/*.hpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c src/path.cpp -o $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-del /Q obj\*.o bin\*.exe 2>NUL
|
||||||
|
|
||||||
19
Makefile.posix
Normal file
19
Makefile.posix
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
CXX = g++
|
||||||
|
OUT = bin/retronfs95
|
||||||
|
OBJS = obj/main.o obj/socket.o obj/xdr.o obj/rpc.o obj/portmap.o obj/mount.o obj/nfs.o obj/path.o
|
||||||
|
CXXFLAGS = -O2 -Wall -Wextra -pedantic -std=c++98 -Iinclude
|
||||||
|
|
||||||
|
all: dirs $(OUT)
|
||||||
|
|
||||||
|
dirs:
|
||||||
|
mkdir -p bin obj
|
||||||
|
|
||||||
|
$(OUT): $(OBJS)
|
||||||
|
$(CXX) -o $@ $(OBJS)
|
||||||
|
|
||||||
|
obj/%.o: src/%.cpp include/*.hpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f obj/*.o bin/retronfs95
|
||||||
|
|
||||||
144
README.md
Normal file
144
README.md
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
# RetroNFS95
|
||||||
|
|
||||||
|
RetroNFS95 is a Windows 95/98 oriented NFSv3 client prototype written in
|
||||||
|
portable C++98. The first deliverable is a real user-mode NFS client core that
|
||||||
|
uses the operating system TCP/IP stack through Winsock instead of shipping a
|
||||||
|
separate IP stack.
|
||||||
|
|
||||||
|
This is intentional: Windows 95/98 already has a TCP/IP stack, and replacing it
|
||||||
|
would make the system less stable and much harder to secure. The project keeps
|
||||||
|
the NFS/RPC logic separate so a drive-mapping redirector can be added later.
|
||||||
|
|
||||||
|
## What Works In This Tree
|
||||||
|
|
||||||
|
- RPC over TCP with ONC record marking
|
||||||
|
- XDR encode/decode helpers
|
||||||
|
- Portmapper v2 `GETPORT`
|
||||||
|
- MOUNT v3 `MNT`
|
||||||
|
- NFS v3 `LOOKUP`, `READDIR`, and `READ`
|
||||||
|
- Command-line client:
|
||||||
|
- list an exported directory
|
||||||
|
- fetch a file from an export
|
||||||
|
- Win95/98 integration source tree:
|
||||||
|
- `provider/` Network Provider DLL entry points for MPR/WNet
|
||||||
|
- `mounter/` mapping manager application and startup remapper
|
||||||
|
- `vxd/` Windows 95/98 VxD control layer with map/query/enum/status IOCTLs
|
||||||
|
- `install/` registry/INF templates
|
||||||
|
- Build artifacts:
|
||||||
|
- `dist/RETROVXD.VXD` as an LE VxD 386 image for Windows 4.10
|
||||||
|
- `dist/RETRONP.DLL`
|
||||||
|
- `dist/RetroMap95.exe`
|
||||||
|
- `dist/retronfs95.exe`
|
||||||
|
|
||||||
|
## Target Platforms
|
||||||
|
|
||||||
|
- Windows 95 OSR2 / Windows 98 / Windows 98 SE with Microsoft TCP/IP installed
|
||||||
|
- Windows XP also builds as a normal Win32 console program
|
||||||
|
- Linux builds are useful for development tests only
|
||||||
|
|
||||||
|
## Non-Goals For Version 0
|
||||||
|
|
||||||
|
- A custom IP stack
|
||||||
|
- NFSv4/Kerberos
|
||||||
|
- A production-ready IFSMgr file system redirector
|
||||||
|
|
||||||
|
The project now has the real Win9x layers laid out. The VxD builds, owns the
|
||||||
|
drive mapping table, is reachable through `DeviceIoControl`, and has a
|
||||||
|
read-only `RetroIFS_Dispatch` scaffold plus build-selectable real IFSMgr
|
||||||
|
registration for open/read/write/close/find and disk-info routing. It still
|
||||||
|
needs live Win95/98 register/deregister validation and NFS handle binding
|
||||||
|
before it can mount a live drive letter for normal file I/O.
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
### Old MinGW / Win95-Friendly
|
||||||
|
|
||||||
|
Use a MinGW version that can still target old Win32 systems.
|
||||||
|
|
||||||
|
```bat
|
||||||
|
mingw32-make -f Makefile.mingw
|
||||||
|
```
|
||||||
|
|
||||||
|
Output:
|
||||||
|
|
||||||
|
```text
|
||||||
|
bin\retronfs95.exe
|
||||||
|
```
|
||||||
|
|
||||||
|
### Linux Development Build
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make -f Makefile.posix
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
List the root of an export:
|
||||||
|
|
||||||
|
```bat
|
||||||
|
retronfs95.exe ls 192.168.1.10 /srv/retro /
|
||||||
|
```
|
||||||
|
|
||||||
|
Fetch a file:
|
||||||
|
|
||||||
|
```bat
|
||||||
|
retronfs95.exe get 192.168.1.10 /srv/retro /README.TXT README.TXT
|
||||||
|
```
|
||||||
|
|
||||||
|
Paths are NFS paths inside the mounted export. Use `/` separators.
|
||||||
|
|
||||||
|
## Win95/98 Mapping Concept
|
||||||
|
|
||||||
|
The mapping path is intentionally similar to the SMB client:
|
||||||
|
|
||||||
|
```text
|
||||||
|
RetroMap95.exe /map R: \\RetroNFS\server\srv_retro
|
||||||
|
|
|
||||||
|
MPR/WNet -> RETRONP.DLL
|
||||||
|
|
|
||||||
|
DeviceIoControl -> RETROVXD.VXD
|
||||||
|
|
|
||||||
|
NFSv3 core -> Winsock TCP/IP
|
||||||
|
```
|
||||||
|
|
||||||
|
Persistent mappings are stored in:
|
||||||
|
|
||||||
|
```text
|
||||||
|
%WINDIR%\RETRO95\mappings.ini
|
||||||
|
```
|
||||||
|
|
||||||
|
and remapped at startup through:
|
||||||
|
|
||||||
|
```text
|
||||||
|
HKLM\Software\Microsoft\Windows\CurrentVersion\Run\RetroNFS95
|
||||||
|
```
|
||||||
|
|
||||||
|
Inspect the loaded VxD state:
|
||||||
|
|
||||||
|
```bat
|
||||||
|
RetroMap95.exe /status
|
||||||
|
RetroMap95.exe /status R:
|
||||||
|
```
|
||||||
|
|
||||||
|
## Security Architecture
|
||||||
|
|
||||||
|
For IT security, do not expose old NFS directly to the whole network. Use a
|
||||||
|
small gateway:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Win95/98 PC -> Retro gateway -> modern storage
|
||||||
|
NFSv3/TCP firewall/NAT SMB3/SFTP/ZFS/NAS/etc.
|
||||||
|
```
|
||||||
|
|
||||||
|
Recommended controls:
|
||||||
|
|
||||||
|
- allow only the legacy PC IP/MAC to reach NFS on the gateway
|
||||||
|
- export a dedicated low-privilege directory
|
||||||
|
- use read-only exports where possible
|
||||||
|
- keep NFSv3 confined to the legacy segment or host firewall rule
|
||||||
|
- synchronize with modern storage using a separate service account
|
||||||
|
|
||||||
|
## Roadmap To Drive Mapping
|
||||||
|
|
||||||
|
The next deliverable is a Windows 95/98 network provider and redirector layer.
|
||||||
|
See `docs/DRIVE_MAPPING.md`.
|
||||||
25
dist/RETRO95.INF
vendored
Normal file
25
dist/RETRO95.INF
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
[version]
|
||||||
|
signature="$CHICAGO$"
|
||||||
|
Class=Net
|
||||||
|
Provider=%Provider%
|
||||||
|
|
||||||
|
[DefaultInstall]
|
||||||
|
CopyFiles=Retro.Copy
|
||||||
|
AddReg=Retro.AddReg
|
||||||
|
|
||||||
|
[DestinationDirs]
|
||||||
|
Retro.Copy=11
|
||||||
|
|
||||||
|
[Retro.Copy]
|
||||||
|
RETRONP.DLL
|
||||||
|
RETROVXD.VXD
|
||||||
|
RetroMap95.exe
|
||||||
|
|
||||||
|
[Retro.AddReg]
|
||||||
|
HKLM,System\CurrentControlSet\Services\Retronfs95\NetworkProvider,Name,0,"RetroNFS95"
|
||||||
|
HKLM,System\CurrentControlSet\Services\Retronfs95\NetworkProvider,ProviderPath,0,"RETRONP.DLL"
|
||||||
|
HKLM,Software\Microsoft\Windows\CurrentVersion\Run,RetroNFS95,0,"C:\RETRO95\RetroMap95.exe /startup"
|
||||||
|
|
||||||
|
[Strings]
|
||||||
|
Provider="RetroNFS95"
|
||||||
|
|
||||||
BIN
dist/RETRONP.DLL
vendored
Executable file
BIN
dist/RETRONP.DLL
vendored
Executable file
Binary file not shown.
BIN
dist/RETROVXD.VXD
vendored
Executable file
BIN
dist/RETROVXD.VXD
vendored
Executable file
Binary file not shown.
BIN
dist/RetroMap95.exe
vendored
Executable file
BIN
dist/RetroMap95.exe
vendored
Executable file
Binary file not shown.
BIN
dist/RetroNFS95-win32-artifacts.zip
vendored
Normal file
BIN
dist/RetroNFS95-win32-artifacts.zip
vendored
Normal file
Binary file not shown.
6
dist/SHA256SUMS.txt
vendored
Normal file
6
dist/SHA256SUMS.txt
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
665cbdc780765c71f463c6740605fb95dcd10607cabfb7fcb9289898bcd34e95 dist/RETRO95.INF
|
||||||
|
c4cca864978f04ed4f66f25941cc90f68c232372f89a9517fec8a1ce4ff20291 dist/RETROVXD.VXD
|
||||||
|
981d7f9453514e256952e4e08bb87c784632c80a2eb32627410ab57cc67384fd dist/RETRONP.DLL
|
||||||
|
5a4771f808a32dce2366ad675c49826fdc659a33dde065c20bb3692528570220 dist/RetroMap95.exe
|
||||||
|
b33c668e729f54ccf62ff7275114fb71e49cc65fe4c83ccea5325b44e3877b6e dist/retronfs95.exe
|
||||||
|
e449abf4d955b2bf3a03b97b51a4496d5882c76109c8aad7c45983544282a52b dist/retronfs95.reg
|
||||||
BIN
dist/retronfs95.exe
vendored
Executable file
BIN
dist/retronfs95.exe
vendored
Executable file
Binary file not shown.
9
dist/retronfs95.reg
vendored
Normal file
9
dist/retronfs95.reg
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
REGEDIT4
|
||||||
|
|
||||||
|
[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Retronfs95\NetworkProvider]
|
||||||
|
"Name"="RetroNFS95"
|
||||||
|
"ProviderPath"="RETRONP.DLL"
|
||||||
|
|
||||||
|
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run]
|
||||||
|
"RetroNFS95"="C:\\RETRO95\\RetroMap95.exe /startup"
|
||||||
|
|
||||||
166
docs/BUILD_TOOLCHAIN.md
Normal file
166
docs/BUILD_TOOLCHAIN.md
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
# Build Toolchains For RetroNFS95
|
||||||
|
|
||||||
|
There are two different build problems:
|
||||||
|
|
||||||
|
1. Win32 user-mode pieces:
|
||||||
|
- `bin/retronfs95.exe`
|
||||||
|
- `provider/RETRONP.DLL`
|
||||||
|
- `mounter/RetroMap95.exe`
|
||||||
|
|
||||||
|
2. Win95/98 ring-0 VxD:
|
||||||
|
- `vxd/RETROVXD.VXD`
|
||||||
|
|
||||||
|
Do not use one modern default Windows compiler for everything. Modern MinGW and
|
||||||
|
MSVC builds often import APIs or CRT startup code that Windows 95/98 cannot
|
||||||
|
load.
|
||||||
|
|
||||||
|
## Recommended Setup
|
||||||
|
|
||||||
|
### User-Mode EXE/DLL
|
||||||
|
|
||||||
|
Best options:
|
||||||
|
|
||||||
|
- old MinGW 3.x/4.x targeting `msvcrt`
|
||||||
|
- MinGW Lite with a Win95/98 profile
|
||||||
|
- Open Watcom v2 targeting Win32
|
||||||
|
|
||||||
|
Avoid:
|
||||||
|
|
||||||
|
- UCRT builds
|
||||||
|
- x86_64 builds
|
||||||
|
- binaries that depend on APIs newer than Win98
|
||||||
|
|
||||||
|
For the current Makefiles, a suitable MinGW command set is:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
mingw32-g++ --version
|
||||||
|
```
|
||||||
|
|
||||||
|
or, on Linux:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
i586-mingw32msvc-g++ --version
|
||||||
|
i686-w64-mingw32-g++ --version
|
||||||
|
```
|
||||||
|
|
||||||
|
The safest CRT target is old `msvcrt.dll`, not UCRT.
|
||||||
|
|
||||||
|
### VxD
|
||||||
|
|
||||||
|
Best options:
|
||||||
|
|
||||||
|
1. Windows 98 DDK in a Windows 98/2000/XP VM
|
||||||
|
- most historically accurate
|
||||||
|
- least surprise
|
||||||
|
|
||||||
|
2. Linux cross build with:
|
||||||
|
- Open Watcom v2
|
||||||
|
- JWasm/UASM
|
||||||
|
- Windows 98 DDK headers/libs/includes
|
||||||
|
- custom linker command file
|
||||||
|
|
||||||
|
Open Watcom's linker has VxD output support, but VxD builds still depend on DDK
|
||||||
|
headers, segment layout, control procedure glue, and import definitions.
|
||||||
|
|
||||||
|
## Practical Recommendation
|
||||||
|
|
||||||
|
Use two build environments:
|
||||||
|
|
||||||
|
```text
|
||||||
|
Linux host
|
||||||
|
builds and tests portable NFS core
|
||||||
|
builds Win32 EXE/DLL if MinGW-Lite or old MinGW is installed
|
||||||
|
|
||||||
|
Win98/XP VM with Win98 DDK
|
||||||
|
builds RETROVXD.VXD
|
||||||
|
tests driver loading and IFSMgr behavior
|
||||||
|
```
|
||||||
|
|
||||||
|
This avoids spending days fighting linker/segment issues before the redirector
|
||||||
|
logic itself is working.
|
||||||
|
|
||||||
|
## Linux Package Names To Look For
|
||||||
|
|
||||||
|
Depending on distribution:
|
||||||
|
|
||||||
|
```text
|
||||||
|
openwatcom-v2
|
||||||
|
jwasm or uasm
|
||||||
|
mingw-w64-i686
|
||||||
|
wine
|
||||||
|
dosbox-x
|
||||||
|
qemu-system-i386
|
||||||
|
```
|
||||||
|
|
||||||
|
For true Win95 compatibility, prefer a dedicated Win95/98-capable MinGW build
|
||||||
|
over a modern distro default.
|
||||||
|
|
||||||
|
## Suggested Build Order
|
||||||
|
|
||||||
|
1. Build portable NFS core:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make -f Makefile.posix
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Build Win32 mapping app and provider:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
tools/build-win32-mingw.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
The script rebuilds `retronfs95.exe`, `RetroMap95.exe`, and `RETRONP.DLL`,
|
||||||
|
then refreshes `dist/RetroNFS95-win32-artifacts.zip` and
|
||||||
|
`dist/SHA256SUMS.txt`.
|
||||||
|
|
||||||
|
3. Build VxD in DDK environment:
|
||||||
|
|
||||||
|
```bat
|
||||||
|
cd vxd
|
||||||
|
build
|
||||||
|
```
|
||||||
|
|
||||||
|
or with an Open Watcom/JWasm cross setup once DDK includes are available:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
tools/build-vxd-watcom.sh /path/to/win98ddk
|
||||||
|
```
|
||||||
|
|
||||||
|
The script prefers `jwasm` when available and assembles the control stub with
|
||||||
|
MASM-compatible options:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
jwasm -nologo -c -omf -Cp -Zm -3p -I/path/to/win98ddk/inc ...
|
||||||
|
```
|
||||||
|
|
||||||
|
`-Cp` preserves symbol case, `-Zm` enables MASM compatibility, and `-omf` is the
|
||||||
|
default because Open Watcom `wlink` expects OMF objects for this VxD flow. COFF
|
||||||
|
can be tested explicitly:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
VXD_OBJ_FORMAT=coff tools/build-vxd-watcom.sh /path/to/win98ddk
|
||||||
|
```
|
||||||
|
|
||||||
|
The VxD build enables the real IFSMgr registration service call by default:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make -C vxd VXD_IFSMGR_REGISTER=real
|
||||||
|
```
|
||||||
|
|
||||||
|
For safer load/debug cycles where the FSD entry should only be prepared and
|
||||||
|
reported through `/status`, use:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make -C vxd VXD_IFSMGR_REGISTER=prepared
|
||||||
|
```
|
||||||
|
|
||||||
|
The Linux DDK include tree may contain both uppercase and lowercase copies such
|
||||||
|
as `VMM.INC` and `vmm.inc`. The current `vxd/retroctrl.asm` avoids that macro
|
||||||
|
path completely: it carries the small DDB/control-dispatch subset needed by
|
||||||
|
RetroNFS95, because the stock Win98 DDK `vmm.inc` MakeCodeSeg macro uses old
|
||||||
|
MASM concatenation syntax that JWasm rejects.
|
||||||
|
|
||||||
|
That script is still not a substitute for a real Win95/98 test machine. It
|
||||||
|
builds a loadable-format `RETROVXD.VXD`; runtime loading, MPR interaction, and
|
||||||
|
IFSMgr file-operation dispatch still need to be tested and completed under
|
||||||
|
Windows 95/98.
|
||||||
69
docs/DRIVE_MAPPING.md
Normal file
69
docs/DRIVE_MAPPING.md
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
# Windows 95/98 Drive Mapping Plan
|
||||||
|
|
||||||
|
The NFS core in this repository is user-mode. Mapping a real drive letter on
|
||||||
|
Windows 95/98 requires a second layer.
|
||||||
|
|
||||||
|
## Goal
|
||||||
|
|
||||||
|
Expose an NFS export as a normal drive such as:
|
||||||
|
|
||||||
|
```text
|
||||||
|
R:\
|
||||||
|
```
|
||||||
|
|
||||||
|
with long filenames visible to Win32 applications.
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
```text
|
||||||
|
Win32 apps
|
||||||
|
|
|
||||||
|
MPR / WNet APIs
|
||||||
|
|
|
||||||
|
RetroNFS network provider DLL
|
||||||
|
|
|
||||||
|
Win9x redirector / IFSMgr layer
|
||||||
|
|
|
||||||
|
RetroNFS user-mode service or VxD bridge
|
||||||
|
|
|
||||||
|
NFSv3 client core
|
||||||
|
|
|
||||||
|
Winsock TCP/IP
|
||||||
|
```
|
||||||
|
|
||||||
|
## Why This Is Separate
|
||||||
|
|
||||||
|
Win95/98 drive mapping is not just an NFS protocol problem. The operating
|
||||||
|
system needs a network provider/redirector that handles file opens, reads,
|
||||||
|
writes, directory enumeration, attributes, locks, and name conversion.
|
||||||
|
|
||||||
|
The current source tree provides the protocol core that this redirector will
|
||||||
|
call.
|
||||||
|
|
||||||
|
## Long Filename Strategy
|
||||||
|
|
||||||
|
Windows 95/98 supports long filenames through Win32 APIs and VFAT semantics.
|
||||||
|
The redirector should:
|
||||||
|
|
||||||
|
- preserve server filenames as long names
|
||||||
|
- synthesize 8.3 aliases for old 16-bit/DOS applications
|
||||||
|
- store no extra metadata on the NFS server unless needed
|
||||||
|
- reject or map characters invalid on Windows clients
|
||||||
|
|
||||||
|
Pure real-mode MS-DOS is different. It has no native LFN layer, so a DOS client
|
||||||
|
would need an LFN TSR/API shim or would expose 8.3 aliases only.
|
||||||
|
|
||||||
|
## Implementation Milestones
|
||||||
|
|
||||||
|
1. Add write/create/remove/rename/mkdir/rmdir to the NFS core.
|
||||||
|
2. Add attribute translation and basic DOS file mode mapping.
|
||||||
|
3. Add file handle cache and directory entry cache.
|
||||||
|
4. Build a Win32 network provider DLL for connection UI and persistent mappings.
|
||||||
|
5. Implement the redirector/VxD bridge for file operations.
|
||||||
|
6. Add installer INF for Win95/98.
|
||||||
|
|
||||||
|
## Risk
|
||||||
|
|
||||||
|
The VxD/IFSMgr portion is the hardest part and needs the Windows 95/98 DDK.
|
||||||
|
The protocol code can be developed and tested first on XP or Linux.
|
||||||
|
|
||||||
36
docs/SECURITY.md
Normal file
36
docs/SECURITY.md
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Security Notes
|
||||||
|
|
||||||
|
NFSv3 with AUTH_SYS is not a modern security boundary. The client tells the
|
||||||
|
server which UID/GID it wants to use, and the server trusts network placement
|
||||||
|
and export rules.
|
||||||
|
|
||||||
|
Use a gateway design:
|
||||||
|
|
||||||
|
```text
|
||||||
|
legacy PC -> gateway -> modern storage/service
|
||||||
|
```
|
||||||
|
|
||||||
|
Gateway controls:
|
||||||
|
|
||||||
|
- host firewall permits NFS only from approved legacy IPs
|
||||||
|
- static DHCP reservation for the old PC
|
||||||
|
- dedicated export path, no shared home directories
|
||||||
|
- read-only export unless writes are necessary
|
||||||
|
- no inbound NFS from the rest of the LAN
|
||||||
|
- logs for mount and file access
|
||||||
|
|
||||||
|
Example Linux export:
|
||||||
|
|
||||||
|
```text
|
||||||
|
/srv/retro 192.168.50.20(ro,sync,no_subtree_check,all_squash,anonuid=65534,anongid=65534)
|
||||||
|
```
|
||||||
|
|
||||||
|
Example nftables idea:
|
||||||
|
|
||||||
|
```text
|
||||||
|
allow tcp dport {111,2049,mountd-port} from 192.168.50.20
|
||||||
|
drop tcp dport {111,2049,mountd-port}
|
||||||
|
```
|
||||||
|
|
||||||
|
Pin mountd/statd/lockd ports if you need firewall predictability.
|
||||||
|
|
||||||
124
docs/WIN9X_REDIRECTOR.md
Normal file
124
docs/WIN9X_REDIRECTOR.md
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
# Win95/98 Redirector Design
|
||||||
|
|
||||||
|
Windows 95/98 SMB-style behavior requires three cooperating pieces:
|
||||||
|
|
||||||
|
1. `RETROVXD.VXD`
|
||||||
|
- remote file system redirector layer
|
||||||
|
- registers with IFSMgr
|
||||||
|
- owns drive-letter mappings
|
||||||
|
- dispatches open/read/write/find/attr operations
|
||||||
|
|
||||||
|
2. `RETRONP.DLL`
|
||||||
|
- Network Provider DLL loaded by MPR
|
||||||
|
- implements `NPGetCaps`, `NPAddConnection3`, `NPCancelConnection`,
|
||||||
|
`NPGetConnection`, and enumeration stubs
|
||||||
|
- persists mappings
|
||||||
|
- talks to the VxD through `DeviceIoControl`
|
||||||
|
|
||||||
|
3. `RetroMap95.exe`
|
||||||
|
- user-facing mapping tool
|
||||||
|
- calls `WNetAddConnection3`
|
||||||
|
- installs a startup remapper in the Run key
|
||||||
|
|
||||||
|
The source tree now contains all three layers.
|
||||||
|
|
||||||
|
## Current VxD Contract
|
||||||
|
|
||||||
|
`RETROVXD.VXD` exposes a small `DeviceIoControl` contract shared in
|
||||||
|
`include/retro_ioctl.h`.
|
||||||
|
|
||||||
|
Supported control codes:
|
||||||
|
|
||||||
|
- `RETRO_IOCTL_MAP`
|
||||||
|
- input: `RETRO_MAP_REQUEST`
|
||||||
|
- output: `RETRO_MAPPING_INFO`
|
||||||
|
- validates `R:`-style drive letters
|
||||||
|
- parses `\\RetroNFS\server\export_path` into server/export fields
|
||||||
|
- stores the mapping in a 26-slot drive table
|
||||||
|
- `RETRO_IOCTL_UNMAP`
|
||||||
|
- input: `RETRO_QUERY_REQUEST`
|
||||||
|
- removes a drive-table entry
|
||||||
|
- `RETRO_IOCTL_QUERY`
|
||||||
|
- input: `RETRO_QUERY_REQUEST`
|
||||||
|
- output: `RETRO_MAPPING_INFO`
|
||||||
|
- returns one mapped drive
|
||||||
|
- `RETRO_IOCTL_ENUM`
|
||||||
|
- input: `RETRO_ENUM_REQUEST`
|
||||||
|
- output: `RETRO_MAPPING_INFO`
|
||||||
|
- enumerates active mappings by zero-based active-entry index
|
||||||
|
- `RETRO_IOCTL_STATUS`
|
||||||
|
- output: `RETRO_STATUS_INFO`
|
||||||
|
- returns loaded-driver state and mapping counts
|
||||||
|
|
||||||
|
`RETRONP.DLL` now calls `MAP` and `UNMAP`; `RetroMap95.exe /status [R:]`
|
||||||
|
queries the VxD directly.
|
||||||
|
|
||||||
|
## Mapping Syntax
|
||||||
|
|
||||||
|
Use UNC-like names so MPR can route them to the provider:
|
||||||
|
|
||||||
|
```text
|
||||||
|
\\RetroNFS\server\export_path
|
||||||
|
```
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
```bat
|
||||||
|
RetroMap95.exe /map R: \\RetroNFS\192.168.1.10\srv_retro
|
||||||
|
RetroMap95.exe /unmap R:
|
||||||
|
RetroMap95.exe /install-startup
|
||||||
|
```
|
||||||
|
|
||||||
|
## Startup Behavior
|
||||||
|
|
||||||
|
Persistent mappings are stored in:
|
||||||
|
|
||||||
|
```text
|
||||||
|
%WINDIR%\RETRO95\mappings.ini
|
||||||
|
```
|
||||||
|
|
||||||
|
`RetroMap95.exe /startup` reads that file and calls `WNetAddConnection3` for
|
||||||
|
each saved drive. This mirrors the user-visible behavior of the Windows SMB
|
||||||
|
client, where Explorer and applications see stable drive letters after login.
|
||||||
|
|
||||||
|
## Remaining VxD Work
|
||||||
|
|
||||||
|
The current VxD source now has:
|
||||||
|
|
||||||
|
- device init/exit hooks
|
||||||
|
- IOCTL command IDs for map/unmap/query/enum/status
|
||||||
|
- payload structures shared with `RETRONP.DLL` and `RetroMap95.exe`
|
||||||
|
- drive-letter mapping table
|
||||||
|
- UNC parser for `\\RetroNFS\server\export_path`
|
||||||
|
- status/query/enumeration support
|
||||||
|
- a JWasm-compatible control stub that builds `RETROVXD.VXD` without including
|
||||||
|
the incompatible Win98 DDK `vmm.inc` macro layer
|
||||||
|
- an `RetroIFS_*` scaffold:
|
||||||
|
- `RetroIFS_Init` / `RetroIFS_Exit`
|
||||||
|
- `RetroIFS_Dispatch`
|
||||||
|
- prepared FSD entry state and optional real `IFSMgr_RegisterFILE_System` /
|
||||||
|
`IFSMgr_DeregisterFILE_System` VxDCall wiring
|
||||||
|
- `IFSFN_*` function-number routing for connect/disconnect/open/read/write/
|
||||||
|
close/find/disk-info
|
||||||
|
- a 64-entry internal open-file cache placeholder
|
||||||
|
- read-only dispatch behavior:
|
||||||
|
- `OPEN` allocates an internal handle and stores the requested path
|
||||||
|
- `READ` returns deterministic EOF until NFS file handles are wired in
|
||||||
|
- `WRITE` returns access denied
|
||||||
|
- `FINDFIRST`/`FINDNEXT` return no-more-files until NFS `READDIR` is wired
|
||||||
|
- `GETDISKINFO` returns stable placeholder geometry
|
||||||
|
|
||||||
|
Still required for a usable drive:
|
||||||
|
|
||||||
|
- live Win95/98 validation of the IFSMgr network FSD register/deregister calls
|
||||||
|
- file operation dispatch table
|
||||||
|
- validation of the simplified IFSMgr parameter tails against a live Win95/98
|
||||||
|
target
|
||||||
|
- NFS `LOOKUP`/`READ`/`READDIR` handle binding
|
||||||
|
- write/create/delete/rename implementation
|
||||||
|
- real directory search implementation
|
||||||
|
- attribute and timestamp translation
|
||||||
|
- 8.3 alias generation for old DOS/16-bit callers
|
||||||
|
- cache invalidation and reconnect handling
|
||||||
|
|
||||||
|
The existing NFSv3 core is the protocol engine the redirector should call.
|
||||||
2
examples/exports.example
Normal file
2
examples/exports.example
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/srv/retro 192.168.50.20(ro,sync,no_subtree_check,all_squash,anonuid=65534,anongid=65534)
|
||||||
|
|
||||||
24
include/compat.hpp
Normal file
24
include/compat.hpp
Normal 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
17
include/mount.hpp
Normal 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
33
include/nfs.hpp
Normal 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
13
include/path.hpp
Normal 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
13
include/portmap.hpp
Normal 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
51
include/retro_ioctl.h
Normal 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
43
include/rpc.hpp
Normal 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
38
include/socket.hpp
Normal 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
44
include/xdr.hpp
Normal 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
|
||||||
|
|
||||||
25
install/RETRO95.INF
Normal file
25
install/RETRO95.INF
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
[version]
|
||||||
|
signature="$CHICAGO$"
|
||||||
|
Class=Net
|
||||||
|
Provider=%Provider%
|
||||||
|
|
||||||
|
[DefaultInstall]
|
||||||
|
CopyFiles=Retro.Copy
|
||||||
|
AddReg=Retro.AddReg
|
||||||
|
|
||||||
|
[DestinationDirs]
|
||||||
|
Retro.Copy=11
|
||||||
|
|
||||||
|
[Retro.Copy]
|
||||||
|
RETRONP.DLL
|
||||||
|
RETROVXD.VXD
|
||||||
|
RetroMap95.exe
|
||||||
|
|
||||||
|
[Retro.AddReg]
|
||||||
|
HKLM,System\CurrentControlSet\Services\Retronfs95\NetworkProvider,Name,0,"RetroNFS95"
|
||||||
|
HKLM,System\CurrentControlSet\Services\Retronfs95\NetworkProvider,ProviderPath,0,"RETRONP.DLL"
|
||||||
|
HKLM,Software\Microsoft\Windows\CurrentVersion\Run,RetroNFS95,0,"C:\RETRO95\RetroMap95.exe /startup"
|
||||||
|
|
||||||
|
[Strings]
|
||||||
|
Provider="RetroNFS95"
|
||||||
|
|
||||||
9
install/retronfs95.reg
Normal file
9
install/retronfs95.reg
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
REGEDIT4
|
||||||
|
|
||||||
|
[HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Retronfs95\NetworkProvider]
|
||||||
|
"Name"="RetroNFS95"
|
||||||
|
"ProviderPath"="RETRONP.DLL"
|
||||||
|
|
||||||
|
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run]
|
||||||
|
"RetroNFS95"="C:\\RETRO95\\RetroMap95.exe /startup"
|
||||||
|
|
||||||
12
mounter/Makefile.mingw
Normal file
12
mounter/Makefile.mingw
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
CXX = g++
|
||||||
|
EXE = RetroMap95.exe
|
||||||
|
CXXFLAGS = -Os -Wall -Wextra -DWIN32_LEAN_AND_MEAN
|
||||||
|
LDFLAGS = -lmpr
|
||||||
|
|
||||||
|
all: $(EXE)
|
||||||
|
|
||||||
|
$(EXE): retromap95.cpp ../include/retro_ioctl.h
|
||||||
|
$(CXX) $(CXXFLAGS) -I../include -o $(EXE) retromap95.cpp $(LDFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-del /Q $(EXE) 2>NUL
|
||||||
186
mounter/retromap95.cpp
Normal file
186
mounter/retromap95.cpp
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
#include <winnetwk.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "../include/retro_ioctl.h"
|
||||||
|
|
||||||
|
static const char* kRunKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
|
||||||
|
static const char* kRunName = "RetroNFS95";
|
||||||
|
static const char* kDeviceName = "\\\\.\\RETROVXD";
|
||||||
|
|
||||||
|
static void usage() {
|
||||||
|
printf("RetroMap95\n");
|
||||||
|
printf("Usage:\n");
|
||||||
|
printf(" RetroMap95 /map R: \\\\RetroNFS\\\\server\\\\export_path\n");
|
||||||
|
printf(" RetroMap95 /unmap R:\n");
|
||||||
|
printf(" RetroMap95 /status [R:]\n");
|
||||||
|
printf(" RetroMap95 /startup\n");
|
||||||
|
printf(" RetroMap95 /install-startup\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static int install_startup() {
|
||||||
|
char exe[MAX_PATH];
|
||||||
|
GetModuleFileNameA(NULL, exe, sizeof(exe));
|
||||||
|
|
||||||
|
char cmd[MAX_PATH + 32];
|
||||||
|
wsprintfA(cmd, "\"%s\" /startup", exe);
|
||||||
|
|
||||||
|
HKEY key;
|
||||||
|
LONG rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, kRunKey, 0, KEY_SET_VALUE, &key);
|
||||||
|
if (rc != ERROR_SUCCESS) {
|
||||||
|
rc = RegCreateKeyA(HKEY_LOCAL_MACHINE, kRunKey, &key);
|
||||||
|
if (rc != ERROR_SUCCESS) return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
RegSetValueExA(key, kRunName, 0, REG_SZ, (const BYTE*)cmd, lstrlenA(cmd) + 1);
|
||||||
|
RegCloseKey(key);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int map_drive(const char* local, const char* remote) {
|
||||||
|
NETRESOURCEA nr;
|
||||||
|
ZeroMemory(&nr, sizeof(nr));
|
||||||
|
nr.dwType = RESOURCETYPE_DISK;
|
||||||
|
nr.lpLocalName = (LPSTR)local;
|
||||||
|
nr.lpRemoteName = (LPSTR)remote;
|
||||||
|
nr.lpProvider = (LPSTR)"RetroNFS95";
|
||||||
|
|
||||||
|
DWORD rc = WNetAddConnection3A(NULL, &nr, NULL, NULL, CONNECT_UPDATE_PROFILE);
|
||||||
|
if (rc != NO_ERROR) {
|
||||||
|
printf("map failed: %lu\n", rc);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
printf("%s mapped to %s\n", local, remote);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int unmap_drive(const char* local) {
|
||||||
|
DWORD rc = WNetCancelConnection2A(local, CONNECT_UPDATE_PROFILE, TRUE);
|
||||||
|
if (rc != NO_ERROR) {
|
||||||
|
printf("unmap failed: %lu\n", rc);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
printf("%s unmapped\n", local);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int print_vxd_status() {
|
||||||
|
HANDLE h = CreateFileA(kDeviceName, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
if (h == INVALID_HANDLE_VALUE) {
|
||||||
|
printf("RETROVXD not loaded\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
RETRO_STATUS_INFO status;
|
||||||
|
ZeroMemory(&status, sizeof(status));
|
||||||
|
DWORD returned = 0;
|
||||||
|
BOOL ok = DeviceIoControl(h,
|
||||||
|
RETRO_IOCTL_STATUS,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
&status,
|
||||||
|
sizeof(status),
|
||||||
|
&returned,
|
||||||
|
NULL);
|
||||||
|
CloseHandle(h);
|
||||||
|
if (!ok) {
|
||||||
|
printf("RETROVXD status query failed\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("RETROVXD loaded, %lu/%lu mappings\n",
|
||||||
|
status.mapping_count,
|
||||||
|
status.max_mappings);
|
||||||
|
printf("IFS scaffold: %s, registration: %s\n",
|
||||||
|
(status.driver_flags & RETRO_DRIVER_FLAG_IFS_STUB) ? "ready" : "not ready",
|
||||||
|
(status.driver_flags & RETRO_DRIVER_FLAG_IFS_REGISTERED) ? "prepared" : "not prepared");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int print_vxd_mapping(const char* local) {
|
||||||
|
HANDLE h = CreateFileA(kDeviceName, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
if (h == INVALID_HANDLE_VALUE) {
|
||||||
|
printf("RETROVXD not loaded\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
RETRO_QUERY_REQUEST request;
|
||||||
|
RETRO_MAPPING_INFO info;
|
||||||
|
ZeroMemory(&request, sizeof(request));
|
||||||
|
ZeroMemory(&info, sizeof(info));
|
||||||
|
lstrcpynA(request.local, local ? local : "", sizeof(request.local));
|
||||||
|
|
||||||
|
DWORD returned = 0;
|
||||||
|
BOOL ok = DeviceIoControl(h,
|
||||||
|
RETRO_IOCTL_QUERY,
|
||||||
|
&request,
|
||||||
|
sizeof(request),
|
||||||
|
&info,
|
||||||
|
sizeof(info),
|
||||||
|
&returned,
|
||||||
|
NULL);
|
||||||
|
CloseHandle(h);
|
||||||
|
if (!ok) {
|
||||||
|
printf("%s is not mapped in RETROVXD\n", local ? local : "");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%s -> %s\n", info.local, info.remote);
|
||||||
|
printf("server=%s export=%s\n", info.server, info.export_path);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void get_config_path(char* out, DWORD len) {
|
||||||
|
GetWindowsDirectoryA(out, len);
|
||||||
|
lstrcatA(out, "\\RETRO95\\mappings.ini");
|
||||||
|
}
|
||||||
|
|
||||||
|
static int remap_startup() {
|
||||||
|
char ini[MAX_PATH];
|
||||||
|
get_config_path(ini, sizeof(ini));
|
||||||
|
|
||||||
|
for (char d = 'A'; d <= 'Z'; ++d) {
|
||||||
|
char section[32];
|
||||||
|
wsprintfA(section, "Drive.%c", d);
|
||||||
|
|
||||||
|
char local[16];
|
||||||
|
char remote[MAX_PATH];
|
||||||
|
GetPrivateProfileStringA(section, "Local", "", local, sizeof(local), ini);
|
||||||
|
GetPrivateProfileStringA(section, "Remote", "", remote, sizeof(remote), ini);
|
||||||
|
if (local[0] && remote[0]) {
|
||||||
|
map_drive(local, remote);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
if (argc < 2) {
|
||||||
|
usage();
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lstrcmpiA(argv[1], "/install-startup") == 0) {
|
||||||
|
return install_startup();
|
||||||
|
}
|
||||||
|
if (lstrcmpiA(argv[1], "/startup") == 0) {
|
||||||
|
return remap_startup();
|
||||||
|
}
|
||||||
|
if (lstrcmpiA(argv[1], "/map") == 0 && argc >= 4) {
|
||||||
|
return map_drive(argv[2], argv[3]);
|
||||||
|
}
|
||||||
|
if (lstrcmpiA(argv[1], "/unmap") == 0 && argc >= 3) {
|
||||||
|
return unmap_drive(argv[2]);
|
||||||
|
}
|
||||||
|
if (lstrcmpiA(argv[1], "/status") == 0) {
|
||||||
|
if (argc >= 3) return print_vxd_mapping(argv[2]);
|
||||||
|
return print_vxd_status();
|
||||||
|
}
|
||||||
|
|
||||||
|
usage();
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
12
provider/Makefile.mingw
Normal file
12
provider/Makefile.mingw
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
CXX = g++
|
||||||
|
DLL = RETRONP.DLL
|
||||||
|
CXXFLAGS = -Os -Wall -Wextra -DWIN32_LEAN_AND_MEAN
|
||||||
|
LDFLAGS = -shared -Wl,--enable-stdcall-fixup -lmpr
|
||||||
|
|
||||||
|
all: $(DLL)
|
||||||
|
|
||||||
|
$(DLL): retronp.cpp retronp.def ../include/retro_ioctl.h
|
||||||
|
$(CXX) $(CXXFLAGS) -I../include -o $(DLL) retronp.cpp retronp.def $(LDFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-del /Q $(DLL) 2>NUL
|
||||||
275
provider/retronp.cpp
Normal file
275
provider/retronp.cpp
Normal file
@@ -0,0 +1,275 @@
|
|||||||
|
#ifndef WIN32_LEAN_AND_MEAN
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#endif
|
||||||
|
#include <windows.h>
|
||||||
|
#include <winnetwk.h>
|
||||||
|
#include <wnnc.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "../include/retro_ioctl.h"
|
||||||
|
|
||||||
|
static const char* kProviderName = "RetroNFS95";
|
||||||
|
static const char* kDeviceName = "\\\\.\\RETROVXD";
|
||||||
|
static const char* kConfigDir = "\\RETRO95";
|
||||||
|
static const char* kConfigFile = "\\RETRO95\\mappings.ini";
|
||||||
|
|
||||||
|
#ifndef WNNC_SPEC_VERSION
|
||||||
|
#define WNNC_SPEC_VERSION 0x00000001
|
||||||
|
#endif
|
||||||
|
#ifndef WNNC_SPEC_VERSION51
|
||||||
|
#define WNNC_SPEC_VERSION51 0x00050001
|
||||||
|
#endif
|
||||||
|
#ifndef WNNC_NET_TYPE
|
||||||
|
#define WNNC_NET_TYPE 0x00000002
|
||||||
|
#endif
|
||||||
|
#ifndef WNNC_CONNECTION
|
||||||
|
#define WNNC_CONNECTION 0x00000006
|
||||||
|
#endif
|
||||||
|
#ifndef WNNC_CON_ADDCONNECTION
|
||||||
|
#define WNNC_CON_ADDCONNECTION 0x00000001
|
||||||
|
#endif
|
||||||
|
#ifndef WNNC_CON_CANCELCONNECTION
|
||||||
|
#define WNNC_CON_CANCELCONNECTION 0x00000002
|
||||||
|
#endif
|
||||||
|
#ifndef WNNC_CON_GETCONNECTIONS
|
||||||
|
#define WNNC_CON_GETCONNECTIONS 0x00000004
|
||||||
|
#endif
|
||||||
|
#ifndef WNNC_CON_ADDCONNECTION3
|
||||||
|
#define WNNC_CON_ADDCONNECTION3 0x00000008
|
||||||
|
#endif
|
||||||
|
#ifndef WNNC_ENUMERATION
|
||||||
|
#define WNNC_ENUMERATION 0x0000000B
|
||||||
|
#endif
|
||||||
|
#ifndef WNNC_ENUM_LOCAL
|
||||||
|
#define WNNC_ENUM_LOCAL 0x00000002
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int prefix_i(const char* value, const char* prefix) {
|
||||||
|
if (!value || !prefix) return 0;
|
||||||
|
while (*prefix) {
|
||||||
|
char a = *value++;
|
||||||
|
char b = *prefix++;
|
||||||
|
if (a >= 'a' && a <= 'z') a = (char)(a - 'a' + 'A');
|
||||||
|
if (b >= 'a' && b <= 'z') b = (char)(b - 'a' + 'A');
|
||||||
|
if (a != b) return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void get_windows_path(char* out, DWORD out_len, const char* suffix) {
|
||||||
|
UINT n = GetWindowsDirectoryA(out, out_len);
|
||||||
|
if (n == 0 || n >= out_len) {
|
||||||
|
lstrcpynA(out, "C:\\WINDOWS", out_len);
|
||||||
|
}
|
||||||
|
lstrcatA(out, suffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL ensure_config_dir() {
|
||||||
|
char path[MAX_PATH];
|
||||||
|
get_windows_path(path, sizeof(path), kConfigDir);
|
||||||
|
CreateDirectoryA(path, NULL);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD save_mapping(const char* local, const char* remote, const char* user) {
|
||||||
|
ensure_config_dir();
|
||||||
|
|
||||||
|
char path[MAX_PATH];
|
||||||
|
get_windows_path(path, sizeof(path), kConfigFile);
|
||||||
|
|
||||||
|
char section[32];
|
||||||
|
wsprintfA(section, "Drive.%c", local && local[0] ? local[0] : '?');
|
||||||
|
|
||||||
|
WritePrivateProfileStringA(section, "Local", local ? local : "", path);
|
||||||
|
WritePrivateProfileStringA(section, "Remote", remote ? remote : "", path);
|
||||||
|
WritePrivateProfileStringA(section, "User", user ? user : "", path);
|
||||||
|
WritePrivateProfileStringA(section, "Provider", kProviderName, path);
|
||||||
|
return WN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD call_vxd_map(const char* local, const char* remote) {
|
||||||
|
HANDLE h = CreateFileA(kDeviceName, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
if (h == INVALID_HANDLE_VALUE) {
|
||||||
|
return WN_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
RETRO_MAP_REQUEST request;
|
||||||
|
RETRO_MAPPING_INFO result;
|
||||||
|
ZeroMemory(&request, sizeof(request));
|
||||||
|
ZeroMemory(&result, sizeof(result));
|
||||||
|
lstrcpynA(request.local, local ? local : "", sizeof(request.local));
|
||||||
|
lstrcpynA(request.remote, remote ? remote : "", sizeof(request.remote));
|
||||||
|
|
||||||
|
DWORD returned = 0;
|
||||||
|
BOOL ok = DeviceIoControl(h,
|
||||||
|
RETRO_IOCTL_MAP,
|
||||||
|
&request,
|
||||||
|
sizeof(request),
|
||||||
|
&result,
|
||||||
|
sizeof(result),
|
||||||
|
&returned,
|
||||||
|
NULL);
|
||||||
|
CloseHandle(h);
|
||||||
|
return ok ? WN_SUCCESS : WN_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD call_vxd_unmap(const char* local) {
|
||||||
|
HANDLE h = CreateFileA(kDeviceName, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
if (h == INVALID_HANDLE_VALUE) {
|
||||||
|
return WN_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
RETRO_QUERY_REQUEST request;
|
||||||
|
ZeroMemory(&request, sizeof(request));
|
||||||
|
lstrcpynA(request.local, local ? local : "", sizeof(request.local));
|
||||||
|
|
||||||
|
DWORD returned = 0;
|
||||||
|
BOOL ok = DeviceIoControl(h,
|
||||||
|
RETRO_IOCTL_UNMAP,
|
||||||
|
&request,
|
||||||
|
sizeof(request),
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
&returned,
|
||||||
|
NULL);
|
||||||
|
CloseHandle(h);
|
||||||
|
return ok ? WN_SUCCESS : WN_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" DWORD APIENTRY NPGetCaps(DWORD index) {
|
||||||
|
switch (index) {
|
||||||
|
case WNNC_SPEC_VERSION:
|
||||||
|
return WNNC_SPEC_VERSION51;
|
||||||
|
case WNNC_NET_TYPE:
|
||||||
|
return WNNC_NET_SUN_PC_NFS;
|
||||||
|
case WNNC_CONNECTION:
|
||||||
|
return WNNC_CON_ADDCONNECTION |
|
||||||
|
WNNC_CON_ADDCONNECTION3 |
|
||||||
|
WNNC_CON_CANCELCONNECTION |
|
||||||
|
WNNC_CON_GETCONNECTIONS;
|
||||||
|
case WNNC_ENUMERATION:
|
||||||
|
return WNNC_ENUM_LOCAL;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" DWORD APIENTRY NPAddConnection3(HWND hwndOwner,
|
||||||
|
LPNETRESOURCEA lpNetResource,
|
||||||
|
LPSTR lpPassword,
|
||||||
|
LPSTR lpUserName,
|
||||||
|
DWORD dwFlags) {
|
||||||
|
(void)hwndOwner;
|
||||||
|
(void)lpPassword;
|
||||||
|
(void)dwFlags;
|
||||||
|
|
||||||
|
if (!lpNetResource || !lpNetResource->lpRemoteName || !lpNetResource->lpLocalName) {
|
||||||
|
return WN_BAD_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!prefix_i(lpNetResource->lpRemoteName, "\\\\RetroNFS\\")) {
|
||||||
|
return WN_BAD_NETNAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
save_mapping(lpNetResource->lpLocalName, lpNetResource->lpRemoteName, lpUserName);
|
||||||
|
|
||||||
|
DWORD vx = call_vxd_map(lpNetResource->lpLocalName, lpNetResource->lpRemoteName);
|
||||||
|
if (vx == WN_SUCCESS) {
|
||||||
|
return WN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep the mapping persistent even before the VxD is complete. This makes
|
||||||
|
// the UI/configuration layer usable while redirector work continues.
|
||||||
|
return WN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" DWORD APIENTRY NPAddConnection(LPNETRESOURCEA lpNetResource,
|
||||||
|
LPSTR lpPassword,
|
||||||
|
LPSTR lpUserName) {
|
||||||
|
return NPAddConnection3(NULL, lpNetResource, lpPassword, lpUserName, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" DWORD APIENTRY NPCancelConnection(LPSTR lpName, BOOL fForce) {
|
||||||
|
(void)fForce;
|
||||||
|
if (!lpName || !lpName[0]) return WN_BAD_VALUE;
|
||||||
|
|
||||||
|
call_vxd_unmap(lpName);
|
||||||
|
|
||||||
|
char path[MAX_PATH];
|
||||||
|
get_windows_path(path, sizeof(path), kConfigFile);
|
||||||
|
|
||||||
|
char section[32];
|
||||||
|
wsprintfA(section, "Drive.%c", lpName[0]);
|
||||||
|
WritePrivateProfileStringA(section, NULL, NULL, path);
|
||||||
|
return WN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" DWORD APIENTRY NPGetConnection(LPSTR lpLocalName,
|
||||||
|
LPSTR lpRemoteName,
|
||||||
|
LPDWORD lpnBufferLen) {
|
||||||
|
if (!lpLocalName || !lpRemoteName || !lpnBufferLen) return WN_BAD_VALUE;
|
||||||
|
|
||||||
|
char path[MAX_PATH];
|
||||||
|
get_windows_path(path, sizeof(path), kConfigFile);
|
||||||
|
|
||||||
|
char section[32];
|
||||||
|
wsprintfA(section, "Drive.%c", lpLocalName[0]);
|
||||||
|
|
||||||
|
char remote[MAX_PATH];
|
||||||
|
GetPrivateProfileStringA(section, "Remote", "", remote, sizeof(remote), path);
|
||||||
|
if (!remote[0]) return WN_NOT_CONNECTED;
|
||||||
|
|
||||||
|
DWORD need = lstrlenA(remote) + 1;
|
||||||
|
if (*lpnBufferLen < need) {
|
||||||
|
*lpnBufferLen = need;
|
||||||
|
return WN_MORE_DATA;
|
||||||
|
}
|
||||||
|
lstrcpyA(lpRemoteName, remote);
|
||||||
|
*lpnBufferLen = need;
|
||||||
|
return WN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" DWORD APIENTRY NPGetResourceInformation(LPNETRESOURCEA lpNetResource,
|
||||||
|
LPVOID lpBuffer,
|
||||||
|
LPDWORD lpcbBuffer,
|
||||||
|
LPSTR* lplpSystem) {
|
||||||
|
(void)lpBuffer;
|
||||||
|
(void)lpcbBuffer;
|
||||||
|
(void)lplpSystem;
|
||||||
|
if (!lpNetResource || !lpNetResource->lpRemoteName) return WN_BAD_VALUE;
|
||||||
|
if (!prefix_i(lpNetResource->lpRemoteName, "\\\\RetroNFS\\")) {
|
||||||
|
return WN_BAD_NETNAME;
|
||||||
|
}
|
||||||
|
return WN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" DWORD APIENTRY NPOpenEnum(DWORD dwScope,
|
||||||
|
DWORD dwType,
|
||||||
|
DWORD dwUsage,
|
||||||
|
LPNETRESOURCEA lpNetResource,
|
||||||
|
LPHANDLE lphEnum) {
|
||||||
|
(void)dwScope; (void)dwType; (void)dwUsage; (void)lpNetResource;
|
||||||
|
if (!lphEnum) return WN_BAD_VALUE;
|
||||||
|
*lphEnum = (HANDLE)1;
|
||||||
|
return WN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" DWORD APIENTRY NPEnumResource(HANDLE hEnum,
|
||||||
|
LPDWORD lpcCount,
|
||||||
|
LPVOID lpBuffer,
|
||||||
|
LPDWORD lpBufferSize) {
|
||||||
|
(void)hEnum; (void)lpBuffer; (void)lpBufferSize;
|
||||||
|
if (lpcCount) *lpcCount = 0;
|
||||||
|
return WN_NO_MORE_ENTRIES;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" DWORD APIENTRY NPCloseEnum(HANDLE hEnum) {
|
||||||
|
(void)hEnum;
|
||||||
|
return WN_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) {
|
||||||
|
(void)hinst; (void)reason; (void)reserved;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
13
provider/retronp.def
Normal file
13
provider/retronp.def
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
LIBRARY RETRONP
|
||||||
|
DESCRIPTION 'RetroNFS95 Network Provider'
|
||||||
|
EXPORTS
|
||||||
|
NPGetCaps
|
||||||
|
NPAddConnection
|
||||||
|
NPAddConnection3
|
||||||
|
NPCancelConnection
|
||||||
|
NPGetConnection
|
||||||
|
NPGetResourceInformation
|
||||||
|
NPOpenEnum
|
||||||
|
NPEnumResource
|
||||||
|
NPCloseEnum
|
||||||
|
|
||||||
83
src/main.cpp
Normal file
83
src/main.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
32
src/mount.cpp
Normal file
32
src/mount.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include "mount.hpp"
|
||||||
|
#include "portmap.hpp"
|
||||||
|
|
||||||
|
namespace retronfs {
|
||||||
|
|
||||||
|
enum {
|
||||||
|
MOUNT_PROG = 100005,
|
||||||
|
MOUNT_V3 = 3,
|
||||||
|
MOUNTPROC_MNT = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
FileHandle mount_export(const std::string& host, const std::string& export_path, const RpcIdentity& identity) {
|
||||||
|
unsigned short port = portmap_get_tcp_port(host, MOUNT_PROG, MOUNT_V3);
|
||||||
|
RpcClient rpc(host, port, MOUNT_PROG, MOUNT_V3);
|
||||||
|
|
||||||
|
XdrWriter args;
|
||||||
|
args.str(export_path);
|
||||||
|
|
||||||
|
Bytes reply = rpc.call(MOUNTPROC_MNT, args.data(), identity);
|
||||||
|
XdrReader r(reply);
|
||||||
|
uint32_t status = r.u32();
|
||||||
|
if (status != 0) {
|
||||||
|
throw Error("mountd rejected export with status " + std::string(status == 13 ? "EACCES" : "nonzero"));
|
||||||
|
}
|
||||||
|
|
||||||
|
FileHandle fh;
|
||||||
|
fh.data = r.opaque();
|
||||||
|
return fh;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
148
src/nfs.cpp
Normal file
148
src/nfs.cpp
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
#include "nfs.hpp"
|
||||||
|
#include "portmap.hpp"
|
||||||
|
#include "path.hpp"
|
||||||
|
|
||||||
|
namespace retronfs {
|
||||||
|
|
||||||
|
enum {
|
||||||
|
NFS_PROG = 100003,
|
||||||
|
NFS_V3 = 3,
|
||||||
|
NFSPROC3_LOOKUP = 3,
|
||||||
|
NFSPROC3_READ = 6,
|
||||||
|
NFSPROC3_READDIR = 16,
|
||||||
|
NFS3_OK = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
static void write_fh(XdrWriter& w, const FileHandle& fh) {
|
||||||
|
w.opaque(fh.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static FileHandle read_fh(XdrReader& r) {
|
||||||
|
FileHandle fh;
|
||||||
|
fh.data = r.opaque();
|
||||||
|
return fh;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void skip_post_op_attr(XdrReader& r) {
|
||||||
|
uint32_t follows = r.u32();
|
||||||
|
if (!follows) return;
|
||||||
|
|
||||||
|
r.u32(); // type
|
||||||
|
r.u32(); // mode
|
||||||
|
r.u32(); // nlink
|
||||||
|
r.u32(); // uid
|
||||||
|
r.u32(); // gid
|
||||||
|
r.u64(); // size
|
||||||
|
r.u64(); // used
|
||||||
|
r.u32(); // rdev specdata1
|
||||||
|
r.u32(); // rdev specdata2
|
||||||
|
r.u64(); // fsid
|
||||||
|
r.u64(); // fileid
|
||||||
|
r.u32(); r.u32(); // atime
|
||||||
|
r.u32(); r.u32(); // mtime
|
||||||
|
r.u32(); r.u32(); // ctime
|
||||||
|
}
|
||||||
|
|
||||||
|
NfsClient::NfsClient(const std::string& host, unsigned short port, const RpcIdentity& identity)
|
||||||
|
: rpc_(host, port, NFS_PROG, NFS_V3), identity_(identity) {}
|
||||||
|
|
||||||
|
FileHandle NfsClient::lookup(const FileHandle& dir, const std::string& name) {
|
||||||
|
XdrWriter args;
|
||||||
|
write_fh(args, dir);
|
||||||
|
args.str(name);
|
||||||
|
|
||||||
|
Bytes reply = rpc_.call(NFSPROC3_LOOKUP, args.data(), identity_);
|
||||||
|
XdrReader r(reply);
|
||||||
|
uint32_t status = r.u32();
|
||||||
|
if (status != NFS3_OK) {
|
||||||
|
throw Error("NFS LOOKUP failed");
|
||||||
|
}
|
||||||
|
FileHandle fh = read_fh(r);
|
||||||
|
skip_post_op_attr(r);
|
||||||
|
skip_post_op_attr(r);
|
||||||
|
return fh;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<DirEntry> NfsClient::readdir(const FileHandle& dir) {
|
||||||
|
std::vector<DirEntry> all;
|
||||||
|
uint64_t cookie = 0;
|
||||||
|
byte verf[8] = {0,0,0,0,0,0,0,0};
|
||||||
|
bool eof = false;
|
||||||
|
|
||||||
|
while (!eof) {
|
||||||
|
XdrWriter args;
|
||||||
|
write_fh(args, dir);
|
||||||
|
args.u64(cookie);
|
||||||
|
args.fixed_opaque(verf, 8);
|
||||||
|
args.u32(8192);
|
||||||
|
|
||||||
|
Bytes reply = rpc_.call(NFSPROC3_READDIR, args.data(), identity_);
|
||||||
|
XdrReader r(reply);
|
||||||
|
uint32_t status = r.u32();
|
||||||
|
if (status != NFS3_OK) {
|
||||||
|
throw Error("NFS READDIR failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
skip_post_op_attr(r);
|
||||||
|
Bytes newverf = r.fixed_opaque(8);
|
||||||
|
for (unsigned i = 0; i < 8 && i < newverf.size(); ++i) verf[i] = newverf[i];
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
uint32_t present = r.u32();
|
||||||
|
if (!present) break;
|
||||||
|
DirEntry e;
|
||||||
|
e.fileid = r.u64();
|
||||||
|
e.name = r.str();
|
||||||
|
e.cookie = r.u64();
|
||||||
|
cookie = e.cookie;
|
||||||
|
all.push_back(e);
|
||||||
|
}
|
||||||
|
eof = r.u32() != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return all;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bytes NfsClient::read(const FileHandle& file, uint64_t offset, uint32_t count, bool* eof) {
|
||||||
|
XdrWriter args;
|
||||||
|
write_fh(args, file);
|
||||||
|
args.u64(offset);
|
||||||
|
args.u32(count);
|
||||||
|
|
||||||
|
Bytes reply = rpc_.call(NFSPROC3_READ, args.data(), identity_);
|
||||||
|
XdrReader r(reply);
|
||||||
|
uint32_t status = r.u32();
|
||||||
|
if (status != NFS3_OK) {
|
||||||
|
throw Error("NFS READ failed");
|
||||||
|
}
|
||||||
|
skip_post_op_attr(r);
|
||||||
|
uint32_t got_count = r.u32();
|
||||||
|
(void)got_count;
|
||||||
|
*eof = r.u32() != 0;
|
||||||
|
return r.opaque();
|
||||||
|
}
|
||||||
|
|
||||||
|
Bytes NfsClient::read_all(const FileHandle& file) {
|
||||||
|
Bytes out;
|
||||||
|
uint64_t off = 0;
|
||||||
|
bool eof = false;
|
||||||
|
while (!eof) {
|
||||||
|
Bytes part = read(file, off, 32768, &eof);
|
||||||
|
if (part.empty()) break;
|
||||||
|
out.insert(out.end(), part.begin(), part.end());
|
||||||
|
off += part.size();
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileHandle resolve_path(NfsClient& nfs, const FileHandle& root, const std::string& path) {
|
||||||
|
FileHandle cur = root;
|
||||||
|
std::vector<std::string> parts = split_nfs_path(path);
|
||||||
|
for (unsigned i = 0; i < parts.size(); ++i) {
|
||||||
|
cur = nfs.lookup(cur, parts[i]);
|
||||||
|
}
|
||||||
|
return cur;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
26
src/path.cpp
Normal file
26
src/path.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "path.hpp"
|
||||||
|
|
||||||
|
namespace retronfs {
|
||||||
|
|
||||||
|
std::vector<std::string> split_nfs_path(const std::string& path) {
|
||||||
|
std::vector<std::string> parts;
|
||||||
|
std::string cur;
|
||||||
|
for (unsigned i = 0; i < path.size(); ++i) {
|
||||||
|
char c = path[i];
|
||||||
|
if (c == '/' || c == '\\') {
|
||||||
|
if (!cur.empty() && cur != ".") {
|
||||||
|
parts.push_back(cur);
|
||||||
|
}
|
||||||
|
cur.clear();
|
||||||
|
} else {
|
||||||
|
cur += c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!cur.empty() && cur != ".") {
|
||||||
|
parts.push_back(cur);
|
||||||
|
}
|
||||||
|
return parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
32
src/portmap.cpp
Normal file
32
src/portmap.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#include "portmap.hpp"
|
||||||
|
|
||||||
|
namespace retronfs {
|
||||||
|
|
||||||
|
enum {
|
||||||
|
PMAP_PROG = 100000,
|
||||||
|
PMAP_VERS = 2,
|
||||||
|
PMAPPROC_GETPORT = 3,
|
||||||
|
IPPROTO_TCP_XDR = 6
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned short portmap_get_tcp_port(const std::string& host, uint32_t program, uint32_t version) {
|
||||||
|
RpcIdentity id;
|
||||||
|
RpcClient rpc(host, 111, PMAP_PROG, PMAP_VERS);
|
||||||
|
|
||||||
|
XdrWriter args;
|
||||||
|
args.u32(program);
|
||||||
|
args.u32(version);
|
||||||
|
args.u32(IPPROTO_TCP_XDR);
|
||||||
|
args.u32(0);
|
||||||
|
|
||||||
|
Bytes reply = rpc.call(PMAPPROC_GETPORT, args.data(), id);
|
||||||
|
XdrReader r(reply);
|
||||||
|
uint32_t port = r.u32();
|
||||||
|
if (port == 0 || port > 65535) {
|
||||||
|
throw Error("portmapper returned no TCP port");
|
||||||
|
}
|
||||||
|
return (unsigned short)port;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
98
src/rpc.cpp
Normal file
98
src/rpc.cpp
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
#include "rpc.hpp"
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
namespace retronfs {
|
||||||
|
|
||||||
|
static void append(Bytes& dst, const Bytes& src) {
|
||||||
|
dst.insert(dst.end(), src.begin(), src.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
RpcClient::RpcClient(const std::string& host, unsigned short port, uint32_t program, uint32_t version)
|
||||||
|
: host_(host), port_(port), program_(program), version_(version), xid_((uint32_t)std::time(0)) {}
|
||||||
|
|
||||||
|
Bytes RpcClient::make_call(uint32_t procedure, const Bytes& args, const RpcIdentity& identity, uint32_t xid) {
|
||||||
|
XdrWriter w;
|
||||||
|
w.u32(xid);
|
||||||
|
w.u32(0); // CALL
|
||||||
|
w.u32(2); // RPC version
|
||||||
|
w.u32(program_);
|
||||||
|
w.u32(version_);
|
||||||
|
w.u32(procedure);
|
||||||
|
|
||||||
|
XdrWriter cred;
|
||||||
|
cred.u32((uint32_t)std::time(0));
|
||||||
|
cred.str(identity.machine);
|
||||||
|
cred.u32(identity.uid);
|
||||||
|
cred.u32(identity.gid);
|
||||||
|
cred.u32((uint32_t)identity.groups.size());
|
||||||
|
for (unsigned i = 0; i < identity.groups.size(); ++i) cred.u32(identity.groups[i]);
|
||||||
|
|
||||||
|
w.u32(AUTH_SYS);
|
||||||
|
w.opaque(cred.data());
|
||||||
|
w.u32(AUTH_NONE);
|
||||||
|
w.u32(0);
|
||||||
|
|
||||||
|
Bytes out = w.data();
|
||||||
|
append(out, args);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bytes RpcClient::read_record(TcpSocket& sock) {
|
||||||
|
Bytes out;
|
||||||
|
bool last = false;
|
||||||
|
while (!last) {
|
||||||
|
Bytes marker = sock.recv_exact(4);
|
||||||
|
uint32_t m = ((uint32_t)marker[0] << 24) |
|
||||||
|
((uint32_t)marker[1] << 16) |
|
||||||
|
((uint32_t)marker[2] << 8) |
|
||||||
|
((uint32_t)marker[3]);
|
||||||
|
last = (m & 0x80000000U) != 0;
|
||||||
|
uint32_t len = m & 0x7fffffffU;
|
||||||
|
Bytes part = sock.recv_exact(len);
|
||||||
|
append(out, part);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bytes RpcClient::call(uint32_t procedure, const Bytes& args, const RpcIdentity& identity) {
|
||||||
|
uint32_t xid = ++xid_;
|
||||||
|
Bytes body = make_call(procedure, args, identity, xid);
|
||||||
|
|
||||||
|
XdrWriter record;
|
||||||
|
record.u32(0x80000000U | (uint32_t)body.size());
|
||||||
|
Bytes framed = record.data();
|
||||||
|
append(framed, body);
|
||||||
|
|
||||||
|
TcpSocket sock;
|
||||||
|
sock.connect_to(host_, port_, 8000);
|
||||||
|
sock.send_all(framed);
|
||||||
|
Bytes reply = read_record(sock);
|
||||||
|
|
||||||
|
XdrReader r(reply);
|
||||||
|
uint32_t rxid = r.u32();
|
||||||
|
if (rxid != xid) throw Error("RPC xid mismatch");
|
||||||
|
if (r.u32() != 1) throw Error("RPC reply was not REPLY");
|
||||||
|
uint32_t stat = r.u32();
|
||||||
|
if (stat != 0) throw Error("RPC message denied");
|
||||||
|
|
||||||
|
uint32_t verf_flavor = r.u32();
|
||||||
|
(void)verf_flavor;
|
||||||
|
Bytes verf = r.opaque();
|
||||||
|
(void)verf;
|
||||||
|
|
||||||
|
uint32_t accept = r.u32();
|
||||||
|
if (accept != 0) {
|
||||||
|
throw Error("RPC call rejected by server");
|
||||||
|
}
|
||||||
|
|
||||||
|
Bytes payload;
|
||||||
|
if (r.remaining()) {
|
||||||
|
Bytes rest = r.fixed_opaque(r.remaining());
|
||||||
|
payload.insert(payload.end(), rest.begin(), rest.end());
|
||||||
|
}
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
157
src/socket.cpp
Normal file
157
src/socket.cpp
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
#include "socket.hpp"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <cerrno>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <winsock2.h>
|
||||||
|
#include <ws2tcpip.h>
|
||||||
|
#else
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace retronfs {
|
||||||
|
|
||||||
|
std::string format_error(const std::string& what, int code) {
|
||||||
|
char buf[64];
|
||||||
|
::sprintf(buf, "%d", code);
|
||||||
|
return what + " failed with error " + buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
SocketSystem::SocketSystem() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
WSADATA data;
|
||||||
|
int rc = WSAStartup(MAKEWORD(2, 0), &data);
|
||||||
|
if (rc != 0) {
|
||||||
|
throw Error(format_error("WSAStartup", rc));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
SocketSystem::~SocketSystem() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
WSACleanup();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
TcpSocket::TcpSocket() : fd_(
|
||||||
|
#ifdef _WIN32
|
||||||
|
INVALID_SOCKET
|
||||||
|
#else
|
||||||
|
-1
|
||||||
|
#endif
|
||||||
|
) {}
|
||||||
|
|
||||||
|
TcpSocket::~TcpSocket() {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpSocket::connect_to(const std::string& host, unsigned short port, unsigned timeout_ms) {
|
||||||
|
close();
|
||||||
|
|
||||||
|
char portbuf[16];
|
||||||
|
::sprintf(portbuf, "%u", (unsigned)port);
|
||||||
|
|
||||||
|
struct addrinfo hints;
|
||||||
|
std::memset(&hints, 0, sizeof(hints));
|
||||||
|
hints.ai_family = AF_INET;
|
||||||
|
hints.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
|
struct addrinfo* result = 0;
|
||||||
|
int rc = getaddrinfo(host.c_str(), portbuf, &hints, &result);
|
||||||
|
if (rc != 0 || !result) {
|
||||||
|
throw Error("could not resolve host " + host);
|
||||||
|
}
|
||||||
|
|
||||||
|
fd_ = (int)::socket(result->ai_family, result->ai_socktype, result->ai_protocol);
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (fd_ == INVALID_SOCKET) {
|
||||||
|
freeaddrinfo(result);
|
||||||
|
throw Error(format_error("socket", WSAGetLastError()));
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (fd_ < 0) {
|
||||||
|
freeaddrinfo(result);
|
||||||
|
throw Error(format_error("socket", errno));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
unsigned seconds = timeout_ms / 1000;
|
||||||
|
if (seconds == 0) seconds = 1;
|
||||||
|
#ifdef _WIN32
|
||||||
|
DWORD tv = seconds * 1000;
|
||||||
|
setsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof(tv));
|
||||||
|
setsockopt(fd_, SOL_SOCKET, SO_SNDTIMEO, (const char*)&tv, sizeof(tv));
|
||||||
|
#else
|
||||||
|
struct timeval tv;
|
||||||
|
tv.tv_sec = seconds;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
setsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
||||||
|
setsockopt(fd_, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rc = ::connect(fd_, result->ai_addr, (int)result->ai_addrlen);
|
||||||
|
freeaddrinfo(result);
|
||||||
|
if (rc != 0) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
int err = WSAGetLastError();
|
||||||
|
#else
|
||||||
|
int err = errno;
|
||||||
|
#endif
|
||||||
|
close();
|
||||||
|
throw Error(format_error("connect", err));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpSocket::send_all(const Bytes& data) {
|
||||||
|
unsigned sent = 0;
|
||||||
|
while (sent < data.size()) {
|
||||||
|
int rc = ::send(fd_, (const char*)&data[sent], (int)(data.size() - sent), 0);
|
||||||
|
if (rc <= 0) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
throw Error(format_error("send", WSAGetLastError()));
|
||||||
|
#else
|
||||||
|
throw Error(format_error("send", errno));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
sent += (unsigned)rc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Bytes TcpSocket::recv_exact(unsigned count) {
|
||||||
|
Bytes out(count);
|
||||||
|
unsigned got = 0;
|
||||||
|
while (got < count) {
|
||||||
|
int rc = ::recv(fd_, (char*)&out[got], (int)(count - got), 0);
|
||||||
|
if (rc <= 0) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
throw Error(format_error("recv", WSAGetLastError()));
|
||||||
|
#else
|
||||||
|
throw Error(format_error("recv", errno));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
got += (unsigned)rc;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpSocket::close() {
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (fd_ != INVALID_SOCKET) {
|
||||||
|
closesocket(fd_);
|
||||||
|
fd_ = INVALID_SOCKET;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (fd_ >= 0) {
|
||||||
|
::close(fd_);
|
||||||
|
fd_ = -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
100
src/xdr.cpp
Normal file
100
src/xdr.cpp
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
#include "xdr.hpp"
|
||||||
|
|
||||||
|
namespace retronfs {
|
||||||
|
|
||||||
|
void XdrWriter::pad(unsigned len) {
|
||||||
|
unsigned p = (4 - (len & 3)) & 3;
|
||||||
|
while (p--) out_.push_back(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XdrWriter::u32(uint32_t v) {
|
||||||
|
out_.push_back((byte)((v >> 24) & 0xff));
|
||||||
|
out_.push_back((byte)((v >> 16) & 0xff));
|
||||||
|
out_.push_back((byte)((v >> 8) & 0xff));
|
||||||
|
out_.push_back((byte)(v & 0xff));
|
||||||
|
}
|
||||||
|
|
||||||
|
void XdrWriter::u64(uint64_t v) {
|
||||||
|
u32((uint32_t)(v >> 32));
|
||||||
|
u32((uint32_t)(v & 0xffffffffU));
|
||||||
|
}
|
||||||
|
|
||||||
|
void XdrWriter::opaque(const Bytes& data) {
|
||||||
|
u32((uint32_t)data.size());
|
||||||
|
fixed_opaque(data.empty() ? 0 : &data[0], (unsigned)data.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void XdrWriter::fixed_opaque(const byte* data, unsigned len) {
|
||||||
|
for (unsigned i = 0; i < len; ++i) out_.push_back(data[i]);
|
||||||
|
pad(len);
|
||||||
|
}
|
||||||
|
|
||||||
|
void XdrWriter::str(const std::string& value) {
|
||||||
|
u32((uint32_t)value.size());
|
||||||
|
for (unsigned i = 0; i < value.size(); ++i) out_.push_back((byte)value[i]);
|
||||||
|
pad((unsigned)value.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
const Bytes& XdrWriter::data() const {
|
||||||
|
return out_;
|
||||||
|
}
|
||||||
|
|
||||||
|
XdrReader::XdrReader(const Bytes& data) : in_(data), pos_(0) {}
|
||||||
|
|
||||||
|
void XdrReader::require(unsigned n) {
|
||||||
|
if (pos_ + n > in_.size()) {
|
||||||
|
throw Error("truncated XDR stream");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void XdrReader::skip_pad(unsigned len) {
|
||||||
|
unsigned p = (4 - (len & 3)) & 3;
|
||||||
|
require(p);
|
||||||
|
pos_ += p;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t XdrReader::u32() {
|
||||||
|
require(4);
|
||||||
|
uint32_t v = ((uint32_t)in_[pos_] << 24) |
|
||||||
|
((uint32_t)in_[pos_ + 1] << 16) |
|
||||||
|
((uint32_t)in_[pos_ + 2] << 8) |
|
||||||
|
((uint32_t)in_[pos_ + 3]);
|
||||||
|
pos_ += 4;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t XdrReader::u64() {
|
||||||
|
uint64_t hi = u32();
|
||||||
|
uint64_t lo = u32();
|
||||||
|
return (hi << 32) | lo;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bytes XdrReader::opaque() {
|
||||||
|
unsigned len = u32();
|
||||||
|
return fixed_opaque(len);
|
||||||
|
}
|
||||||
|
|
||||||
|
Bytes XdrReader::fixed_opaque(unsigned len) {
|
||||||
|
require(len);
|
||||||
|
Bytes out;
|
||||||
|
out.insert(out.end(), in_.begin() + pos_, in_.begin() + pos_ + len);
|
||||||
|
pos_ += len;
|
||||||
|
skip_pad(len);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string XdrReader::str() {
|
||||||
|
Bytes data = opaque();
|
||||||
|
return std::string(data.begin(), data.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool XdrReader::eof() const {
|
||||||
|
return pos_ >= in_.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned XdrReader::remaining() const {
|
||||||
|
return (unsigned)(in_.size() - pos_);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
2
toolchain/DDK-9x-ME-SHA256SUMS.txt
Normal file
2
toolchain/DDK-9x-ME-SHA256SUMS.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
e696e04d30dd4211a3d96e714dcbdcfadaaf662007c6748a30671f1021951f0b 95DDK.RAR
|
||||||
|
bb8a97292d68035b7f6ad23f5a2ecbb3e621125af756a46bbdcfd23c56713801 98DDK.RAR
|
||||||
138
tools/build-vxd-watcom.sh
Executable file
138
tools/build-vxd-watcom.sh
Executable file
@@ -0,0 +1,138 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
if [ $# -lt 1 ]; then
|
||||||
|
echo "Usage: $0 /path/to/win98ddk" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
DDK=$1
|
||||||
|
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||||
|
|
||||||
|
if [ -d /opt/openwatcom-v2/binl ]; then
|
||||||
|
export WATCOM=${WATCOM:-/opt/openwatcom-v2}
|
||||||
|
export PATH="$WATCOM/binl:$PATH"
|
||||||
|
export EDPATH=${EDPATH:-$WATCOM/eddat}
|
||||||
|
export INCLUDE=${INCLUDE:-$WATCOM/h:$WATCOM/h/nt}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v wcc386 >/dev/null 2>&1; then
|
||||||
|
echo "Open Watcom wcc386 not found in PATH." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v wlink >/dev/null 2>&1; then
|
||||||
|
echo "Open Watcom wlink not found in PATH." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
ASM=${ASM:-}
|
||||||
|
if [ -z "$ASM" ]; then
|
||||||
|
if command -v jwasm >/dev/null 2>&1; then
|
||||||
|
ASM=jwasm
|
||||||
|
elif command -v wasm >/dev/null 2>&1; then
|
||||||
|
ASM=wasm
|
||||||
|
else
|
||||||
|
echo "No compatible assembler found. Install jwasm or Open Watcom wasm." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
VXD_OBJ_FORMAT=${VXD_OBJ_FORMAT:-omf}
|
||||||
|
case "$VXD_OBJ_FORMAT" in
|
||||||
|
omf|coff) ;;
|
||||||
|
*)
|
||||||
|
echo "Unsupported VXD_OBJ_FORMAT=$VXD_OBJ_FORMAT; use omf or coff." >&2
|
||||||
|
exit 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
VXD_IFSMGR_REGISTER=${VXD_IFSMGR_REGISTER:-real}
|
||||||
|
case "$VXD_IFSMGR_REGISTER" in
|
||||||
|
real|prepared) ;;
|
||||||
|
*)
|
||||||
|
echo "Unsupported VXD_IFSMGR_REGISTER=$VXD_IFSMGR_REGISTER; use real or prepared." >&2
|
||||||
|
exit 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ ! -d "$DDK/inc" ] && [ ! -d "$DDK/INC" ]; then
|
||||||
|
echo "Windows 98 DDK include directory not found below: $DDK" >&2
|
||||||
|
echo "Provide a real Windows 98 DDK path, for example /opt/win98ddk." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
DDK_INC="$DDK/inc"
|
||||||
|
[ -d "$DDK_INC" ] || DDK_INC="$DDK/INC"
|
||||||
|
|
||||||
|
mkdir -p "$ROOT/vxd/build"
|
||||||
|
|
||||||
|
echo "Compiling VxD skeleton with Open Watcom..."
|
||||||
|
echo "DDK path: $DDK"
|
||||||
|
echo "Assembler: $ASM"
|
||||||
|
echo "Assembler object format: $VXD_OBJ_FORMAT"
|
||||||
|
echo "IFSMgr registration mode: $VXD_IFSMGR_REGISTER"
|
||||||
|
|
||||||
|
WCC_IFSMGR_FLAGS=
|
||||||
|
if [ "$VXD_IFSMGR_REGISTER" = "real" ]; then
|
||||||
|
WCC_IFSMGR_FLAGS="-dRETRO_ENABLE_REAL_IFSMGR_REGISTER"
|
||||||
|
fi
|
||||||
|
|
||||||
|
wcc386 "$ROOT/vxd/retrovxd.c" \
|
||||||
|
-q -bt=windows -d1 -zq -s -5s -zu $WCC_IFSMGR_FLAGS \
|
||||||
|
-I"$DDK_INC" -fo="$ROOT/vxd/build/retrovxd.obj"
|
||||||
|
|
||||||
|
case "$(basename "$ASM")" in
|
||||||
|
jwasm|jwasm.exe|uasm|uasm.exe)
|
||||||
|
"$ASM" -nologo -c "-$VXD_OBJ_FORMAT" -Cp -Zm -3p \
|
||||||
|
-I"$DDK_INC" \
|
||||||
|
-Fo"$ROOT/vxd/build/retroctrl.obj" \
|
||||||
|
"$ROOT/vxd/retroctrl.asm"
|
||||||
|
;;
|
||||||
|
wasm|wasm.exe)
|
||||||
|
if [ "$VXD_OBJ_FORMAT" != "omf" ]; then
|
||||||
|
echo "Open Watcom wasm emits OMF; use ASM=jwasm for VXD_OBJ_FORMAT=coff." >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
"$ASM" "$ROOT/vxd/retroctrl.asm" \
|
||||||
|
-q -zq -Cp -Zm -3p -I"$DDK_INC" -fo="$ROOT/vxd/build/retroctrl.obj"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown assembler '$ASM'; set ASM=jwasm or ASM=wasm." >&2
|
||||||
|
exit 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ ! -s "$ROOT/vxd/build/retroctrl.obj" ]; then
|
||||||
|
echo "Assembler did not create $ROOT/vxd/build/retroctrl.obj." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat > "$ROOT/vxd/build/retrovxd.lnk" <<EOF
|
||||||
|
system win_vxd
|
||||||
|
name $ROOT/vxd/build/RETROVXD.VXD
|
||||||
|
file $ROOT/vxd/build/retrovxd.obj
|
||||||
|
file $ROOT/vxd/build/retroctrl.obj
|
||||||
|
export RETROVXD_DDB
|
||||||
|
option modname=RETROVXD
|
||||||
|
option osname='Windows VxD'
|
||||||
|
option map=$ROOT/vxd/build/RETROVXD.MAP
|
||||||
|
option description 'RetroNFS95 Windows 95/98 Redirector VxD'
|
||||||
|
option quiet
|
||||||
|
EOF
|
||||||
|
|
||||||
|
wlink @"$ROOT/vxd/build/retrovxd.lnk"
|
||||||
|
|
||||||
|
echo "Built $ROOT/vxd/build/RETROVXD.VXD"
|
||||||
|
echo "Note: IFSMgr dispatch is read-only scaffold code; live Win95/98 validation is still required."
|
||||||
|
|
||||||
|
mkdir -p "$ROOT/dist"
|
||||||
|
cp "$ROOT/vxd/build/RETROVXD.VXD" "$ROOT/dist/RETROVXD.VXD"
|
||||||
|
if [ -f "$ROOT/dist/SHA256SUMS.txt" ]; then
|
||||||
|
(
|
||||||
|
cd "$ROOT"
|
||||||
|
grep -v ' dist/RETROVXD.VXD$' dist/SHA256SUMS.txt > dist/SHA256SUMS.tmp
|
||||||
|
sha256sum dist/RETROVXD.VXD >> dist/SHA256SUMS.tmp
|
||||||
|
mv dist/SHA256SUMS.tmp dist/SHA256SUMS.txt
|
||||||
|
)
|
||||||
|
fi
|
||||||
98
tools/build-win32-mingw.sh
Executable file
98
tools/build-win32-mingw.sh
Executable file
@@ -0,0 +1,98 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||||
|
|
||||||
|
CXX=${CXX:-}
|
||||||
|
if [ -z "$CXX" ]; then
|
||||||
|
if command -v i586-mingw32msvc-g++ >/dev/null 2>&1; then
|
||||||
|
CXX=i586-mingw32msvc-g++
|
||||||
|
elif command -v i686-w64-mingw32-g++ >/dev/null 2>&1; then
|
||||||
|
CXX=i686-w64-mingw32-g++
|
||||||
|
elif command -v mingw32-g++ >/dev/null 2>&1; then
|
||||||
|
CXX=mingw32-g++
|
||||||
|
else
|
||||||
|
echo "No MinGW C++ compiler found." >&2
|
||||||
|
echo "Install an old/Win9x-capable MinGW or set CXX=/path/to/compiler." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Using CXX=$CXX"
|
||||||
|
|
||||||
|
mkdir -p "$ROOT/bin" "$ROOT/obj"
|
||||||
|
|
||||||
|
COMMON_CXXFLAGS="-Os -Wall -Wextra -std=c++98 -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0400 -DWINVER=0x0400"
|
||||||
|
COMMON_LDFLAGS="-static-libgcc -static-libstdc++"
|
||||||
|
|
||||||
|
"$CXX" $COMMON_CXXFLAGS -I"$ROOT/include" \
|
||||||
|
-c "$ROOT/src/main.cpp" -o "$ROOT/obj/main.win32.o"
|
||||||
|
"$CXX" $COMMON_CXXFLAGS -I"$ROOT/include" \
|
||||||
|
-c "$ROOT/src/socket.cpp" -o "$ROOT/obj/socket.win32.o"
|
||||||
|
"$CXX" $COMMON_CXXFLAGS -I"$ROOT/include" \
|
||||||
|
-c "$ROOT/src/xdr.cpp" -o "$ROOT/obj/xdr.win32.o"
|
||||||
|
"$CXX" $COMMON_CXXFLAGS -I"$ROOT/include" \
|
||||||
|
-c "$ROOT/src/rpc.cpp" -o "$ROOT/obj/rpc.win32.o"
|
||||||
|
"$CXX" $COMMON_CXXFLAGS -I"$ROOT/include" \
|
||||||
|
-c "$ROOT/src/portmap.cpp" -o "$ROOT/obj/portmap.win32.o"
|
||||||
|
"$CXX" $COMMON_CXXFLAGS -I"$ROOT/include" \
|
||||||
|
-c "$ROOT/src/mount.cpp" -o "$ROOT/obj/mount.win32.o"
|
||||||
|
"$CXX" $COMMON_CXXFLAGS -I"$ROOT/include" \
|
||||||
|
-c "$ROOT/src/nfs.cpp" -o "$ROOT/obj/nfs.win32.o"
|
||||||
|
"$CXX" $COMMON_CXXFLAGS -I"$ROOT/include" \
|
||||||
|
-c "$ROOT/src/path.cpp" -o "$ROOT/obj/path.win32.o"
|
||||||
|
|
||||||
|
"$CXX" -o "$ROOT/bin/retronfs95.exe" \
|
||||||
|
"$ROOT/obj/main.win32.o" \
|
||||||
|
"$ROOT/obj/socket.win32.o" \
|
||||||
|
"$ROOT/obj/xdr.win32.o" \
|
||||||
|
"$ROOT/obj/rpc.win32.o" \
|
||||||
|
"$ROOT/obj/portmap.win32.o" \
|
||||||
|
"$ROOT/obj/mount.win32.o" \
|
||||||
|
"$ROOT/obj/nfs.win32.o" \
|
||||||
|
"$ROOT/obj/path.win32.o" \
|
||||||
|
$COMMON_LDFLAGS -lws2_32
|
||||||
|
|
||||||
|
"$CXX" $COMMON_CXXFLAGS \
|
||||||
|
-o "$ROOT/mounter/RetroMap95.exe" "$ROOT/mounter/retromap95.cpp" $COMMON_LDFLAGS -lmpr
|
||||||
|
|
||||||
|
"$CXX" $COMMON_CXXFLAGS -shared \
|
||||||
|
-Wl,--enable-stdcall-fixup \
|
||||||
|
-o "$ROOT/provider/RETRONP.DLL" \
|
||||||
|
"$ROOT/provider/retronp.cpp" "$ROOT/provider/retronp.def" $COMMON_LDFLAGS -lmpr
|
||||||
|
|
||||||
|
echo "Built:"
|
||||||
|
echo " $ROOT/bin/retronfs95.exe"
|
||||||
|
echo " $ROOT/mounter/RetroMap95.exe"
|
||||||
|
echo " $ROOT/provider/RETRONP.DLL"
|
||||||
|
|
||||||
|
mkdir -p "$ROOT/dist"
|
||||||
|
cp "$ROOT/bin/retronfs95.exe" "$ROOT/dist/retronfs95.exe"
|
||||||
|
cp "$ROOT/mounter/RetroMap95.exe" "$ROOT/dist/RetroMap95.exe"
|
||||||
|
cp "$ROOT/provider/RETRONP.DLL" "$ROOT/dist/RETRONP.DLL"
|
||||||
|
cp "$ROOT/install/RETRO95.INF" "$ROOT/dist/RETRO95.INF"
|
||||||
|
cp "$ROOT/install/retronfs95.reg" "$ROOT/dist/retronfs95.reg"
|
||||||
|
|
||||||
|
(
|
||||||
|
cd "$ROOT"
|
||||||
|
sha256sum \
|
||||||
|
dist/RETRO95.INF \
|
||||||
|
$(test -f dist/RETROVXD.VXD && printf '%s\n' dist/RETROVXD.VXD) \
|
||||||
|
dist/RETRONP.DLL \
|
||||||
|
dist/RetroMap95.exe \
|
||||||
|
dist/retronfs95.exe \
|
||||||
|
dist/retronfs95.reg > dist/SHA256SUMS.txt
|
||||||
|
if command -v zip >/dev/null 2>&1; then
|
||||||
|
zip -j -q dist/RetroNFS95-win32-artifacts.zip \
|
||||||
|
dist/RETRO95.INF \
|
||||||
|
$(test -f dist/RETROVXD.VXD && printf '%s\n' dist/RETROVXD.VXD) \
|
||||||
|
dist/RETRONP.DLL \
|
||||||
|
dist/RetroMap95.exe \
|
||||||
|
dist/retronfs95.exe \
|
||||||
|
dist/retronfs95.reg \
|
||||||
|
dist/SHA256SUMS.txt
|
||||||
|
fi
|
||||||
|
)
|
||||||
|
|
||||||
|
echo "Packaged:"
|
||||||
|
echo " $ROOT/dist/RetroNFS95-win32-artifacts.zip"
|
||||||
6
tools/openwatcom-env.sh
Executable file
6
tools/openwatcom-env.sh
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
export WATCOM=/opt/openwatcom-v2
|
||||||
|
export PATH="$WATCOM/binl:$PATH"
|
||||||
|
export EDPATH="$WATCOM/eddat"
|
||||||
|
export INCLUDE="$WATCOM/h:$WATCOM/h/nt"
|
||||||
|
|
||||||
7
tools/test-linux.sh
Executable file
7
tools/test-linux.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
make -f Makefile.posix
|
||||||
|
echo "Built bin/retronfs95"
|
||||||
|
echo "Try: bin/retronfs95 ls 127.0.0.1 /srv/retro /"
|
||||||
|
|
||||||
12
vxd/Makefile
Normal file
12
vxd/Makefile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
DDK ?= /opt/win98ddk
|
||||||
|
ASM ?= jwasm
|
||||||
|
VXD_OBJ_FORMAT ?= omf
|
||||||
|
VXD_IFSMGR_REGISTER ?= real
|
||||||
|
|
||||||
|
.PHONY: all clean
|
||||||
|
|
||||||
|
all:
|
||||||
|
ASM="$(ASM)" VXD_OBJ_FORMAT="$(VXD_OBJ_FORMAT)" VXD_IFSMGR_REGISTER="$(VXD_IFSMGR_REGISTER)" ../tools/build-vxd-watcom.sh "$(DDK)"
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf build
|
||||||
18
vxd/RETROVXD.DEF
Normal file
18
vxd/RETROVXD.DEF
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
VXD RETROVXD DYNAMIC
|
||||||
|
DESCRIPTION 'RetroNFS95 Windows 95/98 Redirector VxD'
|
||||||
|
SEGMENTS
|
||||||
|
_LPTEXT CLASS 'LCODE' PRELOAD NONDISCARDABLE
|
||||||
|
_LTEXT CLASS 'LCODE' PRELOAD NONDISCARDABLE
|
||||||
|
_LDATA CLASS 'LDATA' PRELOAD NONDISCARDABLE
|
||||||
|
_TEXT CLASS 'LCODE' PRELOAD NONDISCARDABLE
|
||||||
|
_DATA CLASS 'LCODE' PRELOAD NONDISCARDABLE
|
||||||
|
CONST CLASS 'LCODE' PRELOAD NONDISCARDABLE
|
||||||
|
_BSS CLASS 'LCODE' PRELOAD NONDISCARDABLE
|
||||||
|
_ITEXT CLASS 'ICODE' DISCARDABLE
|
||||||
|
_IDATA CLASS 'ICODE' DISCARDABLE
|
||||||
|
_STEXT CLASS 'SCODE' RESIDENT
|
||||||
|
_SDATA CLASS 'SCODE' RESIDENT
|
||||||
|
_16ICODE CLASS '16ICODE' PRELOAD DISCARDABLE
|
||||||
|
_RCODE CLASS 'RCODE'
|
||||||
|
EXPORTS
|
||||||
|
RETROVXD_DDB @1
|
||||||
15
vxd/SOURCES.txt
Normal file
15
vxd/SOURCES.txt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
RETROVXD is a Windows 95/98 DDK target.
|
||||||
|
|
||||||
|
Required SDK/DDK:
|
||||||
|
- Windows 98 DDK or Windows 95 DDK
|
||||||
|
- MASM/ML and DDK build environment
|
||||||
|
- IFSMgr headers/libs from the DDK
|
||||||
|
|
||||||
|
Expected production sources:
|
||||||
|
- retrovxd.c VxD control and IOCTL channel
|
||||||
|
- ifs_dispatch.c IFSMgr/FSD dispatch table
|
||||||
|
- drive_table.c drive-letter and NFS mount state
|
||||||
|
- nfs_bridge.c bridge to shared NFS core
|
||||||
|
|
||||||
|
This repository currently provides retrovxd.c as the VxD entry skeleton.
|
||||||
|
|
||||||
169
vxd/retroctrl.asm
Normal file
169
vxd/retroctrl.asm
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
; RetroNFS95 VxD control stub.
|
||||||
|
;
|
||||||
|
; This file intentionally does not include the Win98 DDK vmm.inc. The stock
|
||||||
|
; DDK macro layer uses old MASM concatenation forms that JWasm rejects. The
|
||||||
|
; stub below defines only the constants, DDB layout, segments, and dispatcher
|
||||||
|
; glue RetroNFS95 needs.
|
||||||
|
|
||||||
|
PAGE 58,132
|
||||||
|
TITLE RETROCTRL - RetroNFS95 VxD Control Dispatch
|
||||||
|
|
||||||
|
.386p
|
||||||
|
OPTION CASEMAP:NONE
|
||||||
|
|
||||||
|
RETROVXD_DEVICE_ID EQU 03F42h
|
||||||
|
RETROVXD_MAJOR EQU 1
|
||||||
|
RETROVXD_MINOR EQU 0
|
||||||
|
DDK_VERSION EQU 040Ah
|
||||||
|
UNDEFINED_INIT_ORDER EQU 080000000h
|
||||||
|
DDB_DYNAMIC_VXD EQU 08000h
|
||||||
|
|
||||||
|
SYS_DYNAMIC_DEVICE_INIT EQU 001Bh
|
||||||
|
SYS_DYNAMIC_DEVICE_EXIT EQU 001Ch
|
||||||
|
W32_DEVICEIOCONTROL EQU 0023h
|
||||||
|
DEVICE_LOAD_OK EQU 0
|
||||||
|
|
||||||
|
VxD_Desc_Block STRUC
|
||||||
|
DDB_Next DD ?
|
||||||
|
DDB_SDK_Version DW ?
|
||||||
|
DDB_Req_Device_Number DW ?
|
||||||
|
DDB_Dev_Major_Version DB ?
|
||||||
|
DDB_Dev_Minor_Version DB ?
|
||||||
|
DDB_Flags DW ?
|
||||||
|
DDB_Name DB 8 DUP (?)
|
||||||
|
DDB_Init_Order DD ?
|
||||||
|
DDB_Control_Proc DD ?
|
||||||
|
DDB_V86_API_Proc DD ?
|
||||||
|
DDB_PM_API_Proc DD ?
|
||||||
|
DDB_V86_API_CSIP DD ?
|
||||||
|
DDB_PM_API_CSIP DD ?
|
||||||
|
DDB_Reference_Data DD ?
|
||||||
|
DDB_Service_Table_Ptr DD ?
|
||||||
|
DDB_Service_Table_Size DD ?
|
||||||
|
DDB_Win32_Service_Table DD ?
|
||||||
|
DDB_Prev DD ?
|
||||||
|
DDB_Size DD ?
|
||||||
|
DDB_Reserved1 DD ?
|
||||||
|
DDB_Reserved2 DD ?
|
||||||
|
DDB_Reserved3 DD ?
|
||||||
|
VxD_Desc_Block ENDS
|
||||||
|
|
||||||
|
EXTRN _RETROVXD_Dynamic_Init@0:NEAR
|
||||||
|
EXTRN _RETROVXD_Dynamic_Exit@0:NEAR
|
||||||
|
EXTRN _RETROVXD_W32_DeviceIoControl@16:NEAR
|
||||||
|
|
||||||
|
_LTEXT SEGMENT DWORD PUBLIC USE32 'LCODE'
|
||||||
|
ASSUME CS:FLAT, DS:FLAT, ES:FLAT, SS:FLAT
|
||||||
|
|
||||||
|
PUBLIC RETROVXD_Control
|
||||||
|
RETROVXD_Control PROC NEAR
|
||||||
|
cmp eax, SYS_DYNAMIC_DEVICE_INIT
|
||||||
|
je short control_dynamic_init
|
||||||
|
|
||||||
|
cmp eax, SYS_DYNAMIC_DEVICE_EXIT
|
||||||
|
je short control_dynamic_exit
|
||||||
|
|
||||||
|
cmp eax, W32_DEVICEIOCONTROL
|
||||||
|
je short control_w32_deviceiocontrol
|
||||||
|
|
||||||
|
clc
|
||||||
|
ret
|
||||||
|
|
||||||
|
control_dynamic_init:
|
||||||
|
call _RETROVXD_Dynamic_Init@0
|
||||||
|
cmp eax, 1
|
||||||
|
ret
|
||||||
|
|
||||||
|
control_dynamic_exit:
|
||||||
|
call _RETROVXD_Dynamic_Exit@0
|
||||||
|
cmp eax, 1
|
||||||
|
ret
|
||||||
|
|
||||||
|
control_w32_deviceiocontrol:
|
||||||
|
push esi
|
||||||
|
push edx
|
||||||
|
push ebx
|
||||||
|
push ecx
|
||||||
|
call _RETROVXD_W32_DeviceIoControl@16
|
||||||
|
clc
|
||||||
|
ret
|
||||||
|
RETROVXD_Control ENDP
|
||||||
|
|
||||||
|
PUBLIC _RETROVXD_IFSMgr_Register@4
|
||||||
|
_RETROVXD_IFSMgr_Register@4 PROC NEAR
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
mov edx, [ebp+8]
|
||||||
|
int 20h
|
||||||
|
DD 00400001h
|
||||||
|
jc short ifsmgr_register_failed
|
||||||
|
mov eax, 1
|
||||||
|
jmp short ifsmgr_register_done
|
||||||
|
ifsmgr_register_failed:
|
||||||
|
xor eax, eax
|
||||||
|
ifsmgr_register_done:
|
||||||
|
pop ebp
|
||||||
|
ret 4
|
||||||
|
_RETROVXD_IFSMgr_Register@4 ENDP
|
||||||
|
|
||||||
|
PUBLIC _RETROVXD_IFSMgr_Deregister@4
|
||||||
|
_RETROVXD_IFSMgr_Deregister@4 PROC NEAR
|
||||||
|
push ebp
|
||||||
|
mov ebp, esp
|
||||||
|
mov edx, [ebp+8]
|
||||||
|
int 20h
|
||||||
|
DD 00400002h
|
||||||
|
jc short ifsmgr_deregister_failed
|
||||||
|
mov eax, 1
|
||||||
|
jmp short ifsmgr_deregister_done
|
||||||
|
ifsmgr_deregister_failed:
|
||||||
|
xor eax, eax
|
||||||
|
ifsmgr_deregister_done:
|
||||||
|
pop ebp
|
||||||
|
ret 4
|
||||||
|
_RETROVXD_IFSMgr_Deregister@4 ENDP
|
||||||
|
|
||||||
|
_LTEXT ENDS
|
||||||
|
|
||||||
|
_LDATA SEGMENT DWORD PUBLIC USE32 'LCODE'
|
||||||
|
PUBLIC RETROVXD_DDB
|
||||||
|
RETROVXD_DDB LABEL BYTE
|
||||||
|
DD 0
|
||||||
|
DW DDK_VERSION
|
||||||
|
DW RETROVXD_DEVICE_ID
|
||||||
|
DB RETROVXD_MAJOR
|
||||||
|
DB RETROVXD_MINOR
|
||||||
|
DW DDB_DYNAMIC_VXD
|
||||||
|
DB "RETROVXD"
|
||||||
|
DD UNDEFINED_INIT_ORDER
|
||||||
|
DD OFFSET RETROVXD_Control
|
||||||
|
DD 0
|
||||||
|
DD 0
|
||||||
|
DD 0
|
||||||
|
DD 0
|
||||||
|
DD 0
|
||||||
|
DD 0
|
||||||
|
DD 0
|
||||||
|
DD 0
|
||||||
|
DD 'Prev'
|
||||||
|
DD SIZEOF VxD_Desc_Block
|
||||||
|
DD 'Rsv1'
|
||||||
|
DD 'Rsv2'
|
||||||
|
DD 'Rsv3'
|
||||||
|
_LDATA ENDS
|
||||||
|
|
||||||
|
_RCODE SEGMENT WORD PUBLIC USE16 'RCODE'
|
||||||
|
ASSUME CS:_RCODE, DS:_RCODE, ES:_RCODE, SS:_RCODE
|
||||||
|
|
||||||
|
PUBLIC RETROVXD_Real_Init
|
||||||
|
RETROVXD_Real_Init PROC NEAR
|
||||||
|
xor bx, bx
|
||||||
|
xor si, si
|
||||||
|
xor edx, edx
|
||||||
|
mov ax, DEVICE_LOAD_OK
|
||||||
|
ret
|
||||||
|
RETROVXD_Real_Init ENDP
|
||||||
|
|
||||||
|
_RCODE ENDS
|
||||||
|
|
||||||
|
END RETROVXD_Real_Init
|
||||||
661
vxd/retrovxd.c
Normal file
661
vxd/retrovxd.c
Normal file
@@ -0,0 +1,661 @@
|
|||||||
|
/*
|
||||||
|
* RetroNFS95 VxD C half.
|
||||||
|
*
|
||||||
|
* This module owns the Win9x-side mapping table and the DeviceIoControl
|
||||||
|
* contract used by RETRONP.DLL. The remaining DDK-dependent step is wiring
|
||||||
|
* these mappings into IFSMgr's network FSD dispatch path.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "../include/retro_ioctl.h"
|
||||||
|
|
||||||
|
typedef unsigned long DWORD;
|
||||||
|
typedef int BOOL;
|
||||||
|
|
||||||
|
#ifdef __WATCOMC__
|
||||||
|
#define RETRO_FAR __far
|
||||||
|
#else
|
||||||
|
#define RETRO_FAR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TRUE 1
|
||||||
|
#define FALSE 0
|
||||||
|
#define NO_ERROR 0
|
||||||
|
#define ERROR_INVALID_PARAMETER 87
|
||||||
|
#define ERROR_NOT_SUPPORTED 50
|
||||||
|
#define ERROR_NOT_CONNECTED 2250
|
||||||
|
#define ERROR_INVALID_FUNCTION 1
|
||||||
|
#define ERROR_TOO_MANY_OPEN_FILES 4
|
||||||
|
#define ERROR_ACCESS_DENIED 5
|
||||||
|
#define ERROR_NO_MORE_FILES 18
|
||||||
|
|
||||||
|
#define DIOC_OPEN 0xffffffffUL
|
||||||
|
#define DIOC_CLOSEHANDLE 0xfffffffeUL
|
||||||
|
|
||||||
|
#define IFSMGR_DEVICE_ID 0x0040
|
||||||
|
#define RETRO_FSD_ORDINAL 1
|
||||||
|
|
||||||
|
#ifndef IFSFN_CONNECT
|
||||||
|
#define IFSFN_CONNECT 0x00
|
||||||
|
#endif
|
||||||
|
#ifndef IFSFN_DISCONNECT
|
||||||
|
#define IFSFN_DISCONNECT 0x01
|
||||||
|
#endif
|
||||||
|
#ifndef IFSFN_OPEN
|
||||||
|
#define IFSFN_OPEN 0x02
|
||||||
|
#endif
|
||||||
|
#ifndef IFSFN_CLOSE
|
||||||
|
#define IFSFN_CLOSE 0x03
|
||||||
|
#endif
|
||||||
|
#ifndef IFSFN_READ
|
||||||
|
#define IFSFN_READ 0x04
|
||||||
|
#endif
|
||||||
|
#ifndef IFSFN_WRITE
|
||||||
|
#define IFSFN_WRITE 0x05
|
||||||
|
#endif
|
||||||
|
#ifndef IFSFN_FINDNEXT
|
||||||
|
#define IFSFN_FINDNEXT 0x0b
|
||||||
|
#endif
|
||||||
|
#ifndef IFSFN_FINDFIRST
|
||||||
|
#define IFSFN_FINDFIRST 0x0e
|
||||||
|
#endif
|
||||||
|
#ifndef IFSFN_GETDISKINFO
|
||||||
|
#define IFSFN_GETDISKINFO 0x18
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define RETRO_IFS_SUCCESS 0
|
||||||
|
#define RETRO_IFS_ERROR 0xffffffffUL
|
||||||
|
#define RETRO_MAX_OPEN_FILES 64
|
||||||
|
#define RETRO_MAX_PATH_LEN 260
|
||||||
|
|
||||||
|
typedef struct DIOCPARAMETERS {
|
||||||
|
DWORD dwIoControlCode;
|
||||||
|
void RETRO_FAR* lpvInBuffer;
|
||||||
|
DWORD cbInBuffer;
|
||||||
|
void RETRO_FAR* lpvOutBuffer;
|
||||||
|
DWORD cbOutBuffer;
|
||||||
|
DWORD RETRO_FAR* lpcbBytesReturned;
|
||||||
|
void RETRO_FAR* lpoOverlapped;
|
||||||
|
} DIOCPARAMETERS;
|
||||||
|
|
||||||
|
typedef struct RETRO_MAPPING_SLOT {
|
||||||
|
int used;
|
||||||
|
RETRO_MAPPING_INFO info;
|
||||||
|
} RETRO_MAPPING_SLOT;
|
||||||
|
|
||||||
|
typedef struct IFS_PARM {
|
||||||
|
unsigned short ip_fsd;
|
||||||
|
unsigned short ip_func;
|
||||||
|
unsigned long ip_result;
|
||||||
|
unsigned long ip_drv;
|
||||||
|
unsigned long ip_user;
|
||||||
|
unsigned long ip_pid;
|
||||||
|
} IFS_PARM;
|
||||||
|
|
||||||
|
typedef struct IFS_OPEN_PARM {
|
||||||
|
unsigned short iop_mode;
|
||||||
|
unsigned short iop_action;
|
||||||
|
unsigned long iop_attr;
|
||||||
|
char RETRO_FAR* iop_pathname;
|
||||||
|
} IFS_OPEN_PARM;
|
||||||
|
|
||||||
|
typedef struct IFS_RW_PARM {
|
||||||
|
unsigned short irp_handle;
|
||||||
|
void RETRO_FAR* irp_buffer;
|
||||||
|
unsigned long irp_count;
|
||||||
|
unsigned long irp_offset;
|
||||||
|
} IFS_RW_PARM;
|
||||||
|
|
||||||
|
typedef struct IFS_FIND_PARM {
|
||||||
|
unsigned short ifp_handle;
|
||||||
|
unsigned short ifp_attrib;
|
||||||
|
unsigned long ifp_unique;
|
||||||
|
char RETRO_FAR* ifp_search_pattern;
|
||||||
|
char RETRO_FAR* ifp_find_buffer;
|
||||||
|
} IFS_FIND_PARM;
|
||||||
|
|
||||||
|
typedef struct FSD_ENTRY {
|
||||||
|
unsigned long fsd_ordinal;
|
||||||
|
unsigned long fsd_entry_point;
|
||||||
|
} FSD_ENTRY;
|
||||||
|
|
||||||
|
typedef struct RETRO_FILE_HANDLE {
|
||||||
|
int in_use;
|
||||||
|
unsigned long drive_index;
|
||||||
|
char server_path[RETRO_MAX_PATH_LEN];
|
||||||
|
unsigned long nfs_cookie;
|
||||||
|
} RETRO_FILE_HANDLE;
|
||||||
|
|
||||||
|
static RETRO_MAPPING_SLOT g_mappings[RETRO_MAX_MAPPINGS];
|
||||||
|
static RETRO_FILE_HANDLE g_open_files[RETRO_MAX_OPEN_FILES];
|
||||||
|
static FSD_ENTRY g_fsd_entry;
|
||||||
|
static int g_ifs_ready = 0;
|
||||||
|
static int g_ifs_registered = 0;
|
||||||
|
|
||||||
|
DWORD __stdcall RetroIFS_Dispatch(IFS_PARM RETRO_FAR* pifs);
|
||||||
|
DWORD __stdcall RETROVXD_IFSMgr_Register(void* fsd_entry);
|
||||||
|
DWORD __stdcall RETROVXD_IFSMgr_Deregister(void* fsd_entry);
|
||||||
|
|
||||||
|
static void retro_zero(void RETRO_FAR* p, unsigned long n) {
|
||||||
|
unsigned char RETRO_FAR* b = (unsigned char RETRO_FAR*)p;
|
||||||
|
while (n--) *b++ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void retro_copy(char RETRO_FAR* dst,
|
||||||
|
unsigned long dst_len,
|
||||||
|
const char RETRO_FAR* src) {
|
||||||
|
unsigned long i = 0;
|
||||||
|
if (!dst || dst_len == 0) return;
|
||||||
|
if (src) {
|
||||||
|
while (i + 1 < dst_len && src[i]) {
|
||||||
|
dst[i] = src[i];
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dst[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char retro_upper(char c) {
|
||||||
|
if (c >= 'a' && c <= 'z') return (char)(c - 'a' + 'A');
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int retro_prefix_i(const char RETRO_FAR* value, const char* prefix) {
|
||||||
|
if (!value || !prefix) return FALSE;
|
||||||
|
while (*prefix) {
|
||||||
|
if (retro_upper(*value) != retro_upper(*prefix)) return FALSE;
|
||||||
|
++value;
|
||||||
|
++prefix;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int retro_drive_index(const char RETRO_FAR* local) {
|
||||||
|
char d;
|
||||||
|
if (!local || !local[0]) return -1;
|
||||||
|
d = retro_upper(local[0]);
|
||||||
|
if (d < 'A' || d > 'Z') return -1;
|
||||||
|
if (local[1] && local[1] != ':') return -1;
|
||||||
|
return d - 'A';
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned long retro_mapping_count(void) {
|
||||||
|
unsigned long i;
|
||||||
|
unsigned long n = 0;
|
||||||
|
for (i = 0; i < RETRO_MAX_MAPPINGS; ++i) {
|
||||||
|
if (g_mappings[i].used) ++n;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int retro_parse_remote(const char RETRO_FAR* remote,
|
||||||
|
char RETRO_FAR* server,
|
||||||
|
unsigned long server_len,
|
||||||
|
char RETRO_FAR* export_path,
|
||||||
|
unsigned long export_len) {
|
||||||
|
const char RETRO_FAR* p;
|
||||||
|
unsigned long i;
|
||||||
|
|
||||||
|
if (!remote || !retro_prefix_i(remote, "\\\\RetroNFS\\")) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = remote + 11;
|
||||||
|
if (!*p) return FALSE;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (*p && *p != '\\' && i + 1 < server_len) {
|
||||||
|
server[i++] = *p++;
|
||||||
|
}
|
||||||
|
server[i] = 0;
|
||||||
|
|
||||||
|
if (!server[0] || *p != '\\') return FALSE;
|
||||||
|
++p;
|
||||||
|
if (!*p) return FALSE;
|
||||||
|
|
||||||
|
export_path[0] = '/';
|
||||||
|
i = 1;
|
||||||
|
while (*p && i + 1 < export_len) {
|
||||||
|
export_path[i++] = (*p == '\\') ? '/' : *p;
|
||||||
|
++p;
|
||||||
|
}
|
||||||
|
export_path[i] = 0;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_write_info(DIOCPARAMETERS* p,
|
||||||
|
const RETRO_MAPPING_INFO RETRO_FAR* info) {
|
||||||
|
if (!p || !p->lpvOutBuffer || p->cbOutBuffer < sizeof(RETRO_MAPPING_INFO)) {
|
||||||
|
return ERROR_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
*((RETRO_MAPPING_INFO*)p->lpvOutBuffer) = *info;
|
||||||
|
if (p->lpcbBytesReturned) {
|
||||||
|
*p->lpcbBytesReturned = sizeof(RETRO_MAPPING_INFO);
|
||||||
|
}
|
||||||
|
return NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_status(DIOCPARAMETERS* p) {
|
||||||
|
RETRO_STATUS_INFO info;
|
||||||
|
|
||||||
|
if (!p || !p->lpvOutBuffer || p->cbOutBuffer < sizeof(RETRO_STATUS_INFO)) {
|
||||||
|
return ERROR_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
retro_zero(&info, sizeof(info));
|
||||||
|
info.status = RETRO_STATUS_OK;
|
||||||
|
info.mapping_count = retro_mapping_count();
|
||||||
|
info.max_mappings = RETRO_MAX_MAPPINGS;
|
||||||
|
if (g_ifs_ready) {
|
||||||
|
info.driver_flags |= RETRO_DRIVER_FLAG_IFS_STUB;
|
||||||
|
}
|
||||||
|
if (g_ifs_registered) {
|
||||||
|
info.driver_flags |= RETRO_DRIVER_FLAG_IFS_REGISTERED;
|
||||||
|
}
|
||||||
|
|
||||||
|
*((RETRO_STATUS_INFO*)p->lpvOutBuffer) = info;
|
||||||
|
if (p->lpcbBytesReturned) {
|
||||||
|
*p->lpcbBytesReturned = sizeof(RETRO_STATUS_INFO);
|
||||||
|
}
|
||||||
|
return NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_map_drive(DIOCPARAMETERS* p) {
|
||||||
|
RETRO_MAP_REQUEST* req;
|
||||||
|
RETRO_MAPPING_INFO info;
|
||||||
|
int idx;
|
||||||
|
|
||||||
|
if (!p || !p->lpvInBuffer || p->cbInBuffer < sizeof(RETRO_MAP_REQUEST)) {
|
||||||
|
return ERROR_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
req = (RETRO_MAP_REQUEST*)p->lpvInBuffer;
|
||||||
|
idx = retro_drive_index(req->local);
|
||||||
|
if (idx < 0 || !req->remote[0]) {
|
||||||
|
return ERROR_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
retro_zero(&info, sizeof(info));
|
||||||
|
info.status = RETRO_STATUS_OK;
|
||||||
|
info.index = (unsigned long)idx;
|
||||||
|
retro_copy(info.local, sizeof(info.local), req->local);
|
||||||
|
retro_copy(info.remote, sizeof(info.remote), req->remote);
|
||||||
|
|
||||||
|
if (!retro_parse_remote(info.remote,
|
||||||
|
info.server,
|
||||||
|
sizeof(info.server),
|
||||||
|
info.export_path,
|
||||||
|
sizeof(info.export_path))) {
|
||||||
|
info.status = RETRO_STATUS_BAD_REMOTE;
|
||||||
|
if (p->lpvOutBuffer && p->cbOutBuffer >= sizeof(info)) {
|
||||||
|
retro_write_info(p, &info);
|
||||||
|
}
|
||||||
|
return ERROR_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_mappings[idx].used = TRUE;
|
||||||
|
g_mappings[idx].info = info;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO with Win98 DDK:
|
||||||
|
* Register/refresh this drive with IFSMgr and attach an FSD context that
|
||||||
|
* points at g_mappings[idx]. Until then, the provider can configure and
|
||||||
|
* inspect mappings, but Win32 file I/O will not reach the NFS core.
|
||||||
|
*/
|
||||||
|
if (p->lpvOutBuffer && p->cbOutBuffer >= sizeof(info)) {
|
||||||
|
return retro_write_info(p, &info);
|
||||||
|
}
|
||||||
|
if (p->lpcbBytesReturned) {
|
||||||
|
*p->lpcbBytesReturned = 0;
|
||||||
|
}
|
||||||
|
return NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_unmap_drive(DIOCPARAMETERS* p) {
|
||||||
|
RETRO_QUERY_REQUEST* req;
|
||||||
|
int idx;
|
||||||
|
|
||||||
|
if (!p || !p->lpvInBuffer || p->cbInBuffer < sizeof(RETRO_QUERY_REQUEST)) {
|
||||||
|
return ERROR_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
req = (RETRO_QUERY_REQUEST*)p->lpvInBuffer;
|
||||||
|
idx = retro_drive_index(req->local);
|
||||||
|
if (idx < 0) return ERROR_INVALID_PARAMETER;
|
||||||
|
|
||||||
|
if (!g_mappings[idx].used) return ERROR_NOT_CONNECTED;
|
||||||
|
|
||||||
|
retro_zero(&g_mappings[idx], sizeof(g_mappings[idx]));
|
||||||
|
if (p->lpcbBytesReturned) {
|
||||||
|
*p->lpcbBytesReturned = 0;
|
||||||
|
}
|
||||||
|
return NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_query_drive(DIOCPARAMETERS* p) {
|
||||||
|
RETRO_QUERY_REQUEST* req;
|
||||||
|
int idx;
|
||||||
|
|
||||||
|
if (!p || !p->lpvInBuffer || p->cbInBuffer < sizeof(RETRO_QUERY_REQUEST)) {
|
||||||
|
return ERROR_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
req = (RETRO_QUERY_REQUEST*)p->lpvInBuffer;
|
||||||
|
idx = retro_drive_index(req->local);
|
||||||
|
if (idx < 0) return ERROR_INVALID_PARAMETER;
|
||||||
|
|
||||||
|
if (!g_mappings[idx].used) return ERROR_NOT_CONNECTED;
|
||||||
|
return retro_write_info(p, &g_mappings[idx].info);
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_enum_drive(DIOCPARAMETERS* p) {
|
||||||
|
RETRO_ENUM_REQUEST* req;
|
||||||
|
unsigned long i;
|
||||||
|
unsigned long seen = 0;
|
||||||
|
|
||||||
|
if (!p || !p->lpvInBuffer || p->cbInBuffer < sizeof(RETRO_ENUM_REQUEST)) {
|
||||||
|
return ERROR_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
req = (RETRO_ENUM_REQUEST*)p->lpvInBuffer;
|
||||||
|
for (i = 0; i < RETRO_MAX_MAPPINGS; ++i) {
|
||||||
|
if (!g_mappings[i].used) continue;
|
||||||
|
if (seen == req->index) {
|
||||||
|
return retro_write_info(p, &g_mappings[i].info);
|
||||||
|
}
|
||||||
|
++seen;
|
||||||
|
}
|
||||||
|
return ERROR_NOT_CONNECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void retro_reset_open_files(void) {
|
||||||
|
retro_zero(g_open_files, sizeof(g_open_files));
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_ifs_register(void) {
|
||||||
|
if (g_ifs_registered) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Keep the FSD entry in static storage so IFSMgr never receives a pointer
|
||||||
|
* to a stack frame that disappears after init.
|
||||||
|
*/
|
||||||
|
g_fsd_entry.fsd_ordinal = RETRO_FSD_ORDINAL;
|
||||||
|
g_fsd_entry.fsd_entry_point = (unsigned long)&RetroIFS_Dispatch;
|
||||||
|
|
||||||
|
#ifdef RETRO_ENABLE_REAL_IFSMGR_REGISTER
|
||||||
|
if (!RETROVXD_IFSMgr_Register(&g_fsd_entry)) {
|
||||||
|
retro_zero(&g_fsd_entry, sizeof(g_fsd_entry));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
g_ifs_registered = TRUE;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_ifs_unregister(void) {
|
||||||
|
if (!g_ifs_registered) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef RETRO_ENABLE_REAL_IFSMGR_REGISTER
|
||||||
|
if (!RETROVXD_IFSMgr_Deregister(&g_fsd_entry)) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
g_ifs_registered = FALSE;
|
||||||
|
retro_zero(&g_fsd_entry, sizeof(g_fsd_entry));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void RETRO_FAR* retro_ifs_tail(IFS_PARM RETRO_FAR* pifs) {
|
||||||
|
return (void RETRO_FAR*)(((char RETRO_FAR*)pifs) + sizeof(IFS_PARM));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int retro_alloc_file_handle(void) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < RETRO_MAX_OPEN_FILES; ++i) {
|
||||||
|
if (!g_open_files[i].in_use) {
|
||||||
|
g_open_files[i].in_use = TRUE;
|
||||||
|
g_open_files[i].drive_index = 0xffffffffUL;
|
||||||
|
g_open_files[i].nfs_cookie = 0;
|
||||||
|
g_open_files[i].server_path[0] = 0;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int retro_valid_file_handle(unsigned int handle) {
|
||||||
|
if (handle >= RETRO_MAX_OPEN_FILES) return FALSE;
|
||||||
|
return g_open_files[handle].in_use ? TRUE : FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void retro_free_file_handle(unsigned int handle) {
|
||||||
|
if (handle < RETRO_MAX_OPEN_FILES) {
|
||||||
|
retro_zero(&g_open_files[handle], sizeof(g_open_files[handle]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void retro_set_ifs_result(IFS_PARM RETRO_FAR* pifs, DWORD result) {
|
||||||
|
if (pifs) {
|
||||||
|
pifs->ip_result = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_ifs_fail(IFS_PARM RETRO_FAR* pifs, DWORD error) {
|
||||||
|
retro_set_ifs_result(pifs, error);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_ifs_connect(IFS_PARM RETRO_FAR* pifs) {
|
||||||
|
retro_set_ifs_result(pifs, RETRO_IFS_SUCCESS);
|
||||||
|
return RETRO_IFS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_ifs_disconnect(IFS_PARM RETRO_FAR* pifs) {
|
||||||
|
retro_set_ifs_result(pifs, RETRO_IFS_SUCCESS);
|
||||||
|
return RETRO_IFS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_ifs_open(IFS_PARM RETRO_FAR* pifs) {
|
||||||
|
IFS_OPEN_PARM RETRO_FAR* iop;
|
||||||
|
int handle;
|
||||||
|
|
||||||
|
iop = (IFS_OPEN_PARM RETRO_FAR*)retro_ifs_tail(pifs);
|
||||||
|
if (!iop) {
|
||||||
|
return retro_ifs_fail(pifs, ERROR_INVALID_PARAMETER);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read-only scaffold: allocate an internal handle and preserve the path
|
||||||
|
* for the later NFS LOOKUP/READ implementation. Write access is blocked
|
||||||
|
* until the redirector has real NFS write support; iop_action is left for
|
||||||
|
* live Win9x validation because the exact action values differ by call
|
||||||
|
* shape in the DDK-era IFSMgr layouts.
|
||||||
|
*/
|
||||||
|
if ((iop->iop_mode & 0x0003) != 0) {
|
||||||
|
return retro_ifs_fail(pifs, ERROR_ACCESS_DENIED);
|
||||||
|
}
|
||||||
|
|
||||||
|
handle = retro_alloc_file_handle();
|
||||||
|
if (handle < 0) {
|
||||||
|
return retro_ifs_fail(pifs, ERROR_TOO_MANY_OPEN_FILES);
|
||||||
|
}
|
||||||
|
|
||||||
|
retro_copy(g_open_files[handle].server_path,
|
||||||
|
sizeof(g_open_files[handle].server_path),
|
||||||
|
iop->iop_pathname);
|
||||||
|
|
||||||
|
retro_set_ifs_result(pifs, (DWORD)handle);
|
||||||
|
return RETRO_IFS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_ifs_close(IFS_PARM RETRO_FAR* pifs) {
|
||||||
|
IFS_RW_PARM RETRO_FAR* irp;
|
||||||
|
unsigned int handle;
|
||||||
|
|
||||||
|
irp = (IFS_RW_PARM RETRO_FAR*)retro_ifs_tail(pifs);
|
||||||
|
handle = (unsigned int)irp->irp_handle;
|
||||||
|
if (!retro_valid_file_handle(handle)) {
|
||||||
|
return retro_ifs_fail(pifs, ERROR_INVALID_PARAMETER);
|
||||||
|
}
|
||||||
|
|
||||||
|
retro_free_file_handle(handle);
|
||||||
|
retro_set_ifs_result(pifs, RETRO_IFS_SUCCESS);
|
||||||
|
return RETRO_IFS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_ifs_read(IFS_PARM RETRO_FAR* pifs) {
|
||||||
|
IFS_RW_PARM RETRO_FAR* irp;
|
||||||
|
unsigned int handle;
|
||||||
|
|
||||||
|
irp = (IFS_RW_PARM RETRO_FAR*)retro_ifs_tail(pifs);
|
||||||
|
handle = (unsigned int)irp->irp_handle;
|
||||||
|
if (!retro_valid_file_handle(handle)) {
|
||||||
|
return retro_ifs_fail(pifs, ERROR_INVALID_PARAMETER);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NFS READ will fill this buffer later. Returning zero bytes now gives
|
||||||
|
* callers a deterministic read-only EOF instead of a fake payload.
|
||||||
|
*/
|
||||||
|
irp->irp_count = 0;
|
||||||
|
retro_set_ifs_result(pifs, RETRO_IFS_SUCCESS);
|
||||||
|
return RETRO_IFS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_ifs_write(IFS_PARM RETRO_FAR* pifs) {
|
||||||
|
return retro_ifs_fail(pifs, ERROR_ACCESS_DENIED);
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_ifs_find(IFS_PARM RETRO_FAR* pifs) {
|
||||||
|
IFS_FIND_PARM RETRO_FAR* ifp;
|
||||||
|
|
||||||
|
ifp = (IFS_FIND_PARM RETRO_FAR*)retro_ifs_tail(pifs);
|
||||||
|
(void)ifp;
|
||||||
|
|
||||||
|
retro_set_ifs_result(pifs, RETRO_IFS_ERROR);
|
||||||
|
return ERROR_NO_MORE_FILES;
|
||||||
|
}
|
||||||
|
|
||||||
|
static DWORD retro_ifs_getdiskinfo(IFS_PARM RETRO_FAR* pifs) {
|
||||||
|
unsigned long RETRO_FAR* disk_info;
|
||||||
|
|
||||||
|
disk_info = (unsigned long RETRO_FAR*)retro_ifs_tail(pifs);
|
||||||
|
disk_info[0] = 64;
|
||||||
|
disk_info[1] = 2048;
|
||||||
|
disk_info[2] = 512;
|
||||||
|
disk_info[3] = 8192;
|
||||||
|
retro_set_ifs_result(pifs, RETRO_IFS_SUCCESS);
|
||||||
|
return RETRO_IFS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IFSMgr entry point scaffold.
|
||||||
|
*
|
||||||
|
* This now decodes the first simplified parameter tails and enforces a
|
||||||
|
* read-only contract. The remaining production work is replacing the EOF and
|
||||||
|
* no-entry fallbacks with NFS LOOKUP/READ/READDIR calls and validating the
|
||||||
|
* final Win9x IFSMgr layouts against a live DDK target.
|
||||||
|
*/
|
||||||
|
DWORD __stdcall RetroIFS_Dispatch(IFS_PARM RETRO_FAR* pifs) {
|
||||||
|
DWORD rc;
|
||||||
|
|
||||||
|
if (!pifs) {
|
||||||
|
return RETRO_IFS_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (pifs->ip_func) {
|
||||||
|
case IFSFN_CONNECT:
|
||||||
|
rc = retro_ifs_connect(pifs);
|
||||||
|
break;
|
||||||
|
case IFSFN_DISCONNECT:
|
||||||
|
rc = retro_ifs_disconnect(pifs);
|
||||||
|
break;
|
||||||
|
case IFSFN_OPEN:
|
||||||
|
rc = retro_ifs_open(pifs);
|
||||||
|
break;
|
||||||
|
case IFSFN_READ:
|
||||||
|
rc = retro_ifs_read(pifs);
|
||||||
|
break;
|
||||||
|
case IFSFN_WRITE:
|
||||||
|
rc = retro_ifs_write(pifs);
|
||||||
|
break;
|
||||||
|
case IFSFN_CLOSE:
|
||||||
|
rc = retro_ifs_close(pifs);
|
||||||
|
break;
|
||||||
|
case IFSFN_FINDFIRST:
|
||||||
|
case IFSFN_FINDNEXT:
|
||||||
|
rc = retro_ifs_find(pifs);
|
||||||
|
break;
|
||||||
|
case IFSFN_GETDISKINFO:
|
||||||
|
rc = retro_ifs_getdiskinfo(pifs);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
rc = retro_ifs_fail(pifs, ERROR_INVALID_FUNCTION);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD __stdcall RetroIFS_Init(void) {
|
||||||
|
retro_reset_open_files();
|
||||||
|
if (!retro_ifs_register()) {
|
||||||
|
g_ifs_ready = 0;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
g_ifs_ready = 1;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD __stdcall RetroIFS_Exit(void) {
|
||||||
|
DWORD ok;
|
||||||
|
|
||||||
|
g_ifs_ready = 0;
|
||||||
|
ok = retro_ifs_unregister();
|
||||||
|
retro_reset_open_files();
|
||||||
|
return ok ? TRUE : FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD __stdcall RETROVXD_Dynamic_Init(void) {
|
||||||
|
retro_zero(g_mappings, sizeof(g_mappings));
|
||||||
|
return RetroIFS_Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD __stdcall RETROVXD_Dynamic_Exit(void) {
|
||||||
|
RetroIFS_Exit();
|
||||||
|
retro_zero(g_mappings, sizeof(g_mappings));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD __stdcall RETROVXD_W32_DeviceIoControl(DWORD service,
|
||||||
|
DWORD ddb,
|
||||||
|
DWORD hDevice,
|
||||||
|
DIOCPARAMETERS* p) {
|
||||||
|
(void)ddb;
|
||||||
|
(void)hDevice;
|
||||||
|
|
||||||
|
if (service == DIOC_OPEN || service == DIOC_CLOSEHANDLE) {
|
||||||
|
return NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (service) {
|
||||||
|
case RETRO_IOCTL_MAP:
|
||||||
|
return retro_map_drive(p);
|
||||||
|
case RETRO_IOCTL_UNMAP:
|
||||||
|
return retro_unmap_drive(p);
|
||||||
|
case RETRO_IOCTL_QUERY:
|
||||||
|
return retro_query_drive(p);
|
||||||
|
case RETRO_IOCTL_ENUM:
|
||||||
|
return retro_enum_drive(p);
|
||||||
|
case RETRO_IOCTL_STATUS:
|
||||||
|
return retro_status(p);
|
||||||
|
default:
|
||||||
|
return ERROR_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user