Posted 04 August 2013 - 05:08 AM
This is the virtual filesystem API I wrote about a year ago for a now defunct server.
It allows you to create special folders (called mount points). When a program tries to access a file inside a mount point, it calls a function you defined.
Download: QuseBy20 on pastebin
Load the API with shell.run or equivalent, NOT os.loadAPI.
Why would you use this?
API functions:
vfs.registerFS(name, factoryFunction)
Registers a filesystem type. factoryFunction must be a function taking two arguments.
The first argument is the mount point path, and the second argument contains extra options in a filesystem-specific format.
The "craftos" type is registered by vfs itself and refers to the actual physical filesystem (or the VFS layer above it; it's possible to have multiple VFS layers by using vfs.createVFSInstance)
vfs.mount(mountPoint, fsTypeName, options)
Creates a mount point.
mountPoint is the path to the mount point, and must end in /
fsTypeName is the name of the filesystem type - the same name passed to vfs.registerFS.
options is passed as the second argument to the filesystem type's factory function.
vfs.unmount(mountPoint)
Removes a mount point.
It is possible to unmount "/". If you do this you'll probably have to reboot the computer with Ctrl-R.
vfsapi, fsapi = vfs.createVFSInstance(oldFSAPI)
Creates a new instance of the vfs API, and a corresponding fs API.
This was originally used with a VPS server program to give each VPS its own isolated filesystem.
Example use: RFS (remote filesystem)
Important note: This was written when rednet was perfectly secure and before the modem API. Do not use it except for demonstration purposes. If you ignore this message and use it anyway, then someone else who did read this message will hack your system.
rfs-client: WDEQ9gCq on pastebin. This might or might not be a good starting point for custom filesystems.
rfs-server: gueBSw3R on pastebin. This is provided so you can set up a test server. It had computer-ID authentication which has been disabled.
RFS has not been tested in about a year, and I will not support it.
Example use: HTTP
This might also be a useful starting point. It contains the bare minimum of functionality for a useful filesystem.
web-vfs: H5wAEU85 on pastebin
Example use:
P.S. What is up with the capitalization of titles here? I tried "VFS API", "vfs API", and "'vfs': virtual filesystem layer" and every time the forum automatically capitalized the first letter of every word and decapitalized all other letters.
It allows you to create special folders (called mount points). When a program tries to access a file inside a mount point, it calls a function you defined.
Download: QuseBy20 on pastebin
Load the API with shell.run or equivalent, NOT os.loadAPI.
Why would you use this?
- Easy access to HTTP (web-vfs works for this, see bottom of this post)
- Want to download a file from pastebin? fs.copy("/pastebin/QuseBy20", "vfs"))
- Load programs directly from github? shell.run("/github/example/example/blob/master/startup.lua")
- File servers (write your own protocol, RFS (below) is insecure)
- Filesystem virtualization/sandboxing (hide files from programs) including chroot
API functions:
vfs.registerFS(name, factoryFunction)
Registers a filesystem type. factoryFunction must be a function taking two arguments.
The first argument is the mount point path, and the second argument contains extra options in a filesystem-specific format.
The "craftos" type is registered by vfs itself and refers to the actual physical filesystem (or the VFS layer above it; it's possible to have multiple VFS layers by using vfs.createVFSInstance)
vfs.mount(mountPoint, fsTypeName, options)
Creates a mount point.
mountPoint is the path to the mount point, and must end in /
fsTypeName is the name of the filesystem type - the same name passed to vfs.registerFS.
options is passed as the second argument to the filesystem type's factory function.
vfs.unmount(mountPoint)
Removes a mount point.
It is possible to unmount "/". If you do this you'll probably have to reboot the computer with Ctrl-R.
vfsapi, fsapi = vfs.createVFSInstance(oldFSAPI)
Creates a new instance of the vfs API, and a corresponding fs API.
This was originally used with a VPS server program to give each VPS its own isolated filesystem.
Example use: RFS (remote filesystem)
Important note: This was written when rednet was perfectly secure and before the modem API. Do not use it except for demonstration purposes. If you ignore this message and use it anyway, then someone else who did read this message will hack your system.
rfs-client: WDEQ9gCq on pastebin. This might or might not be a good starting point for custom filesystems.
rfs-server: gueBSw3R on pastebin. This is provided so you can set up a test server. It had computer-ID authentication which has been disabled.
RFS has not been tested in about a year, and I will not support it.
Example use: HTTP
This might also be a useful starting point. It contains the bare minimum of functionality for a useful filesystem.
web-vfs: H5wAEU85 on pastebin
Example use:
shell.run("web-vfs")
vfs.mount("/wikipedia/", "http", {base="http://en.wikipedia.org/wiki/"})
shell.run("edit /wikipedia/Main_Page")
P.S. What is up with the capitalization of titles here? I tried "VFS API", "vfs API", and "'vfs': virtual filesystem layer" and every time the forum automatically capitalized the first letter of every word and decapitalized all other letters.