swap.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. -- Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local fs = require "nixio.fs"
  4. local util = require "nixio.util"
  5. local devices = {}
  6. util.consume((fs.glob("/dev/sd*")), devices)
  7. util.consume((fs.glob("/dev/hd*")), devices)
  8. util.consume((fs.glob("/dev/scd*")), devices)
  9. util.consume((fs.glob("/dev/mmc*")), devices)
  10. local size = {}
  11. for i, dev in ipairs(devices) do
  12. local s = tonumber((fs.readfile("/sys/class/block/%s/size" % dev:sub(6))))
  13. size[dev] = s and math.floor(s / 2048)
  14. end
  15. m = Map("fstab", translate("Mount Points - Swap Entry"))
  16. m.redirect = luci.dispatcher.build_url("admin/system/fstab")
  17. if not arg[1] or m.uci:get("fstab", arg[1]) ~= "swap" then
  18. luci.http.redirect(m.redirect)
  19. return
  20. end
  21. mount = m:section(NamedSection, arg[1], "swap", translate("Swap Entry"))
  22. mount.anonymous = true
  23. mount.addremove = false
  24. mount:tab("general", translate("General Settings"))
  25. mount:tab("advanced", translate("Advanced Settings"))
  26. mount:taboption("general", Flag, "enabled", translate("Enable this swap")).rmempty = false
  27. o = mount:taboption("general", Value, "device", translate("Device"),
  28. translate("The device file of the memory or partition (<abbr title=\"for example\">e.g.</abbr> <code>/dev/sda1</code>)"))
  29. for i, d in ipairs(devices) do
  30. o:value(d, size[d] and "%s (%s MB)" % {d, size[d]})
  31. end
  32. o = mount:taboption("advanced", Value, "uuid", translate("UUID"),
  33. translate("If specified, mount the device by its UUID instead of a fixed device node"))
  34. o = mount:taboption("advanced", Value, "label", translate("Label"),
  35. translate("If specified, mount the device by the partition label instead of a fixed device node"))
  36. return m