summaryrefslogtreecommitdiffstats
path: root/src/drivers/block/scsi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/block/scsi.c')
-rw-r--r--src/drivers/block/scsi.c30
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;
+}