chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fold multiple consecutive whitespace chars into single '_'
[elogind.git]
/
extras
/
scsi_id
/
scsi_id.c
diff --git
a/extras/scsi_id/scsi_id.c
b/extras/scsi_id/scsi_id.c
index cbefb445dffe1cbbf3992b9be814aeba522e9136..aa1b16009e9f989cd301dfe9d78acd16391de767 100644
(file)
--- a/
extras/scsi_id/scsi_id.c
+++ b/
extras/scsi_id/scsi_id.c
@@
-44,8
+44,8
@@
/*
* temporary names for mknod.
*/
/*
* temporary names for mknod.
*/
-#define TMP_DIR "/
tmp
"
-#define TMP_PREFIX "scsi"
+#define TMP_DIR "/
dev
"
+#define TMP_PREFIX "
tmp-
scsi"
/*
* XXX Note the 'e' (send output to stderr in all cases), and 'c' (callout)
/*
* XXX Note the 'e' (send output to stderr in all cases), and 'c' (callout)
@@
-67,7
+67,7
@@
static int dev_specified;
static int sys_specified;
static char config_file[MAX_NAME_LEN] = SCSI_ID_CONFIG_FILE;
static int display_bus_id;
static int sys_specified;
static char config_file[MAX_NAME_LEN] = SCSI_ID_CONFIG_FILE;
static int display_bus_id;
-static
int
default_page_code;
+static
enum page_code
default_page_code;
static int use_stderr;
static int debug;
static int hotplug_mode;
static int use_stderr;
static int debug;
static int hotplug_mode;
@@
-101,14
+101,13
@@
void log_message (int level, const char *format, ...)
return;
}
return;
}
-static void set_str(char *to, const
unsigned char *from, in
t count)
+static void set_str(char *to, const
char *from, size_
t count)
{
{
- int i, j;
- int len;
+ size_t i, j, len;
/* strip trailing whitespace */
len = strnlen(from, count);
/* strip trailing whitespace */
len = strnlen(from, count);
- while (isspace(from[len-1]))
+ while (
len &&
isspace(from[len-1]))
len--;
/* strip leading whitespace */
len--;
/* strip leading whitespace */
@@
-134,42
+133,42
@@
static void set_str(char *to, const unsigned char *from, int count)
to[j] = '\0';
}
to[j] = '\0';
}
-static void set_type(char *to, const char *from,
int count
)
+static void set_type(char *to, const char *from,
size_t len
)
{
int type_num;
char *eptr;
{
int type_num;
char *eptr;
+ char *type = "generic";
type_num = strtoul(from, &eptr, 0);
if (eptr != from) {
switch (type_num) {
case 0:
type_num = strtoul(from, &eptr, 0);
if (eptr != from) {
switch (type_num) {
case 0:
-
sprintf(to, "disk")
;
+
type = "disk"
;
break;
case 1:
break;
case 1:
-
sprintf(to, "tape")
;
+
type = "tape"
;
break;
case 4:
break;
case 4:
-
sprintf(to, "optical")
;
+
type = "optical"
;
break;
case 5:
break;
case 5:
-
sprintf(to, "cd")
;
+
type = "cd"
;
break;
case 7:
break;
case 7:
-
sprintf(to, "optical")
;
+
type = "optical"
;
break;
case 0xe:
break;
case 0xe:
-
sprintf(to, "disk")
;
+
type = "disk"
;
break;
case 0xf:
break;
case 0xf:
-
sprintf(to, "optical")
;
+
type = "optical"
;
break;
default:
break;
default:
- sprintf(to, "generic");
break;
}
break;
}
- } else {
- sprintf(to, "generic");
}
}
+ strncpy(to, type, len);
+ to[len-1] = '\0';
}
static int get_major_minor(struct sysfs_class_device *class_dev, int *maj,
}
static int get_major_minor(struct sysfs_class_device *class_dev, int *maj,
@@
-476,7
+475,7
@@
static int set_options(int argc, char **argv, const char *short_opts,
*/
optind = 1;
while (1) {
*/
optind = 1;
while (1) {
- option = getopt(argc, argv, short_opt
ion
s);
+ option = getopt(argc, argv, short_opts);
if (option == -1)
break;
if (option == -1)
break;
@@
-520,9
+519,11
@@
static int set_options(int argc, char **argv, const char *short_opts,
case 'p':
if (strcmp(optarg, "0x80") == 0) {
case 'p':
if (strcmp(optarg, "0x80") == 0) {
- default_page_code =
0x
80;
+ default_page_code =
PAGE_
80;
} else if (strcmp(optarg, "0x83") == 0) {
} else if (strcmp(optarg, "0x83") == 0) {
- default_page_code = 0x83;
+ default_page_code = PAGE_83;
+ } else if (strcmp(optarg, "pre-spc3-83") == 0) {
+ default_page_code = PAGE_83_PRE_SPC3;
} else {
log_message(LOG_WARNING,
"Unknown page code '%s'\n", optarg);
} else {
log_message(LOG_WARNING,
"Unknown page code '%s'\n", optarg);
@@
-602,7
+603,7
@@
static int per_dev_options(struct sysfs_device *scsi_dev, int *good_bad,
scsi_dev->name);
return -1;
}
scsi_dev->name);
return -1;
}
- set_type(type_str, type->value, sizeof(type_str)
-1
);
+ set_type(type_str, type->value, sizeof(type_str));
type = sysfs_get_device_attr(scsi_dev, "rev");
if (!type) {
type = sysfs_get_device_attr(scsi_dev, "rev");
if (!type) {
@@
-641,9
+642,11
@@
static int per_dev_options(struct sysfs_device *scsi_dev, int *good_bad,
case 'p':
if (strcmp(optarg, "0x80") == 0) {
case 'p':
if (strcmp(optarg, "0x80") == 0) {
- *page_code =
0x
80;
+ *page_code =
PAGE_
80;
} else if (strcmp(optarg, "0x83") == 0) {
} else if (strcmp(optarg, "0x83") == 0) {
- *page_code = 0x83;
+ *page_code = PAGE_83;
+ } else if (strcmp(optarg, "pre-spc3-83") == 0) {
+ *page_code = PAGE_83_PRE_SPC3;
} else {
log_message(LOG_WARNING,
"Unknown page code '%s'\n", optarg);
} else {
log_message(LOG_WARNING,
"Unknown page code '%s'\n", optarg);
@@
-674,13
+677,22
@@
static int per_dev_options(struct sysfs_device *scsi_dev, int *good_bad,
*/
static void format_serial(char *serial)
{
*/
static void format_serial(char *serial)
{
- char *p = serial;
+ char *p = serial
, *q
;
+ q = p;
while (*p != '\0') {
while (*p != '\0') {
- if (isspace(*p))
- *p = '_';
+ if (isspace(*p)) {
+ if (q > serial && q[-1] != '_') {
+ *q = '_';
+ q++;
+ }
+ } else {
+ *q = *p;
+ q++;
+ }
p++;
}
p++;
}
+ *q = '\0';
}
/*
}
/*
@@
-827,6
+839,7
@@
static int scsi_id(const char *target_path, char *maj_min_dev)
set_str(serial_str, serial, sizeof(serial_str));
printf("ID_SERIAL=%s\n", serial_str);
printf("ID_TYPE=%s\n", type_str);
set_str(serial_str, serial, sizeof(serial_str));
printf("ID_SERIAL=%s\n", serial_str);
printf("ID_TYPE=%s\n", type_str);
+ printf("ID_BUS=scsi\n");
} else {
if (reformat_serial)
format_serial(serial);
} else {
if (reformat_serial)
format_serial(serial);