diff options
Diffstat (limited to 'modules')
4 files changed, 254 insertions, 11 deletions
diff --git a/modules/admin-full/luasrc/controller/admin/system.lua b/modules/admin-full/luasrc/controller/admin/system.lua index 67dbc3fc73..95961f49db 100644 --- a/modules/admin-full/luasrc/controller/admin/system.lua +++ b/modules/admin-full/luasrc/controller/admin/system.lua @@ -29,6 +29,8 @@ function index() if nixio.fs.access("/etc/config/fstab") then entry({"admin", "system", "fstab"}, cbi("admin_system/fstab"), i18n("Mount Points"), 50) + entry({"admin", "system", "fstab", "mount"}, cbi("admin_system/fstab/mount"), nil).leaf = true + entry({"admin", "system", "fstab", "swap"}, cbi("admin_system/fstab/swap"), nil).leaf = true end if nixio.fs.access("/sys/class/leds") then diff --git a/modules/admin-full/luasrc/model/cbi/admin_system/fstab.lua b/modules/admin-full/luasrc/model/cbi/admin_system/fstab.lua index a70174d395..8ac3d6d5e7 100644 --- a/modules/admin-full/luasrc/model/cbi/admin_system/fstab.lua +++ b/modules/admin-full/luasrc/model/cbi/admin_system/fstab.lua @@ -11,6 +11,7 @@ You may obtain a copy of the License at $Id$ ]]-- + require("luci.tools.webadmin") local fs = require "nixio.fs" @@ -62,27 +63,94 @@ mount = m:section(TypedSection, "mount", translate("Mount Points"), translate("M mount.anonymous = true mount.addremove = true mount.template = "cbi/tblsection" +mount.extedit = luci.dispatcher.build_url("admin/system/fstab/mount/%s") + +mount.create = function(...) + local sid = TypedSection.create(...) + if sid then + luci.http.redirect(mount.extedit % sid) + return + end +end + + +mount:option(Flag, "enabled", translate("Enabled")).rmempty = false + +dev = mount:option(DummyValue, "device", translate("Device")) +dev.cfgvalue = function(self, section) + local v + + v = m.uci:get("fstab", section, "uuid") + if v then return "UUID: %s" % v end + + v = m.uci:get("fstab", section, "label") + if v then return "Label: %s" % v end + + v = Value.cfgvalue(self, section) or "?" + return size[v] and "%s (%s MB)" % {v, size[v]} or v +end + +mp = mount:option(DummyValue, "target", translate("Mount Point")) +mp.cfgvalue = function(self, section) + if m.uci:get("fstab", section, "is_rootfs") == "1" then + return "/overlay" + else + return Value.cfgvalue(self, section) or "?" + end +end -mount:option(Flag, "enabled", translate("enable")).rmempty = false -dev = mount:option(Value, "device", translate("Device"), translate("The device file of the memory or partition (<abbr title=\"for example\">e.g.</abbr> <code>/dev/sda1</code>)")) -for i, d in ipairs(devices) do - dev:value(d, size[d] and "%s (%s MB)" % {d, size[d]}) +fs = mount:option(DummyValue, "fstype", translate("Filesystem")) +fs.cfgvalue = function(self, section) + return Value.cfgvalue(self, section) or "?" end -mount:option(Value, "target", translate("Mount Point")) -mount:option(Value, "fstype", translate("Filesystem"), translate("The filesystem that was used to format the memory (<abbr title=\"for example\">e.g.</abbr> <samp><abbr title=\"Third Extended Filesystem\">ext3</abbr></samp>)")) -mount:option(Value, "options", translate("Options"), translate("See \"mount\" manpage for details")) +op = mount:option(DummyValue, "options", translate("Options")) +op.cfgvalue = function(self, section) + return Value.cfgvalue(self, section) or "defaults" +end + +rf = mount:option(DummyValue, "is_rootfs", translate("Root")) +rf.cfgvalue = function(self, section) + return Value.cfgvalue(self, section) == "1" + and translate("yes") or translate("no") +end + +ck = mount:option(DummyValue, "enabled_fsck", translate("Check")) +ck.cfgvalue = function(self, section) + return Value.cfgvalue(self, section) == "1" + and translate("yes") or translate("no") +end 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>.")) swap.anonymous = true swap.addremove = true swap.template = "cbi/tblsection" +swap.extedit = luci.dispatcher.build_url("admin/system/fstab/swap/%s") + +swap.create = function(...) + local sid = TypedSection.create(...) + if sid then + luci.http.redirect(swap.extedit % sid) + return + end +end + + +swap:option(Flag, "enabled", translate("Enabled")).rmempty = false + +dev = swap:option(DummyValue, "device", translate("Device")) +dev.cfgvalue = function(self, section) + local v + + v = m.uci:get("fstab", section, "uuid") + if v then return "UUID: %s" % v end + + v = m.uci:get("fstab", section, "label") + if v then return "Label: %s" % v end -swap:option(Flag, "enabled", translate("enable")).rmempty = false -dev = swap:option(Value, "device", translate("Device"), translate("The device file of the memory or partition (<abbr title=\"for example\">e.g.</abbr> <code>/dev/sda1</code>)")) -for i, d in ipairs(devices) do - dev:value(d, size[d] and "%s (%s MB)" % {d, size[d]}) + v = Value.cfgvalue(self, section) or "?" + return size[v] and "%s (%s MB)" % {v, size[v]} or v end return m diff --git a/modules/admin-full/luasrc/model/cbi/admin_system/fstab/mount.lua b/modules/admin-full/luasrc/model/cbi/admin_system/fstab/mount.lua new file mode 100644 index 0000000000..bb58cca003 --- /dev/null +++ b/modules/admin-full/luasrc/model/cbi/admin_system/fstab/mount.lua @@ -0,0 +1,108 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2010 Jo-Philipp Wich <xm@subsignal.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ +]]-- + +local fs = require "nixio.fs" +local util = require "nixio.util" + +local has_extroot = fs.access("/lib/preinit/00_extroot.conf") +local has_fscheck = fs.access("/lib/functions/fsck.sh") + +local devices = {} +util.consume((fs.glob("/dev/sd*")), devices) +util.consume((fs.glob("/dev/hd*")), devices) +util.consume((fs.glob("/dev/scd*")), devices) +util.consume((fs.glob("/dev/mmc*")), devices) + +local size = {} +for i, dev in ipairs(devices) do + local s = tonumber((fs.readfile("/sys/class/block/%s/size" % dev:sub(6)))) + size[dev] = s and math.floor(s / 2048) +end + + +m = Map("fstab", translate("Mount Points - Mount Entry")) +m.redirect = luci.dispatcher.build_url("admin/system/fstab") + +if not arg[1] or m.uci:get("fstab", arg[1]) ~= "mount" then + luci.http.redirect(m.redirect) + return +end + + + +mount = m:section(NamedSection, arg[1], "mount", translate("Mount Entry")) +mount.anonymous = true +mount.addremove = false + +mount:tab("general", translate("General Settings")) +mount:tab("advanced", translate("Advanced Settings")) + + +mount:taboption("general", Flag, "enabled", translate("Enable this mount")).rmempty = false + + +o = mount:taboption("general", Value, "device", translate("Device"), + translate("The device file of the memory or partition (<abbr title=\"for example\">e.g.</abbr> <code>/dev/sda1</code>)")) + +for i, d in ipairs(devices) do + o:value(d, size[d] and "%s (%s MB)" % {d, size[d]}) +end + +o = mount:taboption("advanced", Value, "uuid", translate("UUID"), + translate("If specified, mount the device by its UUID instead of a fixed device node")) + +o = mount:taboption("advanced", Value, "label", translate("Label"), + translate("If specified, mount the device by the partition label instead of a fixed device node")) + + +o = mount:taboption("general", Value, "target", translate("Mount point"), + translate("Specifies the directory the device is attached to")) + +o:depends("is_rootfs", "") + + +o = mount:taboption("general", Value, "fstype", translate("Filesystem"), + translate("The filesystem that was used to format the memory (<abbr title=\"for example\">e.g.</abbr> <samp><abbr title=\"Third Extended Filesystem\">ext3</abbr></samp>)")) + +local fs +for fs in io.lines("/proc/filesystems") do + fs = fs:match("%S+") + if fs ~= "nodev" then + o:value(fs) + end +end + + +o = mount:taboption("advanced", Value, "options", translate("Mount options"), + translate("See \"mount\" manpage for details")) + +o.placeholder = "defaults" + + +if has_extroot then + o = mount:taboption("general", Flag, "is_rootfs", translate("Use as root filesystem"), + translate("Configures this mount as overlay storage for block-extroot")) + + o:depends("fstype", "jffs") + o:depends("fstype", "ext2") + o:depends("fstype", "ext3") + o:depends("fstype", "ext4") +end + +if has_fscheck then + o = mount:taboption("general", Flag, "enabled_fsck", translate("Run filesystem check"), + translate("Run a filesystem check before mounting the device")) +end + +return m diff --git a/modules/admin-full/luasrc/model/cbi/admin_system/fstab/swap.lua b/modules/admin-full/luasrc/model/cbi/admin_system/fstab/swap.lua new file mode 100644 index 0000000000..01d0ff90a5 --- /dev/null +++ b/modules/admin-full/luasrc/model/cbi/admin_system/fstab/swap.lua @@ -0,0 +1,65 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2010 Jo-Philipp Wich <xm@subsignal.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ +]]-- + +local fs = require "nixio.fs" +local util = require "nixio.util" + +local devices = {} +util.consume((fs.glob("/dev/sd*")), devices) +util.consume((fs.glob("/dev/hd*")), devices) +util.consume((fs.glob("/dev/scd*")), devices) +util.consume((fs.glob("/dev/mmc*")), devices) + +local size = {} +for i, dev in ipairs(devices) do + local s = tonumber((fs.readfile("/sys/class/block/%s/size" % dev:sub(6)))) + size[dev] = s and math.floor(s / 2048) +end + + +m = Map("fstab", translate("Mount Points - Swap Entry")) +m.redirect = luci.dispatcher.build_url("admin/system/fstab") + +if not arg[1] or m.uci:get("fstab", arg[1]) ~= "swap" then + luci.http.redirect(m.redirect) + return +end + + +mount = m:section(NamedSection, arg[1], "swap", translate("Swap Entry")) +mount.anonymous = true +mount.addremove = false + +mount:tab("general", translate("General Settings")) +mount:tab("advanced", translate("Advanced Settings")) + + +mount:taboption("general", Flag, "enabled", translate("Enable this swap")).rmempty = false + + +o = mount:taboption("general", Value, "device", translate("Device"), + translate("The device file of the memory or partition (<abbr title=\"for example\">e.g.</abbr> <code>/dev/sda1</code>)")) + +for i, d in ipairs(devices) do + o:value(d, size[d] and "%s (%s MB)" % {d, size[d]}) +end + +o = mount:taboption("advanced", Value, "uuid", translate("UUID"), + translate("If specified, mount the device by its UUID instead of a fixed device node")) + +o = mount:taboption("advanced", Value, "label", translate("Label"), + translate("If specified, mount the device by the partition label instead of a fixed device node")) + + +return m |