summaryrefslogtreecommitdiff
path: root/extras/ata_id
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@suse.de>2005-06-27 17:04:56 +0200
committerKay Sievers <kay.sievers@suse.de>2005-06-27 17:04:56 +0200
commitaaff09a30ab849186c0d4ad8bde83876d7a1a63d (patch)
treeb59885517762e7ab7eec197370ab139319e55027 /extras/ata_id
parent34129109a1f5dca72af2f3f2d3d14a9a0d0c43f6 (diff)
add ID_TYPE to the id probers
Export the type of device from ata_id and scsi_id, also strip leading and trailing whitespace and substitute consecutive whitespace with a single underline char. From: Hannes Reinecke <hare@suse.de> Signed-off-by: Kay Sievers <kay.sievers@suse.de>
Diffstat (limited to 'extras/ata_id')
-rw-r--r--extras/ata_id/ata_id.c41
1 files changed, 34 insertions, 7 deletions
diff --git a/extras/ata_id/ata_id.c b/extras/ata_id/ata_id.c
index 59e2b3987b..34b1ccdff1 100644
--- a/extras/ata_id/ata_id.c
+++ b/extras/ata_id/ata_id.c
@@ -67,25 +67,30 @@ static void set_str(char *to, const unsigned char *from, int count)
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';
}
@@ -137,6 +142,28 @@ int main(int argc, char *argv[])
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);