lintian doesn't like orphan packages with uploaders...
[debian/amanda] / device-src / null-device.c
index eefa4acd1c84f9c6cf379b5c6758acf51c2cf240..0814dfbcc2b58151ef20b6855ec89290849408bf 100644 (file)
@@ -1,21 +1,22 @@
 /*
- * Copyright (c) 2005-2008 Zmanda Inc.  All Rights Reserved.
- * 
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License version 2.1 as 
- * published by the Free Software Foundation.
- * 
- * This library is distributed in the hope that it will be useful, but
+ * 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
+ * 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
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
- * License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA.
- * 
- * Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300
- * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
+ * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
  */
 
 #include "amanda.h"
@@ -50,7 +51,6 @@ struct _NullDevice {
 typedef struct _NullDeviceClass NullDeviceClass;
 struct _NullDeviceClass {
     DeviceClass __parent__;
-    gboolean in_file;
 };
 
 void null_device_register(void);
@@ -82,7 +82,7 @@ static GType
 null_device_get_type (void)
 {
     static GType type = 0;
-    
+
     if G_UNLIKELY(type == 0) {
         static const GTypeInfo info = {
             sizeof (NullDeviceClass),
@@ -96,7 +96,7 @@ null_device_get_type (void)
             (GInstanceInitFunc) null_device_init,
             NULL
         };
-        
+
         type = g_type_register_static (TYPE_DEVICE, "NullDevice", &info,
                                        (GTypeFlags)0);
     }
@@ -104,7 +104,7 @@ null_device_get_type (void)
     return type;
 }
 
-static void 
+static void
 null_device_init (NullDevice * self)
 {
     Device * dself;
@@ -138,6 +138,18 @@ null_device_init (NullDevice * self)
            &response, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DETECTED);
     g_value_unset(&response);
 
+    g_value_init(&response, G_TYPE_BOOLEAN);
+    g_value_set_boolean(&response, FALSE);
+    device_set_simple_property(dself, PROPERTY_FULL_DELETION,
+           &response, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DETECTED);
+    g_value_unset(&response);
+
+    g_value_init(&response, G_TYPE_BOOLEAN);
+    g_value_set_boolean(&response, FALSE);
+    device_set_simple_property(dself, PROPERTY_LEOM,
+           &response, PROPERTY_SURETY_GOOD, PROPERTY_SOURCE_DETECTED);
+    g_value_unset(&response);
+
     /* this device's canonical name is always "null:", regardless of
      * the name the user supplies; note that we install the simple
      * getter in null_device_class_init. */
@@ -154,7 +166,7 @@ null_device_init (NullDevice * self)
     g_value_unset(&response);
 }
 
-static void 
+static void
 null_device_class_init (NullDeviceClass * c)
 {
     DeviceClass *device_class = (DeviceClass *)c;
@@ -199,7 +211,7 @@ null_device_read_label(Device * dself) {
 
     device_set_error(dself,
        stralloc(_("Can't open NULL device for reading or appending.")),
-       DEVICE_STATUS_DEVICE_ERROR);
+       DEVICE_STATUS_VOLUME_UNLABELED | DEVICE_STATUS_VOLUME_ERROR);
     return FALSE;
 }
 
@@ -225,16 +237,19 @@ null_device_start (Device * pself, DeviceAccessMode mode,
     if (device_in_error(self)) return FALSE;
 
     pself->access_mode = mode;
+    g_mutex_lock(pself->device_mutex);
     pself->in_file = FALSE;
+    g_mutex_unlock(pself->device_mutex);
 
     if (mode == ACCESS_WRITE) {
         pself->volume_label = newstralloc(pself->volume_label, label);
         pself->volume_time = newstralloc(pself->volume_time, timestamp);
+       pself->header_block_size = 32768;
        return TRUE;
     } else {
        device_set_error(pself,
            stralloc(_("Can't open NULL device for reading or appending.")),
-           DEVICE_STATUS_DEVICE_ERROR);
+           DEVICE_STATUS_VOLUME_UNLABELED | DEVICE_STATUS_VOLUME_ERROR);
         return FALSE;
     }
 }
@@ -242,9 +257,10 @@ null_device_start (Device * pself, DeviceAccessMode mode,
 /* This default implementation does very little. */
 static gboolean
 null_device_finish (Device * pself) {
+    pself->access_mode = ACCESS_NULL;
+
     if (device_in_error(pself)) return FALSE;
 
-    pself->access_mode = ACCESS_NULL;
     return TRUE;
 }
 
@@ -252,7 +268,10 @@ static gboolean
 null_device_start_file(Device * d_self,
                    dumpfile_t * jobInfo G_GNUC_UNUSED)
 {
+    g_mutex_lock(d_self->device_mutex);
     d_self->in_file = TRUE;
+    g_mutex_unlock(d_self->device_mutex);
+    d_self->is_eom = FALSE;
     d_self->block = 0;
     if (d_self->file <= 0)
         d_self->file = 1;
@@ -279,6 +298,8 @@ static gboolean
 null_device_finish_file(Device * pself) {
     if (device_in_error(pself)) return FALSE;
 
+    g_mutex_lock(pself->device_mutex);
     pself->in_file = FALSE;
+    g_mutex_unlock(pself->device_mutex);
     return TRUE;
 }