Advertisement
Guest User

Untitled

a guest
Aug 25th, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. local fs = require "filesystem"
  2. local args = {...}
  3.  
  4. local dev = args[1] or error("Must specify a file")
  5.  
  6. local device = fs.open(dev, "wb")
  7.  
  8. local sectors = math.floor(device:seek("end", 0)/512)
  9. print(sectors .. " sectors")
  10. device:seek("set", 0)
  11.  
  12. local fat12 = sectors/4 < 4085
  13. local fatSize = math.ceil(sectors*(fat12 and 1.5 or 2)/2048)
  14.  
  15. local startseq = "\xEB\x3C\x90ocdosfs\0"
  16. local bytesPerSector = "\0\2"
  17. local sectorsPerCluster = "\4"
  18. local reservedSectors = "\1\0"
  19. local fatnum = "\2"
  20. local dirent = "\0\2"
  21. local sectors = string.char(sectors%256) .. string.char(math.floor(sectors/256))
  22. local descriptor = "\xF8"
  23. local sectorsPerFat = string.char(fatSize%256) .. string.char(math.floor(fatSize/256))
  24. local sectorsPerTrack = "\x20\0"
  25. local heads = "\x40\0"
  26. local hiddenSect = "\0\0\0\0"
  27. local largeSectorAmount = "\0\0\0\0"
  28.  
  29. local drivenum = "\x80"
  30. local ntflags = "\0"
  31. local signature = "\x29"
  32. local id = "\0\0\0\0"
  33. local label = "NO NAME    "
  34. local sysid = fat12 and "FAT12   " or "FAT16   "
  35. local bootcode = ("\0"):rep(448)
  36. local bootsig = "\x55\xAA"
  37.  
  38. local bootRecord = startseq .. bytesPerSector .. sectorsPerCluster .. reservedSectors .. fatnum .. dirent .. sectors .. descriptor
  39.     .. sectorsPerFat .. sectorsPerTrack .. heads .. hiddenSect .. largeSectorAmount
  40.     .. drivenum .. ntflags .. signature .. id .. label .. sysid .. bootcode .. bootsig
  41.  
  42. print("Boot record size: " .. #bootRecord)
  43.  
  44. device:write(bootRecord)
  45.  
  46. print("Cleaning FAT tables")
  47. os.sleep(0)
  48.  
  49. for i = 1, fatSize * 2 do --related to fat sizes/count
  50.     device:write(("\0"):rep(512))
  51. end
  52.  
  53. print("Cleaning Root Directory")
  54. os.sleep(0)
  55.  
  56. for i = 1, 512 do
  57.     device:write(("\0"):rep(32))
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement