From mboxrd@z Thu Jan 1 00:00:00 1970 From: Patrick Mansfield Date: Fri, 25 Feb 2005 23:06:14 +0000 Subject: [PATCH udev] update scsi_id to work with libsysfs changes Message-Id: <20050225230614.GA10998@us.ibm.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-hotplug@vger.kernel.org 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. === extras/scsi_id/Makefile 1.12 vs edited ==--- 1.12/extras/scsi_id/Makefile Thu Feb 10 02:41:37 2005 +++ edited/extras/scsi_id/Makefile Fri Feb 25 15:04:48 2005 @@ -14,7 +14,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -SCSI_ID_VERSION=0.8 +SCSI_ID_VERSION=0.9 prefix etcdir = ${prefix}/etc === extras/scsi_id/scsi_id.c 1.12 vs edited ==--- 1.12/extras/scsi_id/scsi_id.c Thu Feb 10 05:08:47 2005 +++ edited/extras/scsi_id/scsi_id.c Thu Feb 24 07:58:57 2005 @@ -100,23 +100,13 @@ 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 @@ * 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 @@ 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 @@ 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 @@ /* * 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; === extras/scsi_id/scsi_id.h 1.7 vs edited ==--- 1.7/extras/scsi_id/scsi_id.h Wed Jul 28 04:58:29 2004 +++ edited/extras/scsi_id/scsi_id.h Thu Feb 24 07:55:43 2005 @@ -44,8 +44,6 @@ */ #define MAX_BUFFER_LEN 256 -extern int sysfs_get_attr(const char *devpath, const char *attr, char *value, - size_t bufsize); extern int scsi_get_serial (struct sysfs_device *scsi_dev, const char *devname, int page_code, char *serial, int len); === extras/scsi_id/scsi_serial.c 1.8 vs edited ==--- 1.8/extras/scsi_id/scsi_serial.c Fri Feb 4 09:38:55 2005 +++ edited/extras/scsi_id/scsi_serial.c Thu Feb 24 07:53:55 2005 @@ -364,7 +364,7 @@ char *buffer, int len) { int retval; - char vendor[MAX_ATTR_LEN]; + struct sysfs_attribute *vendor; memset(buffer, 0, len); retval = scsi_inquiry(scsi_dev, fd, 1, 0x0, buffer, len); @@ -394,14 +394,15 @@ * If the vendor id appears in the page assume the page is * invalid. */ - 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 model attribute\n", scsi_dev->name); return 1; } - if (!strncmp(&buffer[VENDOR_LENGTH], vendor, VENDOR_LENGTH)) { + if (!strncmp(&buffer[VENDOR_LENGTH], vendor->value, + VENDOR_LENGTH)) { log_message(LOG_WARNING, "%s: invalid page0 data\n", scsi_dev->name); return 1; @@ -416,15 +417,16 @@ */ static int prepend_vendor_model(struct sysfs_device *scsi_dev, char *serial) { - char attr[MAX_ATTR_LEN]; + struct sysfs_attribute *attr; int ind; - if (sysfs_get_attr(scsi_dev->path, "vendor", attr, MAX_ATTR_LEN)) { + attr = sysfs_get_device_attr(scsi_dev, "vendor"); + if (!attr) { log_message(LOG_WARNING, "%s: cannot get vendor attribute\n", scsi_dev->name); return 1; } - strncpy(serial, attr, VENDOR_LENGTH); + strncpy(serial, attr->value, VENDOR_LENGTH); ind = strlen(serial) - 1; /* * Remove sysfs added newlines. @@ -432,12 +434,13 @@ if (serial[ind] = '\n') serial[ind] = '\0'; - if (sysfs_get_attr(scsi_dev->path, "model", attr, MAX_ATTR_LEN)) { + attr = sysfs_get_device_attr(scsi_dev, "model"); + if (!attr) { log_message(LOG_WARNING, "%s: cannot get model attribute\n", scsi_dev->name); return 1; } - strncat(serial, attr, MODEL_LENGTH); + strncat(serial, attr->value, MODEL_LENGTH); ind = strlen(serial) - 1; if (serial[ind] = '\n') serial[ind] = '\0'; ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_ide95&alloc_id396&op=click _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel