This commit is contained in:
2025-09-29 00:03:57 -04:00
parent 5111182a4b
commit abd573f686
64 changed files with 2407 additions and 157 deletions

1
disks/1h/sys/db/os.reg Normal file
View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1,40 @@
local driver = {}
driver.type = "fs"
driver.name = "Advanced Computers disk driver"
driver.version = "1.0.0"
driver.apiVersion = 1
driver.description = "Driver for Advanced Computers disks"
driver.manifest = "ac.disk.ko"
driver.api = function(component)
return {
readAllText = function(dir)
local drive = component:open(dir)
local file = drive.read()
drive = nil
return file
end,
writeAllText = function(dir, content)
local drive = component:open(dir)
drive.write(content)
drive = nil
end,
appendAllText = function(dir, content)
local drive = component:open(dir)
drive.append(content)
drive = nil
end,
list = function(dir)
return component:list(dir)
end,
mkFile = function(dir)
component:makeFile(dir)
end,
mkDir = function(dir)
component:makeDirectory(dir)
end
}
end
return driver

View File

@@ -0,0 +1,26 @@
local driver = {}
driver.type = "terminal"
driver.name = "Advanced Computers screen driver"
driver.version = "1.0.0"
driver.apiVersion = 1
driver.description = "Driver for Advanced Computers screens"
driver.manifest = "ac.screen.ko"
driver.api=function(component)
return {
write=function(...)
component.printInline(...)
end,
print=function(...)
component.print(...)
end,
printInline=function(...)
component.printInline(...)
end,
clear=function(...)
component.clear()
end
}
end
return driver

View File

@@ -0,0 +1,16 @@
local driver = {}
driver.type = "ufs"
driver.name = "Advanced Computers unmanaged disk driver"
driver.version = "1.0.0"
driver.apiVersion = 1
driver.description = "Driver for Advanced Computers unmanaged disks"
driver.manifest = "ac.udisk.ko"
driver.api = function(component)
return {
}
end
return driver

View File

@@ -0,0 +1,8 @@
local driver = {}
driver.type = "wlan"
driver.name = "Advanced Computers http driver"
driver.version = "1.0.0"
driver.apiVersion = 1
driver.description = "Driver for Advanced Computers http"
driver.manifest = "ac.wlan.ko"

View File

@@ -0,0 +1,245 @@
-- Copyright (C) 2025 ASTRONAND
-- File open modes
-- M | H | D
-- rc | r | Read and close
-- r | r | Read
-- w | w | Write
-- o | w | Overite file
-- om | m | Overite and modify
-- rw | m | Read and write
-- x | f | get function
local args=({...})[1]
local fs={}
local disks={}
local mounts={}
local bootDrive=args.bootDrive
local auth=args.auth
local log=args.logging
for t, o in component.list() do
if t=="disk" then
if o.id==bootDrive.id then
else disks[o.id]=o end
end
end
local function resolve(path)
if string.sub(path,1,1)~="/" then
path="/"..path
end
local drive=bootDrive
for i,v in pairs(mounts) do
if string.hasPrefix(path,v) then
drive=disks[i]
path=string.getSuffix(path,v)
break
end
end
return drive, path
end
local function checkPerms(path, mode)
end
local function getHandle(backing,typ,clear)
local ret={}
local close=false
ret.close=function()
close=true
end
if typ=="r" then
ret.read=function()
if close then return "Handle closed" end
return backing.read()
end
ret.lines=function()
if close then error() end
local lines=string.split(backing.read(), "\n")
local i=0
return function()
i=i+1
return lines[i]
end
end
elseif typ=="w" then
ret.write=function(data)
if close then return "Handle closed" end
backing.append(data)
end
elseif typ=="m" then
ret.read=function()
if close then return "Handle closed" end
return backing.read()
end
ret.lines=function()
if close then error() end
local lines=string.split(backing.read(), "\n")
local i=0
return function()
i=i+1
return lines[i]
end
end
ret.write=function(data)
if close then return "Handle closed" end
backing.append(data)
end
end
if clear then
ret.clear=function()
if close then return "Handle closed" end
backing.write()
end
end
return ret
end
local function open(path, mode, arg, pc)
if pc then
checkPerms(path, mode)
end
local drive, newPath = resolve(path)
if drive:directoryExists(newPath) then error("Cannot open directory") end
if not drive:fileExists(newPath) then error("File does not exist") end
local backing=drive:open(newPath)
if mode=="rc" then
local file=getHandle(backing,"r")
local text=file.read()
file.close()
return text
elseif mode=="r" then
return getHandle(backing,"r")
elseif mode=="w" then
return getHandle(backing,"w")
elseif mode=="o" then
local file=getHandle(backing,"w",true)
file.clear()
file.clear=nil
return file
elseif mode=="om" then
local file=getHandle(backing,"m",true)
file.clear()
file.clear=nil
return file
elseif mode=="rw" then
return getHandle(backing,"m")
elseif mode=="x" then
local file=getHandle(backing,"r")
local text=file.read()
file.close()
return load(text, path, nil, table.deepcopy(_G))
elseif mode=="xe" then
local file=getHandle(backing,"r")
local text=file.read()
file.close()
return load(text, path, nil, arg)
else
error("Invailid mode")
end
end
function fs.open(path, mode, arg)
return open(path, mode, arg, true)
end
function fs.copy(orig, dest)
local destFile = fs.open(dest,"o")
local origFile = fs.open(orig, "rc")
destFile.write(origFile)
destFile.close()
end
function fs.move(orig, dest)
local destFile = fs.open(dest,"o")
local origFile = fs.open(orig, "rc")
destFile.write(origFile)
destFile.close()
fs.delete(orig)
end
-- This fixes the weirdest bug ever
local isDir = function(path, pc)
if pc then checkPerms(path, "r") end
local drive, newPath = resolve(path)
return drive:directoryExists(newPath)
end
local exists = function(path, pc)
if pc then checkPerms(path, "r") end
local drive, newPath = resolve(path)
return ((drive:directoryExists(newPath)) or (drive:fileExists(newPath)))
end
local delete = function(path, pc)
if pc then checkPerms(path, "w") end
local drive, newPath = resolve(path)
return drive:delete(newPath)
end
local list = function(path, pc)
if pc then checkPerms(path, "w") end
local drive, newPath = resolve(path)
return drive:list(newPath)
end
function fs.list(path)
return list(path, true)
end
function fs.isDir(path)
return isDir(path, true)
end
function fs.exists(path)
return exists(path, true)
end
function fs.delete(path)
return delete(path, true)
end
function fs.getSudo(key)
if auth.sudo.isAproved(key) then
return {
createVirtDisk=function(virtualDiskName,virtualDiskObj)
disks[virtualDiskName]=virtualDiskObj
log.log("Created VirtIO disk named "..virtualDiskName)
end,
mount=function(hardwareDir,path)
mounts[hardwareDir]=path
log.log("Mounted disk ")
end,
unmount=function(hardwareDir)
mounts[hardwareDir]=nil
end,
eject=function(hardwareDir)
disks[hardwareDir]=nil
end,
sfs={
open=function(path, mode, arg)
return open(path, mode, arg)
end,
delete=function(path)
return delete(path)
end,
copy=fs.copy,
move=fs.move,
exists=function(path)
return exists(path)
end,
isDir=function(path)
return isDir(path)
end,
list=function(path)
return list(path)
end
}
}
else
error("sudo request denied")
end
end
return fs

View File

@@ -0,0 +1,50 @@
-- Copyright (C) 2025 ASTRONAND
--local oldComponent = component
--_G.component={}
--local components={}
--local all={}
--local blacklisted={}
--
--function table.contains(tabl, query)
-- for i,v in ipairs(tabl) do
-- if v==query then
-- return true
-- end
-- end
-- return false
--end
--
--for i,v in oldComponent.list() do
-- if not components[i] then
-- components[i]={}
-- end
-- components[i][#components[i]+1]={typ=i,obj=v}
-- all[#all+1]={typ=i,obj=v}
--end
--
--function component.list(filter)
-- filter=filter or "all"
-- local filtered
-- if filter=="all" then
-- filtered=all
-- else
-- filtered=components[filter]
-- end
-- local i=0
-- return function()
-- while i<#filtered do
-- i=i+1
-- if not table.contains(blacklisted, v.typ) then
-- return v.typ, v.obj
-- end
-- end
-- end
--end
--
--function component.getSudo(key)
-- if key==masterKey then
-- return oldComponent
-- end
--end
--
--

View File

@@ -0,0 +1,53 @@
-- Copyright (C) 2025 ASTRONAND
function string.hasSuffix(str, suffix)
return string.sub(str, #suffix+1) == suffix
end
function string.hasPrefix(str, prefix)
return string.sub(str, 1, #prefix) == prefix
end
function string.getSuffix(str, prefix)
return string.sub(str, #prefix+1)
end
function string.getPrefix(str, suffix)
return string.sub(str, 1, #suffix)
end
function string.join(delim, ...)
return table.concat(table.pack(...), delim)
end
function string.split(str, delim, maxResultCountOrNil)
assert(#delim == 1, "only delim len 1 supported for now")
maxResultCountOrNil = (maxResultCountOrNil or 0)-1
local rv = {}
local buf = ""
for i = 1, #str do
local c = string.sub(str,i,i)
if #rv ~= maxResultCountOrNil and c == delim then
table.insert(rv, buf)
buf = ""
else
buf = buf..c
end
end
table.insert(rv, buf)
return rv
end
function string.replace(str, search, replacement)
local rv = ""
local consumedLen = 1
local i = 1
while i<#str do
if string.sub(str, i, i+#search-1) == search then
rv = rv .. string.sub(str, consumedLen, i-1) .. replacement
i=i+#search
consumedLen = i
end
i=i+1
end
return rv .. string.sub(str, consumedLen)
end

View File

@@ -0,0 +1,39 @@
-- Copyright (C) 2025 ASTRONAND
function table.deepcopy(orig, copies)
copies = copies or {}
if type(orig) ~= 'table' then
return orig
elseif copies[orig] then
return copies[orig]
end
local copy = {}
copies[orig] = copy
for k, v in next, orig, nil do
local copied_key = table.deepcopy(k, copies)
local copied_val = table.deepcopy(v, copies)
copy[copied_key] = copied_val
end
return copy
end
function table.hasKey(tabl, query)
for i,v in pairs(tabl) do
if i==query then
return true
end
end
return false
end
function table.hasVal(tabl, query)
for i,v in pairs(tabl) do
if v==query then
return true
end
end
return false
end

View File

@@ -0,0 +1 @@
-- Copyright (C) 2025 ASTRONAND

View File

@@ -0,0 +1,29 @@
-- Copyright (C) 2025 ASTRONAND
local args=({...})[1]
local masterKey=args.masterKey
local disk=args.bootDrive
local auth={}
auth.sudo={}
local keys={}
local ok,sha256=pcall(load(disk:open("/lib/crypto/sha256").read()))
if not ok then
error("sha256 failed to load")
end
local users={}
local file=disk:open("/etc/passwd").read()
-- for p,i in ipairs(string.split(file,"\n")) do
-- for t,v in ipairs(string.split(v,":")) do
-- users[p][t]=v
-- end
-- end
function auth.sudo.isAproved(key)
return true
end
function auth.sudo.elevatePerms(password)
end
return auth

View File

@@ -0,0 +1,14 @@
-- Copyright (C) 2025 ASTRONAND
local lib={}
function lib.create(def)
local function func(fun)
if type(fun)=="function" then
func=fun
end
return def
end
return func
end
return lib

6
disks/1h/sys/modules/ipc Normal file
View File

@@ -0,0 +1,6 @@
-- Copyright (C) 2025 ASTRONAND
local pipes={}
local ports={}
local sharedObjects={}
local net=require("net")

View File

@@ -0,0 +1,86 @@
-- Copyright (C) 2025 ASTRONAND
local args=({...})[1]
local log=args.logging
local fs=args.filesystem
local loaded=args.preload or {}
local function dot_to_slash(name)
local parts = {}
local start = 1
for i = 1, #name do
if name:sub(i, i) == "." then
table.insert(parts, name:sub(start, i - 1))
start = i + 1
end
end
table.insert(parts, name:sub(start))
return table.concat(parts, "/")
end
local function replace_question_mark(path, name_path)
local result = {}
local replaced = false
for i = 1, #path do
local ch = path:sub(i, i)
if ch == "?" and not replaced then
table.insert(result, name_path)
replaced = true
else
table.insert(result, ch)
end
end
return table.concat(result)
end
local function search_module(name,search_paths)
local name_path = dot_to_slash(name)
for _, path in ipairs(search_paths) do
local filename = replace_question_mark(path, name_path)
if fs.exists(filename) and not fs.isDir(filename) then
local code=fs.open(filename,"x")
if code then
return code, filename
end
end
end
return nil, "module not found: " .. name
end
return {
makeRequire=function(search_paths)
local config=string.split(search_paths,";")
return {
require=function(query)
if loaded[query] then return table.deepcopy(loaded[query]) end
local code,file=search_module(query,config)
if code==nil then
error(file)
end
local ok,_,lib=pcall(pcall,code)
if ok then
log.log("Added: \""..query.."\" to require registry.")
loaded[query]=lib
return table.deepcopy(lib), file
else
log.warn("ERR in module "..file)
return nil, "ERR in module "..file.."."
end
end,
load=function(query, lib)
loaded[query]=lib
end
}
end,
list=function()
local list={}
for i,v in pairs(loaded) do
list[#list+1]={i=i,v=v}
end
local i=0
while i<#list do
i=i+1
return list[i].i, list[i].v
end
end
}

View File

View File

@@ -0,0 +1,152 @@
-- Copyright (C) 2025 ASTRONAND
local args=({...})[1]
local fs=require("filesystem")
--local sfs=fs.getSudo(args.masterKey)
local auth=require("auth")
local system={}
local uuid=-1
local computer=component.getFirst("computer")
local time=computer.time()
local tasks={}
local currentTask={}
system.version="1.0.0"
system.name="HyperionOS"
-- Task status
-- "R" | Runnable/Running
-- "S" | Sleeping/Waiting
-- "P" | Stopped/Paused
-- "Z" | Exited/Zombie
-- "E" | Errored
-- "T" | Terminate
-- "X" | Marked for GC
local function UUID()
uuid=uuid+1
return tostring(uuid)
end
function system.createTaskFromFunc(func, name, ...)
local id=UUID()
local fargs={...}
local task={}
local handle={}
task={
sleep=0,
state="N",
thread=coroutine.create(function()
local ret={pcall(func, table.unpack(fargs))}
local ok, tret = ret[1], {table.unpack(ret,2)}
if not ok then
task.state="E"
task.exit_state=tret[1]
task.exit_code=1
else
if #tret>0 then
task.state="Z"
task.exit_state=tret
task.exit_code=0
else
task.state="X"
end
end
end),
PID=id,
name=name,
comm=string.sub(name, 1, 32),
parent=currentTask,
chlidren={},
sibling=currentTask.chlidren,
files={},
nvcsw=0,
nivcsw=0,
handle=handle,
start_time=computer.time()
}
tasks[id]=task
local close=false
function handle.exists()
return not close
end
function handle.kill()
close=true
task.state="T"
end
function handle.pause()
if close then return "Handle closed" end
if task.state=="R" then
task.state="P"
return true
else
return false
end
end
function handle.resume()
if close then return "Handle closed" end
if task.state=="P" then
task.state="R"
return true
else
return false
end
end
function handle.getPID()
if close then return "Handle closed" end
return task.PID
end
function handle.getParent()
if close then return "Handle closed" end
return task.parent.PID
end
function handle.getChildren()
if close then return "Handle closed" end
local ret = {}
for i,v in pairs(task.chlidren) do
ret[#ret+1] = v.PID
end
return ret
end
function handle.getState()
if close then return "Handle closed" end
return task.state
end
return handle
end
function system.createTaskFromFile(path, name, ...)
local file = fs.open(path, "x")
return system.createTaskFromFunc(file, name, ...)
end
function system.getTaskInfo(pid)
local task = tasks[pid]
if task == nil then return "No task with id "..pid end
return {
PID=task.PID,
parent=task.parent.PID,
sibling=(function()
local ret = {}
for i,v in pairs(task.sibling) do
ret[#ret+1] = i
end
return ret
end)(),
chlidren=(function()
local ret = {}
for i,v in pairs(task.chlidren) do
ret[#ret+1] = i
end
return ret
end)(),
name=task.name,
state=task.state,
nvcsw=task.nvcsw,
nivcsw=task.nivcsw,
start_time=task.start_time
}
end
function system.getCurrentTask()
return system.getTaskInfo(currentTask.PID)
end