On Fri, Aug 01, 2008 at 03:35:06AM -0400, Guido Günther wrote:
> * hack in enough support for -s so we can update udev without
>   updating multipath-tools - this can probably be done by just
>   implementing -s as -d and simply doing a: s%^/block/%^/dev/% in
>   set_options if "-s" was set. I just did this but then noticed:
It turned out that the code for another usage of '-s' is there but it
isn't in the options passed to getopt_long, so we can safely keep the
compat code. Possible patch attached.
 -- Guido
>From 749a45a54e8c12aa2ca2a89b3768b89c3c50ee66 Mon Sep 17 00:00:00 2001
From: Guido Guenther <[EMAIL PROTECTED]>
Date: Fri, 1 Aug 2008 03:16:05 -0400
Subject: [PATCH] convert sysfs paths for block devices into device names

adds some backwardscompatibility for programms/udev rules that use
"-s/--devpath"
---
 extras/scsi_id/scsi_id.c |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/extras/scsi_id/scsi_id.c b/extras/scsi_id/scsi_id.c
index 5eb95e8..badda7f 100644
--- a/extras/scsi_id/scsi_id.c
+++ b/extras/scsi_id/scsi_id.c
@@ -33,12 +33,12 @@
 
 static const struct option options[] = {
 	{ "device", 1, NULL, 'd' },
+	{ "devpath", 1, NULL, 's' },
 	{ "config", 1, NULL, 'f' },
 	{ "page", 1, NULL, 'p' },
 	{ "blacklisted", 0, NULL, 'b' },
 	{ "whitelisted", 0, NULL, 'g' },
 	{ "replace-whitespace", 0, NULL, 'u' },
-	{ "sg-version", 1, NULL, 's' },
 	{ "verbose", 0, NULL, 'v' },
 	{ "version", 0, NULL, 'V' },
 	{ "export", 0, NULL, 'x' },
@@ -46,7 +46,7 @@ static const struct option options[] = {
 	{}
 };
 
-static const char short_options[] = "d:f:ghip:uvVx";
+static const char short_options[] = "d:f:ghip:uvVxs:";
 static const char dev_short_options[] = "bgp:";
 
 static int all_good;
@@ -374,6 +374,16 @@ static int get_file_options(const char *vendor, const char *model,
 	return retval;
 }
 
+static void convert_sysfs_path(const char* sysfs, char *devpath)
+{
+	if (!strncmp(optarg, "/block/", 7)) {
+		snprintf(devpath, MAX_PATH_LEN, "/dev/%s", &(optarg[7]));
+        } else {
+		strncpy(devpath, optarg, MAX_PATH_LEN);
+	}
+	devpath[MAX_PATH_LEN-1] = '\0';
+}
+
 static int set_options(int argc, char **argv, const char *short_opts,
 		       char *maj_min_dev)
 {
@@ -406,6 +416,11 @@ static int set_options(int argc, char **argv, const char *short_opts,
 			maj_min_dev[MAX_PATH_LEN-1] = '\0';
 			break;
 
+		case 's':
+			dev_specified = 1;
+			convert_sysfs_path(optarg, maj_min_dev);
+			break;
+
 		case 'e':
 			use_stderr = 1;
 			break;
@@ -447,14 +462,6 @@ static int set_options(int argc, char **argv, const char *short_opts,
 			}
 			break;
 
-		case 's':
-			sg_version = atoi(optarg);
-			if (sg_version < 3 || sg_version > 4) {
-				err("Unknown SG version '%s'\n", optarg);
-				return -1;
-			}
-			break;
-
 		case 'u':
 			reformat_serial = 1;
 			break;
-- 
1.5.6.3

Reply via email to