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