-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpartitions.lua
76 lines (56 loc) · 1.38 KB
/
partitions.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
-- functions related to lookups of filesystems/partitions
function LookupPartitionsGetList()
local toks, str
local parts={}
toks=strutil.TOKENIZER(settings.display, "$(|^(|:|)", "ms")
str=toks:next()
while str ~= nil
do
if str=="$(" or str=="^("
then
str=toks:next()
if str=="fs"
then
str=toks:next() --consume the ':'
str=toks:next()
parts[str]="y"
end
end
str=toks:next()
end
return parts
end
function LookupPartitionsAnalyzePartition(part_info, requested_partitions)
local fs_dev, fs_mount, fs_type, toks
toks=strutil.TOKENIZER(part_info, "\\S")
fs_dev=toks:next()
fs_mount=toks:next()
fs_type=toks:next()
if fs_dev == "none" and fs_type ~= "tmpfs" then return nil end
if fs_dev == "cgroups" then return nil end
if requested_partitions[fs_mount] ~= nil then return fs_mount end
return nil
end
function LookupPartitions()
local str, perc
local fs_mount
local S, requested_partitions
requested_partitions=LookupPartitionsGetList()
S=stream.STREAM("/proc/self/mounts", "r")
if S ~= nil
then
str=S:readln()
while str ~= nil
do
fs_mount=LookupPartitionsAnalyzePartition(str, requested_partitions)
if fs_mount ~= nil
then
perc=math.floor( (filesys.fs_used(fs_mount) * 100 / filesys.fs_size(fs_mount)) + 0.5)
AddDisplayValue("fs:"..fs_mount, perc, nil, usage_color_map)
end
str=S:readln()
end
S:close()
end
return str
end