summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2019-09-21 18:30:34 +0200
committerJo-Philipp Wich <jo@mein.io>2019-09-21 18:30:34 +0200
commit54cab2f26be6c925cab8651c254380877474a130 (patch)
treed2dad14c35fd0c128e31fe1b08c70b70ba20f5e4 /modules/luci-base
parent6dba41cadc82785f23773f219d30403f6b12956e (diff)
luci-base: add rpc methods for mount management
This commit introduces the new methods luci/getBlockDevices, luci/setBlockDetect, luci/getMountPoints, luci/setUmount in preparation for the reworked mount point management. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base')
-rwxr-xr-xmodules/luci-base/root/usr/libexec/rpcd/luci95
1 files changed, 95 insertions, 0 deletions
diff --git a/modules/luci-base/root/usr/libexec/rpcd/luci b/modules/luci-base/root/usr/libexec/rpcd/luci
index fb15dab6a5..8215fb95dd 100755
--- a/modules/luci-base/root/usr/libexec/rpcd/luci
+++ b/modules/luci-base/root/usr/libexec/rpcd/luci
@@ -590,6 +590,101 @@ local methods = {
}) == 0)
}
end
+ },
+
+ getBlockDevices = {
+ call = function()
+ local fs = require "nixio.fs"
+
+ local block = io.popen("/sbin/block info", "r")
+ if block then
+ local rv = {}
+
+ while true do
+ local ln = block:read("*l")
+ if not ln then
+ break
+ end
+
+ local dev = ln:match("^/dev/(.-):")
+ if dev then
+ local s = tonumber((fs.readfile("/sys/class/block/" .. dev .."/size")))
+ local e = {
+ dev = "/dev/" .. dev,
+ size = s and s * 512
+ }
+
+ local key, val = { }
+ for key, val in ln:gmatch([[(%w+)="(.-)"]]) do
+ e[key:lower()] = val
+ end
+
+ rv[dev] = e
+ end
+ end
+
+ block:close()
+
+ return rv
+ else
+ return { error = "Unable to execute block utility" }
+ end
+ end
+ },
+
+ setBlockDetect = {
+ call = function()
+ return { result = (os.execute("/sbin/block detect > /etc/config/fstab") == 0) }
+ end
+ },
+
+ getMountPoints = {
+ call = function()
+ local fs = require "nixio.fs"
+
+ local fd, err = io.open("/proc/mounts", "r")
+ if fd then
+ local rv = {}
+
+ while true do
+ local ln = fd:read("*l")
+ if not ln then
+ break
+ end
+
+ local device, mount, fstype, options, freq, pass = ln:match("^(%S*) (%S*) (%S*) (%S*) (%d+) (%d+)$")
+ if device and mount then
+ device = device:gsub("\\(%d+)", function(n) return string.char(tonumber(n, 8)) end)
+ mount = mount:gsub("\\(%d+)", function(n) return string.char(tonumber(n, 8)) end)
+
+ local stat = fs.statvfs(mount)
+ if stat and stat.blocks > 0 then
+ rv[#rv+1] = {
+ device = device,
+ mount = mount,
+ size = stat.bsize * stat.blocks,
+ avail = stat.bsize * stat.bavail,
+ free = stat.bsize * stat.bfree
+ }
+ end
+ end
+ end
+
+ fd:close()
+
+ return { result = rv }
+ else
+ return { error = err }
+ end
+ end
+ },
+
+ setUmount = {
+ args = { path = "/mnt" },
+ call = function(args)
+ local util = require "luci.util"
+ return { result = (os.execute(string.format("/bin/umount %s", util.shellquote(args.path))) == 0) }
+ end
}
}