int i, j;
int len;
+ /* strip trailing whitespace */
len = strnlen(from, count);
while (isspace(from[len-1]))
len--;
+ /* strip leading whitespace */
i = 0;
while (isspace(from[i]) && (i < len))
i++;
j = 0;
while (i < len) {
- switch(from[i]) {
- case '/':
- case ' ':
+ /* substitute multiple whitespace */
+ if (isspace(from[i])) {
+ while (isspace(from[i]))
+ i++;
to[j++] = '_';
- break;
- default:
- to[j++] = from[i];
}
- i++;
+ /* skip chars */
+ if (from[i] == '/') {
+ i++;
+ continue;
+ }
+ to[j++] = from[i++];
}
to[j] = '\0';
}
set_str(revision, id.fw_rev, 8);
if (export) {
+ if ((id.config >> 8) & 0x80) {
+ /* This is an ATAPI device */
+ switch ((id.config >> 8) & 0x1f) {
+ case 0:
+ printf("ID_TYPE=cd\n");
+ break;
+ case 1:
+ printf("ID_TYPE=tape\n");
+ break;
+ case 5:
+ printf("ID_TYPE=cd\n");
+ break;
+ case 7:
+ printf("ID_TYPE=optical\n");
+ break;
+ default:
+ printf("ID_TYPE=generic\n");
+ break;
+ }
+ } else {
+ printf("ID_TYPE=disk\n");
+ }
printf("ID_MODEL=%s\n", model);
printf("ID_SERIAL=%s\n", serial);
printf("ID_REVISION=%s\n", revision);
static int export;
static char vendor_str[64];
static char model_str[64];
+static char revision_str[16];
+static char type_str[16];
void log_message (int level, const char *format, ...)
{
int i, j;
int len;
+ /* strip trailing whitespace */
len = strnlen(from, count);
while (isspace(from[len-1]))
len--;
+ /* strip leading whitespace */
i = 0;
while (isspace(from[i]) && (i < len))
i++;
j = 0;
while (i < len) {
- switch(from[i]) {
- case '/':
- case ' ':
+ /* substitute multiple whitespace */
+ if (isspace(from[i])) {
+ while (isspace(from[i]))
+ i++;
to[j++] = '_';
+ }
+ /* skip chars */
+ if (from[i] == '/') {
+ i++;
+ continue;
+ }
+ to[j++] = from[i++];
+ }
+ to[j] = '\0';
+}
+
+static void set_type(char *to, const char *from, int count)
+{
+ int type_num;
+ char *eptr;
+
+ type_num = strtoul(from, &eptr, 0);
+ if (eptr != from) {
+ switch (type_num) {
+ case 0:
+ sprintf(to, "disk");
+ break;
+ case 1:
+ sprintf(to, "tape");
+ break;
+ case 4:
+ sprintf(to, "optical");
+ break;
+ case 5:
+ sprintf(to, "cd");
+ break;
+ case 7:
+ sprintf(to, "optical");
+ break;
+ case 0xe:
+ sprintf(to, "disk");
+ break;
+ case 0xf:
+ sprintf(to, "optical");
break;
default:
- to[j++] = from[i];
+ sprintf(to, "generic");
+ break;
}
- i++;
+ } else {
+ sprintf(to, "generic");
}
- to[j] = '\0';
}
static int get_major_minor(struct sysfs_class_device *class_dev, int *maj,
int retval;
int newargc;
char **newargv = NULL;
- struct sysfs_attribute *vendor, *model;
+ struct sysfs_attribute *vendor, *model, *type;
int option;
*good_bad = all_good;
}
set_str(model_str, model->value, sizeof(model_str)-1);
+ type = sysfs_get_device_attr(scsi_dev, "type");
+ if (!type) {
+ log_message(LOG_WARNING, "%s: cannot get type attribute\n",
+ scsi_dev->name);
+ return -1;
+ }
+ set_type(type_str, type->value, sizeof(type_str)-1);
+
+ type = sysfs_get_device_attr(scsi_dev, "rev");
+ if (!type) {
+ log_message(LOG_WARNING, "%s: cannot get type attribute\n",
+ scsi_dev->name);
+ return -1;
+ }
+ set_str(revision_str, type->value, sizeof(revision_str)-1);
+
retval = get_file_options(vendor->value, model->value, &newargc,
&newargv);
*p = '_';
p++;
}
-return;
}
/*
static char serial_str[64];
printf("ID_VENDOR=%s\n", vendor_str);
printf("ID_MODEL=%s\n", model_str);
+ printf("ID_REVISION=%s\n", revision_str);
set_str(serial_str, serial, sizeof(serial_str));
printf("ID_SERIAL=%s\n", serial_str);
+ printf("ID_TYPE=%s\n", type_str);
} else {
if (reformat_serial)
format_serial(serial);