2019-09-14 05:33:40 +02:00
|
|
|
-- widget type providing RAID array information on GNU/Linux
|
|
|
|
-- Copyright (C) 2010 Hagen Schink <troja84@googlemail.com>
|
|
|
|
-- Copyright (C) 2017 mutlusun <mutlusun@github.com>
|
|
|
|
--
|
|
|
|
-- This file is part of Vicious.
|
|
|
|
--
|
|
|
|
-- Vicious is free software: you can redistribute it and/or modify
|
|
|
|
-- it under the terms of the GNU General Public License as
|
|
|
|
-- published by the Free Software Foundation, either version 2 of the
|
|
|
|
-- License, or (at your option) any later version.
|
|
|
|
--
|
|
|
|
-- Vicious is distributed in the hope that it will be useful,
|
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
-- GNU General Public License for more details.
|
|
|
|
--
|
|
|
|
-- You should have received a copy of the GNU General Public License
|
|
|
|
-- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
|
2010-03-26 00:59:01 +01:00
|
|
|
|
|
|
|
-- {{{ Grab environment
|
2012-06-16 12:54:51 +02:00
|
|
|
local io = { open = io.open }
|
2010-03-26 00:59:01 +01:00
|
|
|
local string = {
|
|
|
|
len = string.len,
|
|
|
|
sub = string.sub,
|
|
|
|
match = string.match,
|
|
|
|
gmatch = string.gmatch
|
|
|
|
}
|
|
|
|
|
2019-09-14 05:33:40 +02:00
|
|
|
local helpers = require"vicious.helpers"
|
|
|
|
-- }}}
|
2010-03-26 00:59:01 +01:00
|
|
|
|
2010-04-02 01:08:12 +02:00
|
|
|
-- Initialize function tables
|
|
|
|
local mddev = {}
|
|
|
|
|
2010-03-26 00:59:01 +01:00
|
|
|
-- {{{ RAID widget type
|
2019-10-16 09:42:31 +02:00
|
|
|
return helpers.setcall(function (format, warg)
|
2010-03-26 00:59:01 +01:00
|
|
|
if not warg then return end
|
2010-04-28 14:55:19 +02:00
|
|
|
mddev[warg] = {
|
|
|
|
["found"] = false,
|
|
|
|
["active"] = 0,
|
|
|
|
["assigned"] = 0
|
|
|
|
}
|
2010-03-26 00:59:01 +01:00
|
|
|
|
|
|
|
-- Linux manual page: md(4)
|
2012-06-18 01:30:26 +02:00
|
|
|
local f = io.open("/proc/mdstat")
|
|
|
|
for line in f:lines() do
|
2010-04-02 01:08:12 +02:00
|
|
|
if mddev[warg]["found"] then
|
2010-03-26 00:59:01 +01:00
|
|
|
local updev = string.match(line, "%[[_U]+%]")
|
|
|
|
|
2019-09-14 05:33:40 +02:00
|
|
|
for _ in string.gmatch(updev, "U") do
|
2010-03-26 00:59:01 +01:00
|
|
|
mddev[warg]["active"] = mddev[warg]["active"] + 1
|
|
|
|
end
|
|
|
|
|
|
|
|
break
|
|
|
|
elseif string.sub(line, 1, string.len(warg)) == warg then
|
2010-04-02 01:08:12 +02:00
|
|
|
mddev[warg]["found"] = true
|
2010-03-26 00:59:01 +01:00
|
|
|
|
2019-09-14 05:33:40 +02:00
|
|
|
for _ in string.gmatch(line, "%[[%d]%]") do
|
2010-03-26 00:59:01 +01:00
|
|
|
mddev[warg]["assigned"] = mddev[warg]["assigned"] + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-06-18 01:30:26 +02:00
|
|
|
f:close()
|
2010-03-26 00:59:01 +01:00
|
|
|
|
|
|
|
return {mddev[warg]["assigned"], mddev[warg]["active"]}
|
2019-10-16 09:42:31 +02:00
|
|
|
end)
|
2010-03-26 00:59:01 +01:00
|
|
|
-- }}}
|