aa4f12e554ce979e207a7869bd3e977a8702944b
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_system / fstab.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5
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
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14 require("luci.tools.webadmin")
15
16 local fs   = require "nixio.fs"
17 local util = require "nixio.util"
18
19 local devices = {}
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)
24
25 local size = {}
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)
29 end
30
31
32 m = Map("fstab", translate("a_s_fstab"))
33
34 local mounts = luci.sys.mounts()
35
36 v = m:section(Table, mounts, translate("a_s_fstab_active"))
37
38 fs = v:option(DummyValue, "fs", translate("filesystem"))
39
40 mp = v:option(DummyValue, "mountpoint", translate("a_s_fstab_mountpoint"))
41
42 avail = v:option(DummyValue, "avail", translate("a_s_fstab_avail"))
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
48         )
49 end
50
51 used = v:option(DummyValue, "used", translate("a_s_fstab_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
56         ) .. ")"
57 end
58
59
60
61 mount = m:section(TypedSection, "mount", translate("a_s_fstab_mountpoints"), translate("a_s_fstab_mountpoints1"))
62 mount.anonymous = true
63 mount.addremove = true
64 mount.template = "cbi/tblsection"
65
66 mount:option(Flag, "enabled", translate("enable")).rmempty = false
67 dev = mount:option(Value, "device", translate("device"), translate("a_s_fstab_device1"))
68 for i, d in ipairs(devices) do
69         dev:value(d, size[d] and "%s (%s MB)" % {d, size[d]})
70 end
71
72 mount:option(Value, "target", translate("a_s_fstab_mountpoint"))
73 mount:option(Value, "fstype", translate("filesystem"), translate("a_s_fstab_fs1"))
74 mount:option(Value, "options", translate("options"), translatef("manpage", "siehe '%s' manpage", "mount"))
75
76
77 swap = m:section(TypedSection, "swap", "SWAP", translate("a_s_fstab_swap1"))
78 swap.anonymous = true
79 swap.addremove = true
80 swap.template = "cbi/tblsection"
81
82 swap:option(Flag, "enabled", translate("enable")).rmempty = false
83 dev = swap:option(Value, "device", translate("device"), translate("a_s_fstab_device1"))
84 for i, d in ipairs(devices) do
85         dev:value(d, size[d] and "%s (%s MB)" % {d, size[d]})
86 end
87
88 return m