chiark / gitweb /
[PATCH] libsysfs 0.4.0 patch
[elogind.git] / extras / scsi_id / scsi_id.c
1 /*
2  * scsi_id.c
3  *
4  * Main section of the scsi_id program
5  *
6  * Copyright (C) IBM Corp. 2003
7  *
8  *  This library is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU Lesser General Public License as
10  *  published by the Free Software Foundation; either version 2.1 of the
11  *  License, or (at your option) any later version.
12  *
13  *  This library is distributed in the hope that it will be useful, but
14  *  WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  *  Lesser General Public License for more details.
17  *
18  *  You should have received a copy of the GNU Lesser General Public
19  *  License along with this library; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  *  USA
22  */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <signal.h>
28 #include <fcntl.h>
29 #include <errno.h>
30 #include <string.h>
31 #include <syslog.h>
32 #include <stdarg.h>
33 #include <ctype.h>
34 #include <sys/stat.h>
35 #ifdef __KLIBC__
36 /*
37  * Assume built under udev with KLIBC
38  */
39 #include <libsysfs.h>
40 #else
41 #include <sysfs/libsysfs.h>
42 #endif
43 #include "scsi_id.h"
44
45 #ifndef SCSI_ID_VERSION
46 #warning No version
47 #define SCSI_ID_VERSION "unknown"
48 #endif
49
50 /*
51  * temporary names for mknod.
52  */
53 #define TMP_DIR "/tmp"
54 #define TMP_PREFIX "scsi"
55
56 #define CONFIG_FILE "/etc/scsi_id.config"
57
58 static const char short_options[] = "bc:d:ef:gip:s:vV";
59 /*
60  * Just duplicate per dev options.
61  */
62 static const char dev_short_options[] = "bc:gp:";
63
64 char sysfs_mnt_path[SYSFS_PATH_MAX];
65
66 static int all_good;
67 static char *default_callout;
68 static int dev_specified;
69 static int sys_specified;
70 static char config_file[MAX_NAME_LEN] = CONFIG_FILE;
71 static int display_bus_id;
72 static int default_page_code;
73 static int use_stderr;
74 static int debug;
75 static int hotplug_mode;
76
77 void log_message (int level, const char *format, ...)
78 {
79         va_list args;
80
81         if (!debug && level == LOG_DEBUG)
82                 return;
83
84         va_start (args, format);
85         if (!hotplug_mode || use_stderr) {
86                 vfprintf(stderr, format, args);
87         } else {
88                 static int logging_init = 0;
89                 static unsigned char logname[32];
90                 if (!logging_init) {
91                         /*
92                          * klibc does not have LOG_PID.
93                          */
94                         snprintf(logname, 32, "scsi_id[%d]", getpid());
95                         openlog (logname, 0, LOG_DAEMON);
96                         logging_init = 1;
97                 }
98
99                 vsyslog(level, format, args);
100         }
101         va_end (args);
102         return;
103 }
104
105 static int sysfs_get_actual_dev(const char *sysfs_path, char *dev, int len)
106 {
107         dprintf("%s\n", sysfs_path);
108         strncpy(dev, sysfs_path, len);
109         strncat(dev, "/device", len);
110         if (sysfs_get_link(dev, dev, len)) {
111                 if (!hotplug_mode)
112                         log_message(LOG_WARNING, "%s: %s\n", dev,
113                                     strerror(errno));
114                 return -1;
115         }
116         return 0;
117 }
118
119 /*
120  * sysfs_is_bus: Given the sysfs_path to a device, return 1 if sysfs_path
121  * is on bus, 0 if not on bus, and < 0 on error
122  */
123 static int sysfs_is_bus(const char *sysfs_path, const char *bus)
124 {
125         char bus_dev_name[SYSFS_PATH_MAX];
126         char bus_id[SYSFS_NAME_LEN];
127         struct stat stat_buf;
128         ino_t dev_inode;
129
130         dprintf("%s\n", sysfs_path);
131
132         if (sysfs_get_name_from_path(sysfs_path, bus_id, SYSFS_NAME_LEN))
133                 return -1;
134
135         snprintf(bus_dev_name, MAX_NAME_LEN, "%s/%s/%s/%s/%s", sysfs_mnt_path,
136                  SYSFS_BUS_NAME, bus, SYSFS_DEVICES_NAME, bus_id);
137
138         if (stat(sysfs_path, &stat_buf))
139                 return -1;
140         dev_inode = stat_buf.st_ino;
141
142         if (stat(bus_dev_name, &stat_buf)) {
143                 if (errno == ENOENT)
144                         return 0;
145                 else
146                         return -1;
147         }
148         if (dev_inode == stat_buf.st_ino)
149                 return 1;
150         else
151                 return 0;
152 }
153
154 static int get_major_minor(const char *devpath, int *major, int *minor)
155 {
156         struct sysfs_class_device *class_dev;
157         char dev_value[SYSFS_NAME_LEN];
158         char *dev;
159
160         dprintf("%s\n", devpath);
161         class_dev = sysfs_open_class_device_path(devpath);
162         if (!class_dev) {
163                 log_message(LOG_WARNING, "open class %s failed: %s\n", devpath,
164                             strerror(errno));
165                 return -1;
166         }
167
168         dev = sysfs_get_attr(class_dev, "dev");
169         if (dev)
170                 strncpy(dev_value, dev, SYSFS_NAME_LEN);
171         sysfs_close_class_device(class_dev);
172         if (!dev) {
173                 /*
174                  * XXX This happens a lot, since sg has no dev attr.
175                  * Someday change this back to a LOG_WARNING.
176                  */
177                 log_message(LOG_DEBUG, "%s could not get dev attribute: %s\n",
178                         devpath, strerror(errno));
179                 return -1;
180         }
181         dev = NULL;
182
183         dprintf("dev %s", dev_value); /* dev_value has a trailing \n */
184         if (sscanf(dev_value, "%u:%u", major, minor) != 2) {
185                 log_message(LOG_WARNING, "%s: invalid dev major/minor\n",
186                             devpath);
187                 return -1;
188         }
189
190         return 0;
191 }
192
193 static int create_tmp_dev(const char *devpath, char *tmpdev, int dev_type)
194 {
195         int major, minor;
196
197         dprintf("(%s)\n", devpath);
198
199         if (get_major_minor(devpath, &major, &minor))
200                 return -1;
201         snprintf(tmpdev, MAX_NAME_LEN, "%s/%s-maj%d-min%d-%u",
202                  TMP_DIR, TMP_PREFIX, major, minor, getpid());
203
204         dprintf("tmpdev '%s'\n", tmpdev);
205
206         if (mknod(tmpdev, 0600 | dev_type, makedev(major, minor))) {
207                 log_message(LOG_WARNING, "mknod failed: %s\n", strerror(errno));
208                 return -1;
209         }
210         return 0;
211 }
212
213 static int has_sysfs_prefix(const char *path, const char *prefix)
214 {
215         char match[MAX_NAME_LEN];
216
217         strncpy(match, sysfs_mnt_path, MAX_NAME_LEN);
218         strncat(match, prefix, MAX_NAME_LEN);
219         if (strncmp(path, match, strlen(match)) == 0)
220                 return 1;
221         else
222                 return 0;
223 }
224
225 /*
226  * get_value:
227  *
228  * buf points to an '=' followed by a quoted string ("foo") or a string ending
229  * with a space or ','.
230  *
231  * Return a pointer to the NUL terminated string, returns NULL if no
232  * matches.
233  */
234 static char *get_value(char **buffer)
235 {
236         static char *quote_string = "\"\n";
237         static char *comma_string = ",\n";
238         char *val;
239         char *end;
240
241         if (**buffer == '"') {
242                 /*
243                  * skip leading quote, terminate when quote seen
244                  */
245                 (*buffer)++;
246                 end = quote_string;
247         } else {
248                 end = comma_string;
249         }
250         val = strsep(buffer, end);
251         if (val && end == quote_string)
252                 /*
253                  * skip trailing quote
254                  */
255                 (*buffer)++;
256
257         while (isspace(**buffer))
258                 (*buffer)++;
259
260         return val;
261 }
262
263 static int argc_count(char *opts)
264 {
265         int i = 0;
266         while (*opts != '\0')
267                 if (*opts++ == ' ')
268                         i++;
269         return i;
270 }
271
272 /*
273  * get_file_options:
274  *
275  * If vendor == NULL, find a line in the config file with only "OPTIONS=";
276  * if vendor and model are set find the first OPTIONS line in the config
277  * file that matches. Set argc and argv to match the OPTIONS string.
278  *
279  * vendor and model can end in '\n'.
280  */
281 static int get_file_options(char *vendor, char *model, int *argc,
282                             char ***newargv)
283 {
284         char *buffer;
285         FILE *fd;
286         char *buf;
287         char *str1;
288         char *vendor_in, *model_in, *options_in; /* read in from file */
289         int lineno;
290         int c;
291         int retval = 0;
292
293         dprintf("vendor='%s'; model='%s'\n", vendor, model);
294         fd = fopen(config_file, "r");
295         if (fd == NULL) {
296                 dprintf("can't open %s\n", config_file);
297                 if (errno == ENOENT) {
298                         return 1;
299                 } else {
300                         log_message(LOG_WARNING, "can't open %s: %s\n",
301                                 config_file, strerror(errno));
302                         return -1;
303                 }
304         }
305
306         /*
307          * Allocate a buffer rather than put it on the stack so we can
308          * keep it around to parse any options (any allocated newargv
309          * points into this buffer for its strings).
310          */
311         buffer = malloc(MAX_BUFFER_LEN);
312         if (!buffer) {
313                 log_message(LOG_WARNING, "Can't allocate memory.\n");
314                 return -1;
315         }
316
317         *newargv = NULL;
318         lineno = 0;
319         while (1) {
320                 vendor_in = model_in = options_in = NULL;
321
322                 buf = fgets(buffer, MAX_BUFFER_LEN, fd);
323                 if (buf == NULL)
324                         break;
325                 lineno++;
326                 if (buf[strlen(buffer) - 1] != '\n') {
327                         log_message(LOG_WARNING,
328                                     "Config file line %d too long.\n", lineno);
329                         break;
330                 }
331
332                 while (isspace(*buf))
333                         buf++;
334
335                 if (*buf == '\0')
336                         /*
337                          * blank or all whitespace line
338                          */
339                         continue;
340
341                 if (*buf == '#')
342                         /*
343                          * comment line
344                          */
345                         continue;
346
347 #ifdef LOTS
348                 dprintf("lineno %d: '%s'\n", lineno, buf);
349 #endif
350                 str1 = strsep(&buf, "=");
351                 if (str1 && strcasecmp(str1, "VENDOR") == 0) {
352                         str1 = get_value(&buf);
353                         if (!str1) {
354                                 retval = -1;
355                                 break;
356                         }
357                         vendor_in = str1;
358
359                         str1 = strsep(&buf, "=");
360                         if (str1 && strcasecmp(str1, "MODEL") == 0) {
361                                 str1 = get_value(&buf);
362                                 if (!str1) {
363                                         retval = -1;
364                                         break;
365                                 }
366                                 model_in = str1;
367                                 str1 = strsep(&buf, "=");
368                         }
369                 }
370
371                 if (str1 && strcasecmp(str1, "OPTIONS") == 0) {
372                         str1 = get_value(&buf);
373                         if (!str1) {
374                                 retval = -1;
375                                 break;
376                         }
377                         options_in = str1;
378                 }
379                 dprintf("config file line %d:"
380                         " vendor '%s'; model '%s'; options '%s'\n",
381                         lineno, vendor_in, model_in, options_in);
382                 /*
383                  * Only allow: [vendor=foo[,model=bar]]options=stuff
384                  */
385                 if (!options_in || (!vendor_in && model_in)) {
386                         log_message(LOG_WARNING,
387                                     "Error parsing config file line %d '%s'\n",
388                                     lineno, buffer);
389                         retval = -1;
390                         break;
391                 }
392                 if (vendor == NULL) {
393                         if (vendor_in == NULL) {
394                                 dprintf("matched global option\n");
395                                 break;
396                         }
397                 } else if ((vendor_in && strncmp(vendor, vendor_in,
398                                                  strlen(vendor_in)) == 0) &&
399                            (!model_in || (strncmp(model, model_in,
400                                                   strlen(model_in)) == 0))) {
401                                 /*
402                                  * Matched vendor and optionally model.
403                                  *
404                                  * Note: a short vendor_in or model_in can
405                                  * give a partial match (that is FOO
406                                  * matches FOOBAR).
407                                  */
408                                 dprintf("matched vendor/model\n");
409                                 break;
410                 } else {
411                         dprintf("no match\n");
412                 }
413         }
414
415         if (retval == 0) {
416                 if (vendor_in != NULL || model_in != NULL ||
417                     options_in != NULL) {
418                         /*
419                          * Something matched. Allocate newargv, and store
420                          * values found in options_in.
421                          */
422                         strcpy(buffer, options_in);
423                         c = argc_count(buffer) + 2;
424                         *newargv = calloc(c, sizeof(**newargv));
425                         if (!*newargv) {
426                                 log_message(LOG_WARNING,
427                                             "Can't allocate memory.\n");
428                                 retval = -1;
429                         } else {
430                                 *argc = c;
431                                 c = 0;
432                                 /*
433                                  * argv[0] at 0 is skipped by getopt, but
434                                  * store the buffer address there for
435                                  * alter freeing.
436                                  */
437                                 (*newargv)[c] = buffer;
438                                 for (c = 1; c < *argc; c++)
439                                         (*newargv)[c] = strsep(&buffer, " ");
440                         }
441                 } else {
442                         /*
443                          * No matches.
444                          */
445                         retval = 1;
446                 }
447         }
448         if (retval != 0)
449                 free(buffer);
450         fclose(fd);
451         return retval;
452 }
453
454 static int set_options(int argc, char **argv, const char *short_opts,
455                        char *target, char *maj_min_dev)
456 {
457         int option;
458
459         /*
460          * optind is a global extern used by getopt. Since we can call
461          * set_options twice (once for command line, and once for config
462          * file) we have to reset this back to 1. [Note glibc handles
463          * setting this to 0, but klibc does not.]
464          */
465         optind = 1;
466         while (1) {
467                 option = getopt(argc, argv, short_options);
468                 if (option == -1)
469                         break;
470
471                 if (optarg)
472                         dprintf("option '%c' arg '%s'\n", option, optarg);
473                 else
474                         dprintf("option '%c'\n", option);
475
476                 switch (option) {
477                 case 'b':
478                         all_good = 0;
479                         break;
480
481                 case 'c':
482                         default_callout = optarg;
483                         break;
484
485                 case 'd':
486                         dev_specified = 1;
487                         strncpy(maj_min_dev, optarg, MAX_NAME_LEN);
488                         break;
489
490                 case 'e':
491                         use_stderr = 1;
492                         break;
493
494                 case 'f':
495                         strncpy(config_file, optarg, MAX_NAME_LEN);
496                         break;
497
498                 case 'g':
499                         all_good = 1;
500                         break;
501
502                 case 'i':
503                         display_bus_id = 1;
504                         break;
505
506                 case 'p':
507                         if (strcmp(optarg, "0x80") == 0) {
508                                 default_page_code = 0x80;
509                         } else if (strcmp(optarg, "0x83") == 0) {
510                                 default_page_code = 0x83;
511                         } else {
512                                 log_message(LOG_WARNING,
513                                             "Unknown page code '%s'\n", optarg);
514                                 return -1;
515                         }
516                         break;
517
518                 case 's':
519                         sys_specified = 1;
520                         strncpy(target, sysfs_mnt_path, MAX_NAME_LEN);
521                         strncat(target, optarg, MAX_NAME_LEN);
522                         break;
523
524                 case 'v':
525                         debug++;
526                         break;
527
528                 case 'V':
529                         log_message(LOG_WARNING, "scsi_id version: %s\n",
530                                     SCSI_ID_VERSION);
531                         exit(0);
532                         break;
533
534                 default:
535                         log_message(LOG_WARNING,
536                                     "Unknown or bad option '%c' (0x%x)\n",
537                                     option, option);
538                         return -1;
539                 }
540         }
541         return 0;
542 }
543
544 static int per_dev_options(struct sysfs_class_device *scsi_dev, int *good_bad,
545                            int *page_code, char *callout)
546 {
547         int retval;
548         int newargc;
549         char **newargv = NULL;
550         char *vendor;
551         char *model;
552         int option;
553
554         *good_bad = all_good;
555         *page_code = default_page_code;
556         if (default_callout && (callout != default_callout))
557                 strncpy(callout, default_callout, MAX_NAME_LEN);
558         else
559                 callout[0] = '\0';
560
561         vendor = sysfs_get_attr(scsi_dev, "vendor");
562         if (!vendor) {
563                 log_message(LOG_WARNING, "%s: no vendor attribute\n",
564                             scsi_dev->name);
565                 return -1;
566         }
567
568         model = sysfs_get_attr(scsi_dev, "model");
569         if (!model) {
570                 log_message(LOG_WARNING, "%s: no model attribute\n",
571                             scsi_dev->name);
572                 return -1;
573         }
574
575         retval = get_file_options(vendor, model, &newargc, &newargv);
576
577         optind = 1; /* reset this global extern */
578         while (retval == 0) {
579                 option = getopt(newargc, newargv, dev_short_options);
580                 if (option == -1)
581                         break;
582
583                 if (optarg)
584                         dprintf("option '%c' arg '%s'\n", option, optarg);
585                 else
586                         dprintf("option '%c'\n", option);
587
588                 switch (option) {
589                 case 'b':
590                         *good_bad = 0;
591                         break;
592
593                 case 'c':
594                         strncpy(callout, default_callout, MAX_NAME_LEN);
595                         break;
596
597                 case 'g':
598                         *good_bad = 1;
599                         break;
600
601                 case 'p':
602                         if (strcmp(optarg, "0x80") == 0) {
603                                 *page_code = 0x80;
604                         } else if (strcmp(optarg, "0x83") == 0) {
605                                 *page_code = 0x83;
606                         } else {
607                                 log_message(LOG_WARNING,
608                                             "Unknown page code '%s'\n", optarg);
609                                 retval = -1;
610                         }
611                         break;
612
613                 default:
614                         log_message(LOG_WARNING,
615                                     "Unknown or bad option '%c' (0x%x)\n",
616                                     option, option);
617                         retval = -1;
618                         break;
619                 }
620         }
621
622         if (newargv) {
623                 free(newargv[0]);
624                 free(newargv);
625         }
626         return retval;
627 }
628
629 /*
630  * scsi_id: try to get an id, if one is found, printf it to stdout.
631  * returns a value passed to exit() - 0 if printed an id, else 1. This
632  * could be expanded, for example, if we want to report a failure like no
633  * memory etc. return 2, and return 1 for expected cases (like broken
634  * device found) that do not print an id.
635  */
636 static int scsi_id(const char *target_path, char *maj_min_dev)
637 {
638         int retval;
639         int dev_type = 0;
640         char full_dev_path[MAX_NAME_LEN];
641         char serial[MAX_SERIAL_LEN];
642         struct sysfs_class_device *scsi_dev; /* of scsi_device full_dev_path */
643         int good_dev;
644         int page_code;
645         char callout[MAX_NAME_LEN];
646
647         dprintf("target_path %s\n", target_path);
648
649         /*
650          * Ugly: depend on the sysfs path to tell us whether this is a
651          * block or char device. This should probably be encoded in the
652          * "dev" along with the major/minor.
653          */
654         if (has_sysfs_prefix(target_path, "/block")) {
655                 dev_type = S_IFBLK;
656         } else if (has_sysfs_prefix(target_path, "/class")) {
657                 dev_type = S_IFCHR;
658         } else {
659                 if (!hotplug_mode) {
660                         log_message(LOG_WARNING,
661                                     "Non block or class device '%s'\n",
662                                     target_path);
663                         return 1;
664                 } else {
665                         /*
666                          * Expected in some cases.
667                          */
668                         dprintf("Non block or class device\n");
669                         return 0;
670                 }
671         }
672
673         if (sysfs_get_actual_dev(target_path, full_dev_path, MAX_NAME_LEN))
674                 return 1;
675
676         dprintf("full_dev_path %s\n", full_dev_path);
677
678         /*
679          * Allow only scsi devices (those that have a matching device
680          * under /bus/scsi/devices).
681          *
682          * Other block devices can support SG IO, but only ide-cd does, so
683          * for now, don't bother with anything else.
684          */
685         retval = sysfs_is_bus(full_dev_path, "scsi");
686         if (retval == 0) {
687                 if (hotplug_mode)
688                         /*
689                          * Expected in some cases.
690                          */
691                         dprintf("%s is not a scsi device\n", target_path);
692                 else
693                         log_message(LOG_WARNING, "%s is not a scsi device\n",
694                                     target_path);
695                 return 1;
696         } else if (retval < 0) {
697                 log_message(LOG_WARNING, "sysfs_is_bus failed: %s\n",
698                         strerror(errno));
699                 return 1;
700         }
701
702         /*
703          * mknod a temp dev to communicate with the device.
704          */
705         if (!dev_specified && create_tmp_dev(target_path, maj_min_dev,
706                                              dev_type)) {
707                 dprintf("create_tmp_dev failed\n");
708                 return 1;
709         }
710
711         scsi_dev = sysfs_open_class_device_path(full_dev_path);
712         if (!scsi_dev) {
713                 log_message(LOG_WARNING, "open class %s failed: %s\n",
714                             full_dev_path, strerror(errno));
715                 return 1;
716         }
717
718         /*
719          * Get any per device (vendor + model) options from the config
720          * file.
721          */
722         retval = per_dev_options(scsi_dev, &good_dev, &page_code, callout);
723         dprintf("per dev options: good %d; page code 0x%x; callout '%s'\n",
724                 good_dev, page_code, callout);
725
726         if (!good_dev) {
727                 retval = 1;
728         } else if (callout[0] != '\0') {
729                 /*
730                  * exec vendor callout, pass it only the "name" to be used
731                  * for error messages, and the dev to open.
732                  *
733                  * This won't work if we need to pass on the original
734                  * command line (when not hotplug mode) since the option
735                  * parsing and per dev parsing modify the argv's.
736                  *
737                  * XXX Not implemented yet. And not fully tested ;-)
738                  */
739                 retval = 1;
740         } else if (scsi_get_serial(scsi_dev, maj_min_dev, page_code,
741                                    serial, MAX_SERIAL_LEN)) {
742                 retval = 1;
743         } else {
744                 retval = 0;
745         }
746         if (!retval) {
747                 if (display_bus_id)
748                         printf("%s ", scsi_dev->name);
749                 printf("%s", serial);
750                 if (!hotplug_mode)
751                         printf("\n");
752                 dprintf("%s\n", serial);
753                 retval = 0;
754         }
755         sysfs_close_class_device(scsi_dev);
756
757         if (!dev_specified)
758                 unlink(maj_min_dev);
759
760         return retval;
761 }
762
763 int main(int argc, char **argv)
764 {
765         int retval;
766         char *devpath;
767         char target_path[MAX_NAME_LEN];
768         char maj_min_dev[MAX_NAME_LEN];
769         int newargc;
770         char **newargv;
771
772         if (getenv("DEBUG"))
773                 debug++;
774
775         if ((argc == 2) && (argv[1][0] != '-')) {
776                 hotplug_mode = 1;
777                 dprintf("hotplug assumed\n");
778         }
779
780         dprintf("argc is %d\n", argc);
781         if (sysfs_get_mnt_path(sysfs_mnt_path, MAX_NAME_LEN)) {
782                 log_message(LOG_WARNING, "sysfs_get_mnt_path failed: %s\n",
783                         strerror(errno));
784                 exit(1);
785         }
786
787         if (hotplug_mode) {
788                 /*
789                  * There is a kernel race creating attributes, if called
790                  * directly, uncomment the sleep.
791                  */
792                 /* sleep(1); */
793
794                 devpath = getenv("DEVPATH");
795                 if (!devpath) {
796                         log_message(LOG_WARNING, "DEVPATH is not set\n");
797                         exit(1);
798                 }
799                 sys_specified = 1;
800
801                 strncpy(target_path, sysfs_mnt_path, MAX_NAME_LEN);
802                 strncat(target_path, devpath, MAX_NAME_LEN);
803         } else {
804                 if (set_options(argc, argv, short_options, target_path,
805                                 maj_min_dev) < 0)
806                         exit(1);
807         }
808
809         /*
810          * Override any command line options set via the config file. This
811          * is the only way to set options when in hotplug mode.
812          */
813         newargv = NULL;
814         retval = get_file_options(NULL, NULL, &newargc, &newargv);
815         if (retval < 0) {
816                 exit(1);
817         } else if (newargv && (retval == 0)) {
818                 if (set_options(newargc, newargv, short_options, target_path,
819                                 maj_min_dev) < 0)
820                         exit(1);
821                 free(newargv);
822         }
823
824         if (!sys_specified) {
825                 log_message(LOG_WARNING, "-s must be specified\n");
826                 exit(1);
827         }
828
829         retval = scsi_id(target_path, maj_min_dev);
830         exit(retval);
831 }