diff options
author | Michael Brown | 2009-08-09 16:30:07 +0200 |
---|---|---|
committer | Michael Brown | 2009-08-10 20:30:41 +0200 |
commit | d94479468010ba2f64bc8664585e9c3491129303 (patch) | |
tree | fb48575d8470301f17e2a6ecd997fba2f40cef0f /src/drivers/block | |
parent | [scsi] Generalise iscsi_detached_command() to scsi_detached_command() (diff) | |
download | ipxe-d94479468010ba2f64bc8664585e9c3491129303.tar.gz ipxe-d94479468010ba2f64bc8664585e9c3491129303.tar.xz ipxe-d94479468010ba2f64bc8664585e9c3491129303.zip |
[scsi] Generalise iscsi_parse_lun() to scsi_parse_lun()
Diffstat (limited to 'src/drivers/block')
-rw-r--r-- | src/drivers/block/scsi.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/drivers/block/scsi.c b/src/drivers/block/scsi.c index 19f99f82..a51b3af6 100644 --- a/src/drivers/block/scsi.c +++ b/src/drivers/block/scsi.c @@ -19,6 +19,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <stddef.h> +#include <stdlib.h> #include <string.h> #include <byteswap.h> #include <errno.h> @@ -334,3 +335,32 @@ int init_scsidev ( struct scsi_device *scsi ) { return 0; } + +/** + * Parse SCSI LUN + * + * @v lun_string LUN string representation + * @v lun LUN to fill in + * @ret rc Return status code + */ +int scsi_parse_lun ( const char *lun_string, struct scsi_lun *lun ) { + char *p; + int i; + + memset ( lun, 0, sizeof ( *lun ) ); + if ( lun_string ) { + p = ( char * ) lun_string; + for ( i = 0 ; i < 4 ; i++ ) { + lun->u16[i] = htons ( strtoul ( p, &p, 16 ) ); + if ( *p == '\0' ) + break; + if ( *p != '-' ) + return -EINVAL; + p++; + } + if ( *p ) + return -EINVAL; + } + + return 0; +} |