Update my email addresses in the license headers
[project/luci.git] / modules / luci-mod-admin-full / luasrc / model / cbi / admin_system / fstab / mount.lua
1 -- Copyright 2010 Jo-Philipp Wich <jow@openwrt.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 local fs   = require "nixio.fs"
5 local util = require "nixio.util"
6
7 local has_extroot = fs.access("/sbin/block")
8 local has_fscheck = fs.access("/usr/sbin/e2fsck")
9
10 local devices = {}
11 util.consume((fs.glob("/dev/sd*")), devices)
12 util.consume((fs.glob("/dev/hd*")), devices)
13 util.consume((fs.glob("/dev/scd*")), devices)
14 util.consume((fs.glob("/dev/mmc*")), devices)
15
16 local size = {}
17 for i, dev in ipairs(devices) do
18         local s = tonumber((fs.readfile("/sys/class/block/%s/size" % dev:sub(6))))
19         size[dev] = s and math.floor(s / 2048)
20 end
21
22
23 m = Map("fstab", translate("Mount Points - Mount Entry"))
24 m.redirect = luci.dispatcher.build_url("admin/system/fstab")
25
26 if not arg[1] or m.uci:get("fstab", arg[1]) ~= "mount" then
27         luci.http.redirect(m.redirect)
28         return
29 end
30
31
32
33 mount = m:section(NamedSection, arg[1], "mount", translate("Mount Entry"))
34 mount.anonymous = true
35 mount.addremove = false
36
37 mount:tab("general",  translate("General Settings"))
38 mount:tab("advanced", translate("Advanced Settings"))
39
40
41 mount:taboption("general", Flag, "enabled", translate("Enable this mount")).rmempty = false
42
43
44 o = mount:taboption("general", Value, "device", translate("Device"),
45         translate("The device file of the memory or partition (<abbr title=\"for example\">e.g.</abbr> <code>/dev/sda1</code>)"))
46
47 for i, d in ipairs(devices) do
48         o:value(d, size[d] and "%s (%s MB)" % {d, size[d]})
49 end
50
51 o = mount:taboption("advanced", Value, "uuid", translate("UUID"),
52         translate("If specified, mount the device by its UUID instead of a fixed device node"))
53
54 o = mount:taboption("advanced", Value, "label", translate("Label"),
55         translate("If specified, mount the device by the partition label instead of a fixed device node"))
56
57
58 o = mount:taboption("general", Value, "target", translate("Mount point"),
59         translate("Specifies the directory the device is attached to"))
60
61 o:depends("is_rootfs", "")
62
63
64 o = mount:taboption("general", Value, "fstype", translate("Filesystem"),
65         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>)"))
66
67 local fs
68 for fs in io.lines("/proc/filesystems") do
69         fs = fs:match("%S+")
70         if fs ~= "nodev" then
71                 o:value(fs)
72         end
73 end
74
75
76 o = mount:taboption("advanced", Value, "options", translate("Mount options"),
77         translate("See \"mount\" manpage for details"))
78
79 o.placeholder = "defaults"
80
81
82 if has_extroot then
83         o = mount:taboption("general", Flag, "is_rootfs", translate("Use as root filesystem"),
84                 translate("Configures this mount as overlay storage for block-extroot"))
85
86         o:depends("fstype", "jffs")
87         o:depends("fstype", "ext2")
88         o:depends("fstype", "ext3")
89         o:depends("fstype", "ext4")
90 end
91
92 if has_fscheck then
93         o = mount:taboption("general", Flag, "enabled_fsck", translate("Run filesystem check"),
94                 translate("Run a filesystem check before mounting the device"))
95 end
96
97 return m