summaryrefslogtreecommitdiff
path: root/extras/scsi_id/scsi_id.c
diff options
context:
space:
mode:
authorpatmans@us.ibm.com <patmans@us.ibm.com>2005-02-25 23:51:17 -0800
committerGreg KH <gregkh@suse.de>2005-04-26 23:39:48 -0700
commit4e05e4238b2cb63eb3f3cd51cf76f136fa684f2e (patch)
treec7743c75d9ff8cac53a3eb97c3e6f2390d5ac300 /extras/scsi_id/scsi_id.c
parent77313cd0d13ed3682f25c745f71f648292b28215 (diff)
[PATCH] update scsi_id to work with libsysfs changes
Update scsi_id to work with the libsysfs changes in udev: use sysfs_get_classdev_attr and sysfs_get_device_attr in place of sysfs_read_attribute_value.
Diffstat (limited to 'extras/scsi_id/scsi_id.c')
-rw-r--r--extras/scsi_id/scsi_id.c51
1 files changed, 21 insertions, 30 deletions
diff --git a/extras/scsi_id/scsi_id.c b/extras/scsi_id/scsi_id.c
index 507fa27766..32a96d8adb 100644
--- a/extras/scsi_id/scsi_id.c
+++ b/extras/scsi_id/scsi_id.c
@@ -100,23 +100,13 @@ void log_message (int level, const char *format, ...)
return;
}
-int sysfs_get_attr(const char *devpath, const char *attr, char *value,
- size_t bufsize)
+static int get_major_minor(struct sysfs_class_device *class_dev, int *maj,
+ int *min)
{
- char attr_path[SYSFS_PATH_MAX];
+ struct sysfs_attribute *dev_attr;
- strncpy(attr_path, devpath, SYSFS_PATH_MAX);
- strncat(attr_path, "/", SYSFS_PATH_MAX);
- strncat(attr_path, attr, SYSFS_PATH_MAX);
- dprintf("%s\n", attr_path);
- return sysfs_read_attribute_value(attr_path, value, SYSFS_NAME_LEN);
-}
-
-static int get_major_minor(const char *devpath, int *maj, int *min)
-{
- char dev_value[MAX_ATTR_LEN];
-
- if (sysfs_get_attr(devpath, "dev", dev_value, MAX_ATTR_LEN)) {
+ dev_attr = sysfs_get_classdev_attr(class_dev, "dev");
+ if (!dev_attr) {
/*
* XXX This happens a lot, since sg has no dev attr.
* And now sysfsutils does not set a meaningful errno
@@ -125,27 +115,28 @@ static int get_major_minor(const char *devpath, int *maj, int *min)
* it separately.
*/
log_message(LOG_DEBUG, "%s: could not get dev attribute: %s\n",
- devpath, strerror(errno));
+ class_dev->name, strerror(errno));
return -1;
}
- dprintf("dev value %s", dev_value); /* dev_value has a trailing \n */
- if (sscanf(dev_value, "%u:%u", maj, min) != 2) {
+ dprintf("dev value %s", dev_attr->value); /* value has a trailing \n */
+ if (sscanf(dev_attr->value, "%u:%u", maj, min) != 2) {
log_message(LOG_WARNING, "%s: invalid dev major/minor\n",
- devpath);
+ class_dev->name);
return -1;
}
return 0;
}
-static int create_tmp_dev(const char *devpath, char *tmpdev, int dev_type)
+static int create_tmp_dev(struct sysfs_class_device *class_dev, char *tmpdev,
+ int dev_type)
{
int maj, min;
- dprintf("(%s)\n", devpath);
+ dprintf("(%s)\n", class_dev->name);
- if (get_major_minor(devpath, &maj, &min))
+ if (get_major_minor(class_dev, &maj, &min))
return -1;
snprintf(tmpdev, MAX_NAME_LEN, "%s/%s-maj%d-min%d-%u",
TMP_DIR, TMP_PREFIX, maj, min, getpid());
@@ -500,8 +491,7 @@ static int per_dev_options(struct sysfs_device *scsi_dev, int *good_bad,
int retval;
int newargc;
char **newargv = NULL;
- char vendor[MAX_ATTR_LEN];
- char model[MAX_ATTR_LEN];
+ struct sysfs_attribute *vendor, *model;
int option;
*good_bad = all_good;
@@ -511,19 +501,22 @@ static int per_dev_options(struct sysfs_device *scsi_dev, int *good_bad,
else
callout[0] = '\0';
- if (sysfs_get_attr(scsi_dev->path, "vendor", vendor, MAX_ATTR_LEN)) {
+ vendor = sysfs_get_device_attr(scsi_dev, "vendor");
+ if (!vendor) {
log_message(LOG_WARNING, "%s: cannot get vendor attribute\n",
scsi_dev->name);
return -1;
}
- if (sysfs_get_attr(scsi_dev->path, "model", model, MAX_ATTR_LEN)) {
+ model = sysfs_get_device_attr(scsi_dev, "model");
+ if (!model) {
log_message(LOG_WARNING, "%s: cannot get model attribute\n",
scsi_dev->name);
return -1;
}
- retval = get_file_options(vendor, model, &newargc, &newargv);
+ retval = get_file_options(vendor->value, model->value, &newargc,
+ &newargv);
optind = 1; /* reset this global extern */
while (retval == 0) {
@@ -694,10 +687,8 @@ static int scsi_id(const char *target_path, char *maj_min_dev)
/*
* mknod a temp dev to communicate with the device.
- *
- * XXX pass down class_dev or class_dev_parent.
*/
- if (!dev_specified && create_tmp_dev(target_path, maj_min_dev,
+ if (!dev_specified && create_tmp_dev(class_dev, maj_min_dev,
dev_type)) {
dprintf("create_tmp_dev failed\n");
return 1;