Mounting into HTTPS filesystem
Spectranext allows you to mount HTTPS URLs as read-only filesystems directly from Spectrum programs. This allows accessing files hosted on web servers as if they were local files.
This means that files/tapes can be hosted anywhere and not just TNFS. However, it is important to note that such an endpoint would not work on the original Spectranet, but it is very convenient.
Overview
HTTPS Filesystem provides:
- Web-Based File Access: Mount HTTPS URLs as filesystems
- Standard VFS Interface: Uses Spectranet's standard VFS (Virtual File System) API with
https://prefix - Read-Only Access: Files can be read directly from web servers
- Directory Listing: Browse directory contents using
index.txtfiles - Transparent HTTPS/TLS: All communication is encrypted using TLS
Mounting HTTPS Filesystems
To use HTTPS filesystem, you must first mount it using an HTTPS URL.
Mounting an HTTPS URL
- BASIC
- C
- Assembly
%mount 0, "https://example.com/path/"
The URL should point to a directory on the web server. The path can include subdirectories:
%mount 0, "https://spectranext.net/test/https/"
#include <spdos.h>
mount(0, NULL, NULL, "/path", "example.com", "https");
The URL should point to a directory on the web server. The path can include subdirectories:
mount(0, NULL, NULL, "/test/https", "spectranext.net", "https");
.include "spectranet.inc"
; Mount structure
mount_struct:
defw protocol_str
defw hostname_str
defw path_str
defw user_str
defw password_str
protocol_str: defb "https",0
hostname_str: defb "example.com",0
path_str: defb "/path",0
user_str: defb 0
password_str: defb 0
; Mount at mount point 0
ld ix, mount_struct
ld a, 0
call MOUNT
Unmounting
- BASIC
- C
- Assembly
%umount 0
umount(0);
ld a, 0
call UMOUNT
Accessing Files
Once an HTTPS filesystem is mounted, you can access files directly by their path. Files are fetched transparently over HTTPS when opened.
Opening Files
- BASIC
- C
- Assembly
%open #4, "file.txt", "r" ; Open for reading
#include <spdos.h>
#include <fcntl.h>
int fd = open("file.txt", O_RDONLY, 0);
if (fd >= 0) {
// File opened successfully
// ... read from file ...
close(fd);
}
; Open file for reading
ld hl, filename
ld de, O_RDONLY ; Open flags
call OPEN ; ROM routine at 0x3EB1
; Returns file handle in HL (carry set on error)
Reading Files
Files are downloaded automatically when opened.
- BASIC
- C
%open #4, "data.bin", "r"
%read #4, buffer$, 1024 ; Read 1024 bytes
%close #4
#include <spdos.h>
#include <unistd.h>
int fd = open("data.bin", O_RDONLY, 0);
if (fd >= 0) {
unsigned char buffer[1024];
ssize_t bytes_read = read(fd, buffer, sizeof(buffer));
close(fd);
}
Directory Listing
To enable directory listing (%cat, opendir, etc.), you must create an index.txt
file in each directory you want to browse. The HTTPS filesystem will fetch this file to determine
the directory contents.
index.txt Format
The index.txt file uses a simple key=value format, with one entry per line.
Each line contains space-separated key=value pairs:
For files:
type=file name=filename.txt size=1024
For directories:
type=dir name=subdirectory
Example index.txt
Here's an example index.txt file:
type=file name=readme.txt size=1234
type=file name=program.bin size=4096
type=dir name=docs
type=file name=data.dat size=8192
Required Fields
type: Must be eitherfileordirfile: Regular file entrydir: Directory entry
name: The filename or directory namesize: File size in bytes (required for files, ignored for directories)
Directory Listing Operations
Once index.txt is present, you can use standard directory operations:
- BASIC
- C
- Assembly
%cat ; List current directory
%cat subdirectory ; List subdirectory
#include <spdos.h>
#include <dirent.h>
DIR* dir = opendir(".");
if (dir) {
struct dirent* entry;
while ((entry = readdir(dir)) != NULL) {
printf("Entry: %s\n", entry->d_name);
}
closedir(dir);
}
; Open directory
ld hl, dirname
call OPENDIR ; ROM routine
; Returns directory handle in A (carry set on error)
; Read directory entry
ld de, buffer
call READDIR ; ROM routine
; Returns entry name in buffer (carry set on error/EOF)
; Close directory
call CLOSEDIR ; ROM routine
Server Setup
To make your files accessible via HTTPS filesystem:
- Host files on an HTTPS server: Ensure your web server supports HTTPS with valid TLS certificates.
- Create
index.txtfiles: For each directory you want to browse, create anindex.txtfile listing its contents. This is optional, if you don't want directory listing, files would still fetch.
Example Server Structure
https://example.com/files/
├── index.txt
├─ ─ boot.zx
├── program.tap
└── docs/
├── index.txt
├── manual.pdf
└── guide.txt
The root index.txt would contain:
type=file name=boot.zx size=60
type=file name=program.tap size=4096
type=dir name=docs
And docs/index.txt would contain:
type=file name=manual.pdf size=56789
type=file name=guide.txt size=2345
Limitations
- Read-Only: HTTPS filesystem is read-only. Write operations are not supported
- No Write Operations:
write(),mkdir(),rmdir(),unlink(), andrename()operations are not supported - Maximum Entries: Directory listings are limited to 128 entries per directory