forked from adamlaska/systemd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevice-util.c
More file actions
63 lines (43 loc) · 1.71 KB
/
device-util.c
File metadata and controls
63 lines (43 loc) · 1.71 KB
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
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <fnmatch.h>
#include "device-util.h"
#include "path-util.h"
static bool device_match_sysattr_value(sd_device *device, const char *sysattr, const char *match_value) {
const char *value;
assert(device);
assert(sysattr);
if (sd_device_get_sysattr_value(device, sysattr, &value) < 0)
return false;
if (!match_value)
return true;
if (fnmatch(match_value, value, 0) == 0)
return true;
return false;
}
bool device_match_sysattr(sd_device *device, Hashmap *match_sysattr, Hashmap *nomatch_sysattr) {
const char *sysattr;
const char *value;
assert(device);
HASHMAP_FOREACH_KEY(value, sysattr, match_sysattr)
if (!device_match_sysattr_value(device, sysattr, value))
return false;
HASHMAP_FOREACH_KEY(value, sysattr, nomatch_sysattr)
if (device_match_sysattr_value(device, sysattr, value))
return false;
return true;
}
bool device_match_parent(sd_device *device, Set *match_parent, Set *nomatch_parent) {
const char *syspath_parent, *syspath;
assert(device);
if (sd_device_get_syspath(device, &syspath) < 0)
return false;
SET_FOREACH(syspath_parent, nomatch_parent)
if (path_startswith(syspath, syspath_parent))
return false;
if (set_isempty(match_parent))
return true;
SET_FOREACH(syspath_parent, match_parent)
if (path_startswith(syspath, syspath_parent))
return true;
return false;
}