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()
40 local non_system_mounts = {}
41 for rawmount, val in pairs(mounts) do
44 if (val.mountpoint == "/") then
46 elseif (val.mountpoint == "/overlay") then
48 elseif (val.mountpoint == "/rom") then
50 elseif (val.mountpoint == "/tmp") then
52 elseif (val.mountpoint == "/tmp/shm") then
54 elseif (val.mountpoint == "/tmp/upgrade") then
56 elseif (val.mountpoint == "/dev") then
61 non_system_mounts[rawmount] = val
65 v = m:section(Table, non_system_mounts, translate("Mounted file systems"))
67 fs = v:option(DummyValue, "fs", translate("Filesystem"))
69 mp = v:option(DummyValue, "mountpoint", translate("Mount Point"))
71 avail = v:option(DummyValue, "avail", translate("Available"))
72 function avail.cfgvalue(self, section)
73 return luci.tools.webadmin.byte_format(
74 ( tonumber(mounts[section].available) or 0 ) * 1024
75 ) .. " / " .. luci.tools.webadmin.byte_format(
76 ( tonumber(mounts[section].blocks) or 0 ) * 1024
80 used = v:option(DummyValue, "used", translate("Used"))
81 function used.cfgvalue(self, section)
82 return ( mounts[section].percent or "0%" ) .. " (" ..
83 luci.tools.webadmin.byte_format(
84 ( tonumber(mounts[section].used) or 0 ) * 1024
88 unmount = v:option(Button, "unmount", translate("Unmount"))
89 unmount.render = function(self, section, scope)
90 if non_system_mounts[section].umount then
91 self.title = translate("Unmount")
92 self.inputstyle = "remove"
93 Button.render(self, section, scope)
97 unmount.write = function(self, section)
98 if non_system_mounts[section].umount then
99 luci.sys.call("/bin/umount '%s'" % luci.util.shellstartsqescape(non_system_mounts[section].mountpoint))
100 return luci.http.redirect(luci.dispatcher.build_url("admin/system", "fstab"))
104 mount = m:section(TypedSection, "mount", translate("Mount Points"), translate("Mount Points define at which point a memory device will be attached to the filesystem"))
105 mount.anonymous = true
106 mount.addremove = true
107 mount.template = "cbi/tblsection"
108 mount.extedit = luci.dispatcher.build_url("admin/system/fstab/mount/%s")
110 mount.create = function(...)
111 local sid = TypedSection.create(...)
113 luci.http.redirect(mount.extedit % sid)
119 mount:option(Flag, "enabled", translate("Enabled")).rmempty = false
121 dev = mount:option(DummyValue, "device", translate("Device"))
123 dev.cfgvalue = function(self, section)
126 v = m.uci:get("fstab", section, "uuid")
127 e = v and devices[v:lower()]
128 if v and e and e.size then
129 return "UUID: %s (%s, %d MB)" %{ tp.pcdata(v), e.dev, e.size }
131 return "UUID: %s (%s)" %{ tp.pcdata(v), e.dev }
133 return "UUID: %s (<em>%s</em>)" %{ tp.pcdata(v), translate("not present") }
136 v = m.uci:get("fstab", section, "label")
138 if v and e and e.size then
139 return "Label: %s (%s, %d MB)" %{ tp.pcdata(v), e.dev, e.size }
141 return "Label: %s (%s)" %{ tp.pcdata(v), e.dev }
143 return "Label: %s (<em>%s</em>)" %{ tp.pcdata(v), translate("not present") }
146 v = Value.cfgvalue(self, section) or "?"
148 if v and e and e.size then
149 return "%s (%d MB)" %{ tp.pcdata(v), e.size }
153 return "%s (<em>%s</em>)" %{ tp.pcdata(v), translate("not present") }
157 mp = mount:option(DummyValue, "target", translate("Mount Point"))
158 mp.cfgvalue = function(self, section)
159 if m.uci:get("fstab", section, "is_rootfs") == "1" then
162 return Value.cfgvalue(self, section) or "?"
166 fs = mount:option(DummyValue, "fstype", translate("Filesystem"))
167 fs.cfgvalue = function(self, section)
170 v = m.uci:get("fstab", section, "uuid")
171 v = v and v:lower() or m.uci:get("fstab", section, "label")
172 v = v or m.uci:get("fstab", section, "device")
176 return e and e.type or m.uci:get("fstab", section, "fstype") or "?"
179 op = mount:option(DummyValue, "options", translate("Options"))
180 op.cfgvalue = function(self, section)
181 return Value.cfgvalue(self, section) or "defaults"
184 rf = mount:option(DummyValue, "is_rootfs", translate("Root"))
185 rf.cfgvalue = function(self, section)
186 local target = m.uci:get("fstab", section, "target")
187 if target == "/" then
188 return translate("yes")
189 elseif target == "/overlay" then
190 return translate("overlay")
192 return translate("no")
196 ck = mount:option(DummyValue, "enabled_fsck", translate("Check"))
197 ck.cfgvalue = function(self, section)
198 return Value.cfgvalue(self, section) == "1"
199 and translate("yes") or translate("no")
203 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>."))
204 swap.anonymous = true
205 swap.addremove = true
206 swap.template = "cbi/tblsection"
207 swap.extedit = luci.dispatcher.build_url("admin/system/fstab/swap/%s")
209 swap.create = function(...)
210 local sid = TypedSection.create(...)
212 luci.http.redirect(swap.extedit % sid)
218 swap:option(Flag, "enabled", translate("Enabled")).rmempty = false
220 dev = swap:option(DummyValue, "device", translate("Device"))
221 dev.cfgvalue = function(self, section)
224 v = m.uci:get("fstab", section, "uuid")
225 if v then return "UUID: %s" % v end
227 v = m.uci:get("fstab", section, "label")
228 if v then return "Label: %s" % v end
230 v = Value.cfgvalue(self, section) or "?"
232 if v and e and e.size then
233 return "%s (%s MB)" % {v, e.size}