linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* model/vendor enc strings
@ 2009-02-17 19:15 David Zeuthen
  2009-02-17 20:49 ` Kay Sievers
  0 siblings, 1 reply; 2+ messages in thread
From: David Zeuthen @ 2009-02-17 19:15 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 1012 bytes --]


Hey Kay,

So ID_MODEL and ID_VENDOR are pretty useful keys. However since we fix
them up (removing leading/trailing whitespace, converts spaces to
underscores) for use in device naming etc. we also force these fixups on
the desktop shell. And this looks pretty ugly.

The attached patch introduces the ID_MODEL_ENC and ID_VENDOR_ENC keys
that contains the encoded version of the raw strings obtained. It's
pretty similar in spirit to ID_FS_LABEL and its cousin ID_FS_LABEL_ENC.

With this patch a desktop shell can fix up these strings as it sees fit.
Note that some fixup is still needed though, for example

# /lib/udev/ata_id --export /dev/sda |grep ID_MODEL
ID_MODEL=INTEL_SSDSA2MH080G1GC
ID_MODEL_ENC=INTEL\x20SSDSA2MH080G1GC\x20\x20\x20\x20\x20\x20\x20\x20
\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20

Note the trailing and leading whitespace. Anyway with the attached patch
the desktop shell should be able to display "INTEL SSDSA2MH080G1GC"
rather than "INTEL_SSDSA2MH080G1GC" to the user.

    David


[-- Attachment #2: udev-model-vendor-enc.patch --]
[-- Type: text/x-patch, Size: 4415 bytes --]

diff --git a/extras/ata_id/ata_id.c b/extras/ata_id/ata_id.c
index 6f2e28b..3996a04 100644
--- a/extras/ata_id/ata_id.c
+++ b/extras/ata_id/ata_id.c
@@ -49,6 +49,7 @@ int main(int argc, char *argv[])
 	struct udev *udev;
 	struct hd_driveid id;
 	char model[41];
+	char model_enc[256];
 	char serial[21];
 	char revision[9];
 	const char *node = NULL;
@@ -114,6 +115,9 @@ int main(int argc, char *argv[])
 		goto close;
 	}
 
+	memcpy (model, id.model, 40);
+	model[40] = '\0';
+	udev_util_encode_string(model, model_enc, sizeof(model_enc));
 	udev_util_replace_whitespace((char *) id.model, model, 40);
 	udev_util_replace_chars(model, NULL);
 	udev_util_replace_whitespace((char *) id.serial_no, serial, 20);
@@ -145,6 +149,7 @@ int main(int argc, char *argv[])
 			printf("ID_TYPE=disk\n");
 		}
 		printf("ID_MODEL=%s\n", model);
+		printf("ID_MODEL_ENC=%s\n", model_enc);
 		printf("ID_SERIAL=%s\n", serial);
 		printf("ID_REVISION=%s\n", revision);
 		printf("ID_BUS=ata\n");
diff --git a/extras/scsi_id/scsi_id.c b/extras/scsi_id/scsi_id.c
index 21b7cbe..d630cf9 100644
--- a/extras/scsi_id/scsi_id.c
+++ b/extras/scsi_id/scsi_id.c
@@ -59,6 +59,8 @@ static int reformat_serial;
 static int export;
 static char vendor_str[64];
 static char model_str[64];
+static char vendor_enc_str[256];
+static char model_enc_str[256];
 static char revision_str[16];
 static char type_str[16];
 
@@ -501,6 +503,9 @@ static int set_inq_values(struct udev *udev, struct scsi_id_device *dev_scsi, co
 	if (retval)
 		return retval;
 
+	udev_util_encode_string(dev_scsi->vendor, vendor_enc_str, sizeof(vendor_enc_str));
+	udev_util_encode_string(dev_scsi->model, model_enc_str, sizeof(model_enc_str));
+
 	udev_util_replace_whitespace(dev_scsi->vendor, vendor_str, sizeof(vendor_str));
 	udev_util_replace_chars(vendor_str, NULL);
 	udev_util_replace_whitespace(dev_scsi->model, model_str, sizeof(model_str));
@@ -569,7 +574,9 @@ static int scsi_id(struct udev *udev, char *maj_min_dev)
 		char serial_str[MAX_SERIAL_LEN];
 
 		printf("ID_VENDOR=%s\n", vendor_str);
+		printf("ID_VENDOR_ENC=%s\n", vendor_enc_str);
 		printf("ID_MODEL=%s\n", model_str);
+		printf("ID_MODEL_ENC=%s\n", model_enc_str);
 		printf("ID_REVISION=%s\n", revision_str);
 		printf("ID_TYPE=%s\n", type_str);
 		if (dev_scsi.serial[0] != '\0') {
diff --git a/extras/usb_id/usb_id.c b/extras/usb_id/usb_id.c
index 3d007f9..cbbb4d2 100644
--- a/extras/usb_id/usb_id.c
+++ b/extras/usb_id/usb_id.c
@@ -38,6 +38,8 @@ static void log_fn(struct udev *udev, int priority,
 
 static char vendor_str[64];
 static char model_str[64];
+static char model_str_enc[256];
+static char vendor_str_enc[256];
 static char serial_str[UTIL_NAME_SIZE];
 static char revision_str[64];
 static char type_str[64];
@@ -251,6 +253,7 @@ static int usb_id(struct udev_device *dev)
 			     udev_device_get_sysname(dev_scsi));
 			goto fallback;
 		}
+		udev_util_encode_string(scsi_vendor, vendor_str_enc, sizeof(vendor_str_enc));
 		udev_util_replace_whitespace(scsi_vendor, vendor_str, sizeof(vendor_str)-1);
 		udev_util_replace_chars(vendor_str, NULL);
 
@@ -260,6 +263,7 @@ static int usb_id(struct udev_device *dev)
 			     udev_device_get_sysname(dev_scsi));
 			goto fallback;
 		}
+		udev_util_encode_string(scsi_model, model_str_enc, sizeof(model_str_enc));
 		udev_util_replace_whitespace(scsi_model, model_str, sizeof(model_str)-1);
 		udev_util_replace_chars(model_str, NULL);
 
@@ -302,6 +306,7 @@ fallback:
 			info(udev, "No USB vendor information available\n");
 			return 1;
 		}
+		udev_util_encode_string(usb_vendor, vendor_str_enc, sizeof(vendor_str_enc));
 		udev_util_replace_whitespace(usb_vendor, vendor_str, sizeof(vendor_str)-1);
 		udev_util_replace_chars(vendor_str, NULL);
 	}
@@ -319,6 +324,7 @@ fallback:
 			dbg(udev, "No USB model information available\n");
 			return 1;
 		}
+		udev_util_encode_string(usb_model, model_str_enc, sizeof(model_str_enc));
 		udev_util_replace_whitespace(usb_model, model_str, sizeof(model_str)-1);
 		udev_util_replace_chars(model_str, NULL);
 	}
@@ -439,7 +445,9 @@ int main(int argc, char **argv)
 
 		if (export) {
 			printf("ID_VENDOR=%s\n", vendor_str);
+			printf("ID_VENDOR_ENC=%s\n", vendor_str_enc);
 			printf("ID_MODEL=%s\n", model_str);
+			printf("ID_MODEL_ENC=%s\n", model_str_enc);
 			printf("ID_REVISION=%s\n", revision_str);
 			printf("ID_SERIAL=%s\n", serial);
 			if (serial_str[0] != '\0')

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: model/vendor enc strings
  2009-02-17 19:15 model/vendor enc strings David Zeuthen
@ 2009-02-17 20:49 ` Kay Sievers
  0 siblings, 0 replies; 2+ messages in thread
From: Kay Sievers @ 2009-02-17 20:49 UTC (permalink / raw)
  To: linux-hotplug

On Tue, Feb 17, 2009 at 20:15, David Zeuthen <david@fubar.dk> wrote:

> The attached patch introduces the ID_MODEL_ENC and ID_VENDOR_ENC keys

Applied.

Thanks,
Kay

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-02-17 20:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-17 19:15 model/vendor enc strings David Zeuthen
2009-02-17 20:49 ` Kay Sievers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).