X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fstored%2Fansi_label.c;h=a6bacf547c34c87e104d1448b9b8c18da341932c;hb=0d99c317e0ac4a98ccbe01ac960e4d0c35184eb9;hp=c87f2d484fe064272fcfef845bfe505dbbdd09dd;hpb=8f6aa55a5cdbde1cde8eead45135e489f6838d01;p=bacula%2Fbacula diff --git a/bacula/src/stored/ansi_label.c b/bacula/src/stored/ansi_label.c index c87f2d484f..a6bacf547c 100644 --- a/bacula/src/stored/ansi_label.c +++ b/bacula/src/stored/ansi_label.c @@ -1,3 +1,30 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2005-2007 Free Software Foundation Europe e.V. + + The main author of Bacula is Kern Sibbald, with contributions from + many others, a complete list can be found in the file AUTHORS. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + 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 + 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., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of Kern Sibbald. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ /* * * ansi_label.c routines to handle ANSI (and perhaps one day IBM) @@ -9,20 +36,6 @@ * * Version $Id$ */ -/* - Copyright (C) 2005 Kern Sibbald - - 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 ammended with additional clauses defined in the - file LICENSE in the main source directory. - - 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 - the file LICENSE for additional details. - - */ #include "bacula.h" /* pull in global headers */ #include "stored.h" /* pull in Storage Deamon headers */ @@ -52,7 +65,7 @@ static bool same_label_names(char *bacula_name, char *ansi_name); */ int read_ansi_ibm_label(DCR *dcr) { - DEVICE *dev = dcr->dev; + DEVICE * volatile dev = dcr->dev; JCR *jcr = dcr->jcr; char label[80]; /* tape label */ int stat, i; @@ -74,14 +87,14 @@ int read_ansi_ibm_label(DCR *dcr) /* Read a maximum of 5 records VOL1, HDR1, ... HDR4 */ for (i=0; i < 6; i++) { do { - stat = read(dev->fd, label, sizeof(label)); + stat = dev->read(label, sizeof(label)); } while (stat == -1 && errno == EINTR); if (stat < 0) { berrno be; - clrerror_dev(dev, -1); - Dmsg1(100, "Read device got: ERR=%s\n", be.strerror()); + dev->clrerror(-1); + Dmsg1(100, "Read device got: ERR=%s\n", be.bstrerror()); Mmsg2(jcr->errmsg, _("Read error on device %s in ANSI label. ERR=%s\n"), - dev->dev_name, be.strerror()); + dev->dev_name, be.bstrerror()); Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg); dev->VolCatInfo.VolCatErrors++; return VOL_IO_ERROR; @@ -102,12 +115,15 @@ int read_ansi_ibm_label(DCR *dcr) if (strncmp("VOL1", label, 4) == 0) { ok = true; dev->label_type = B_ANSI_LABEL; + Dmsg0(100, "Got ANSI VOL1 label\n"); } else { /* Try EBCDIC */ ebcdic_to_ascii(label, label, sizeof(label)); if (strncmp("VOL1", label, 4) == 0) { ok = true;; dev->label_type = B_IBM_LABEL; + Dmsg0(100, "Found IBM label.\n"); + Dmsg0(100, "Got IBM VOL1 label\n"); } } } @@ -122,14 +138,20 @@ int read_ansi_ibm_label(DCR *dcr) if (VolName && *VolName && *VolName != '*') { if (!same_label_names(VolName, &label[4])) { char *p = &label[4]; - char *q = dev->VolHdr.VolumeName; + char *q; + + free_volume(dev); + /* Store new Volume name */ + q = dev->VolHdr.VolumeName; for (int i=0; *p != ' ' && i < 6; i++) { *q++ = *p++; } *q = 0; - new_volume(dev->VolHdr.VolumeName, dev); + Dmsg0(100, "Call reserve_volume\n"); + reserve_volume(dcr, dev->VolHdr.VolumeName); + dev = dcr->dev; /* may have changed in reserve_volume */ Dmsg2(100, "Wanted ANSI Vol %s got %6s\n", VolName, dev->VolHdr.VolumeName); - Mmsg2(jcr->errmsg, "Wanted ANSI Volume \"%s\" got \"%s\"\n", VolName, dev->VolHdr.VolumeName); + Mmsg2(jcr->errmsg, _("Wanted ANSI Volume \"%s\" got \"%s\"\n"), VolName, dev->VolHdr.VolumeName); return VOL_NAME_ERROR; } } @@ -150,6 +172,7 @@ int read_ansi_ibm_label(DCR *dcr) dev->VolHdr.VolumeName); return VOL_NAME_ERROR; /* Not a Bacula label */ } + Dmsg0(100, "Got HDR1 label\n"); break; case 2: if (dev->label_type == B_IBM_LABEL) { @@ -160,6 +183,7 @@ int read_ansi_ibm_label(DCR *dcr) Mmsg0(jcr->errmsg, _("No HDR2 label while reading ANSI/IBM label.\n")); return VOL_LABEL_ERROR; } + Dmsg0(100, "Got ANSI HDR2 label\n"); break; default: if (stat == 0) { @@ -174,6 +198,7 @@ int read_ansi_ibm_label(DCR *dcr) Mmsg0(jcr->errmsg, _("Unknown or bad ANSI/IBM label record.\n")); return VOL_LABEL_ERROR; } + Dmsg0(100, "Got HDR label\n"); break; } } @@ -291,11 +316,11 @@ bool write_ansi_ibm_labels(DCR *dcr, int type, const char *VolName) } else { label[79] = '3'; /* ANSI label flag */ } - stat = write(dev->fd, label, sizeof(label)); + stat = dev->write(label, sizeof(label)); if (stat != sizeof(label)) { berrno be; Jmsg1(jcr, M_FATAL, 0, _("Could not write ANSI VOL1 label. ERR=%s\n"), - be.strerror()); + be.bstrerror()); return false; } } @@ -318,15 +343,30 @@ bool write_ansi_ibm_labels(DCR *dcr, int type, const char *VolName) if (label_type == B_IBM_LABEL) { ascii_to_ebcdic(label, label, sizeof(label)); } - stat = write(dev->fd, label, sizeof(label)); + + /* + * This could come at the end of a tape, ignore + * EOT errors. + */ + stat = dev->write(label, sizeof(label)); if (stat != sizeof(label)) { berrno be; - Jmsg1(jcr, M_FATAL, 0, _("Could not write ANSI HDR1 label. ERR=%s\n"), - be.strerror()); - return false; + if (stat == -1) { + dev->clrerror(-1); + if (dev->dev_errno == 0) { + dev->dev_errno = ENOSPC; /* out of space */ + } + if (dev->dev_errno != ENOSPC) { + Jmsg1(jcr, M_FATAL, 0, _("Could not write ANSI HDR1 label. ERR=%s\n"), + be.bstrerror()); + return false; + } + } else { + Jmsg(jcr, M_FATAL, 0, _("Could not write ANSI HDR1 label.\n")); + return false; + } } - /* Now construct HDR2 label */ memset(label, ' ', sizeof(label)); ser_begin(label, sizeof(label)); @@ -337,14 +377,27 @@ bool write_ansi_ibm_labels(DCR *dcr, int type, const char *VolName) label[4] = 'V'; ascii_to_ebcdic(label, label, sizeof(label)); } - stat = write(dev->fd, label, sizeof(label)); + stat = dev->write(label, sizeof(label)); if (stat != sizeof(label)) { berrno be; - Jmsg1(jcr, M_FATAL, 0, _("Could not write ANSI HDR1 label. ERR=%s\n"), - be.strerror()); - return false; + if (stat == -1) { + dev->clrerror(-1); + if (dev->dev_errno == 0) { + dev->dev_errno = ENOSPC; /* out of space */ + } + if (dev->dev_errno != ENOSPC) { + Jmsg1(jcr, M_FATAL, 0, _("Could not write ANSI HDR1 label. ERR=%s\n"), + be.bstrerror()); + return false; + } + dev->weof(1); + return true; + } else { + Jmsg(jcr, M_FATAL, 0, _("Could not write ANSI HDR1 label.\n")); + return false; + } } - if (weof_dev(dev, 1) < 0) { + if (!dev->weof(1)) { Jmsg(jcr, M_FATAL, 0, _("Error writing EOF to tape. ERR=%s"), dev->errmsg); return false; }