2 * Copyright (c) 2009-2012 Zmanda, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
21 %module "Amanda::NDMP"
22 %include "amglue/amglue.swg"
23 %include "exception.i"
25 %include "Amanda/NDMP.pod"
28 #include "ndmpconnobj.h"
29 #include "glib-util.h"
32 /* initialize glib, and in particular GType */
37 /* supporting typemaps */
39 /* treat all enums in this file as regular UV's - no need for BigInt */
41 typedef guint ndmp_enum;
44 /* Any enumeration, input */
45 %typemap(in) ndmp_enum "$1 = SvIV($input);";
47 /* Any enumeration, output argument */
48 %typemap(in,numinputs=0) ndmp_enum * (int temp) "$1 = &temp; temp = 0;";
49 %typemap(argout) ndmp_enum * {
54 $result = sv_newmortal();
55 sv_setuv($result, (UV)(*$1));
59 /* gsize, output argument */
60 %typemap(in,numinputs=0) gsize * (gsize temp) "$1 = &temp; temp = 0;"
61 %typemap(argout) gsize * {
67 $result = sv_2mortal(amglue_newSVu64(*$1));
71 /* guint64, output argument */
72 %typemap(in,numinputs=0) guint64 * (guint64 temp) "$1 = &temp; temp = 0;"
73 %typemap(argout) guint64 * {
79 $result = sv_2mortal(amglue_newSVu64(*$1));
83 /* guint, output argument */
84 %typemap(in,numinputs=0) guint * (guint temp) "$1 = &temp; temp = 0;"
85 %typemap(argout) guint * {
91 $result = sv_2mortal(amglue_newSVu64(*$1));
95 typedef struct NDMPConnection {
105 return ndmp_connection_new(
106 hostname, port, username, password, auth);
110 g_object_unref(self);
117 return ndmp_connection_err_code(self);
123 return ndmp_connection_err_msg(self);
127 set_verbose(gboolean verbose) {
128 ndmp_connection_set_verbose(self, verbose);
134 scsi_open(gchar *device) {
135 return ndmp_connection_scsi_open(
142 return ndmp_connection_scsi_close(self);
145 /* NOTE: this method is wrapped with a more perlish interface; see below */
148 %typemap(in) (gpointer cdb, gsize cdb_len) {
150 int alloc = SWIG_OLDOBJ;
151 SWIG_AsCharPtrAndSize($input, (char **)&$1, &$2, &alloc);
152 if ($2) $2--; /* strip trailing NUL byte */
155 /* handle dataout and its response */
156 %typemap(in,numinputs=1)
157 (gpointer dataout, gsize dataout_len, gsize *actual_dataout_len)
158 (gsize dataout_len) {
161 /* handle the actual input here */
162 int alloc = SWIG_OLDOBJ;
163 SWIG_AsCharPtrAndSize($input, (char **)&$1, &$2, &alloc);
164 if ($2) $2--; /* strip trailing NUL byte */
165 /* set up for argout typemap, below */
170 (gpointer dataout, gsize dataout_len, gsize *actual_dataout_len) {
171 if (argvi >= items) {
175 SP += argvi; PUTBACK;
176 $result = sv_2mortal(amglue_newSVu64(*$3));
177 SP -= argvi; argvi++;
180 /* handle datain and its response */
181 %typemap(in,numinputs=1)
182 (gpointer datain, gsize datain_max_len, gsize *actual_datain_len)
183 (gpointer datain_buf, gsize actual_datain_len) {
185 gsize max_size = amglue_SvU64($input);
188 $1 = g_malloc(max_size);
192 actual_datain_len = 0;
193 $3 = &actual_datain_len;
196 (gpointer datain, gsize datain_max_len, gsize *actual_datain_len) {
197 if (argvi >= items) {
201 /* convert the value, even if it's NULL */
202 $result = SWIG_FromCharPtrAndSize($1, *$3);
208 %typemap(in,numinputs=0) (guint8 *status) (guint8 temp) "$1 = &temp;";
209 %typemap(argout) (guint8 *status) {
210 if (argvi >= items) {
214 $result = sv_newmortal();
215 sv_setuv($result, (UV)(*$1));
219 /* handle ext_status */
220 %typemap(in,numinputs=0)
221 (gpointer ext_sense, gsize ext_sense_max_len, gsize *actual_ext_sense_len)
222 (guint8 ext_sense_buf[128], gsize actual_ext_sense_len) {
224 $2 = sizeof(ext_sense_buf); /* always allocate 128 bytes for sense */
225 actual_ext_sense_len = 0;
226 $3 = &actual_ext_sense_len;
229 (gpointer ext_sense, gsize ext_sense_max_len, gsize *actual_ext_sense_len) {
230 if (argvi >= items) {
234 $result = SWIG_FromCharPtrAndSize($1, *$3);
246 gsize *actual_dataout_len,
248 gsize datain_max_len,
249 gsize *actual_datain_len,
252 gsize ext_sense_max_len,
253 gsize *actual_ext_sense_len
255 return ndmp_connection_scsi_execute_cdb(
278 return ndmp_connection_tape_open(
286 return ndmp_connection_tape_close(self);
294 return ndmp_connection_tape_mtio(
301 %typemap(in) (gpointer buf, guint64 len) {
302 int alloc = SWIG_OLDOBJ;
303 size_t len_tmp; /* use a temporary with the right type */
304 SWIG_AsCharPtrAndSize($input, (char **)&$1, &len_tmp, &alloc);
305 if (len_tmp) len_tmp--; /* strip trailing NUL byte */
313 return ndmp_connection_tape_write(
320 %typemap(in,numinputs=1)
321 (gpointer buf, guint64 count, guint64 *out_count)
322 (guint64 out_count) {
323 $2 = amglue_SvU64($input);
324 $1 = $2?g_malloc($2):NULL;
329 (gpointer buf, guint64 count, guint64 *out_count) {
330 if (argvi >= items) {
334 /* convert the value, even if it's NULL */
335 $result = SWIG_FromCharPtrAndSize($1, *$3);
343 guint64 *out_count) {
344 return ndmp_connection_tape_read(
356 return ndmp_connection_tape_get_state(
363 /* mover interface is not yet SWIGged */
367 /* perlish wrappers */
369 package Amanda::NDMP::NDMPConnection;
371 sub scsi_execute_cdb {
375 die "no 'flags' parameter'" unless defined $params{'flags'};
376 die "no 'timeout' parameter'" unless defined $params{'timeout'};
377 die "no 'cdb' parameter'" unless defined $params{'cdb'};
378 if ($params{'flags'} & $Amanda::NDMP::NDMP9_SCSI_DATA_DIR_IN) {
379 die "no 'datain_len' parameter'" unless defined $params{'datain_len'};
381 $params{'datain_len'} = 0;
383 if ($params{'flags'} & $Amanda::NDMP::NDMP9_SCSI_DATA_DIR_OUT) {
384 die "no 'dataout' parameter'" unless defined $params{'dataout'};
386 $params{'dataout'} = undef;
389 my ($ok, $dataout_len, $datain, $status, $ext_sense) =
390 $self->scsi_execute_cdb_C(
391 $params{'flags'}, $params{'timeout'},
392 $params{'cdb'}, $params{'dataout'},
393 $params{'datain_len'});
395 return 0 unless ($ok);
399 ext_sense => $ext_sense);
400 if ($params{'flags'} & $Amanda::NDMP::NDMP9_SCSI_DATA_DIR_IN) {
401 $result{'datain'} = $datain;
403 if ($params{'flags'} & $Amanda::NDMP::NDMP9_SCSI_DATA_DIR_OUT) {
404 $result{'dataout_len'} = $dataout_len;
409 package Amanda::NDMP;
412 /* selected NDMP constants; note that the "NDMP9_" prfix is required */
414 amglue_add_flag_tag_fns(scsi_data_dir);
415 amglue_add_constant_short(NDMP9_SCSI_DATA_DIR_NONE, "NDMP9_SCSI_DATA_DIR_NONE", scsi_data_dir);
416 amglue_add_constant_short(NDMP9_SCSI_DATA_DIR_IN, "NDMP9_SCSI_DATA_DIR_IN", scsi_data_dir);
417 amglue_add_constant_short(NDMP9_SCSI_DATA_DIR_OUT, "NDMP9_SCSI_DATA_DIR_OUT", scsi_data_dir);
418 amglue_copy_to_tag(scsi_data_dir, constants);
420 amglue_add_flag_tag_fns(tape_open_mode);
421 amglue_add_constant_short(NDMP9_TAPE_READ_MODE, "NDMP9_TAPE_READ_MODE", tape_open_mode);
422 amglue_add_constant_short(NDMP9_TAPE_RDWR_MODE, "NDMP9_TAPE_RDRW_MODE", tape_open_mode);
423 amglue_add_constant_short(NDMP9_TAPE_RAW_MODE, "NDMP9_TAPE_RAW_MODE", tape_open_mode);
424 amglue_copy_to_tag(tape_open_mode, constants);
426 amglue_add_flag_tag_fns(tape_mtio_op);
427 amglue_add_constant_short(NDMP9_MTIO_FSF, "NDMP9_MTIO_FSF", tape_mtio_op);
428 amglue_add_constant_short(NDMP9_MTIO_BSF, "NDMP9_MTIO_BSF", tape_mtio_op);
429 amglue_add_constant_short(NDMP9_MTIO_FSR, "NDMP9_MTIO_FSR", tape_mtio_op);
430 amglue_add_constant_short(NDMP9_MTIO_BSR, "NDMP9_MTIO_BSR", tape_mtio_op);
431 amglue_add_constant_short(NDMP9_MTIO_REW, "NDMP9_MTIO_REW", tape_mtio_op);
432 amglue_add_constant_short(NDMP9_MTIO_EOF, "NDMP9_MTIO_EOF", tape_mtio_op);
433 amglue_add_constant_short(NDMP9_MTIO_OFF, "NDMP9_MTIO_OFF", tape_mtio_op);
434 amglue_copy_to_tag(tape_mtio_op, constants);
436 amglue_add_flag_tag_fns(mover_mode);
437 amglue_add_constant_short(NDMP9_MOVER_MODE_READ, "NDMP9_MOVER_MODE_READ", mover_mode);
438 amglue_add_constant_short(NDMP9_MOVER_MODE_WRITE, "NDMP9_MOVER_MODE_WRITE", mover_mode);
439 amglue_copy_to_tag(mover_mode, constants);
441 amglue_add_flag_tag_fns(addr_type);
442 amglue_add_constant_short(NDMP9_ADDR_LOCAL, "NDMP9_ADDR_LOCAL", addr_type);
443 amglue_add_constant_short(NDMP9_ADDR_TCP, "NDMP9_ADDR_TCP", addr_type);
444 amglue_add_constant_short(NDMP9_ADDR_AS_CONNECTED, "NDMP9_ADDR_AS_CONNECTED", addr_type);
445 amglue_copy_to_tag(addr_type, constants);
447 amglue_add_flag_tag_fns(mover_state);
448 amglue_add_constant_short(NDMP9_MOVER_STATE_IDLE, "NDMP9_MOVER_STATE_IDLE", mover_state);
449 amglue_add_constant_short(NDMP9_MOVER_STATE_LISTEN, "NDMP9_MOVER_STATE_LISTEN", mover_state);
450 amglue_add_constant_short(NDMP9_MOVER_STATE_ACTIVE, "NDMP9_MOVER_STATE_ACTIVE", mover_state);
451 amglue_add_constant_short(NDMP9_MOVER_STATE_PAUSED, "NDMP9_MOVER_STATE_PAUSED", mover_state);
452 amglue_add_constant_short(NDMP9_MOVER_STATE_HALTED, "NDMP9_MOVER_STATE_HALTED", mover_state);
453 amglue_add_constant_short(NDMP9_MOVER_STATE_STANDBY, "NDMP9_MOVER_STATE_STANDBY", mover_state);
454 amglue_copy_to_tag(mover_state, constants);
456 amglue_add_flag_tag_fns(data_halt_reason);
457 amglue_add_constant_short(NDMP9_DATA_HALT_NA, "NDMP9_DATA_HALT_NA", data_halt_reason);
458 amglue_add_constant_short(NDMP9_DATA_HALT_SUCCESSFUL, "NDMP9_DATA_HALT_SUCCESSFUL", data_halt_reason);
459 amglue_add_constant_short(NDMP9_DATA_HALT_ABORTED, "NDMP9_DATA_HALT_ABORTED", data_halt_reason);
460 amglue_add_constant_short(NDMP9_DATA_HALT_INTERNAL_ERROR, "NDMP9_DATA_HALT_INTERNAL_ERROR", data_halt_reason);
461 amglue_add_constant_short(NDMP9_DATA_HALT_CONNECT_ERROR, "NDMP9_DATA_HALT_CONNECT_ERROR", data_halt_reason);
462 amglue_copy_to_tag(data_halt_reason, constants);
464 amglue_add_flag_tag_fns(mover_halt_reason);
465 amglue_add_constant_short(NDMP9_MOVER_HALT_NA, "NDMP9_MOVER_HALT_NA", mover_halt_reason);
466 amglue_add_constant_short(NDMP9_MOVER_HALT_CONNECT_CLOSED, "NDMP9_MOVER_HALT_CONNECT_CLOSED", mover_halt_reason);
467 amglue_add_constant_short(NDMP9_MOVER_HALT_ABORTED, "NDMP9_MOVER_HALT_ABORTED", mover_halt_reason);
468 amglue_add_constant_short(NDMP9_MOVER_HALT_INTERNAL_ERROR, "NDMP9_MOVER_HALT_INTERNAL_ERROR", mover_halt_reason);
469 amglue_add_constant_short(NDMP9_MOVER_HALT_CONNECT_ERROR, "NDMP9_MOVER_HALT_CONNECT_ERROR", mover_halt_reason);
470 amglue_copy_to_tag(mover_halt_reason, constants);
472 amglue_add_flag_tag_fns(mover_pause_reason);
473 amglue_add_constant_short(NDMP9_MOVER_PAUSE_NA, "NDMP9_MOVER_PAUSE_NA", mover_pause_reason);
474 amglue_add_constant_short(NDMP9_MOVER_PAUSE_EOM, "NDMP9_MOVER_PAUSE_EOM", mover_pause_reason);
475 amglue_add_constant_short(NDMP9_MOVER_PAUSE_EOF, "NDMP9_MOVER_PAUSE_EOF", mover_pause_reason);
476 amglue_add_constant_short(NDMP9_MOVER_PAUSE_SEEK, "NDMP9_MOVER_PAUSE_SEEK", mover_pause_reason);
477 amglue_add_constant_short(NDMP9_MOVER_PAUSE_MEDIA_ERROR, "NDMP9_MOVER_PAUSE_MEDIA_ERROR", mover_pause_reason);
478 amglue_add_constant_short(NDMP9_MOVER_PAUSE_EOW, "NDMP9_MOVER_PAUSE_EOW", mover_pause_reason);
479 amglue_copy_to_tag(mover_pause_reason, constants);