Apply some fixes from HEO SeonMeyong to allow the iSCSI target to build

and operate on Mac OS X - with apologies for taking so long to apply them.
This commit is contained in:
agc 2009-06-23 05:11:46 +00:00
parent cacd735007
commit d94c46b0c4
4 changed files with 33 additions and 46 deletions

View File

@ -74,28 +74,4 @@ size_t strlcpy(char *, const char *, size_t);
#define INFTIM -1
#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_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: storage.h,v 1.5 2007/12/09 09:16:42 agc Exp $ */
/* $NetBSD: storage.h,v 1.6 2009/06/23 05:11:46 agc Exp $ */
/*
* Copyright © 2006 Alistair Crooks. All rights reserved.
@ -32,6 +32,28 @@
#include "defs.h"
/* Length of a node address (an IEEE 802 address). */
#define NB_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 nbuuid_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[NB_UUID_NODE_LEN];
} nbuuid_t;
void nbuuid_create(nbuuid_t *, uint32_t *);
void nbuuid_to_string(nbuuid_t *, char **, uint32_t *);
enum {
DE_EXTENT,
DE_DEVICE
@ -51,7 +73,7 @@ typedef struct disc_de_t {
typedef struct disc_extent_t {
char *extent; /* extent name */
char *dev; /* device associated with it */
uint64_t sacred; /* offset of extent from start of device */
uint64_t sacred; /* offset of extent from start of dev */
uint64_t len; /* size of extent */
int fd; /* in-core file descriptor */
int used; /* extent has been used in a device */

12
dist/iscsi/src/disk.c vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: disk.c,v 1.39 2009/01/25 14:25:27 lukem Exp $ */
/* $NetBSD: disk.c,v 1.40 2009/06/23 05:11:47 agc Exp $ */
/*
* Copyright © 2006 Alistair Crooks. All rights reserved.
@ -108,10 +108,6 @@
#include <unistd.h>
#ifdef HAVE_UUID_H
#include <uuid.h>
#endif
#include "scsi_cmd_codes.h"
#include "iscsi.h"
@ -151,7 +147,7 @@ typedef struct iscsi_disk_t {
uint64_t blocklen; /* block size */
uint64_t luns; /* # of luns */
uint64_t size; /* size of complete disk */
uuid_t uuid; /* disk's uuid */
nbuuid_t uuid; /* disk's uuid */
char *uuid_string; /* uuid string */
targv_t *tv; /* the component devices and extents */
uint32_t resc; /* # of reservation keys */
@ -976,8 +972,8 @@ device_command(target_session_t * sess, target_cmd_t * cmd)
cp[0] = (INQUIRY_DEVICE_ISCSI_PROTOCOL << 4) | INQUIRY_DEVICE_CODESET_UTF8;
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);
nbuuid_create(&disks.v[sess->d].uuid, &status);
nbuuid_to_string(&disks.v[sess->d].uuid, &disks.v[sess->d].uuid_string, &status);
}
len = (uint8_t) snprintf((char *)&cp[4],
(unsigned)(*totsize - (int)(cp - &data[4])),

17
dist/iscsi/src/uuid.c vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: uuid.c,v 1.3 2007/06/16 23:13:26 agc Exp $ */
/* $NetBSD: uuid.c,v 1.4 2009/06/23 05:11:47 agc Exp $ */
/*
* Copyright © 2006 Alistair Crooks. All rights reserved.
@ -48,23 +48,19 @@
#include <string.h>
#include <unistd.h>
#ifdef HAVE_UUID_H
#include <uuid.h>
#endif
#include "storage.h"
#include "compat.h"
#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)
nbuuid_create(nbuuid_t *uuid, uint32_t *status)
{
uint64_t ether;
time_t t;
(void) time(&t);
ether = (random() << 32) | random();
ether = ((uint64_t)random() << 32) | random();
uuid->time_low = t;
uuid->time_mid = (uint16_t)(random() & 0xffff);
uuid->time_hi_and_version = (uint16_t)(random() & 0xffff);
@ -73,12 +69,10 @@ uuid_create(uuid_t *uuid, uint32_t *status)
(void) memcpy(&uuid->node, &ether, 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)
nbuuid_to_string(nbuuid_t *uuid, char **str, uint32_t *status)
{
char s[64];
@ -97,4 +91,3 @@ uuid_to_string(uuid_t *uuid, char **str, uint32_t *status)
*str = strdup(s);
*status = 0;
}
#endif