*/
/*
- Copyright (C) 2002-2004 Kern Sibbald and John Walker
+ Copyright (C) 2002-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 as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ 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,
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., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
-typedef struct s_bpipe {
+class BPIPE {
+public:
pid_t worker_pid;
time_t worker_stime;
int wait;
btimer_t *timer_id;
FILE *rfd;
FILE *wfd;
-} BPIPE;
+};
off_t DEVICE::lseek(DCR *dcr, off_t offset, int whence)
{
- if (is_dvd()) {
+ switch (dev_type) {
+ case B_DVD_DEV:
return lseek_dvd(dcr, offset, whence);
- }
- if (is_file()) {
+ case B_FILE_DEV:
return ::lseek(fd, offset, whence);
- }
+ }
return -1;
}
bool DEVICE::truncate(DCR *dcr) /* We need the DCR for DVD-writing */
{
Dmsg1(100, "truncate %s\n", print_name());
- if (is_tape()) {
- return true; /* we don't really truncate tapes */
+ switch (dev_type) {
+ case B_TAPE_DEV:
/* maybe we should rewind and write and eof ???? */
- }
-
- if (is_dvd()) {
+ return true; /* we don't really truncate tapes */
+ case B_DVD_DEV:
return truncate_dvd(dcr);
+ case B_FILE_DEV:
+ /* ***FIXME*** we really need to unlink() the file so that
+ * its name can be changed for a relabel.
+ */
+ if (ftruncate(fd, 0) != 0) {
+ berrno be;
+ Mmsg2(errmsg, _("Unable to truncate device %s. ERR=%s\n"),
+ print_name(), be.strerror());
+ return false;
+ }
+ return true;
}
-
- /* ***FIXME*** we really need to unlink() the file so that
- * its name can be changed for a relabel.
- */
- if (ftruncate(fd, 0) != 0) {
- berrno be;
- Mmsg2(errmsg, _("Unable to truncate device %s. ERR=%s\n"),
- print_name(), be.strerror());
- return false;
- }
- return true;
+ return false;
}
/* Mount the device.
if (!dev->rewind(dcr)) {
Mmsg(jcr->errmsg, _("Couldn't rewind device %s: ERR=%s\n"),
- dev->print_name(), dev->bstrerror());
+ dev->print_name(), dev->print_errmsg());
Dmsg1(30, "return VOL_NO_MEDIA: %s", jcr->errmsg);
return VOL_NO_MEDIA;
}
if (!read_block_from_dev(dcr, NO_BLOCK_NUMBER_CHECK)) {
Mmsg(jcr->errmsg, _("Requested Volume \"%s\" on %s is not a Bacula "
"labeled Volume, because: ERR=%s"), NPRT(VolName),
- dev->print_name(), dev->bstrerror());
+ dev->print_name(), dev->print_errmsg());
Dmsg1(30, "%s", jcr->errmsg);
} else if (!read_record_from_block(block, record)) {
Mmsg(jcr->errmsg, _("Could not read Volume label from block.\n"));
Dmsg1(30, "%s", jcr->errmsg);
} else if (!unser_volume_label(dev, record)) {
Mmsg(jcr->errmsg, _("Could not unserialize Volume label: ERR=%s\n"),
- dev->bstrerror());
+ dev->print_errmsg());
Dmsg1(30, "%s", jcr->errmsg);
} else if (strcmp(dev->VolHdr.Id, BaculaId) != 0 &&
strcmp(dev->VolHdr.Id, OldBaculaId) != 0) {
if (!dev->rewind(dcr)) {
free_volume(dev);
memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
- Dmsg2(30, "Bad status on %s from rewind: ERR=%s\n", dev->print_name(), dev->bstrerror());
+ Dmsg2(30, "Bad status on %s from rewind: ERR=%s\n", dev->print_name(), dev->print_errmsg());
if (!forge_on) {
goto bail_out;
}
/* Temporarily mark in append state to enable writing */
dev->set_append();
if (!write_record_to_block(dcr->block, dcr->rec)) {
- Dmsg2(30, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->bstrerror());
+ Dmsg2(30, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->print_errmsg());
goto bail_out;
} else {
Dmsg2(30, "Wrote label of %d bytes to %s\n", dcr->rec->data_len, dev->print_name());
Dmsg0(99, "Call write_block_to_dev()\n");
if (!write_block_to_dev(dcr)) {
- Dmsg2(30, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->bstrerror());
+ Dmsg2(30, "Bad Label write on %s: ERR=%s\n", dev->print_name(), dev->print_errmsg());
goto bail_out;
}
if (dev->is_dvd() && dvdnow) {
Dmsg1(150, "New VolName=%s\n", dev->VolCatInfo.VolCatName);
if (!dvd_write_part(dcr)) {
- Dmsg2(30, "Bad DVD write on %s: ERR=%s\n", dev->print_name(), dev->bstrerror());
+ Dmsg2(30, "Bad DVD write on %s: ERR=%s\n", dev->print_name(), dev->print_errmsg());
goto bail_out;
}
}
if (!dev_cap(dev, CAP_STREAM)) {
if (!dev->rewind(dcr)) {
Jmsg2(jcr, M_FATAL, 0, _("Rewind error on device %s: ERR=%s\n"),
- dev->print_name(), dev->bstrerror());
+ dev->print_name(), dev->print_errmsg());
return false;
}
if (recycle) {
if (!dev->truncate(dcr)) {
Jmsg2(jcr, M_FATAL, 0, _("Truncate error on device %s: ERR=%s\n"),
- dev->print_name(), dev->bstrerror());
+ dev->print_name(), dev->print_errmsg());
+ return false;
+ }
+ if (dev->open(dcr, OPEN_READ_WRITE) < 0) {
+ Jmsg2(jcr, M_FATAL, 0,
+ _("Failed to re-open DVD after truncate on device %s: ERR=%s\n"),
+ dev->print_name(), dev->print_errmsg());
return false;
}
}
Dmsg1(200, "Attempt to write to device fd=%d.\n", dev->fd);
if (!write_block_to_dev(dcr)) {
Jmsg2(jcr, M_ERROR, 0, _("Unable to write device %s: ERR=%s\n"),
- dev->print_name(), dev->bstrerror());
+ dev->print_name(), dev->print_errmsg());
Dmsg0(200, "===ERROR write block to dev\n");
return false;
}
}
+ dev->set_labeled();
/* Set or reset Volume statistics */
dev->VolCatInfo.VolCatJobs = 0;
dev->VolCatInfo.VolCatFiles = 0;