mirror of
https://github.com/ipxe/ipxe
synced 2025-12-20 12:00:19 +03:00
[scsi] Generalise iscsi_parse_lun() to scsi_parse_lun()
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user