X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=device-src%2Fdevice.c;h=6eed5238e43fa14f973c55ebd9b540996a90685c;hb=HEAD;hp=f0258d5d25b20cba4b4a69aa999312e21016fa82;hpb=8eb7e8e19f1373f6be7f1f7837b997748ce31d0e;p=debian%2Famanda diff --git a/device-src/device.c b/device-src/device.c index f0258d5..6eed523 100644 --- a/device-src/device.c +++ b/device-src/device.c @@ -1,9 +1,10 @@ /* - * Copyright (c) 2007, 2008, 2009, 2010 Zmanda, Inc. All Rights Reserved. + * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY @@ -526,6 +527,7 @@ device_open (char * device_name) device = factory(device_name, device_type, device_node); g_assert(device != NULL); /* factories must always return a device */ + device->device_mutex = g_mutex_new(); amfree(device_type); amfree(device_node); @@ -648,8 +650,8 @@ dumpfile_t * make_tapestart_header(Device * self, char * label, } else { self->volume_time = g_strdup(timestamp); } - strncpy(rval->datestamp, self->volume_time, sizeof(rval->datestamp)); - strncpy(rval->name, label, sizeof(rval->name)); + g_strlcpy(rval->datestamp, self->volume_time, sizeof(rval->datestamp)); + g_strlcpy(rval->name, label, sizeof(rval->name)); return rval; } @@ -661,7 +663,7 @@ dumpfile_t * make_tapeend_header(void) { rval = malloc(sizeof(*rval)); rval->type = F_TAPEEND; timestamp = get_timestamp_from_time(time(NULL)); - strncpy(rval->datestamp, timestamp, sizeof(rval->datestamp)); + g_strlcpy(rval->datestamp, timestamp, sizeof(rval->datestamp)); amfree(timestamp); return rval; } @@ -1116,6 +1118,46 @@ device_finish (Device * self) { return (klass->finish)(self); } +guint64 +device_get_bytes_read (Device * self) { + DeviceClass *klass; + guint64 bytes = 0; + + g_assert(IS_DEVICE (self)); + + g_mutex_lock(self->device_mutex); + if (self->in_file) { + klass = DEVICE_GET_CLASS(self); + if (klass->get_bytes_read) { + bytes = (klass->get_bytes_read)(self); + } else { + bytes = self->bytes_read; + } + } + g_mutex_unlock(self->device_mutex); + return bytes; +} + +guint64 +device_get_bytes_written (Device * self) { + DeviceClass *klass; + guint64 bytes = 0; + + g_assert(IS_DEVICE (self)); + + g_mutex_lock(self->device_mutex); + if (self->in_file) { + klass = DEVICE_GET_CLASS(self); + if (klass->get_bytes_written) { + bytes = (klass->get_bytes_written)(self); + } else { + bytes = self->bytes_written; + } + } + g_mutex_unlock(self->device_mutex); + return bytes; +} + gboolean device_configure (Device * self, gboolean use_global_config) { @@ -1372,53 +1414,60 @@ device_listen( } } -gboolean +int device_accept( Device *self, DirectTCPConnection **conn, - ProlongProc prolong, - gpointer prolong_data) + int *cancelled, + GMutex *abort_mutex, + GCond *abort_cond) { DeviceClass *klass; klass = DEVICE_GET_CLASS(self); if(klass->accept) { - return (klass->accept)(self, conn, prolong, prolong_data); + return (klass->accept)(self, conn, cancelled, abort_mutex, abort_cond); } else { device_set_error(self, - stralloc(_("Unimplemented method")), + g_strdup(_("Unimplemented method")), DEVICE_STATUS_DEVICE_ERROR); - return FALSE; + return 1; } } -gboolean + +int device_connect( Device *self, gboolean for_writing, DirectTCPAddr *addrs, DirectTCPConnection **conn, - ProlongProc prolong, - gpointer prolong_data) + int *cancelled, + GMutex *abort_mutex, + GCond *abort_cond) { DeviceClass *klass; klass = DEVICE_GET_CLASS(self); if(klass->connect) { - return (klass->connect)(self, for_writing, addrs, conn, prolong, prolong_data); + return (klass->connect)(self, for_writing, addrs, conn, cancelled, + abort_mutex, abort_cond); } else { device_set_error(self, - stralloc(_("Unimplemented method")), + g_strdup(_("Unimplemented method")), DEVICE_STATUS_DEVICE_ERROR); - return FALSE; + return 1; } } -gboolean +int device_write_from_connection( Device *self, guint64 size, - guint64 *actual_size) + guint64 *actual_size, + int *cancelled, + GMutex *abort_mutex, + GCond *abort_cond) { DeviceClass *klass; @@ -1428,20 +1477,25 @@ device_write_from_connection( g_assert(IS_WRITABLE_ACCESS_MODE(self->access_mode)); if(klass->write_from_connection) { - return (klass->write_from_connection)(self, size, actual_size); + return (klass->write_from_connection)(self, size, actual_size, + cancelled, + abort_mutex, abort_cond); } else { device_set_error(self, stralloc(_("Unimplemented method")), DEVICE_STATUS_DEVICE_ERROR); - return FALSE; + return 1; } } -gboolean +int device_read_to_connection( Device *self, guint64 size, - guint64 *actual_size) + guint64 *actual_size, + int *cancelled, + GMutex *abort_mutex, + GCond *abort_cond) { DeviceClass *klass; @@ -1450,12 +1504,13 @@ device_read_to_connection( klass = DEVICE_GET_CLASS(self); if(klass->read_to_connection) { - return (klass->read_to_connection)(self, size, actual_size); + return (klass->read_to_connection)(self, size, actual_size, + cancelled, abort_mutex, abort_cond); } else { device_set_error(self, stralloc(_("Unimplemented method")), DEVICE_STATUS_DEVICE_ERROR); - return FALSE; + return 1; } }