Debian Codegraph @

vicious/widgets/raid_linux.lua

raw symbols SCIP
1 -- widget type providing RAID array information on GNU/Linux
2 -- Copyright (C) 2010 Hagen Schink <[email protected]>
3 -- Copyright (C) 2017 mutlusun <[email protected]>
4 --
5 -- This file is part of Vicious.
6 --
7 -- Vicious is free software: you can redistribute it and/or modify
8 -- it under the terms of the GNU General Public License as
9 -- published by the Free Software Foundation, either version 2 of the
10 -- License, or (at your option) any later version.
11 --
12 -- Vicious is distributed in the hope that it will be useful,
13 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 -- GNU General Public License for more details.
16 --
17 -- You should have received a copy of the GNU General Public License
18 -- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
19
20 -- {{{ Grab environment
21 local io = { open = io.open }
22 local string = {
23 len = string.len,
24 sub = string.sub,
25 match = string.match,
26 gmatch = string.gmatch
27 }
28
29 local helpers = require"vicious.helpers"
30 -- }}}
31
32 -- Initialize function tables
33 local mddev = {}
34
35 -- {{{ RAID widget type
36 return helpers.setcall(function (format, warg)
37 if not warg then return end
38 mddev[warg] = {
39 ["found"] = false,
40 ["active"] = 0,
41 ["assigned"] = 0
42 }
43
44 -- Linux manual page: md(4)
45 local f = io.open("/proc/mdstat")
46 for line in f:lines() do
47 if mddev[warg]["found"] then
48 local updev = string.match(line, "%[[_U]+%]")
49
50 for _ in string.gmatch(updev, "U") do
51 mddev[warg]["active"] = mddev[warg]["active"] + 1
52 end
53
54 break
55 elseif string.sub(line, 1, string.len(warg)) == warg then
56 mddev[warg]["found"] = true
57
58 for _ in string.gmatch(line, "%[[%d]%]") do
59 mddev[warg]["assigned"] = mddev[warg]["assigned"] + 1
60 end
61 end
62 end
63 f:close()
64
65 return {mddev[warg]["assigned"], mddev[warg]["active"]}
66 end)
67 -- }}}