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