]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/device-nodes.c
8d4e38ec0638b74f720bab461ce5eabd88fd97ff
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
7 #include "device-nodes.h"
9 #include "string-util.h"
12 int allow_listed_char_for_devnode(char c
, const char *additional
) {
16 strchr("#+-.:=@_", c
) ||
17 (additional
&& strchr(additional
, c
));
20 int encode_devnode_name(const char *str
, char *str_enc
, size_t len
) {
26 for (i
= 0, j
= 0; str
[i
] != '\0'; i
++) {
29 seqlen
= utf8_encoded_valid_unichar(str
+ i
, SIZE_MAX
);
32 if (len
-j
< (size_t) seqlen
)
35 memcpy(&str_enc
[j
], &str
[i
], seqlen
);
39 } else if (str
[i
] == '\\' || !allow_listed_char_for_devnode(str
[i
], NULL
)) {
44 sprintf(&str_enc
[j
], "\\x%02x", (unsigned char) str
[i
]);
63 int devnode_same(const char *a
, const char *b
) {
69 if (!valid_device_node_path(a
) || !valid_device_node_path(b
))
77 if (!S_ISBLK(sa
.st_mode
) && !S_ISCHR(sa
.st_mode
))
79 if (!S_ISBLK(sb
.st_mode
) && !S_ISCHR(sb
.st_mode
))
82 if (((sa
.st_mode
^ sb
.st_mode
) & S_IFMT
) != 0) /* both inode same device node type? */
85 return sa
.st_rdev
== sb
.st_rdev
;