* Copyright (C) 2005 John Hull <John_Hull@Dell.com>
* Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
*
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation version 2 of the License.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _GNU_SOURCE
#include <dirent.h>
#include <stdint.h>
-#include "../../udev/udev.h"
+#include "libudev.h"
+#include "libudev-private.h"
static void log_fn(struct udev *udev, int priority,
const char *file, int line, const char *fn,
int sysfs_fd;
DIR *dir = NULL;
int rc = 1;
- char match[NAME_MAX] = "";
+ char filename[UTIL_PATH_SIZE];
+ char match[UTIL_PATH_SIZE];
- udev = udev_new();
+ udev = udev_new();
if (udev == NULL)
goto exit;
- logging_init("edd_id");
+ udev_log_init("edd_id");
udev_set_log_fn(udev, log_fn);
for (i = 1 ; i < argc; i++) {
}
/* check for kernel support */
- dir = opendir("/sys/firmware/edd");
+ util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), "/firmware/edd", NULL);
+ dir = opendir(filename);
if (dir == NULL) {
info(udev, "no kernel EDD support\n");
fprintf(stderr, "no kernel EDD support\n");
}
/* lookup signature in sysfs to determine the name */
+ match[0] = '\0';
for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
- char file[PATH_SIZE];
char sysfs_id_buf[256];
uint32_t sysfs_id;
ssize_t size;
if (dent->d_name[0] == '.')
continue;
- snprintf(file, sizeof(file), "/sys/firmware/edd/%s/mbr_signature", dent->d_name);
- file[sizeof(file)-1] = '\0';
-
- sysfs_fd = open(file, O_RDONLY);
+ util_strscpyl(filename, sizeof(filename), dent->d_name, "/mbr_signature", NULL);
+ sysfs_fd = openat(dirfd(dir), filename, O_RDONLY);
if (sysfs_fd < 0) {
- info(udev, "unable to open sysfs '%s'\n", file);
+ info(udev, "unable to open sysfs '%s'\n", filename);
continue;
}
size = read(sysfs_fd, sysfs_id_buf, sizeof(sysfs_id_buf)-1);
close(sysfs_fd);
if (size <= 0) {
- info(udev, "read sysfs '%s' failed\n", file);
+ info(udev, "read sysfs '%s' failed\n", filename);
continue;
}
sysfs_id_buf[size] = '\0';
- info(udev, "read '%s' from '%s'\n", sysfs_id_buf, file);
+ info(udev, "read '%s' from '%s'\n", sysfs_id_buf, filename);
sysfs_id = strtoul(sysfs_id_buf, NULL, 16);
/* look for matching value, that appears only once */
if (disk_id == sysfs_id) {
if (match[0] == '\0') {
/* store id */
- util_strlcpy(match, dent->d_name, sizeof(match));
+ util_strscpy(match, sizeof(match), dent->d_name);
} else {
/* error, same signature for another device */
info(udev, "'%s' does not have a unique signature\n", node);
closedir(dir);
exit:
udev_unref(udev);
- logging_close();
+ udev_log_close();
return rc;
}