From e32a776a5a4cdd3e7c4eb430fbc34d0dbe8101d9 Mon Sep 17 00:00:00 2001 From: agc Date: Sun, 21 May 2006 09:26:37 +0000 Subject: [PATCH] Adjust the data VPD returns, to work around a problem in the Cisco initiator (used on Solaris 10 Update 1) - the initiator demands that a UUID is returned, so give it one. Add autoconf glue for that, and a compat uuid_create(3) and uuid_to_string(3). This still spews a lot of output via the target's syslog, but persevere, since it does actually make the target work with the Solaris initiator: solaris10# format Searching for disks...done AVAILABLE DISK SELECTIONS: 0. c1d0 /pci@0,0/pci-ide@1f,1/ide@0/cmdk@0,0 1. c2t5d0 /iscsi/disk@0000iqn.1994-04.org.netbsd.iscsi-target%3Atarget00001,0 Specify disk (enter its number): ^D solaris10# df -k /mnt Filesystem kbytes used avail capacity Mounted on /dev/dsk/c2t5d0s0 91407 1041 81226 2% /mnt solaris10# uname -a SunOS solaris10 5.10 Generic_118844-26 i86pc i386 i86pc solaris10# --- dist/iscsi/include/compat.h | 35 ++++++++-- dist/iscsi/include/config.h | 16 ++++- dist/iscsi/include/config.h.in | 12 ++++ dist/iscsi/include/scsi_cmd_codes.h | 9 ++- dist/iscsi/include/util.h | 4 +- dist/iscsi/src/Makefile.in | 2 +- dist/iscsi/src/TODO | 2 + dist/iscsi/src/configure | 26 ++++--- dist/iscsi/src/configure.ac | 6 +- dist/iscsi/src/disk.c | 79 +++++++++++++++------ dist/iscsi/src/uuid.c | 103 ++++++++++++++++++++++++++++ 11 files changed, 247 insertions(+), 47 deletions(-) create mode 100644 dist/iscsi/src/uuid.c diff --git a/dist/iscsi/include/compat.h b/dist/iscsi/include/compat.h index e681e136740f..7ff72b6327cc 100644 --- a/dist/iscsi/include/compat.h +++ b/dist/iscsi/include/compat.h @@ -44,17 +44,18 @@ size_t strlcpy(char *, const char *, size_t); #ifndef HTOBE64 # if defined(HAVE_LIBKERN_OSBYTEORDER_H) -# define HTOBE64(x) (x) = OSSwapBigToHostInt64((u_int64_t)(x)) +# define HTOBE64(x) (x) = OSSwapBigToHostInt64((u_int64_t)(x)) # elif _BYTE_ORDER == _BIG_ENDIAN -# define HTOBE64(x) (x) +# define HTOBE64(x) (x) +# elif defined(HAVE___BSWAP64) +# define HTOBE64(x) (x) = __bswap64((u_int64_t)(x)) # else /* LITTLE_ENDIAN */ -# define HTOBE64(x) (x) = __bswap64((u_int64_t)(x)) -# define bswap64(x) __bswap64(x) +# define HTOBE64(x) (((uint64_t)(ISCSI_NTOHL((uint32_t)(((x) << 32) >> 32))) << 32) | (uint32_t)ISCSI_NTOHL(((uint32_t)((x) >> 32)))) # endif /* LITTLE_ENDIAN */ #endif #ifndef BE64TOH -#define BE64TOH(x) HTOBE64(x) +# define BE64TOH(x) HTOBE64(x) #endif #ifndef _DIAGASSERT @@ -64,4 +65,28 @@ size_t strlcpy(char *, const char *, size_t); #define _DIAGASSERT(e) (__static_cast(void,0)) #endif +#ifndef HAVE_UUID_H +/* Length of a node address (an IEEE 802 address). */ +#define _UUID_NODE_LEN 6 + +/* + * See also: + * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt + * http://www.opengroup.org/onlinepubs/009629399/apdxa.htm + * + * A DCE 1.1 compatible source representation of UUIDs. + */ +typedef struct uuid_t { + uint32_t time_low; + uint16_t time_mid; + uint16_t time_hi_and_version; + uint8_t clock_seq_hi_and_reserved; + uint8_t clock_seq_low; + uint8_t node[_UUID_NODE_LEN]; +} uuid_t; + +void uuid_create(uuid_t *, uint32_t *); +void uuid_to_string(uuid_t *, char **, uint32_t *); +#endif + #endif /* COMPAT_H_ */ diff --git a/dist/iscsi/include/config.h b/dist/iscsi/include/config.h index 8183c660da67..448fb926e425 100644 --- a/dist/iscsi/include/config.h +++ b/dist/iscsi/include/config.h @@ -145,6 +145,15 @@ /* Define to 1 if you have the header file. */ #define HAVE_UTIME_H 1 +/* Define to 1 if you have the `uuid_create' function. */ +#define HAVE_UUID_CREATE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UUID_H 1 + +/* Define to 1 if you have the `uuid_to_string' function. */ +#define HAVE_UUID_TO_STRING 1 + /* Define to 1 if you have the `vasnprintf' function. */ /* #undef HAVE_VASNPRINTF */ @@ -154,6 +163,9 @@ /* Define to 1 if you have the `vsnprintf' function. */ #define HAVE_VSNPRINTF 1 +/* Define to 1 if you have the `__bswap64' function. */ +/* #undef HAVE___BSWAP64 */ + /* Define to the address where bug reports for this package should be sent. */ #define PACKAGE_BUGREPORT "Alistair Crooks " @@ -161,13 +173,13 @@ #define PACKAGE_NAME "netbsd-iscsi" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "netbsd-iscsi 20060417" +#define PACKAGE_STRING "netbsd-iscsi 20060520" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "netbsd-iscsi" /* Define to the version of this package. */ -#define PACKAGE_VERSION "20060417" +#define PACKAGE_VERSION "20060520" /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1 diff --git a/dist/iscsi/include/config.h.in b/dist/iscsi/include/config.h.in index 85f7ab777d60..0a6c45b6bd3e 100644 --- a/dist/iscsi/include/config.h.in +++ b/dist/iscsi/include/config.h.in @@ -144,6 +144,15 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UTIME_H +/* Define to 1 if you have the `uuid_create' function. */ +#undef HAVE_UUID_CREATE + +/* Define to 1 if you have the header file. */ +#undef HAVE_UUID_H + +/* Define to 1 if you have the `uuid_to_string' function. */ +#undef HAVE_UUID_TO_STRING + /* Define to 1 if you have the `vasnprintf' function. */ #undef HAVE_VASNPRINTF @@ -153,6 +162,9 @@ /* Define to 1 if you have the `vsnprintf' function. */ #undef HAVE_VSNPRINTF +/* Define to 1 if you have the `__bswap64' function. */ +#undef HAVE___BSWAP64 + /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT diff --git a/dist/iscsi/include/scsi_cmd_codes.h b/dist/iscsi/include/scsi_cmd_codes.h index cb04c85b3418..e1a827e3c0d8 100644 --- a/dist/iscsi/include/scsi_cmd_codes.h +++ b/dist/iscsi/include/scsi_cmd_codes.h @@ -1,4 +1,4 @@ -/* $NetBSD: scsi_cmd_codes.h,v 1.6 2006/04/26 20:29:56 agc Exp $ */ +/* $NetBSD: scsi_cmd_codes.h,v 1.7 2006/05/21 09:26:37 agc Exp $ */ /* * Copyright © 2006 Alistair Crooks. All rights reserved. @@ -68,8 +68,15 @@ enum { INQUIRY_DEVICE_IDENTIFICATION_VPD = 0x83, INQUIRY_SUPPORTED_VPD_PAGES = 0x0, INQUIRY_DEVICE_PIV = 0x1, + + INQUIRY_IDENTIFIER_TYPE_T10 = 0x1, + INQUIRY_IDENTIFIER_TYPE_EUI64 = 0x2, + INQUIRY_IDENTIFIER_TYPE_NAA = 0x3, + + INQUIRY_DEVICE_ASSOCIATION_LOGICAL_UNIT = 0x0, INQUIRY_DEVICE_ASSOCIATION_TARGET_PORT = 0x1, INQUIRY_DEVICE_ASSOCIATION_TARGET_DEVICE = 0x2, + INQUIRY_DEVICE_CODESET_UTF8 = 0x3, INQUIRY_DEVICE_ISCSI_PROTOCOL = 0x5, INQUIRY_DEVICE_T10_VENDOR = 0x1, diff --git a/dist/iscsi/include/util.h b/dist/iscsi/include/util.h index 77ef981932a9..bdfe16862395 100644 --- a/dist/iscsi/include/util.h +++ b/dist/iscsi/include/util.h @@ -167,8 +167,8 @@ void iscsi_print_buffer(const char *, const size_t); #define __BIG_ENDIAN _BIG_ENDIAN #define __LITTLE_ENDIAN _LITTLE_ENDIAN -#define ISCSI_NTOHLL(x) be64toh(x) -#define ISCSI_HTONLL(x) htobe64(x) +#define ISCSI_NTOHLL(a) BE64TOH(a) +#define ISCSI_HTONLL(a) HTOBE64(a) #define ISCSI_NTOHL(a) ntohl(a) #define ISCSI_HTONL(a) htonl(a) #define ISCSI_NTOHS(a) ntohs(a) diff --git a/dist/iscsi/src/Makefile.in b/dist/iscsi/src/Makefile.in index 73771530338c..760cda074c5f 100644 --- a/dist/iscsi/src/Makefile.in +++ b/dist/iscsi/src/Makefile.in @@ -45,7 +45,7 @@ $(BIN): # # User-level Targets # -COMPATOBJS= strlcpy.o snprintf.o strtoll.o +COMPATOBJS= strlcpy.o snprintf.o strtoll.o uuid.o USER_TARGET_OBJS = target.o iscsi.o util.o parameters.o netmask.o conffile.o storage.o ${COMPATOBJS} $(BIN)/osd: osd-target.c osd.c $(USER_TARGET_OBJS) diff --git a/dist/iscsi/src/TODO b/dist/iscsi/src/TODO index 33d9ebea030d..3c6fa529c73e 100644 --- a/dist/iscsi/src/TODO +++ b/dist/iscsi/src/TODO @@ -31,3 +31,5 @@ raid0 add discovery masking clean up IPv6 add socklen_t awareness +add uuid +Solaris initiator compatibility diff --git a/dist/iscsi/src/configure b/dist/iscsi/src/configure index 8e0c0a1b43bd..423131ffd139 100755 --- a/dist/iscsi/src/configure +++ b/dist/iscsi/src/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.59 for netbsd-iscsi 20060417. +# Generated by GNU Autoconf 2.59 for netbsd-iscsi 20060520. # # Report bugs to >. # @@ -269,8 +269,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='netbsd-iscsi' PACKAGE_TARNAME='netbsd-iscsi' -PACKAGE_VERSION='20060417' -PACKAGE_STRING='netbsd-iscsi 20060417' +PACKAGE_VERSION='20060520' +PACKAGE_STRING='netbsd-iscsi 20060520' PACKAGE_BUGREPORT='Alistair Crooks ' ac_unique_file="iscsi.c" @@ -780,7 +780,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures netbsd-iscsi 20060417 to adapt to many kinds of systems. +\`configure' configures netbsd-iscsi 20060520 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -837,7 +837,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of netbsd-iscsi 20060417:";; + short | recursive ) echo "Configuration of netbsd-iscsi 20060520:";; esac cat <<\_ACEOF @@ -949,7 +949,7 @@ fi test -n "$ac_init_help" && exit 0 if $ac_init_version; then cat <<\_ACEOF -netbsd-iscsi configure 20060417 +netbsd-iscsi configure 20060520 generated by GNU Autoconf 2.59 Copyright (C) 2003 Free Software Foundation, Inc. @@ -963,7 +963,7 @@ cat >&5 <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by netbsd-iscsi $as_me 20060417, which was +It was created by netbsd-iscsi $as_me 20060520, which was generated by GNU Autoconf 2.59. Invocation command line was $ $0 $@ @@ -3384,7 +3384,8 @@ done -for ac_header in ctype.h errno.h fcntl.h pthread.h pwd.h signal.h stdlib.h syslog.h unistd.h string.h stdarg.h utime.h + +for ac_header in ctype.h errno.h fcntl.h pthread.h pwd.h signal.h stdlib.h syslog.h unistd.h string.h stdarg.h utime.h uuid.h do as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` if eval "test \"\${$as_ac_Header+set}\" = set"; then @@ -4153,7 +4154,10 @@ fi -for ac_func in asprintf asnprintf bswap64 daemon fsync_range snprintf strlcpy strtoll syslog vasprintf vasnprintf vsnprintf + + + +for ac_func in __bswap64 asprintf asnprintf bswap64 daemon fsync_range snprintf strlcpy strtoll syslog vasprintf vasnprintf vsnprintf uuid_create uuid_to_string do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 @@ -4618,7 +4622,7 @@ _ASBOX } >&5 cat >&5 <<_CSEOF -This file was extended by netbsd-iscsi $as_me 20060417, which was +This file was extended by netbsd-iscsi $as_me 20060520, which was generated by GNU Autoconf 2.59. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -4678,7 +4682,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -netbsd-iscsi config.status 20060417 +netbsd-iscsi config.status 20060520 configured by $0, generated by GNU Autoconf 2.59, with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" diff --git a/dist/iscsi/src/configure.ac b/dist/iscsi/src/configure.ac index b0e86134b955..a549701696df 100644 --- a/dist/iscsi/src/configure.ac +++ b/dist/iscsi/src/configure.ac @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.57) -AC_INIT([netbsd-iscsi],[20060417],[Alistair Crooks ]) +AC_INIT([netbsd-iscsi],[20060520],[Alistair Crooks ]) AC_CONFIG_SRCDIR([iscsi.c]) AC_CONFIG_HEADER(../include/config.h) @@ -14,7 +14,7 @@ AC_HEADER_STDC AC_CHECK_HEADERS(sys/types.h sys/param.h sys/stat.h sys/time.h sys/mman.h sys/uio.h sys/socket.h sys/time.h sys/vfs.h) AC_CHECK_HEADERS(arpa/inet.h netinet/in.h netinet/tcp.h netdb.h) AC_CHECK_HEADERS(asm/byteorder.h sys/byteorder.h libkern/OSByteOrder.h byteswap.h machine/endian.h) -AC_CHECK_HEADERS(ctype.h errno.h fcntl.h pthread.h pwd.h signal.h stdlib.h syslog.h unistd.h string.h stdarg.h utime.h) +AC_CHECK_HEADERS(ctype.h errno.h fcntl.h pthread.h pwd.h signal.h stdlib.h syslog.h unistd.h string.h stdarg.h utime.h uuid.h) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST @@ -34,7 +34,7 @@ AC_CHECK_LIB(socket, connect) AC_CHECK_LIB(resolv, inet_aton) dnl Check for functionality -AC_CHECK_FUNCS(asprintf asnprintf bswap64 daemon fsync_range snprintf strlcpy strtoll syslog vasprintf vasnprintf vsnprintf) +AC_CHECK_FUNCS(__bswap64 asprintf asnprintf bswap64 daemon fsync_range snprintf strlcpy strtoll syslog vasprintf vasnprintf vsnprintf uuid_create uuid_to_string) dnl that's it for now... AC_OUTPUT(Makefile) diff --git a/dist/iscsi/src/disk.c b/dist/iscsi/src/disk.c index 6f862d11b34a..e053988fdf35 100644 --- a/dist/iscsi/src/disk.c +++ b/dist/iscsi/src/disk.c @@ -1,4 +1,4 @@ -/* $NetBSD: disk.c,v 1.16 2006/04/26 20:31:43 agc Exp $ */ +/* $NetBSD: disk.c,v 1.17 2006/05/21 09:26:38 agc Exp $ */ /* * Copyright © 2006 Alistair Crooks. All rights reserved. @@ -112,9 +112,14 @@ #include +#ifdef HAVE_UUID_H +#include +#endif + #include "scsi_cmd_codes.h" #include "iscsi.h" +#include "compat.h" #include "util.h" #include "device.h" #include "target.h" @@ -157,7 +162,9 @@ typedef struct iscsi_disk_t { uint64_t blocklen; uint64_t luns; uint64_t size; - targv_t *tv; + uuid_t uuid; + char *uuid_string; + targv_t *tv; } iscsi_disk_t; DEFINE_ARRAY(disks_t, iscsi_disk_t); @@ -822,14 +829,14 @@ strpadcpy(uint8_t *dst, size_t dstlen, const char *src, const size_t srclen, cha static int report_luns(uint8_t *data, int64_t luns) { - uint64_t i; + uint64_t lun; int32_t off; - for (i = 0, off = 8 ; i < luns ; i++, off += sizeof(i)) { - *((uint64_t *) (void *)data + off) = ISCSI_HTONLL(i); + for (lun = 0, off = 8 ; lun < luns ; lun++, off += sizeof(lun)) { + *((uint64_t *) (void *)data + off) = ISCSI_HTONLL(lun); } *((uint32_t *) (void *)data) = ISCSI_HTONL(off - 7); - return (off - 7) * sizeof(i); + return (int)(luns * sizeof(lun)); } /* initialise the device */ @@ -898,14 +905,15 @@ device_init(globals_t *gp, targv_t *tvp, disc_target_t *tp) int device_command(target_session_t * sess, target_cmd_t * cmd) { - iscsi_scsi_cmd_args_t *args = cmd->scsi_cmd; - uint32_t lba; - uint16_t len; - uint8_t *cp; - uint8_t *data; - uint8_t *cdb = args->cdb; - uint8_t lun = (uint8_t) (args->lun >> 32); - int mode_data_len; + iscsi_scsi_cmd_args_t *args = cmd->scsi_cmd; + uint32_t status; + uint32_t lba; + uint16_t len; + uint8_t *cp; + uint8_t *data; + uint8_t *cdb = args->cdb; + uint8_t lun = (uint8_t) (args->lun >> 32); + int mode_data_len; #if (CONFIG_DISK_INITIAL_CHECK_CONDITION==1) static int initialized = 0; @@ -965,22 +973,48 @@ device_command(target_session_t * sess, target_cmd_t * cmd) case INQUIRY_DEVICE_IDENTIFICATION_VPD: data[0] = DISK_PERIPHERAL_DEVICE; data[1] = INQUIRY_DEVICE_IDENTIFICATION_VPD; - len = data[3] = cdb[4] - 7; + data[3] = 0; cp = &data[4]; + /* add target device's IQN */ cp[0] = (INQUIRY_DEVICE_ISCSI_PROTOCOL << 4) | INQUIRY_DEVICE_CODESET_UTF8; cp[1] = (INQUIRY_DEVICE_PIV << 7) | (INQUIRY_DEVICE_ASSOCIATION_TARGET_DEVICE << 4) | INQUIRY_DEVICE_IDENTIFIER_SCSI_NAME; - len = (uint8_t) snprintf((char *)&cp[4], (int)len, "%s", sess->globals->targetname) + 4; + len = (uint8_t) snprintf((char *)&cp[4], (int)(cdb[4] - 7), "%s", sess->globals->targetname); cp[3] = len; - cp += len; + data[3] += len + 4; + cp += len + 4; + /* add target port's IQN + LUN */ cp[0] = (INQUIRY_DEVICE_ISCSI_PROTOCOL << 4) | INQUIRY_DEVICE_CODESET_UTF8; cp[1] = (INQUIRY_DEVICE_PIV << 7) | (INQUIRY_DEVICE_ASSOCIATION_TARGET_PORT << 4) | INQUIRY_DEVICE_IDENTIFIER_SCSI_NAME; - len = (uint8_t) snprintf((char *)&cp[4], (int)len, "%s,t,0x%x", sess->globals->targetname, lun) + 4; + len = (uint8_t) snprintf((char *)&cp[4], (int)(cdb[4] - 7), "%s,t,0x%x", sess->globals->targetname, lun); cp[3] = len; - cp += len; + data[3] += len + 4; + cp += len + 4; + /* add target port's IQN + LUN extension */ cp[0] = (INQUIRY_DEVICE_ISCSI_PROTOCOL << 4) | INQUIRY_DEVICE_CODESET_UTF8; - cp[1] = (INQUIRY_DEVICE_PIV << 7) | (INQUIRY_DEVICE_ASSOCIATION_TARGET_DEVICE << 4) | INQUIRY_DEVICE_T10_VENDOR; + cp[1] = (INQUIRY_DEVICE_PIV << 7) | (INQUIRY_DEVICE_ASSOCIATION_LOGICAL_UNIT << 4) | INQUIRY_DEVICE_IDENTIFIER_SCSI_NAME; + if (disks.v[sess->d].uuid_string == NULL) { + uuid_create(&disks.v[sess->d].uuid, &status); + uuid_to_string(&disks.v[sess->d].uuid, &disks.v[sess->d].uuid_string, &status); + } + len = (uint8_t) snprintf((char *)&cp[4], (int)(cdb[4] - 7), "%s,L,0x%8.8s%4.4s%4.4s", + sess->globals->targetname, + disks.v[sess->d].uuid_string, + &disks.v[sess->d].uuid_string[9], + &disks.v[sess->d].uuid_string[14]); + cp[3] = len; + data[3] += len + 4; + cp += len + 4; + /* add target's uuid as a T10 identifier */ + cp[0] = (INQUIRY_DEVICE_ISCSI_PROTOCOL << 4) | INQUIRY_DEVICE_CODESET_UTF8; + cp[1] = (INQUIRY_DEVICE_PIV << 7) | (INQUIRY_DEVICE_ASSOCIATION_TARGET_DEVICE << 4) | INQUIRY_IDENTIFIER_TYPE_T10; strpadcpy(&cp[4], 8, ISCSI_VENDOR, strlen(ISCSI_VENDOR), ' '); - cp[3] = 8; + len = (uint8_t) snprintf((char *)&cp[8 + 4], (int)(cdb[8 + 4] - 7), "0x%8.8s%4.4s%4.4s", + disks.v[sess->d].uuid_string, + &disks.v[sess->d].uuid_string[9], + &disks.v[sess->d].uuid_string[14]); + cp[3] = len; + data[3] += len + 4; + args->length = data[3] + 6; break; case INQUIRY_SUPPORTED_VPD_PAGES: data[0] = DISK_PERIPHERAL_DEVICE; @@ -988,6 +1022,7 @@ device_command(target_session_t * sess, target_cmd_t * cmd) data[3] = 2; /* # of supported pages */ data[4] = INQUIRY_SUPPORTED_VPD_PAGES; data[5] = INQUIRY_DEVICE_IDENTIFICATION_VPD; + args->length = cdb[4] + 1; break; default: iscsi_trace_error(__FILE__, __LINE__, "Unsupported INQUIRY VPD page %x\n", cdb[2]); @@ -1005,10 +1040,10 @@ device_command(target_session_t * sess, target_cmd_t * cmd) strpadcpy(&data[16], 16, ISCSI_PRODUCT, strlen(ISCSI_PRODUCT), ' '); (void) snprintf(versionstr, sizeof(versionstr), "%d", ISCSI_VERSION); strpadcpy(&data[32], 4, versionstr, strlen(versionstr), ' '); + args->length = cdb[4] + 1; } if (args->status == 0) { args->input = 1; - args->length = cdb[4] + 1; } break; diff --git a/dist/iscsi/src/uuid.c b/dist/iscsi/src/uuid.c new file mode 100644 index 000000000000..375916184236 --- /dev/null +++ b/dist/iscsi/src/uuid.c @@ -0,0 +1,103 @@ +/* $NetBSD: uuid.c,v 1.1 2006/05/21 09:26:38 agc Exp $ */ + +/* + * Copyright © 2006 Alistair Crooks. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Alistair Crooks + * for the NetBSD project. + * 4. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "config.h" + +#ifdef HAVE_INTTYPES_H +#include +#endif + +#include + +#ifdef HAVE_SYS_PARAM_H +#include +#endif + +#ifdef HAVE_SYS_TIME_H +#include +#endif + +#include +#include +#include +#include + +#ifdef HAVE_UUID_H +#include +#endif + +#include "defs.h" + +#ifndef HAVE_UUID_CREATE +/* just fill the struct with random values for now */ +void +uuid_create(uuid_t *uuid, uint32_t *status) +{ + uint64_t ether; + time_t t; + + (void) time(&t); + ether = (random() << 32) | random(); + uuid->time_low = t; + uuid->time_mid = (uint16_t)(random() & 0xffff); + uuid->time_hi_and_version = (uint16_t)(random() & 0xffff); + uuid->clock_seq_low = random() & 0xff; + uuid->clock_seq_hi_and_reserved = random() & 0xff; + (void) memcpy(&uuid->node, ðer, sizeof(uuid->node)); + *status = 0; +} +#endif + +#ifndef HAVE_UUID_TO_STRING +/* convert the struct to a printable string */ +void +uuid_to_string(uuid_t *uuid, char **str, uint32_t *status) +{ + char s[64]; + + (void) snprintf(s, sizeof(s), "%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x", + uuid->time_low, + uuid->time_mid, + uuid->time_hi_and_version, + uuid->clock_seq_hi_and_reserved, + uuid->clock_seq_low, + uuid->node[0], + uuid->node[1], + uuid->node[2], + uuid->node[3], + uuid->node[4], + uuid->node[5]); + *str = strdup(s); + *status = 0; +} +#endif