X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=device-src%2Fvfs-device.c;h=5733995ad83fff71dae3ed45eb5d5e09d410b606;hb=0ecda6e9f4e039d4bc029845970235020ddcc111;hp=4906c29a02db60c2da0796170f78309ff89b4f8a;hpb=cd0b924f27312d57bd42f6c4fae2b795139e2d0b;p=debian%2Famanda diff --git a/device-src/vfs-device.c b/device-src/vfs-device.c index 4906c29..5733995 100644 --- a/device-src/vfs-device.c +++ b/device-src/vfs-device.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2008, 2009, 2010, 2011 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 @@ -585,11 +585,9 @@ vfs_device_open_device (Device * pself, char * device_name, char * device_type, static gboolean delete_vfs_files_functor(const char * filename, gpointer user_data) { VfsDevice * self; - Device * d_self; char * path_name; self = VFS_DEVICE(user_data); - d_self = DEVICE(self); /* Skip the volume lock. */ if (strcmp(filename, VOLUME_LOCKFILE_NAME) == 0) @@ -691,6 +689,7 @@ static gboolean clear_and_prepare_label(VfsDevice * self, char * label, return FALSE; } dumpfile_free(d_self->volume_header); + d_self->header_block_size = VFS_DEVICE_LABEL_SIZE; d_self->volume_header = label_header; self->volume_bytes = VFS_DEVICE_LABEL_SIZE; return TRUE; @@ -796,9 +795,10 @@ static gboolean vfs_device_write_block(Device * pself, guint size, gpointer data pself->is_eom = TRUE; if (check_at_peom(self, size)) { + /* check_at_peom() only checks against MAX_VOLUME_USAGE limit */ pself->is_eom = TRUE; device_set_error(pself, - stralloc(_("No space left on device")), + stralloc(_("No space left on device: more than MAX_VOLUME_USAGE bytes written")), DEVICE_STATUS_VOLUME_ERROR); return FALSE; } @@ -812,6 +812,9 @@ static gboolean vfs_device_write_block(Device * pself, guint size, gpointer data self->volume_bytes += size; self->checked_bytes_used += size; pself->block ++; + g_mutex_lock(pself->device_mutex); + pself->bytes_written += size; + g_mutex_unlock(pself->device_mutex); return TRUE; } @@ -838,11 +841,16 @@ vfs_device_read_block(Device * pself, gpointer data, int * size_req) { switch (result) { case RESULT_SUCCESS: *size_req = size; + g_mutex_lock(pself->device_mutex); + pself->bytes_read += size; + g_mutex_unlock(pself->device_mutex); pself->block++; return size; 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); @@ -868,7 +876,9 @@ vfs_device_start(Device * dself, return FALSE; } + g_mutex_lock(dself->device_mutex); dself->in_file = FALSE; + g_mutex_unlock(dself->device_mutex); if (mode == ACCESS_WRITE) { promote_volume_lock(self); @@ -908,7 +918,9 @@ vfs_device_finish (Device * pself) { release_file(self); pself->access_mode = ACCESS_NULL; + g_mutex_lock(pself->device_mutex); pself->in_file = FALSE; + g_mutex_unlock(pself->device_mutex); if (device_in_error(self)) return FALSE; @@ -1060,9 +1072,10 @@ vfs_device_start_file (Device * dself, dumpfile_t * ji) { dself->is_eom = TRUE; if (check_at_peom(self, VFS_DEVICE_LABEL_SIZE)) { + /* check_at_peom() only checks against MAX_VOLUME_USAGE limit */ dself->is_eom = TRUE; device_set_error(dself, - stralloc(_("No space left on device")), + stralloc(_("No space left on device: more than MAX_VOLUME_USAGE bytes written")), DEVICE_STATUS_DEVICE_ERROR); return FALSE; } @@ -1103,8 +1116,11 @@ vfs_device_start_file (Device * dself, dumpfile_t * ji) { /* handle some accounting business */ self->volume_bytes += VFS_DEVICE_LABEL_SIZE; self->checked_bytes_used += VFS_DEVICE_LABEL_SIZE; - dself->in_file = TRUE; dself->block = 0; + g_mutex_lock(dself->device_mutex); + dself->in_file = TRUE; + dself->bytes_written = 0; + g_mutex_unlock(dself->device_mutex); /* make_new_file_name set pself->file for us */ return TRUE; @@ -1118,7 +1134,9 @@ vfs_device_finish_file(Device * dself) { release_file(self); + g_mutex_lock(dself->device_mutex); dself->in_file = FALSE; + g_mutex_unlock(dself->device_mutex); return TRUE; } @@ -1138,9 +1156,12 @@ vfs_device_seek_file (Device * dself, guint requested_file) { if (device_in_error(self)) return NULL; - dself->in_file = FALSE; dself->is_eof = FALSE; dself->block = 0; + g_mutex_lock(dself->device_mutex); + dself->in_file = FALSE; + dself->bytes_read = 0; + g_mutex_unlock(dself->device_mutex); release_file(self); @@ -1230,7 +1251,12 @@ vfs_device_seek_file (Device * dself, guint requested_file) { } /* update our state */ + if (requested_file == 0) { + dself->header_block_size = header_buffer_size; + } + g_mutex_lock(dself->device_mutex); dself->in_file = TRUE; + g_mutex_unlock(dself->device_mutex); dself->file = file; return rval; @@ -1404,6 +1430,11 @@ vfs_device_erase (Device * dself) { release_file(self); + dumpfile_free(dself->volume_header); + dself->volume_header = NULL; + device_set_error(dself, g_strdup("Unlabeled volume"), + DEVICE_STATUS_VOLUME_UNLABELED); + return TRUE; }