+ strlcpy(file, path, sizeof(file));
+ strlcat(file, "/", sizeof(file));
+ strlcat(file, attr, sizeof(file));
+
+ if (match_value != NULL) {
+ /* match file content */
+ char value[NAME_SIZE];
+ int fd;
+ ssize_t size;
+
+ fd = open(file, O_RDONLY);
+ if (fd < 0)
+ return 0;
+ size = read(fd, value, sizeof(value));
+ close(fd);
+ if (size < 0)
+ return 0;
+ value[size] = '\0';
+ remove_trailing_chars(value, '\n');
+
+ /* match if attribute value matches */
+ if (fnmatch(match_value, value, 0) == 0)
+ return 1;
+ } else {
+ /* match if attribute exists */
+ struct stat statbuf;
+
+ if (stat(file, &statbuf) == 0)
+ return 1;
+ }
+ return 0;
+}
+
+static int attr_filtered(const char *path)
+{
+ struct name_entry *loop_name;
+
+ /* skip devices matching the listed sysfs attributes */
+ list_for_each_entry(loop_name, &filter_attr_nomatch_list, node)
+ if (attr_match(path, loop_name->name))
+ return 1;
+
+ /* skip devices not matching the listed sysfs attributes */
+ if (!list_empty(&filter_attr_match_list)) {
+ list_for_each_entry(loop_name, &filter_attr_match_list, node)
+ if (attr_match(path, loop_name->name))
+ return 0;
+ return 1;
+ }
+ return 0;