Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local c = require("component")
- local fs = require("filesystem")
- local event = require("event")
- local tape = c.tape_drive
- local readed = 0
- local file0, file1, file2, file3, file4, file5, file6, file7, file8, file9
- print("Mounting tape to \"/usr/tape\"...")
- local pos = tape.getPosition()
- tape.seek(-pos)
- local isTapeFS = tape.read(4)
- if isTapeFS=="TPFS" then
- print("Tape has filesystem. So, tape can have files")
- for i=0, 9, 1 do
- local file = fs.open("/usr/tape/file" .. i .. ".raw", "a")
- print("Writed 4KB file to /usr/tape/file" .. i .. ".raw")
- file:write(tape.read(4000))
- file:close()
- end
- print("Writing done!")
- else
- print("Filesystem error. Tape will mounted as one file")
- print("Reading all data to 1 file")
- tape.seek(-4)
- fs.remove("/usr/tape/tape.raw")
- local file = fs.open("/usr/tape/tape.raw", "a")
- for i = 1, tape.getSize(),100 do
- local byte = tape.read(100)
- if string.byte(byte)==0 then
- break
- else
- readed = readed + 100
- file:write(byte)
- print("Writed \"" .. byte .. "\". First byte: " .. string.byte(byte))
- end
- end
- file:close()
- print("Writing done!")
- end
- while true do
- os.execute("cls")
- if isTapeFS=="TPFS" then
- print("TapeFS v1 - Working with prepared cassete By !( Del )!")
- print("-------------------------------------------------------------------------------")
- print("1. Edit cassete files data ")
- print("2. Apply changes, Unmount cassete and exit from program ")
- print(" ")
- print("-------------------------------------------------------------------------------")
- print("Cassete size: " .. tape.getSize() / 1000 .. "KB, but can work with 10 4KB files")
- print("-------------------------------------------------------------------------------")
- local _, _, _, choice = event.pull("key_down")
- if choice==2 then
- os.execute("cls")
- print("Number of file(0-9)")
- local file = io.read()
- os.execute("edit /usr/tape/file" .. file .. ".raw")
- end
- if choice==3 then
- tape.seek(-900000)
- tape.write(string.rep(" ", 900000))
- tape.seek(-900000)
- tape.seek(4)
- local skip = 0
- for i=0, 9, 1 do
- skip = 0
- local file = fs.open("/usr/tape/file" .. i .. ".raw")
- local content = file:read(4000)
- if not content then content = "" end
- if content:len() < 4000 then
- skip = 4000 - content:len()
- end
- file:close()
- print("Writing data to file " .. i .. "... Position: " .. tape.getPosition() .. "b")
- tape.write(content)
- tape.seek(skip)
- fs.remove("/usr/tape/file" .. i .. ".raw")
- --tape.seek(4000)
- end
- tape.seek(-900000)
- tape.write("TPFS")
- os.exit()
- end
- else
- print("TapeFS v1 - Working with not prepared cassete By !( Del )!")
- print("----------------------------------------------------------------------")
- print("1. Edit cassete data ")
- print("2. Unmount cassete and exit from program ")
- print("3. Make a filesystem on cassete ")
- print("----------------------------------------------------------------------")
- print("Cassete size: " .. tape.getSize() / 1000 .. "KB ")
- print("----------------------------------------------------------------------")
- local _, _, _, choice = event.pull("key_down")
- if choice==2 then
- os.execute("edit /usr/tape/tape.raw")
- local file = fs.open("/usr/tape/tape.raw")
- local content = file:read(4000)
- if not content then content = "" end
- file:close()
- print("Writing data...")
- for i=1, readed,100 do
- tape.write(string.rep(string.char(0), 100))
- end
- tape.seek(-9000000)
- tape.write(content)
- end
- if choice==3 then
- fs.remove("/usr/tape/tape.raw")
- os.exit()
- end
- if choice==4 then
- os.execute("cls")
- print("Making a filesystem will erase ALL data from cassete. Are you sure?(Y/n)")
- local confirm = io.read()
- if confirm=="y" then
- print("That your choice... Removing all data from cassete...")
- tape.seek(-900000)
- for i=1, readed, 100 do
- tape.write(string.rep(string.char(0), 100))
- end
- tape.seek(-900000)
- print("Removing complete.")
- print("Writing data about filesystem")
- tape.write("TPFS")
- print("All done!")
- os.exit()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement