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