From a8916c3400e2968aa17b296deff8736db86c338a Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Sun, 28 Jun 2009 02:27:23 +0200 Subject: [PATCH] scsi_id: --reformat_serial - use udev_util_replace_whitespace() --- extras/scsi_id/scsi_id.c | 37 ++++++++++-------------------------- extras/scsi_id/scsi_serial.c | 7 ++----- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/extras/scsi_id/scsi_id.c b/extras/scsi_id/scsi_id.c index 7cf2f376..72a72571 100644 --- a/extras/scsi_id/scsi_id.c +++ b/extras/scsi_id/scsi_id.c @@ -517,31 +517,6 @@ static int set_inq_values(struct udev *udev, struct scsi_id_device *dev_scsi, co return 0; } -/* - * format_serial: replace to whitespaces by underscores for calling - * programs that use the serial for device naming (multipath, Suse - * naming, etc...) - */ -static void format_serial(char *serial) -{ - char *p = serial, *q; - - q = p; - while (*p != '\0') { - if (isspace(*p)) { - if (q > serial && q[-1] != '_') { - *q = '_'; - q++; - } - } else { - *q = *p; - q++; - } - p++; - } - *q = '\0'; -} - /* * scsi_id: try to get an id, if one is found, printf it to stdout. * returns a value passed to exit() - 0 if printed an id, else 1. @@ -595,8 +570,16 @@ static int scsi_id(struct udev *udev, char *maj_min_dev) retval = 1; goto out; } - if (reformat_serial) - format_serial(dev_scsi.serial); + + if (reformat_serial) { + char serial_str[MAX_SERIAL_LEN]; + + udev_util_replace_whitespace(dev_scsi.serial, serial_str, sizeof(serial_str)); + udev_util_replace_chars(serial_str, NULL); + printf("%s\n", serial_str); + goto out; + } + printf("%s\n", dev_scsi.serial); out: return retval; diff --git a/extras/scsi_id/scsi_serial.c b/extras/scsi_id/scsi_serial.c index c47712d8..68bed082 100644 --- a/extras/scsi_id/scsi_serial.c +++ b/extras/scsi_id/scsi_serial.c @@ -457,11 +457,8 @@ static int prepend_vendor_model(struct udev *udev, int ind; strncpy(serial, dev_scsi->vendor, VENDOR_LENGTH); - ind = strlen(serial) - 1; - strncat(serial, dev_scsi->model, MODEL_LENGTH); - ind = strlen(serial) - 1; - ind++; + ind = strlen(serial); /* * This is not a complete check, since we are using strncat/cpy @@ -773,7 +770,7 @@ static int do_scsi_page80_inquiry(struct udev *udev, len = 1 + VENDOR_LENGTH + MODEL_LENGTH + buf[3]; if (max_len < len) { info(udev, "%s: length %d too short - need %d\n", - dev_scsi->kernel, max_len, len); + dev_scsi->kernel, max_len, len); return 1; } /* -- 2.39.5