Drives and serial. #3

Closed
sam wants to merge 4 commits from sam/LuPPC:blkdev-and-serial into master
21 changed files with 555 additions and 24 deletions

View File

@ -4,6 +4,7 @@ extern char lua_boot[];
extern char lua_component[];
extern char lua_computer[];
extern char lua_debug[];
extern char lua_drive[];
extern char lua_eeprom[];
extern char lua_fbgpu[];
extern char lua_filesystem[];
@ -12,9 +13,11 @@ extern char lua_gpudetect[];
extern char lua_init[];
extern char lua_internet[];
extern char lua_sandbox[];
extern char lua_serial[];
extern char lua_textgpu[];
extern char lua_util_buffer[];
extern char lua_util_color[];
extern char lua_util_random[];
extern char lua_uuidmgr[];
extern char lua_winapigpu[];
#endif

View File

@ -22,9 +22,13 @@ typedef unsigned short ushort;
lua_State* getL();
char * get_kbid(); // ugly hack
void run_init(int argc, char **argv);
void lupi_init();
void luanative_start(lua_State *L);
void serial_start(lua_State *L);
void blk_start(lua_State *L);
void fb_start(lua_State *L);
void setup_modules(lua_State *L);
void termutils_start(lua_State *L);

155
src/c/blkdev.c Normal file
View File

@ -0,0 +1,155 @@
#include "lupi.h"
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <linux/fs.h>
#include <linux/hdreg.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
struct blkdev {
int fd;
int secsize;
int platters;
size_t size;
char * buffer;
};
int blk_open(lua_State * L) {
char * path = luaL_checkstring(L, 1);
char rpath[255];
sprintf(rpath, "/dev/%s", path);
int fd = open(rpath, O_RDWR | O_DSYNC);
if (fd == -1) {
luaL_error(L, "Failed to open %s: %s", rpath, strerror(errno));
}
struct blkdev * dev = lua_newuserdata(L, sizeof(struct blkdev));
dev->fd = fd;
struct hd_driveid driveid;
if (ioctl(fd, HDIO_GET_IDENTITY, &driveid) < 0) {
//luaL_error("Failed to get identity for %s", rpath);
dev->platters = 3;
// Use another ioctl call to get sector size.
if (!ioctl(fd, BLKSSZGET, &dev->secsize)) {
// Fuck it, i guess it's 512 bytes.
dev->secsize = 512;
// Maybe a warning here?
}
dev->size = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
} else {
dev->size = driveid.lba_capacity_2*driveid.sector_bytes;
dev->platters = driveid.cur_heads/2;
dev->secsize = driveid.sector_bytes;
if (dev->size == 0) {
dev->size = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
}
if (dev->platters == 0) {
dev->platters = 3;
}
if (dev->secsize == 0) {
if (!ioctl(fd, BLKSSZGET, &dev->secsize)) {
// Fuck it, i guess it's 512 bytes.
dev->secsize = 512;
// Maybe a warning here too?
}
}
}
dev->buffer = malloc(dev->secsize);
return 1;
}
int blk_readbyte(lua_State * L) {
struct blkdev * dev = lua_touserdata(L, 1);
off_t offset = luaL_checkinteger(L, 2);
lseek(dev->fd, offset-1, SEEK_SET);
uint8_t c = 0;
size_t ioc = 0;
if ((ioc = read(dev->fd, &c, 1)) != 1) {
luaL_error(L, "io error! %llu != %llu", ioc, 1);
}
lua_pushinteger(L, c);
return 1;
}
int blk_writebyte(lua_State * L) {
struct blkdev * dev = lua_touserdata(L, 1);
off_t offset = luaL_checkinteger(L, 2);
long byte = luaL_checkinteger(L, 3);
if (byte > 255 || byte < 0)
luaL_error(L, "%lld is out of range (should be between 0 and 255)", byte);
uint8_t i = byte & 0xFF;
lseek(dev->fd, offset-1, SEEK_SET);
size_t ioc = 0;
if ((ioc = write(dev->fd, &i, 1)) != 1) {
luaL_error(L, "io error! %llu != %llu", ioc, 1);
}
return 0;
}
int blk_readsector(lua_State * L) {
struct blkdev * dev = lua_touserdata(L, 1);
off_t offset = luaL_checkinteger(L, 2);
lseek(dev->fd, (offset-1)*dev->secsize, SEEK_SET);
size_t ioc = 0;
if ((ioc = read(dev->fd, dev->buffer, dev->secsize)) != dev->secsize) {
luaL_error(L, "io error! %llu != %llu", ioc, dev->secsize);
}
lua_pushlstring(L, dev->buffer, dev->secsize);
return 1;
}
int blk_writesector(lua_State * L) {
struct blkdev * dev = lua_touserdata(L, 1);
off_t offset = luaL_checkinteger(L, 2);
size_t len = 0;
char * sec = luaL_checklstring(L, 3, &len);
lseek(dev->fd, (offset-1)*dev->secsize, SEEK_SET);
if (len > dev->secsize) {
len = dev->secsize;
}
size_t ioc = 0;
if ((ioc = write(dev->fd, sec, len)) != len) {
luaL_error(L, "io error! %llu != %llu", ioc, dev->secsize);
}
return 0;
}
int blk_getsecsize(lua_State * L) {
struct blkdev * dev = lua_touserdata(L, 1);
lua_pushinteger(L, dev->secsize);
return 1;
}
int blk_getsize(lua_State * L) {
struct blkdev * dev = lua_touserdata(L, 1);
lua_pushinteger(L, dev->size);
return 1;
}
int blk_getplatcount(lua_State * L) {
struct blkdev * dev = lua_touserdata(L, 1);
lua_pushinteger(L, dev->platters);
return 1;
}
void blk_start(lua_State * L) {
struct luaL_Reg blklib[] = {
{"open", blk_open},
{"readbyte", blk_readbyte},
{"writebyte", blk_writebyte},
{"readsector", blk_readsector},
{"writesector", blk_writesector},
{"secsize", blk_getsecsize},
{"size", blk_getsize},
{"platcount", blk_getplatcount},
{NULL, NULL}
};
luaL_openlib(L, "blk", blklib, 0);
}

View File

@ -35,7 +35,7 @@ static void handleStdin(evutil_socket_t fd, short what, void *eventc) {
lua_getglobal(L, "pushEvent");
lua_pushstring(L, "key_down");
lua_pushstring(L, "TODO:SetThisUuid");/* Also in textgpu.lua */
lua_pushstring(L, get_kbid());/* Also in textgpu.lua */
lua_pushnumber(L, buf);
lua_pushnumber(L, -1);
lua_pushstring(L, "root");
@ -43,7 +43,7 @@ static void handleStdin(evutil_socket_t fd, short what, void *eventc) {
lua_getglobal(L, "pushEvent");
lua_pushstring(L, "key_up");
lua_pushstring(L, "TODO:SetThisUuid");
lua_pushstring(L, get_kbid());
lua_pushnumber(L, buf);
lua_pushnumber(L, -1);
lua_pushstring(L, "root");

View File

@ -12,6 +12,7 @@ void lupi_init() {
mount(NULL, "/sys", "sysfs", 0, NULL);
mount(NULL, "/proc", "procfs", 0, NULL);
mount(NULL, "/tmp", "tmpfs", 0, NULL);
mount(NULL, "/dev", "devtmpfs", 0, NULL);
}
struct statvfs fsstat;

View File

@ -476,6 +476,20 @@ static int l_debug (lua_State *L) {
}
#endif
char * kbid = "TODO:SetThisUuid";
static int l_setkbid(lua_State *L) {
size_t len = 0;
char * id = luaL_checklstring(L, 1, &len);
kbid = malloc(len+1);
memcpy(kbid, id, len);
return 0;
}
char * get_kbid() {
return kbid;
}
void luanative_start(lua_State *L) {
struct timeval tp;
@ -511,6 +525,7 @@ void luanative_start(lua_State *L) {
{"pull", l_pull},
{"platform", l_platform},
{"isinit", l_isinit},
{"setkbid", l_setkbid},
#ifdef DEBUG
{"debug", l_debug},
#endif

View File

@ -14,17 +14,20 @@ void setup_modules(lua_State *L) {
pushstuple(L, "component", lua_component);
pushstuple(L, "computer", lua_computer);
pushstuple(L, "debug", lua_debug);
pushstuple(L, "drive", lua_drive);
pushstuple(L, "eeprom", lua_eeprom);
pushstuple(L, "filesystem", lua_filesystem);
pushstuple(L, "gpio", lua_gpio);
pushstuple(L, "gpudetect", lua_gpudetect);
pushstuple(L, "internet", lua_internet);
pushstuple(L, "sandbox", lua_sandbox);
pushstuple(L, "serial", lua_serial);
pushstuple(L, "textgpu", lua_textgpu);
pushstuple(L, "fbgpu", lua_fbgpu);
pushstuple(L, "winapigpu", lua_winapigpu);
pushstuple(L, "color", lua_util_color);
pushstuple(L, "random", lua_util_random);
pushstuple(L, "uuidmgr", lua_uuidmgr);
pushstuple(L, "buffer", lua_util_buffer);
pushstuple(L, "eepromDefault", res_eepromDefault);

View File

@ -31,6 +31,8 @@ void run_init(int argc, char **argv) {
#endif
fb_start (L);
termutils_start (L);
serial_start (L);
blk_start (L);
event_prepare();
int status = luaL_loadbuffer(L, lua_init, strlen(lua_init), "=INIT");

159
src/c/serial.c Normal file
View File

@ -0,0 +1,159 @@
#include "lupi.h"
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <sys/stat.h>
int s_listports(lua_State * L) {
DIR * d = opendir("/sys/class/tty");
struct dirent * ent = NULL;
struct stat statbuf;
char path[255];
char linkpath[255];
lua_newtable(L);
size_t index = 1;
while ((ent = readdir(d)) != NULL) {
sprintf(path, "/sys/class/tty/%s/device", ent->d_name);
if (stat(path, &statbuf) == 0) {
readlink(path, linkpath, 255);
if (strstr(linkpath, "serial8250") == NULL) {
// We have a serial port
lua_pushinteger(L, index);
lua_pushstring(L, ent->d_name);
lua_settable(L, -3);
}
}
}
return 1;
}
struct baudrate {
uint32_t baud;
tcflag_t flags;
};
// taken from here: https://man7.org/linux/man-pages/man3/termios.3.html
struct baudrate baudrates[] = {
{0, B0},
{50, B50},
{75, B75},
{110, B110},
{134, B134},
{150, B150},
{200, B200},
{300, B300},
{600, B600},
{1200, B1200},
{1800, B1800},
{2400, B2400},
{4800, B4800},
{9600, B9600},
{19200, B19200},
{38400, B38400},
{57600, B57600},
{115200, B115200},
{230400, B230400}
};
struct baudrate * getbaud(uint32_t baud) {
for (size_t i=0; i<sizeof(baudrates)/sizeof(struct baudrate); ++i) {
if (baudrates[i].baud == baud) {
return &baudrates[i];
} else if (baudrates[i].baud > baud) {
return &baudrates[i-1];
}
}
return getbaud(230400);
}
struct sport {
uint32_t baudrate;
int fd;
struct termios options;
};
int s_openport(lua_State * L) {
char * path = luaL_checkstring(L, 1);
struct sport * port = lua_newuserdata(L, sizeof(struct sport));
port->baudrate = 9600;
char rpath[255];
sprintf(rpath, "/dev/%s", path);
port->fd = open(rpath, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK);
if (port->fd == -1)
luaL_error(L, "unable to open port %s: ", path, strerror(errno));
tcgetattr(port->fd, &port->options);
cfsetispeed(&port->options, B9600);
cfsetospeed(&port->options, B9600);
tcsetattr(port->fd, TCSANOW, &port->options);
return 1;
}
int s_setbaudrate(lua_State * L) {
struct sport * port = lua_touserdata(L, 1);
long raw_br = luaL_checkinteger(L, 2);
struct baudrate * br = getbaud(raw_br & 0xFFFFFFFF);
//port->options.c_cflag &= ~(CBAUD);
//port->options.c_cflag |= br->flags;
cfsetispeed(&port->options, br->flags);
cfsetospeed(&port->options, br->flags);
port->baudrate = br->baud;
lua_pushinteger(L, br->baud);
port->options.c_cflag &= ~PARENB;
port->options.c_cflag &= ~CSTOPB;
port->options.c_cflag &= ~CSIZE;
port->options.c_cflag |= CS8;
tcsetattr(port->fd, TCSANOW, &port->options);
return 1;
}
int s_getbaudrate(lua_State * L) {
struct sport * port = lua_touserdata(L, 1);
lua_pushinteger(L, port->baudrate);
return 1;
}
int s_write(lua_State * L) {
struct sport * port = lua_touserdata(L, 1);
size_t len = 0;
char * data = luaL_checklstring(L, 2, &len);
size_t ioc = 0;
if ((ioc = write(port->fd, data, len)) != len) {
luaL_error(L, "io error! %llu != %llu", ioc, len);
}
return 0;
}
int s_read(lua_State * L) {
struct sport * port = lua_touserdata(L, 1);
char buffer[2048]; // Max packet size
long size = luaL_checkinteger(L, 2);
size_t ioc = read(port->fd, buffer, size);
if (ioc != size && ioc != 0) {
luaL_error(L, "io error! %llu != %llu or 0", ioc, size);
} else if (ioc != 0) {
lua_pushlstring(L, buffer, size);
return 1;
}
return 0;
}
void serial_start(lua_State * L) {
struct luaL_Reg seriallib[] = {
{"open", s_openport},
{"list", s_listports},
{"write", s_write},
{"read", s_read},
{"setbaud", s_setbaudrate},
{"getbaud", s_getbaudrate},
{NULL, NULL}
};
luaL_openlib(L, "serial", seriallib, 0);
}

View File

@ -109,7 +109,7 @@ function api.invoke(address, method, ...)
local msg = tostring((native.uptime() - start) / 1000) .. " [+" .. native.uptime() - last .. "] " .. caller.short_src .. ":".. caller.currentline .. " > c.invoke(" .. address .. "): "
.. components[address].type .. "." .. method
.. "(" .. table.concat(t, ", ") .. ")"
native.log(msg)
--native.log(msg)
end
return components[address].rawproxy[method](...)
end

74
src/lua/core/drive.lua Normal file
View File

@ -0,0 +1,74 @@
local drive = {}
function drive.register()
local list = native.fs_list("/sys/block")
for _, ent in ipairs(list) do
-- Match hard drives. floppy drives, an rewindable tape drives
if (ent:match("sd%a%d*") or ent:match("hd%a%d*") or ent:match("fd%d+") or ent:match("n?st%d+[lma]?") or ent:match("n?ht%d+[lma]?")) then
--if true then
lprint("Attempting to open: "..ent)
local ok, disk = pcall(blk.open, ent)
if ok then
local nh = io.open("/sys/block/"..ent.."/device/model", "r")
local name = nh:read("*a"):gsub("%s+$", "")
nh:close()
nh = io.open("/sys/block/"..ent.."/device/vendor", "r")
local vendor = nh:read("*a"):gsub("%s+$", "")
nh:close()
nh = io.open("/sys/block/"..ent.."/device/wwid", "r")
local wwid
if nh then
wwid = nh:read("*a"):gsub("%s+$", "")
nh:close()
end
local component = {}
function component.readByte(offset)
return blk.readbyte(disk, offset)
end
function component.writeByte(offset, value)
return blk.writebyte(disk, offset, value)
end
function component.getLabel()
return name
end
function component.setLabel(str)
-- stub
return name
end
function component.readSector(sec)
return blk.readsector(disk, sec)
end
function component.writeSector(sec, val)
return blk.writesector(disk, sec, val)
end
function component.getPlatterCount()
return blk.platcount(disk)
end
function component.getSectorSize()
return blk.secsize(disk)
end
function component.getCapacity()
return blk.size(disk)
end
local gid = wwid or (vendor.." "..name.." "..ent)
modules.component.api.register(modules.uuidmgr.lookup("drive", gid), "drive", component)
else
lprint("Can't open blkdev: "..ent..": "..disk)
end
end
end
end
return drive

View File

@ -62,7 +62,7 @@ function eeprom.register()
function component.makeReadonly()
return false, "Method stub"
end
modules.component.api.register(nil, "eeprom", component)
modules.component.api.register(modules.uuidmgr.lookup("eeprom", "lmao"), "eeprom", component)
end
return eeprom

View File

@ -165,9 +165,9 @@ function fbgpu.start()
termutils.init()
write("\x1b[?25l") --Disable cursor
modules.component.api.register(nil, "gpu", gpu)
screenAddr = modules.component.api.register(nil, "screen", {getKeyboards = function() return {"TODO:SetThisUuid"} end}) --verry dummy screen, TODO: make it better, kbd uuid also in epoll.c
modules.component.api.register("TODO:SetThisUuid", "keyboard", {})
modules.component.api.register(modules.uuidmgr.lookup("gpu", "fbgpu"), "gpu", gpu)
screenAddr = modules.component.api.register(modules.uuidmgr.lookup("screen", "lmao"), "screen", {getKeyboards = function() return {modules.uuidmgr.lookup("keyboard", "lmao")} end}) --verry dummy screen, TODO: make it better, kbd uuid also in epoll.c
modules.component.api.register(modules.uuidmgr.lookup("keyboard", "lmao"), "keyboard", {})
deadhooks[#deadhooks + 1] = function()
write("\x1b[?25h") --Enable cursor on quit

View File

@ -50,7 +50,7 @@ local function concat(pathA, pathB, ...)
return canonical(_concat(2, pathA, pathB, ...))
end
function filesystem.register(basePath, uuid)
function filesystem.register(basePath, identifier)
checkArg(1, basePath, "string")
if not native.fs_exists(basePath) then
@ -156,7 +156,7 @@ function filesystem.register(basePath, uuid)
checkArg(1, value, "number")
return value --TODO: Implement, use real labels
end
return modules.component.api.register(uuid, "filesystem", fs)
return modules.component.api.register(modules.uuidmgr.lookup("filesystem", identifier or basePath), "filesystem", fs)
end
return filesystem

View File

@ -68,7 +68,7 @@ gpio.register = function ()
end
return _read("/sys/class/gpio/gpio" .. pin .. "/value")
end
return modules.component.api.register(uuid, "gpio", component)
return modules.component.api.register(modules.uuidmgr.lookup("gpio", "lmao"), "gpio", component)
end
return gpio

View File

@ -44,6 +44,10 @@ lprint = function (...)
end
lprint("LuPI L1 INIT")
local ports = serial.list()
for i=1, #ports do
lprint(ports[i])
end
modules = {}
deadhooks = {}
@ -74,10 +78,14 @@ function main()
loadModule("debug")
end
loadModule("random")
loadModule("uuidmgr")
loadModule("color")
loadModule("buffer")
modules.address = modules.random.uuid() --TODO: PREALPHA: Make constant
--modules.address = modules.random.uuid() --TODO: PREALPHA: Make constant
modules.address = modules.uuidmgr.lookup("modules", "lmao") --Made constant
native.setkbid(modules.uuidmgr.lookup("keyboard", "lmao"))
--Core
loadModule("component")
@ -90,6 +98,8 @@ function main()
loadModule("gpudetect")
loadModule("filesystem")
loadModule("internet")
loadModule("serial")
loadModule("drive")
--Userspace
loadModule("sandbox")
@ -99,19 +109,20 @@ function main()
modules.component.prepare()
modules.computer.prepare()
_G.pushEvent = modules.computer.api.pushSignal
modules.serial.register()
modules.drive.register()
modules.eeprom.register()
modules.gpio.register()
modules.internet.start()
modules.filesystem.register("root")
modules.filesystem.register("root", "root")
if native.debug and native.platform():match("unix") then
modules.filesystem.register("/", "11111111-1111-1111-1111-111111111111")
modules.filesystem.register("/", "realroot")
end
if native.platform():match("unix") then
modules.computer.tmp = modules.filesystem.register("/tmp/lupi-" .. modules.random.uuid())
modules.computer.tmp = modules.filesystem.register("/tmp/lupi-" .. modules.random.uuid(), "tmpfs")
else
native.fs_mkdir("tmp")
modules.computer.tmp = modules.filesystem.register("tmp/lupi-" .. modules.random.uuid())
modules.computer.tmp = modules.filesystem.register("tmp/lupi-" .. modules.random.uuid(), "tmpfs")
--TODO: cleaning hook or something
end
@ -120,7 +131,7 @@ function main()
if native.debug then
modules.debug.hook()
end
modules.uuidmgr.store()
modules.boot.boot()
end

View File

@ -157,7 +157,7 @@ function internet.start()
}
end
modules.component.api.register(nil, "internet", component)
modules.component.api.register(modules.uuidmgr.lookup("internet", "lmao"), "internet", component)
end
return internet

32
src/lua/core/serial.lua Normal file
View File

@ -0,0 +1,32 @@
local com = {}
function com.register()
local ports = serial.list()
for i=1, #ports do
lprint("Serial port: "..ports[i])
local component = {}
local ok, dev = pcall(serial.open, ports[i])
if not dev then lprint("Can't open port: "..ports[i]..": "..dev) goto continue end
--lprint(dev)
function component.setBaudRate(baud)
return serial.setbaud(dev, baud)
end
function component.getBaudRate()
return serial.getbaud(dev)
end
function component.write(s)
return serial.write(dev, s)
end
function component.read(amt)
return serial.read(dev, amt)
end
modules.component.api.register(modules.uuidmgr.lookup("serial", ports[i]), "serial", component)
::continue::
end
end
return com

View File

@ -255,9 +255,9 @@ function textgpu.start()
gpu.setForeground(0xFFFFFF)
gpu.setBackground(0x000000)
local gpuaddr = modules.component.api.register(nil, "gpu", gpu)
screenAddr = modules.component.api.register(nil, "screen", {getKeyboards = function() return {"TODO:SetThisUuid"} end}) --verry dummy screen, TODO: make it better, kbd uuid also in epoll.c
modules.component.api.register("TODO:SetThisUuid", "keyboard", {})
local gpuaddr = modules.component.api.register(modules.uuidmgr.lookup("gpu", "text"), "gpu", gpu)
screenAddr = modules.component.api.register(modules.uuidmgr.lookup("screen", "lmao"), "screen", {getKeyboards = function() return {modules.uuidmgr.lookup("keyboard", "lmao")} end}) --verry dummy screen, TODO: make it better, kbd uuid also in epoll.c
modules.component.api.register(modules.uuidmgr.lookup("keyboard", "lmao"), "keyboard", {})
deadhooks[#deadhooks + 1] = function()
write("\x1b[?25h\x1b[" .. ((h-1)|0) .. ";1H") --Enable cursor on quit

72
src/lua/core/uuidmgr.lua Normal file
View File

@ -0,0 +1,72 @@
local uuidmgr = {
fileversion = 0
}
local uuidstorage = {}
local storeheader = "c36HH" -- oops
do
local store = io.open("uuidstore.dat", "r")
if store then
if native.debug then lprint("DEBUG: Loading uuidstore.dat...") end
pcall(function()
local version, count = string.unpack("IH", store:read(6))
if native.debug then lprint(string.format("DEBUG: File version %u, count %u", version, count)) end
if version > uuidmgr.fileversion then
lprint("ERROR: Invalid version!")
error("invalid version")
end
for i=1, count do
local uuid, clen, ilen = storeheader:unpack(store:read(storeheader:packsize()))
local cname, id = store:read(clen), store:read(ilen)
uuidstorage[cname] = uuidstorage[cname] or {}
uuidstorage[cname][id] = uuid
if native.debug then lprint(string.format("DEBUG: Found %s:%s's UUID of %s", cname, id, uuid)) end
end
store:close()
end)
end
end
function uuidmgr.lookup(component, identifier)
uuidstorage[component] = uuidstorage[component] or {}
local uuid = uuidstorage[component][identifier]
if not uuid then
uuid = modules.random.uuid()
if native.debug then
lprint(string.format("DEBUG: Registed component of type %s with identifier %s as uuid %s", component, identifier, uuid))
end
uuidstorage[component][identifier] = uuid
uuidmgr.store()
else
if native.debug then
lprint(string.format("DEBUG: Looked up component of type %s with identifier %s as uuid %s", component, identifier, uuid))
end
end
return uuid
end
function uuidmgr.store()
local store = io.open("uuidstore.dat", "w")
local saved_ids = {}
for component, ids in pairs(uuidstorage) do
for id, uuid in pairs(ids) do
table.insert(saved_ids, {uuid=uuid, component=component, id=id})
end
end
if native.debug then
lprint(string.format("DEBUG: Saving %d static UUIDs", #saved_ids))
end
store:write(string.pack("IH", uuidmgr.fileversion, #saved_ids))
for i=1, #saved_ids do
local uuid, component, id = saved_ids[i].uuid, saved_ids[i].component, saved_ids[i].id
store:write(storeheader:pack(uuid, #component, #id),component,id)
if native.debug then
lprint(string.format("DEBUG: Saving %s:%s as %s", component, id, uuid))
end
end
store:close()
end
return uuidmgr

View File

@ -158,9 +158,9 @@ function wingpu.start()
lprint("Couldn't open window: " .. tostring(reason))
end
modules.component.api.register(nil, "gpu", gpu)
screenAddr = modules.component.api.register(nil, "screen", {getKeyboards = function() return {"TODO:SetThisUuid"} end}) --verry dummy screen, TODO: make it better, kbd uuid also in epoll.c
modules.component.api.register("TODO:SetThisUuid", "keyboard", {})
modules.component.api.register(modules.uuidmgr.lookup("gpu", "wingpu"), "gpu", gpu)
screenAddr = modules.component.api.register(modules.uuidmgr.lookup("screen", "lmao"), "screen", {getKeyboards = function() return {modules.uuidmgr.lookup("keyboard", "lmao")} end}) --verry dummy screen, TODO: make it better, kbd uuid also in epoll.c
modules.component.api.register(modules.uuidmgr.lookup("keyboard", "lmao"), "keyboard", {})
return s
end