From 200b99eb0c4d0497db3781bfd9b68983916408b5 Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Fri, 20 Dec 2019 15:22:18 +1100 Subject: [PATCH] moved tape-iofs to tape-devfs, made it handle tape drive addition/removal over time --- service/tape-devfs.lua | 23 +++++++++++++++++++++++ service/tape-iofs.lua | 8 -------- 2 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 service/tape-devfs.lua delete mode 100644 service/tape-iofs.lua diff --git a/service/tape-devfs.lua b/service/tape-devfs.lua new file mode 100644 index 0000000..3fd0421 --- /dev/null +++ b/service/tape-devfs.lua @@ -0,0 +1,23 @@ +local counter = 0 +local td = {} +local function addNode(addr) + devfs.register("tape"..tonumber(counter),function() + local tape = component.proxy(addr) + return tape.read, tape.write, function() end, tape.seek + end) + td[addr] = counter + counter = counter + 1 +end +for addr in component.list("tape_drive") do + addNode(addr) +end +while true do + local tE = {coroutine.yield()} + if tE[1] == "component_added" and tE[3] == "tape_drive" then + addNode[tE[2]] + elseif tE[1] == "component_removed" and tE[3] == "tape_drive" then + if td[tE[2]] then + fs.remove("/dev/tape"..tostring(td[tE[2]])) + end + end +end diff --git a/service/tape-iofs.lua b/service/tape-iofs.lua deleted file mode 100644 index 4a0a7d1..0000000 --- a/service/tape-iofs.lua +++ /dev/null @@ -1,8 +0,0 @@ -local counter = 0 -for addr in component.list("tape_drive") do - iofs.register("tape"..tonumber(counter),function() - local tape = component.proxy(addr) - return tape.read, tape.write, function() end, tape.seek - end) - counter = counter + 1 -end