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()]
91 return "UUID: %s (%s, %d MB)" %{ tp.pcdata(v), e.dev, e.size }
93 return "UUID: %s (<em>%s</em>)" %{ tp.pcdata(v), translate("not present") }
96 v = m.uci:get("fstab", section, "label")
99 return "Label: %s (%s, %d MB)" %{ tp.pcdata(v), e.dev, e.size }
101 return "Label: %s (<em>%s</em>)" %{ tp.pcdata(v), translate("not present") }
104 v = Value.cfgvalue(self, section) or "?"
107 return "%s (%d MB)" %{ tp.pcdata(v), e.size }
109 return "%s (<em>%s</em>)" %{ tp.pcdata(v), translate("not present") }
113 mp = mount:option(DummyValue, "target", translate("Mount Point"))
114 mp.cfgvalue = function(self, section)
115 if m.uci:get("fstab", section, "is_rootfs") == "1" then
118 return Value.cfgvalue(self, section) or "?"
122 fs = mount:option(DummyValue, "fstype", translate("Filesystem"))
123 fs.cfgvalue = function(self, section)
126 v = m.uci:get("fstab", section, "uuid")
127 v = v and v:lower() or m.uci:get("fstab", section, "label")
128 v = v or m.uci:get("fstab", section, "device")
132 return e and e.type or m.uci:get("fstab", section, "fstype") or "?"
135 op = mount:option(DummyValue, "options", translate("Options"))
136 op.cfgvalue = function(self, section)
137 return Value.cfgvalue(self, section) or "defaults"
140 rf = mount:option(DummyValue, "is_rootfs", translate("Root"))
141 rf.cfgvalue = function(self, section)
142 local target = m.uci:get("fstab", section, "target")
143 if target == "/" then
144 return translate("yes")
145 elseif target == "/overlay" then
146 return translate("overlay")
148 return translate("no")
152 ck = mount:option(DummyValue, "enabled_fsck", translate("Check"))
153 ck.cfgvalue = function(self, section)
154 return Value.cfgvalue(self, section) == "1"
155 and translate("yes") or translate("no")
159 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>."))
160 swap.anonymous = true
161 swap.addremove = true
162 swap.template = "cbi/tblsection"
163 swap.extedit = luci.dispatcher.build_url("admin/system/fstab/swap/%s")
165 swap.create = function(...)
166 local sid = TypedSection.create(...)
168 luci.http.redirect(swap.extedit % sid)
174 swap:option(Flag, "enabled", translate("Enabled")).rmempty = false
176 dev = swap:option(DummyValue, "device", translate("Device"))
177 dev.cfgvalue = function(self, section)
180 v = m.uci:get("fstab", section, "uuid")
181 if v then return "UUID: %s" % v end
183 v = m.uci:get("fstab", section, "label")
184 if v then return "Label: %s" % v end
186 v = Value.cfgvalue(self, section) or "?"
187 return size[v] and "%s (%s MB)" % {v, size[v]} or v