X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fstored%2Fansi_label.c;h=28fba900f77e321ece6163257208c2bf4dfaccbe;hb=65f843b332c5fd751863c6dbbc2028ca46bdf2d6;hp=e47f6645faf199840acb27bcfbcaeb92f5adf4b8;hpb=10508e4663c244cbab9ba09d7ca6ae81310b2d72;p=bacula%2Fbacula diff --git a/bacula/src/stored/ansi_label.c b/bacula/src/stored/ansi_label.c index e47f6645fa..28fba900f7 100644 --- a/bacula/src/stored/ansi_label.c +++ b/bacula/src/stored/ansi_label.c @@ -10,11 +10,11 @@ * Version $Id$ */ /* - Copyright (C) 2005 Kern Sibbald + Copyright (C) 2005-2006 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 + version 2 as amended 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, @@ -78,7 +78,7 @@ int read_ansi_ibm_label(DCR *dcr) } while (stat == -1 && errno == EINTR); if (stat < 0) { berrno be; - clrerror_dev(dev, -1); + dev->clrerror(-1); Dmsg1(100, "Read device got: ERR=%s\n", be.strerror()); Mmsg2(jcr->errmsg, _("Read error on device %s in ANSI label. ERR=%s\n"), dev->dev_name, be.strerror()); @@ -108,6 +108,7 @@ int read_ansi_ibm_label(DCR *dcr) if (strncmp("VOL1", label, 4) == 0) { ok = true;; dev->label_type = B_IBM_LABEL; + Dmsg0(100, "Found IBM label.\n"); } } } @@ -122,14 +123,18 @@ 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.VolName; + 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.VolName, dev); - Dmsg2(100, "Wanted ANSI Vol %s got %6s\n", VolName, dev->VolHdr.VolName); - Mmsg2(jcr->errmsg, "Wanted ANSI Volume \"%s\" got \"%s\"\n", VolName, dev->VolHdr.VolName); + new_volume(dcr, dev->VolHdr.VolumeName); + 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); return VOL_NAME_ERROR; } } @@ -147,7 +152,7 @@ int read_ansi_ibm_label(DCR *dcr) Dmsg1(100, "HD1 not Bacula label. Wanted BACULA.DATA got %11s\n", &label[4]); Mmsg1(jcr->errmsg, _("ANSI/IBM Volume \"%s\" does not belong to Bacula.\n"), - dev->VolHdr.VolName); + dev->VolHdr.VolumeName); return VOL_NAME_ERROR; /* Not a Bacula label */ } break; @@ -318,15 +323,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)); } + + /* + * This could come at the end of a tape, ignore + * EOT errors. + */ stat = write(dev->fd, 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.strerror()); + 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)); @@ -340,11 +360,24 @@ bool write_ansi_ibm_labels(DCR *dcr, int type, const char *VolName) stat = write(dev->fd, 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.strerror()); + 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; }