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
14 require("luci.tools.webadmin")
16 local fs = require "nixio.fs"
17 local util = require "nixio.util"
20 util.consume((fs.glob("/dev/sd*")), devices)
21 util.consume((fs.glob("/dev/hd*")), devices)
22 util.consume((fs.glob("/dev/scd*")), devices)
23 util.consume((fs.glob("/dev/mmc*")), devices)
26 for i, dev in ipairs(devices) do
27 local s = tonumber((fs.readfile("/sys/class/block/%s/size" % dev:sub(6))))
28 size[dev] = s and math.floor(s / 2048)
32 m = Map("fstab", translate("Mount Points"))
34 local mounts = luci.sys.mounts()
36 v = m:section(Table, mounts, translate("Mounted file systems"))
38 fs = v:option(DummyValue, "fs", translate("Filesystem"))
40 mp = v:option(DummyValue, "mountpoint", translate("Mount Point"))
42 avail = v:option(DummyValue, "avail", translate("Available"))
43 function avail.cfgvalue(self, section)
44 return luci.tools.webadmin.byte_format(
45 ( tonumber(mounts[section].available) or 0 ) * 1024
46 ) .. " / " .. luci.tools.webadmin.byte_format(
47 ( tonumber(mounts[section].blocks) or 0 ) * 1024
51 used = v:option(DummyValue, "used", translate("Used"))
52 function used.cfgvalue(self, section)
53 return ( mounts[section].percent or "0%" ) .. " (" ..
54 luci.tools.webadmin.byte_format(
55 ( tonumber(mounts[section].used) or 0 ) * 1024
61 mount = m:section(TypedSection, "mount", translate("Mount Points"), translate("Mount Points define at which point a memory device will be attached to the filesystem"))
62 mount.anonymous = true
63 mount.addremove = true
64 mount.template = "cbi/tblsection"
66 mount:option(Flag, "enabled", translate("enable")).rmempty = false
67 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>)"))
68 for i, d in ipairs(devices) do
69 dev:value(d, size[d] and "%s (%s MB)" % {d, size[d]})
72 mount:option(Value, "target", translate("Mount Point"))
73 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>)"))
74 mount:option(Value, "options", translate("Options"), translate("See \"mount\" manpage for details"))
77 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>."))
80 swap.template = "cbi/tblsection"
82 swap:option(Flag, "enabled", translate("enable")).rmempty = false
83 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>)"))
84 for i, d in ipairs(devices) do
85 dev:value(d, size[d] and "%s (%s MB)" % {d, size[d]})