Globally reduce copyright headers
[project/luci.git] / modules / luci-mod-admin-full / luasrc / model / cbi / admin_system / fstab.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 require("luci.tools.webadmin")
5
6 local fs   = require "nixio.fs"
7 local util = require "nixio.util"
8
9 local devices = {}
10 util.consume((fs.glob("/dev/sd*")), devices)
11 util.consume((fs.glob("/dev/hd*")), devices)
12 util.consume((fs.glob("/dev/scd*")), devices)
13 util.consume((fs.glob("/dev/mmc*")), devices)
14
15 local size = {}
16 for i, dev in ipairs(devices) do
17         local s = tonumber((fs.readfile("/sys/class/block/%s/size" % dev:sub(6))))
18         size[dev] = s and math.floor(s / 2048)
19 end
20
21
22 m = Map("fstab", translate("Mount Points"))
23
24 local mounts = luci.sys.mounts()
25
26 v = m:section(Table, mounts, translate("Mounted file systems"))
27
28 fs = v:option(DummyValue, "fs", translate("Filesystem"))
29
30 mp = v:option(DummyValue, "mountpoint", translate("Mount Point"))
31
32 avail = v:option(DummyValue, "avail", translate("Available"))
33 function avail.cfgvalue(self, section)
34         return luci.tools.webadmin.byte_format(
35                 ( tonumber(mounts[section].available) or 0 ) * 1024
36         ) .. " / " .. luci.tools.webadmin.byte_format(
37                 ( tonumber(mounts[section].blocks) or 0 ) * 1024
38         )
39 end
40
41 used = v:option(DummyValue, "used", translate("Used"))
42 function used.cfgvalue(self, section)
43         return ( mounts[section].percent or "0%" ) .. " (" ..
44         luci.tools.webadmin.byte_format(
45                 ( tonumber(mounts[section].used) or 0 ) * 1024
46         ) .. ")"
47 end
48
49
50
51 mount = m:section(TypedSection, "mount", translate("Mount Points"), translate("Mount Points define at which point a memory device will be attached to the filesystem"))
52 mount.anonymous = true
53 mount.addremove = true
54 mount.template = "cbi/tblsection"
55 mount.extedit  = luci.dispatcher.build_url("admin/system/fstab/mount/%s")
56
57 mount.create = function(...)
58         local sid = TypedSection.create(...)
59         if sid then
60                 luci.http.redirect(mount.extedit % sid)
61                 return
62         end
63 end
64
65
66 mount:option(Flag, "enabled", translate("Enabled")).rmempty = false
67
68 dev = mount:option(DummyValue, "device", translate("Device"))
69 dev.cfgvalue = function(self, section)
70         local v
71
72         v = m.uci:get("fstab", section, "uuid")
73         if v then return "UUID: %s" % v end
74
75         v = m.uci:get("fstab", section, "label")
76         if v then return "Label: %s" % v end
77
78         v = Value.cfgvalue(self, section) or "?"
79         return size[v] and "%s (%s MB)" % {v, size[v]} or v
80 end
81
82 mp = mount:option(DummyValue, "target", translate("Mount Point"))
83 mp.cfgvalue = function(self, section)
84         if m.uci:get("fstab", section, "is_rootfs") == "1" then
85                 return "/overlay"
86         else
87                 return Value.cfgvalue(self, section) or "?"
88         end
89 end
90
91 fs = mount:option(DummyValue, "fstype", translate("Filesystem"))
92 fs.cfgvalue = function(self, section)
93         return Value.cfgvalue(self, section) or "?"
94 end
95
96 op = mount:option(DummyValue, "options", translate("Options"))
97 op.cfgvalue = function(self, section)
98         return Value.cfgvalue(self, section) or "defaults"
99 end
100
101 rf = mount:option(DummyValue, "is_rootfs", translate("Root"))
102 rf.cfgvalue = function(self, section)
103         return Value.cfgvalue(self, section) == "1"
104                 and translate("yes") or translate("no")
105 end
106
107 ck = mount:option(DummyValue, "enabled_fsck", translate("Check"))
108 ck.cfgvalue = function(self, section)
109         return Value.cfgvalue(self, section) == "1"
110                 and translate("yes") or translate("no")
111 end
112
113
114 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>."))
115 swap.anonymous = true
116 swap.addremove = true
117 swap.template = "cbi/tblsection"
118 swap.extedit  = luci.dispatcher.build_url("admin/system/fstab/swap/%s")
119
120 swap.create = function(...)
121         local sid = TypedSection.create(...)
122         if sid then
123                 luci.http.redirect(swap.extedit % sid)
124                 return
125         end
126 end
127
128
129 swap:option(Flag, "enabled", translate("Enabled")).rmempty = false
130
131 dev = swap:option(DummyValue, "device", translate("Device"))
132 dev.cfgvalue = function(self, section)
133         local v
134
135         v = m.uci:get("fstab", section, "uuid")
136         if v then return "UUID: %s" % v end
137
138         v = m.uci:get("fstab", section, "label")
139         if v then return "Label: %s" % v end
140
141         v = Value.cfgvalue(self, section) or "?"
142         return size[v] and "%s (%s MB)" % {v, size[v]} or v
143 end
144
145 return m