1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
4 require("luci.tools.webadmin")
6 local fs = require "nixio.fs"
7 local util = require "nixio.util"
8 local tp = require "luci.template.parser"
10 local block = io.popen("block info", "r")
11 local ln, dev, devices = nil, nil, {}
15 dev = ln and ln:match("^/dev/(.-):")
18 local e, s, key, val = { }
20 for key, val in ln:gmatch([[(%w+)="(.-)"]]) do
25 s = tonumber((fs.readfile("/sys/class/block/%s/size" % dev)))
27 e.dev = "/dev/%s" % dev
28 e.size = s and math.floor(s / 2048)
37 m = Map("fstab", translate("Mount Points"))
39 local mounts = luci.sys.mounts()
41 v = m:section(Table, mounts, translate("Mounted file systems"))
43 fs = v:option(DummyValue, "fs", translate("Filesystem"))
45 mp = v:option(DummyValue, "mountpoint", translate("Mount Point"))
47 avail = v:option(DummyValue, "avail", translate("Available"))
48 function avail.cfgvalue(self, section)
49 return luci.tools.webadmin.byte_format(
50 ( tonumber(mounts[section].available) or 0 ) * 1024
51 ) .. " / " .. luci.tools.webadmin.byte_format(
52 ( tonumber(mounts[section].blocks) or 0 ) * 1024
56 used = v:option(DummyValue, "used", translate("Used"))
57 function used.cfgvalue(self, section)
58 return ( mounts[section].percent or "0%" ) .. " (" ..
59 luci.tools.webadmin.byte_format(
60 ( tonumber(mounts[section].used) or 0 ) * 1024
66 mount = m:section(TypedSection, "mount", translate("Mount Points"), translate("Mount Points define at which point a memory device will be attached to the filesystem"))
67 mount.anonymous = true
68 mount.addremove = true
69 mount.template = "cbi/tblsection"
70 mount.extedit = luci.dispatcher.build_url("admin/system/fstab/mount/%s")
72 mount.create = function(...)
73 local sid = TypedSection.create(...)
75 luci.http.redirect(mount.extedit % sid)
81 mount:option(Flag, "enabled", translate("Enabled")).rmempty = false
83 dev = mount:option(DummyValue, "device", translate("Device"))
85 dev.cfgvalue = function(self, section)
88 v = m.uci:get("fstab", section, "uuid")
89 e = v and devices[v:lower()]
90 if v and e and e.size then
91 return "UUID: %s (%s, %d MB)" %{ tp.pcdata(v), e.dev, e.size }
93 return "UUID: %s (%s)" %{ tp.pcdata(v), e.dev }
95 return "UUID: %s (<em>%s</em>)" %{ tp.pcdata(v), translate("not present") }
98 v = m.uci:get("fstab", section, "label")
100 if v and e and e.size then
101 return "Label: %s (%s, %d MB)" %{ tp.pcdata(v), e.dev, e.size }
103 return "Label: %s (%s)" %{ tp.pcdata(v), e.dev }
105 return "Label: %s (<em>%s</em>)" %{ tp.pcdata(v), translate("not present") }
108 v = Value.cfgvalue(self, section) or "?"
110 if v and e and e.size then
111 return "%s (%d MB)" %{ tp.pcdata(v), e.size }
115 return "%s (<em>%s</em>)" %{ tp.pcdata(v), translate("not present") }
119 mp = mount:option(DummyValue, "target", translate("Mount Point"))
120 mp.cfgvalue = function(self, section)
121 if m.uci:get("fstab", section, "is_rootfs") == "1" then
124 return Value.cfgvalue(self, section) or "?"
128 fs = mount:option(DummyValue, "fstype", translate("Filesystem"))
129 fs.cfgvalue = function(self, section)
132 v = m.uci:get("fstab", section, "uuid")
133 v = v and v:lower() or m.uci:get("fstab", section, "label")
134 v = v or m.uci:get("fstab", section, "device")
138 return e and e.type or m.uci:get("fstab", section, "fstype") or "?"
141 op = mount:option(DummyValue, "options", translate("Options"))
142 op.cfgvalue = function(self, section)
143 return Value.cfgvalue(self, section) or "defaults"
146 rf = mount:option(DummyValue, "is_rootfs", translate("Root"))
147 rf.cfgvalue = function(self, section)
148 local target = m.uci:get("fstab", section, "target")
149 if target == "/" then
150 return translate("yes")
151 elseif target == "/overlay" then
152 return translate("overlay")
154 return translate("no")
158 ck = mount:option(DummyValue, "enabled_fsck", translate("Check"))
159 ck.cfgvalue = function(self, section)
160 return Value.cfgvalue(self, section) == "1"
161 and translate("yes") or translate("no")
165 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>."))
166 swap.anonymous = true
167 swap.addremove = true
168 swap.template = "cbi/tblsection"
169 swap.extedit = luci.dispatcher.build_url("admin/system/fstab/swap/%s")
171 swap.create = function(...)
172 local sid = TypedSection.create(...)
174 luci.http.redirect(swap.extedit % sid)
180 swap:option(Flag, "enabled", translate("Enabled")).rmempty = false
182 dev = swap:option(DummyValue, "device", translate("Device"))
183 dev.cfgvalue = function(self, section)
186 v = m.uci:get("fstab", section, "uuid")
187 if v then return "UUID: %s" % v end
189 v = m.uci:get("fstab", section, "label")
190 if v then return "Label: %s" % v end
192 v = Value.cfgvalue(self, section) or "?"
194 if v and e and e.size then
195 return "%s (%s MB)" % {v, e.size}