7873842f817418e865dced5cf7571658e289196d
[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 "luci.fs"
17 local devices = {}
18 luci.util.update(devices, fs.glob("/dev/sd*") or {})
19 luci.util.update(devices, fs.glob("/dev/hd*") or {})
20 luci.util.update(devices, fs.glob("/dev/scd*") or {})
21 luci.util.update(devices, fs.glob("/dev/mmc*") or {})
22
23 local size = {}
24 for i, dev in ipairs(devices) do
25         local s = tonumber((luci.fs.readfile("/sys/class/block/%s/size" % dev:sub(6))))
26         size[dev] = s and math.floor(s / 2048)
27 end
28
29
30 m = Map("fstab", translate("a_s_fstab"))
31
32 local mounts = luci.sys.mounts()
33
34 v = m:section(Table, mounts, translate("a_s_fstab_active"))
35
36 fs = v:option(DummyValue, "fs", translate("filesystem"))
37
38 mp = v:option(DummyValue, "mountpoint", translate("a_s_fstab_mountpoint"))
39
40 avail = v:option(DummyValue, "avail", translate("a_s_fstab_avail"))
41 function avail.cfgvalue(self, section)
42         return luci.tools.webadmin.byte_format(
43                 ( tonumber(mounts[section].available) or 0 ) * 1024
44         ) .. " / " .. luci.tools.webadmin.byte_format(
45                 ( tonumber(mounts[section].blocks) or 0 ) * 1024
46         )
47 end
48
49 used = v:option(DummyValue, "used", translate("a_s_fstab_used"))
50 function used.cfgvalue(self, section)
51         return ( mounts[section].percent or "0%" ) .. " (" ..
52         luci.tools.webadmin.byte_format(
53                 ( tonumber(mounts[section].used) or 0 ) * 1024
54         ) .. ")"
55 end
56
57
58
59 mount = m:section(TypedSection, "mount", translate("a_s_fstab_mountpoints"), translate("a_s_fstab_mountpoints1"))
60 mount.anonymous = true
61 mount.addremove = true
62 mount.template = "cbi/tblsection"
63
64 mount:option(Flag, "enabled", translate("enable"))
65 dev = mount:option(Value, "device", translate("device"), translate("a_s_fstab_device1"))
66 for i, d in ipairs(devices) do
67         dev:value(d, size[d] and "%s (%s MB)" % {d, size[d]})
68 end
69
70 mount:option(Value, "target", translate("a_s_fstab_mountpoint"))
71 mount:option(Value, "fstype", translate("filesystem"), translate("a_s_fstab_fs1"))
72 mount:option(Value, "options", translate("options"), translatef("manpage", "siehe '%s' manpage", "mount"))
73
74
75 swap = m:section(TypedSection, "swap", "SWAP", translate("a_s_fstab_swap1"))
76 swap.anonymous = true
77 swap.addremove = true
78 swap.template = "cbi/tblsection"
79
80 swap:option(Flag, "enabled", translate("enable"))
81 dev = swap:option(Value, "device", translate("device"), translate("a_s_fstab_device1"))
82 for i, d in ipairs(devices) do
83         dev:value(d, size[d] and "%s (%s MB)" % {d, size[d]})
84 end
85
86 return m