diff options
author | Michael Brown <mcb30@etherboot.org> | 2009-08-09 15:30:07 +0100 |
---|---|---|
committer | Michael Brown <mcb30@etherboot.org> | 2009-08-10 19:30:41 +0100 |
commit | d94479468010ba2f64bc8664585e9c3491129303 (patch) | |
tree | fb48575d8470301f17e2a6ecd997fba2f40cef0f /src/drivers/block/scsi.c | |
parent | 976f12c50120637410f30c17f8fbfcd5a49ed8fd (diff) | |
download | ipxe-d94479468010ba2f64bc8664585e9c3491129303.tar.gz |
[scsi] Generalise iscsi_parse_lun() to scsi_parse_lun()
Diffstat (limited to 'src/drivers/block/scsi.c')
-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; +} |