2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
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
10 http://www.apache.org/licenses/LICENSE-2.0
15 require("luci.tools.webadmin")
17 local fs = require "nixio.fs"
18 local util = require "nixio.util"
21 util.consume((fs.glob("/dev/sd*")), devices)
22 util.consume((fs.glob("/dev/hd*")), devices)
23 util.consume((fs.glob("/dev/scd*")), devices)
24 util.consume((fs.glob("/dev/mmc*")), devices)
27 for i, dev in ipairs(devices) do
28 local s = tonumber((fs.readfile("/sys/class/block/%s/size" % dev:sub(6))))
29 size[dev] = s and math.floor(s / 2048)
33 m = Map("fstab", translate("Mount Points"))
35 local mounts = luci.sys.mounts()
37 v = m:section(Table, mounts, translate("Mounted file systems"))
39 fs = v:option(DummyValue, "fs", translate("Filesystem"))
41 mp = v:option(DummyValue, "mountpoint", translate("Mount Point"))
43 avail = v:option(DummyValue, "avail", translate("Available"))
44 function avail.cfgvalue(self, section)
45 return luci.tools.webadmin.byte_format(
46 ( tonumber(mounts[section].available) or 0 ) * 1024
47 ) .. " / " .. luci.tools.webadmin.byte_format(
48 ( tonumber(mounts[section].blocks) or 0 ) * 1024
52 used = v:option(DummyValue, "used", translate("Used"))
53 function used.cfgvalue(self, section)
54 return ( mounts[section].percent or "0%" ) .. " (" ..
55 luci.tools.webadmin.byte_format(
56 ( tonumber(mounts[section].used) or 0 ) * 1024
62 mount = m:section(TypedSection, "mount", translate("Mount Points"), translate("Mount Points define at which point a memory device will be attached to the filesystem"))
63 mount.anonymous = true
64 mount.addremove = true
65 mount.template = "cbi/tblsection"
66 mount.extedit = luci.dispatcher.build_url("admin/system/fstab/mount/%s")
68 mount.create = function(...)
69 local sid = TypedSection.create(...)
71 luci.http.redirect(mount.extedit % sid)
77 mount:option(Flag, "enabled", translate("Enabled")).rmempty = false
79 dev = mount:option(DummyValue, "device", translate("Device"))
80 dev.cfgvalue = function(self, section)
83 v = m.uci:get("fstab", section, "uuid")
84 if v then return "UUID: %s" % v end
86 v = m.uci:get("fstab", section, "label")
87 if v then return "Label: %s" % v end
89 v = Value.cfgvalue(self, section) or "?"
90 return size[v] and "%s (%s MB)" % {v, size[v]} or v
93 mp = mount:option(DummyValue, "target", translate("Mount Point"))
94 mp.cfgvalue = function(self, section)
95 if m.uci:get("fstab", section, "is_rootfs") == "1" then
98 return Value.cfgvalue(self, section) or "?"
102 fs = mount:option(DummyValue, "fstype", translate("Filesystem"))
103 fs.cfgvalue = function(self, section)
104 return Value.cfgvalue(self, section) or "?"
107 op = mount:option(DummyValue, "options", translate("Options"))
108 op.cfgvalue = function(self, section)
109 return Value.cfgvalue(self, section) or "defaults"
112 rf = mount:option(DummyValue, "is_rootfs", translate("Root"))
113 rf.cfgvalue = function(self, section)
114 return Value.cfgvalue(self, section) == "1"
115 and translate("yes") or translate("no")
118 ck = mount:option(DummyValue, "enabled_fsck", translate("Check"))
119 ck.cfgvalue = function(self, section)
120 return Value.cfgvalue(self, section) == "1"
121 and translate("yes") or translate("no")
125 swap = m:section(TypedSection, "swap", "SWAP", translate("If your physical memory is insufficient unused data can be temporarily swapped to a swap-device resulting in a higher amount of usable <abbr title=\"Random Access Memory\">RAM</abbr>. Be aware that swapping data is a very slow process as the swap-device cannot be accessed with the high datarates of the <abbr title=\"Random Access Memory\">RAM</abbr>."))
126 swap.anonymous = true
127 swap.addremove = true
128 swap.template = "cbi/tblsection"
129 swap.extedit = luci.dispatcher.build_url("admin/system/fstab/swap/%s")
131 swap.create = function(...)
132 local sid = TypedSection.create(...)
134 luci.http.redirect(swap.extedit % sid)
140 swap:option(Flag, "enabled", translate("Enabled")).rmempty = false
142 dev = swap:option(DummyValue, "device", translate("Device"))
143 dev.cfgvalue = function(self, section)
146 v = m.uci:get("fstab", section, "uuid")
147 if v then return "UUID: %s" % v end
149 v = m.uci:get("fstab", section, "label")
150 if v then return "Label: %s" % v end
152 v = Value.cfgvalue(self, section) or "?"
153 return size[v] and "%s (%s MB)" % {v, size[v]} or v