This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Sewbacca's profile picture

FSector

Started by Sewbacca, 05 October 2016 - 05:25 PM
Sewbacca #1
Posted 05 October 2016 - 07:25 PM
[BETA] FSector (ysq0bCcH)

What is FSector?
Short description:
FSector creates separated fs, like window.create for the terminal.

Why should I use FSector?
Here are some examples:
  • Sandbox programs
  • Virtual machines (mount rom into a directory and create the handle)
  • Virtual hard disk drives
  • Set ReadOnly (e. g. an OS folder or password files (to prevent setting a password to '' for example))
  • Save storage with mounting paths into directories
  • handle.mount simulates hard links
  • Hierarchy your file systems (e. g. native fs -> Drives/{0} or native fs -> rom/help (i mean the help files))
  • Mount disks into other directorys (for example in Drives/{0}/disk)
  • Sharing data between programs (by using handle.mount())
  • Executing programs relative to their destinations.
  • Things i forgot.
Are there other things, I should now?

Documentation
SpoilerFSector.create(object parent, string rootDir)
The first argument is the parent of your sector created by FSector.create().
By the first call, use fs as a parent.

handle.mount(string source, string destination)
Mounts a path to destination in this instance and for childs of this.
The destination can be read only.

handle.dismount(string path)
Dismounts a path in this instance.

handle.isMounted(string path)
Checks, if a path is mounted in this instance

handle.setReadOnly(string path, bool readOnly)
Set read only or read and write to a directory of this instance.


Load API
To load the API, just dofile the API (it returns the API) or edit:
FSector = {} to
FSector = _ENV
and load it by os.loadAPI().

Example
SpoilerExample with an inserted disk.

local root= FSector.create(fs, '') -- Creates a fs-handle pointing to /
root.mount('disk', 'rom/disk')
local rom = FSector.create(root, 'rom') -- Creates a fs-handle with root as a parent to import all mounted paths, pointing to /rom.
textutils.tabulate(rom.list 'disk')
sleep(1)
root.dismount 'rom/disk'
textutils.tabulate(rom.list 'disk') -- ERROR: Not a directory

Screenshots
Spoiler

WIP [Work in progress]
Spoilerresolving mounted paths
handle.find() and handle.list()
They don't find mounted paths yet.
fs.redirect()
fs.current()
fs.native()

Error Messages

License
SpoilerThe source file contains this license:

MIT License

Copyright © 2016 Sewbacca

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.










Thanks all people, who helped me choosing a name =)


Please report any bugs and

feel free to post suggestions and constructive criticism to this API.


Enjoy it

Sewbacca
Edited on 12 October 2016 - 02:39 PM
Creator #2
Posted 05 October 2016 - 08:18 PM
This is great! I don't say this often, but there some programs that simply amaze me. This is one of them.
Sewbacca #3
Posted 05 October 2016 - 08:39 PM
This is great! I don't say this often, but there some programs that simply amaze me. This is one of them.
Thank you very much =)
TheRockettek #4
Posted 05 October 2016 - 09:13 PM
This program gave me an idea to make like VMWare for computercraft :D/> and instead of it just sandboxing shell and stuff, you can emulate all the files on a computer (bios and rom) in a computer :D/>

tldr vmware in cc
Sewbacca #5
Posted 06 October 2016 - 12:33 PM
This program gave me an idea to make like VMWare for computercraft :D/> and instead of it just sandboxing shell and stuff, you can emulate all the files on a computer (bios and rom) in a computer :D/>

tldr vmware in cc
I got the idea of creating fs handles, by developing a VMWare Player. Also SOSP (An Operating System Package manager) will use this API to emulates hard drives with different OS. It (will) contains BIOS, kernel and a boot loader.
thecrimulo #6
Posted 06 October 2016 - 03:00 PM
This is amazing. Full control over filesystem and adding new functions, tho I'd like documentation for all the functions!
Keep up the good work

~Dael
Sewbacca #7
Posted 06 October 2016 - 06:47 PM
This is amazing. Full control over filesystem and adding new functions, tho I'd like documentation for all the functions!
Keep up the good work

~Dael

Shortly i added one, thank you =)
Sewbacca
Sewbacca #8
Posted 06 October 2016 - 10:06 PM
Oh, i found a bug in my screenshots, i add it to WIP.
TheRockettek #9
Posted 07 October 2016 - 08:45 PM
would be cool if the errors werent like what it shows in the screenshots d: you could just use printError and a return :D/>
Sewbacca #10
Posted 09 October 2016 - 12:53 PM
would be cool if the errors werent like what it shows in the screenshots d: you could just use printError and a return :D/>

Thank you, but i am currently working on resolving mounted paths, what sadly doesn't work right andIthe error messages are a minor problem.

I added fs.current() etc. but i need some help to find the problem with resolving mounted paths.
Can sb. help me please, with debugging my code?
Edited on 09 October 2016 - 11:07 AM
Sewbacca #11
Posted 10 October 2016 - 02:04 PM
Had anyone found the problem?
Creator #12
Posted 10 October 2016 - 04:10 PM
It truly is a pain. Maybe take a look at this code, since it should do the same thing. I haven't looked at your code yet since I'm short on time, but I will at some point.
Sewbacca #13
Posted 10 October 2016 - 04:35 PM
Here my question in Ask a pro.
Edited on 10 October 2016 - 02:35 PM
Sewbacca #14
Posted 12 October 2016 - 01:25 PM
Here my question in Ask a pro.

I found the problem. The redirection of a fs and the example of my question works now and i updated the code =)
Sewbacca =)
Edited on 12 October 2016 - 11:30 AM
HaddockDev #15
Posted 14 October 2016 - 11:54 AM
This seems really neat, it's been a while since I've seen something like this so its the kind of thing that goes in my bookmarks.
I will try this once some bugs are ironed out and I'd probably include this into something of mine because of what this is, it really could help
with the temporary folders and/or sandboxing.

tldr its good
Sewbacca #16
Posted 16 October 2016 - 04:58 PM
This seems really neat, it's been a while since I've seen something like this so its the kind of thing that goes in my bookmarks.
I will try this once some bugs are ironed out and I'd probably include this into something of mine because of what this is, it really could help
with the temporary folders and/or sandboxing.

tldr its good

Thank you
Spoilervery much =)

Sewbacca
HaddockDev #17
Posted 26 November 2016 - 05:14 PM
Well, I have tried it out with sandboxing, and it works pretty well.
You do need to work on things trying not to get out, especially if somebody's going to be developing a VMWare or something for this.
When emulating a computer (copying /rom into a folder, removing all the apis and such) the shell is breaking out of the sandbox,
allowing direct access to the real /, instead of the one where it is just /rom.
That's my only complaint.
Good job though.
This is the code I

local sandbox_env = {
assert = assert,
error = error,
ipairs = ipairs,
pairs = pairs,
next = next,
pcall = pcall,
print = print,
select = select,
tonumber = tonumber,
tostring = tostring,
type = type,
unpack = unpack,
xpcall = xpcall,
coroutine = coroutine,
string = string,
math = math,
table = table,
read = read,
write = io.write,
io = io,
os = os,
bit = bit,
bit32 = bit32,
colors = colors,
colours = colours,
--disk = disk, create a custom disk api
--fs = fs, using Sewbacca's FSector,
gps = gps,
help = help,
http = http,
keys = keys,
paintutils = paintutils,
parallel = parallel,
--peripheral = peripheral, make custom
--rednet = rednet, make custom
--redstone = redstone, make custom
--rs = rs, same as redstone
--shell = shell, make custom
term = term,
textutils = textutils,
window = window,
}
FSector = dofile(shell.dir() .. "/fsec")
local sandbox_fs = FSector.create(fs, "/sandbox")
sandbox_env.fs = sandbox_fs
sandbox_env.fs.mount("/sandbox/rom","rom")
local tArgs = {...}
os.run(sandbox_env, tArgs[1])
Edited on 26 November 2016 - 04:20 PM
Sewbacca #18
Posted 26 November 2016 - 06:15 PM
–snip

First, thanks trying out my API =)
But you did a mistake:
handle.mount(source, destination)
not destination, source
And the fs you setted has only access to /sandbox.
So you have to create a parent with access to the root directory, mount the directory and then create a child:

local toplevel = FSector.create(fs.current(), '')
local sandbox_fs = FSector.create(toplevel, 'sandbox')
toplevel.mount('rom', 'sandbox/rom') -- Now sandbox_fs sees rom in his root directory
This code should work.
Thank you testing my API =)
Edited on 26 November 2016 - 06:05 PM