LIBS=
CC=gcc
-CFLAGS=-g -O0 -Wall -W -I../.. "-D_U_=__attribute__((unused))"
+CFLAGS=-g -O0 -Wall -W -I../..
LIBISCSI_OBJ = socket.o init.o login.o nop.o pdu.o discovery.o scsi-command.o scsi-lowlevel.o
all: tools/iscsiclient
return 1;
if (strcmp(argv[1], "depends") == 0) {
+ printf("ccan/compiler\n");
return 0;
}
-/*
+/*
Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
This program is free software; you can redistribute it and/or modify
free(addresses);
addresses = next;
}
-}
+}
int iscsi_process_text_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size)
{
pdu->callback(iscsi, ISCSI_STATUS_ERROR, NULL, pdu->private_data);
iscsi_free_discovery_addresses(targets);
return -1;
- }
+ }
/* parse the strings */
if (!strncmp((char *)hdr, "TargetName=", 11)) {
-/*
+/*
Unix SMB/CIFS implementation.
some simple double linked list macros
-/*
+/*
Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
This program is free software; you can redistribute it and/or modify
-/*
+/*
Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
This program is free software; you can redistribute it and/or modify
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#ifndef CCAN_ISCSI_PRIVATE_H
+#define CCAN_ISCSI_PRIVATE_H
#include <stdint.h>
-#ifndef _U_
-#define _U_
-#endif
-
#ifndef discard_const
#define discard_const(ptr) ((void *)((intptr_t)(ptr)))
#endif
int iscsi_process_scsi_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size);
int iscsi_process_scsi_data_in(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size, int *is_finished);
int iscsi_process_nop_out_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size);
+
+#endif /* CCAN_ISCSI_PRIVATE_H */
-/*
+/*
Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
This program is free software; you can redistribute it and/or modify
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
+#ifndef CCAN_ISCSI_H
+#define CCAN_ISCSI_H
struct iscsi_context;
struct sockaddr;
ISCSI_STATUS_ERROR =0x0f000001 };
-/*
+/*
* Generic callback for completion of iscsi_*_async().
* command_data depends on status.
*/
* ISCSI_STATUS_GOOD : Connection was successful. Command_data is NULL.
* In this case the callback will be invoked a second time once the connection
* is torn down.
- *
+ *
* ISCSI_STATUS_ERROR : Either failed to establish the connection, or an already established connection
* has failed with an error.
*
*
* status :
* ISCSI_STATUS_GOOD the scsi command completed successfullt on the target.
- * If this scsi command returns DATA-IN, that data is stored in an scsi_task structure
+ * If this scsi command returns DATA-IN, that data is stored in an scsi_task structure
* returned in the command_data parameter. This buffer will be automatically freed once the callback
* returns.
*
int iscsi_modesense6_async(struct iscsi_context *iscsi, int lun, iscsi_command_cb cb, int dbd, int pc, int page_code, int sub_page_code, unsigned char alloc_len, void *private_data);
-
+#endif /* CCAN_ISCSI_H */
-/*
+/*
Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
This program is free software; you can redistribute it and/or modify
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
+#include <ccan/compiler/compiler.h>
#include "iscsi.h"
#include "iscsi-private.h"
* some parameters.
* we should also do proper handshaking if the target is not yet prepared to transition
* to the next stage
- */
+ */
status = ntohs(*(uint16_t *)&hdr[36]);
if (status != 0) {
pdu->callback(iscsi, ISCSI_STATUS_ERROR, NULL, pdu->private_data);
return 0;
}
-int iscsi_process_logout_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size _U_)
+int iscsi_process_logout_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size UNNEEDED_ATTRIBUTE)
{
iscsi->is_loggedin = 0;
pdu->callback(iscsi, ISCSI_STATUS_GOOD, NULL, pdu->private_data);
-/*
+/*
Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
This program is free software; you can redistribute it and/or modify
-/*
+/*
Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
This program is free software; you can redistribute it and/or modify
aligned = (aligned+3)&0xfffffffc;
}
buf = malloc(aligned);
- if (buf == NULL) {
+ if (buf == NULL) {
printf("failed to allocate buffer for %d bytes\n", len);
return -2;
}
int iscsi_pdu_add_data(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, unsigned char *dptr, int dsize)
{
- int len, aligned;
- unsigned char *buf;
-
if (pdu == NULL) {
printf("trying to add data to NULL pdu\n");
return -1;
-/*
+/*
Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
This program is free software; you can redistribute it and/or modify
switch (status) {
case ISCSI_STATUS_CHECK_CONDITION:
- scsi_cbdata->callback(iscsi, ISCSI_STATUS_CHECK_CONDITION, task, scsi_cbdata->private_data);
+ scsi_cbdata->callback(iscsi, ISCSI_STATUS_CHECK_CONDITION, task, scsi_cbdata->private_data);
return;
case ISCSI_STATUS_GOOD:
- scsi_cbdata->callback(iscsi, ISCSI_STATUS_GOOD, task, scsi_cbdata->private_data);
+ scsi_cbdata->callback(iscsi, ISCSI_STATUS_GOOD, task, scsi_cbdata->private_data);
return;
default:
printf("Cant handle scsi status %d yet\n", status);
- scsi_cbdata->callback(iscsi, ISCSI_STATUS_ERROR, task, scsi_cbdata->private_data);
+ scsi_cbdata->callback(iscsi, ISCSI_STATUS_ERROR, task, scsi_cbdata->private_data);
}
}
task->sense.key = task->datain.data[4] & 0x0f;
task->sense.ascq = ntohs(*(uint16_t *)&(task->datain.data[14]));
- pdu->callback(iscsi, ISCSI_STATUS_CHECK_CONDITION, task, pdu->private_data);
+ pdu->callback(iscsi, ISCSI_STATUS_CHECK_CONDITION, task, pdu->private_data);
break;
default:
printf("Unknown status :%d\n", status);
- pdu->callback(iscsi, ISCSI_STATUS_ERROR, task, pdu->private_data);
+ pdu->callback(iscsi, ISCSI_STATUS_ERROR, task, pdu->private_data);
return -1;
}
-/*
+/*
Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
This program is free software; you can redistribute it and/or modify
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
/*
- * would be nice if this could grow into a full blown library for scsi to
+ * would be nice if this could grow into a full blown library for scsi to
* 1, build a CDB
* 2, check how big a complete data-in structure needs to be
* 3, unmarshall data-in into a real structure
#include <strings.h>
#include <stdint.h>
#include <arpa/inet.h>
+#include <ccan/compiler/compiler.h>
#include "scsi-lowlevel.h"
#include "dlinklist.h"
free(task);
}
-void *scsi_malloc(struct scsi_task *task, size_t size)
+static void *scsi_malloc(struct scsi_task *task, size_t size)
{
struct scsi_allocated_memory *mem;
}
return list;
-}
+}
/*
/*
* parse the data in blob and calcualte the size of a full readcapacity10 datain structure
*/
-static int scsi_readcapacity10_datain_getfullsize(struct scsi_task *task _U_)
+static int scsi_readcapacity10_datain_getfullsize(struct scsi_task *task
+ UNNEEDED_ATTRIBUTE)
{
return 8;
}
/*
* unmarshall the data in blob for inquiry into a structure
*/
-void *scsi_inquiry_datain_unmarshall(struct scsi_task *task)
+static void *scsi_inquiry_datain_unmarshall(struct scsi_task *task)
{
struct scsi_inquiry_standard *inq;
-/*
+/*
Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
This program is free software; you can redistribute it and/or modify
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
-
-#ifndef _U_
-#define _U_
-#endif
+#ifndef CCAN_ISCSI_SCSI_LOWLEVEL_H
+#define CCAN_ISCSI_SCSI_LOWLEVEL_H
#define SCSI_CDB_MAX_SIZE 16
char vendor_identification[8+1];
char product_identification[16+1];
char product_revision_level[4+1];
-};
+};
struct scsi_task *scsi_cdb_inquiry(int evpd, int page_code, int alloc_len);
struct scsi_task *scsi_cdb_read10(int lba, int xferlen, int blocksize);
struct scsi_task *scsi_cdb_write10(int lba, int xferlen, int fua, int fuanv, int blocksize);
+#endif /* CCAN_ISCSI_SCSI_LOWLEVEL_H */
-/*
+/*
Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
This program is free software; you can redistribute it and/or modify
int port = 3260;
char *str;
char *addr;
- struct sockaddr_storage s;
- struct sockaddr_in *sin = (struct sockaddr_in *)&s;
+ union {
+ struct sockaddr sa;
+ struct sockaddr_storage ss;
+ struct sockaddr_in sin;
+ } s;
int socksize;
if (iscsi == NULL) {
str[0] = 0;
}
- sin->sin_family = AF_INET;
- sin->sin_port = htons(port);
- if (inet_pton(AF_INET, addr, &sin->sin_addr) != 1) {
+ s.sin.sin_family = AF_INET;
+ s.sin.sin_port = htons(port);
+ if (inet_pton(AF_INET, addr, &s.sin.sin_addr) != 1) {
printf("failed to convert to ip address\n");
free(addr);
return -4;
}
free(addr);
- switch (s.ss_family) {
+ switch (s.ss.ss_family) {
case AF_INET:
iscsi->fd = socket(AF_INET, SOCK_STREAM, 0);
socksize = sizeof(struct sockaddr_in);
break;
default:
- printf("Unknown family :%d\n", s.ss_family);
+ printf("Unknown family :%d\n", s.ss.ss_family);
return -5;
}
set_nonblocking(iscsi->fd);
- if (connect(iscsi->fd, (struct sockaddr *)&s, socksize) != 0 && errno != EINPROGRESS) {
+ if (connect(iscsi->fd, &s.sa, socksize) != 0 && errno != EINPROGRESS) {
printf("Connect failed errno : %s (%d)\n", strerror(errno), errno);
return -7;
- }
+ }
return 0;
-}
+}
int iscsi_disconnect(struct iscsi_context *iscsi)
{
if (iscsi->is_connected == 0) {
events |= POLLOUT;
- }
+ }
if (iscsi->outqueue) {
events |= POLLOUT;
--- /dev/null
+#include <ccan/iscsi/iscsi.h>
+#include <ccan/iscsi/discovery.c>
+#include <ccan/iscsi/socket.c>
+#include <ccan/iscsi/init.c>
+#include <ccan/iscsi/pdu.c>
+#include <ccan/iscsi/scsi-lowlevel.c>
+#include <ccan/iscsi/nop.c>
+#include <ccan/iscsi/login.c>
+#include <ccan/iscsi/scsi-command.c>
+#include <ccan/tap/tap.h>
+
+int main(void)
+{
+ struct iscsi_context *iscsi;
+
+ plan_tests(2);
+
+ iscsi = iscsi_create_context("some name");
+ ok1(iscsi);
+ ok1(iscsi_destroy_context(iscsi) == 0);
+
+ /* This exits depending on whether all tests passed */
+ return exit_status();
+}