lintian doesn't like orphan packages with uploaders...
[debian/amanda] / device-src / tape-device.c
index c6b88ced0a30549b4e10b4d042492975eb5d85d9..d8139dddc8a0ad2a80c7b2ca3d1cc8a18f464b13 100644 (file)
@@ -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
@@ -578,6 +579,9 @@ tape_device_set_compression_fn(Device *p_self, DevicePropertyBase *base,
        /* looks good .. let's start the device over, though */
        device_clear_volume_details(p_self);
     } else {
+       device_set_error(p_self,
+           g_strdup("Error setting COMPRESION property"),
+           DEVICE_STATUS_DEVICE_ERROR);
        return FALSE;
     }
 
@@ -602,8 +606,12 @@ tape_device_set_read_block_size_fn(Device *p_self, DevicePropertyBase *base G_GN
 
     if (read_block_size != 0 &&
            ((gsize)read_block_size < p_self->block_size ||
-            (gsize)read_block_size > p_self->max_block_size))
+            (gsize)read_block_size > p_self->max_block_size)) {
+       device_set_error(p_self,
+           g_strdup_printf("Error setting READ-BLOCk-SIZE property to '%u', it must be between %zu and %zu", read_block_size, p_self->block_size, p_self->max_block_size),
+           DEVICE_STATUS_DEVICE_ERROR);
        return FALSE;
+    }
 
     self->private->read_block_size = read_block_size;
 
@@ -919,6 +927,7 @@ static DeviceStatusFlags tape_device_read_label(Device * dself) {
        return dself->status;
     }
 
+    dself->header_block_size = buffer_len;
     header = dself->volume_header = g_new(dumpfile_t, 1);
     fh_init(header);
 
@@ -988,6 +997,9 @@ tape_device_write_block(Device * pself, guint size, gpointer data) {
     }
 
     pself->block++;
+    g_mutex_lock(pself->device_mutex);
+    pself->bytes_written += size;
+    g_mutex_unlock(pself->device_mutex);
 
     return TRUE;
 }
@@ -1018,6 +1030,9 @@ static int tape_device_read_block (Device * pself, gpointer buf,
     case RESULT_SUCCESS:
         *size_req = size;
         pself->block++;
+       g_mutex_lock(pself->device_mutex);
+       pself->bytes_read += size;
+       g_mutex_unlock(pself->device_mutex);
         return size;
     case RESULT_SMALL_BUFFER: {
         gsize new_size;
@@ -1052,7 +1067,9 @@ static int tape_device_read_block (Device * pself, gpointer buf,
     }
     case RESULT_NO_DATA:
         pself->is_eof = TRUE;
+       g_mutex_lock(pself->device_mutex);
        pself->in_file = FALSE;
+       g_mutex_unlock(pself->device_mutex);
        device_set_error(pself,
            stralloc(_("EOF")),
            DEVICE_STATUS_SUCCESS);
@@ -1111,6 +1128,7 @@ static gboolean write_tapestart_header(TapeDevice * self, char * label,
        return FALSE;
      }
 
+     d_self->header_block_size = d_self->block_size;
      amfree(header_buf);
 
      if (!tape_weof(self->fd, 1)) {
@@ -1152,7 +1170,9 @@ tape_device_start (Device * d_self, DeviceAccessMode mode, char * label,
     }
 
     d_self->access_mode = mode;
+    g_mutex_lock(d_self->device_mutex);
     d_self->in_file = FALSE;
+    g_mutex_unlock(d_self->device_mutex);
 
     if (IS_WRITABLE_ACCESS_MODE(mode)) {
         if (self->write_open_errno != 0) {
@@ -1264,10 +1284,13 @@ static gboolean tape_device_start_file(Device * d_self,
     amfree(amanda_header);
 
     /* arrange the file numbers correctly */
-    d_self->in_file = TRUE;
     d_self->block = 0;
     if (d_self->file >= 0)
         d_self->file ++;
+    g_mutex_lock(d_self->device_mutex);
+    d_self->in_file = TRUE;
+    d_self->bytes_written = 0;
+    g_mutex_unlock(d_self->device_mutex);
     return TRUE;
 }
 
@@ -1287,7 +1310,9 @@ tape_device_finish_file (Device * d_self) {
         return FALSE;
     }
 
+    g_mutex_lock(d_self->device_mutex);
     d_self->in_file = FALSE;
+    g_mutex_unlock(d_self->device_mutex);
     return TRUE;
 }
 
@@ -1315,9 +1340,12 @@ tape_device_seek_file (Device * d_self, guint file) {
         difference --;
     }
 
-    d_self->in_file = FALSE;
     d_self->is_eof = FALSE;
     d_self->block = 0;
+    g_mutex_lock(d_self->device_mutex);
+    d_self->in_file = FALSE;
+    d_self->bytes_read = 0;
+    g_mutex_unlock(d_self->device_mutex);
 
 reseek:
     if (difference > 0) {
@@ -1444,7 +1472,9 @@ reseek:
         return NULL;
     }
 
+    g_mutex_lock(d_self->device_mutex);
     d_self->in_file = TRUE;
+    g_mutex_unlock(d_self->device_mutex);
     d_self->file = file;
 
     return rval;
@@ -1538,9 +1568,14 @@ tape_device_finish (Device * d_self) {
     }
 
     /* Polish off this file, if relevant. */
+    g_mutex_lock(d_self->device_mutex);
     if (d_self->in_file && IS_WRITABLE_ACCESS_MODE(d_self->access_mode)) {
-        if (!device_finish_file(d_self))
+       g_mutex_unlock(d_self->device_mutex);
+        if (!device_finish_file(d_self)) {
            goto finish_error;
+       }
+    } else {
+       g_mutex_unlock(d_self->device_mutex);
     }
 
     /* Straighten out the filemarks.  We already wrote one in finish_file, and