diff options
author | Sami Kerola | 2012-06-11 21:17:38 +0200 |
---|---|---|
committer | Sami Kerola | 2012-06-11 22:06:06 +0200 |
commit | ba32a9465a3bedb0ba750cdc80a4e84fe2de6eda (patch) | |
tree | ac0ac7d16cb282bb7b3e63a63974e3b22acb0a0d /lib/blkdev.c | |
parent | wipefs: use symbolic value for markup mode (diff) | |
download | kernel-qcow2-util-linux-ba32a9465a3bedb0ba750cdc80a4e84fe2de6eda.tar.gz kernel-qcow2-util-linux-ba32a9465a3bedb0ba750cdc80a4e84fe2de6eda.tar.xz kernel-qcow2-util-linux-ba32a9465a3bedb0ba750cdc80a4e84fe2de6eda.zip |
blkdev: add blkdev_scsi_type_to_name()
Add a function, and necessary symbols, to convert scsi type id's
to name strings.
Reference: http://permalink.gmane.org/gmane.linux.utilities.util-linux-ng/5994
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'lib/blkdev.c')
-rw-r--r-- | lib/blkdev.c | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/lib/blkdev.c b/lib/blkdev.c index 9e13e1370..35ec36954 100644 --- a/lib/blkdev.c +++ b/lib/blkdev.c @@ -21,8 +21,9 @@ #endif #include "blkdev.h" -#include "linux_version.h" #include "c.h" +#include "linux_version.h" +#include "xalloc.h" static long blkdev_valid_offset (int fd, off_t offset) { @@ -288,6 +289,51 @@ int blkdev_get_geometry(int fd, unsigned int *h, unsigned int *s) return -1; } +/* + * Convert scsi type to human readable string. Return value is + * expected to free'd after use. + */ +char *blkdev_scsi_type_to_name(int type) +{ + char *type_str = NULL; + + switch (type) { + case SCSI_TYPE_DISK: + return xstrdup("disk"); + case SCSI_TYPE_TAPE: + return xstrdup("tape"); + case SCSI_TYPE_PRINTER: + return xstrdup("printer"); + case SCSI_TYPE_PROCESSOR: + return xstrdup("processor"); + case SCSI_TYPE_WORM: + return xstrdup("worm"); + case SCSI_TYPE_ROM: + return xstrdup("rom"); + case SCSI_TYPE_SCANNER: + return xstrdup("scanner"); + case SCSI_TYPE_MOD: + return xstrdup("mo-disk"); + case SCSI_TYPE_MEDIUM_CHANGER: + return xstrdup("changer"); + case SCSI_TYPE_COMM: + return xstrdup("comm"); + case SCSI_TYPE_RAID: + return xstrdup("raid"); + case SCSI_TYPE_ENCLOSURE: + return xstrdup("enclosure"); + case SCSI_TYPE_RBC: + return xstrdup("rbc"); + case SCSI_TYPE_OSD: + return xstrdup("osd"); + case SCSI_TYPE_NO_LUN: + return xstrdup("no-lun"); + default: + xasprintf(&type_str, "0x%02x", type); + return type_str; + } +} + #ifdef TEST_PROGRAM #include <stdio.h> #include <stdlib.h> |