forked from Hyperion/HyperionOS
super dupper system update (it runs)
This commit is contained in:
@@ -1,57 +1,196 @@
|
||||
local args = {...}
|
||||
local kernel = args[1]
|
||||
local data = kernel.fs.mkvirtfs("devfs0000", true, "devfs", true)
|
||||
if not kernel.fs.isDir("/dev") then kernel.fs.makeDir("/dev") end
|
||||
kernel.devfs={}
|
||||
kernel.devfs.data=data
|
||||
local kernel = ...
|
||||
|
||||
data["/"]["OSVERSION"]="Hyperion 1.0.0"
|
||||
data["/"]["eeprom"]={
|
||||
__file=true,
|
||||
read=function()
|
||||
return kernel.computer:getEEPROM()
|
||||
local proxy = {}
|
||||
local data = {}
|
||||
|
||||
proxy.address = "devfs0000"
|
||||
proxy.isReadOnly = false
|
||||
proxy.spaceUsed = function() return 0 end
|
||||
proxy.spaceTotal = function() return 0 end
|
||||
proxy.makeDirectory = function() error("Permission denied") end
|
||||
proxy.remove = function() error("Permission denied") end
|
||||
proxy.setLabel = function() error("Permission denied") end
|
||||
proxy.getLabel = function() return "devfs" end
|
||||
proxy.attributes = function(path) return {
|
||||
type = proxy.type(path),
|
||||
isReadOnly = false,
|
||||
size = 0,
|
||||
lastModified = 0,
|
||||
created = 0,
|
||||
Permissions = "666",
|
||||
owner = "root",
|
||||
group = "root"
|
||||
} end
|
||||
|
||||
local function getNode(path)
|
||||
local parts = string.split(path, "/")
|
||||
if parts[1] == "" then
|
||||
table.remove(parts, 1)
|
||||
end
|
||||
|
||||
local node = data
|
||||
for _, part in ipairs(parts) do
|
||||
if node[part] then
|
||||
node = node[part]
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
return node
|
||||
end
|
||||
|
||||
proxy.type = function(path)
|
||||
local node = getNode(path)
|
||||
if node then
|
||||
return node.type
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
proxy.list = function(path)
|
||||
local node = getNode(path)
|
||||
if node and node.type == "directory" then
|
||||
local content = table.keys(node)
|
||||
table.remove(content, table.indexOf(content, "type"))
|
||||
return content
|
||||
else
|
||||
error("Not a directory")
|
||||
end
|
||||
end
|
||||
|
||||
proxy.open = function(path, mode)
|
||||
local node = getNode(path)
|
||||
if node and (node.type == "file" or node.type == "character device") then
|
||||
if mode == "r" then
|
||||
return {
|
||||
read = node.read,
|
||||
close = function() end
|
||||
}
|
||||
elseif mode == "w" then
|
||||
return {
|
||||
write = node.write,
|
||||
close = function() end
|
||||
}
|
||||
else
|
||||
error("Invalid mode")
|
||||
end
|
||||
else
|
||||
error("Not a file"..type(node))
|
||||
end
|
||||
end
|
||||
|
||||
local function newStringFile(content)
|
||||
return {
|
||||
type = "file",
|
||||
read = function() return content end,
|
||||
write = function(newContent) content = newContent end
|
||||
}
|
||||
end
|
||||
|
||||
local function newDirectory()
|
||||
return {
|
||||
type = "directory"
|
||||
}
|
||||
end
|
||||
|
||||
data["random"] = {
|
||||
type = "character device",
|
||||
read = function(amount)
|
||||
local result = ""
|
||||
for _ = 1, amount do
|
||||
result = result .. string.char(math.random(0, 255))
|
||||
end
|
||||
return result
|
||||
end,
|
||||
write=function(text)
|
||||
if kernel.uid ~= 0 then error("Permission Denied") end
|
||||
kernel.computer:setEEPROM(text)
|
||||
write = function() error("Permission denied") end
|
||||
}
|
||||
|
||||
data["null"] = {
|
||||
type = "character device",
|
||||
read = function() return "" end,
|
||||
write = function() end
|
||||
}
|
||||
|
||||
data["zero"] = {
|
||||
type = "character device",
|
||||
read = function(amount)
|
||||
return string.rep("\0", amount)
|
||||
end,
|
||||
write = function() error("Permission denied") end
|
||||
}
|
||||
|
||||
data["rtc"] = {
|
||||
type = "character device",
|
||||
read = function() return kernel.computer:time() end,
|
||||
write = function() error("Permission denied") end
|
||||
}
|
||||
|
||||
data["rtc0"] = {
|
||||
type = "character device",
|
||||
read = function() return kernel.computer:time() end,
|
||||
write = function() error("Permission denied") end
|
||||
}
|
||||
|
||||
data["eeprom"] = {
|
||||
type = "character device",
|
||||
read = function() return kernel.computer:getEEPROM() end,
|
||||
write = function(data)
|
||||
if kernel.uid ~= 0 then
|
||||
error("Permission denied")
|
||||
end
|
||||
kernel.computer:setEEPROM(data)
|
||||
end
|
||||
}
|
||||
data["/"]["null"]={
|
||||
__file=true,
|
||||
read=function() end,
|
||||
write=function() end
|
||||
}
|
||||
data["/"]["random"]={
|
||||
__file=true,
|
||||
read=function(amount)
|
||||
local s = ""
|
||||
for i = 1, amount do
|
||||
s = s .. string.char(math.random(0, 255))
|
||||
end
|
||||
return s
|
||||
|
||||
data["stdin"] = {
|
||||
type = "link",
|
||||
read = function(amount)
|
||||
return kernel.currentTask.fd[0].read(amount)
|
||||
end,
|
||||
write=function() end
|
||||
}
|
||||
data["/"]["zero"]={
|
||||
__file=true,
|
||||
read=function(amount)
|
||||
return ("\0"):rep(amount)
|
||||
end,
|
||||
write=function() end
|
||||
}
|
||||
data["/"]["rtc0"]={
|
||||
__file=true,
|
||||
read=function()
|
||||
return kernel.computer:time()
|
||||
end,
|
||||
write=function() end
|
||||
}
|
||||
data["/"]["rtc"]={
|
||||
__file=true,
|
||||
read=function()
|
||||
return kernel.computer:time()
|
||||
end,
|
||||
write=function() end
|
||||
write = function() error("Permission denied") end
|
||||
}
|
||||
|
||||
kernel.log("Created devfs")
|
||||
data["stdout"] = {
|
||||
type = "link",
|
||||
read = function() error("Permission denied") end,
|
||||
write = function(data)
|
||||
kernel.currentTask.fd[1].write(data)
|
||||
end
|
||||
}
|
||||
|
||||
data["stderr"] = {
|
||||
type = "link",
|
||||
read = function() error("Permission denied") end,
|
||||
write = function(data)
|
||||
kernel.currentTask.fd[2] = data
|
||||
end
|
||||
}
|
||||
|
||||
local keyboard = kernel.newFifo()
|
||||
local mouse = kernel.newFifo()
|
||||
data["input"] = newDirectory()
|
||||
data["input"]["keyboard"] = {
|
||||
type = "pipe",
|
||||
read = function(amount)
|
||||
return keyboard.pop()
|
||||
end,
|
||||
write = function() error("Permission denied") end
|
||||
}
|
||||
data["input"]["mouse"] = {
|
||||
type = "pipe",
|
||||
read = function(amount)
|
||||
return mouse.pop()
|
||||
end,
|
||||
write = function() error("Permission denied") end
|
||||
}
|
||||
|
||||
data["pts"] = newDirectory()
|
||||
|
||||
kernel.devfs = {}
|
||||
kernel.devfs.keyboard = keyboard
|
||||
kernel.devfs.mouse = mouse
|
||||
kernel.devfs.proxy = proxy
|
||||
kernel.devfs.data = data
|
||||
kernel.vfs.virtdisk(proxy)
|
||||
Reference in New Issue
Block a user