* If it is a tape, it checks the volume name
*/
Dmsg1(100, "bstored: open vol=%s\n", dcr->VolumeName);
- if (dev->open(dcr, OPEN_READ_ONLY) < 0) {
+ if (!dev->open(dcr, OPEN_READ_ONLY)) {
if (!dev->poll) {
Jmsg3(jcr, M_WARNING, 0, _("Read open device %s Volume \"%s\" failed: ERR=%s\n"),
dev->print_name(), dcr->VolumeName, dev->bstrerror());
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2002-2010 Free Software Foundation Europe e.V.
+ Copyright (C) 2002-2012 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.
Dmsg0(100, "About to acquire device for writing\n");
/* For we must now acquire the device for writing */
out_dev->r_dlock();
- if (out_dev->open(out_jcr->dcr, OPEN_READ_WRITE) < 0) {
+ if (!out_dev->open(out_jcr->dcr, OPEN_READ_WRITE)) {
Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), out_dev->errmsg);
out_dev->dunlock();
exit(1);
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2012 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.
block = new_block(dev);
dev->r_dlock();
Dmsg1(200, "Opening device %s\n", dcr->VolumeName);
- if (dev->open(dcr, OPEN_READ_WRITE) < 0) {
+ if (!dev->open(dcr, OPEN_READ_WRITE)) {
Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg);
ok = false;
goto bail_out;
* Open the device with the operating system and
* initialize buffer pointers.
*
- * Returns: -1 on error
- * fd on success
+ * Returns: true on success
+ * false on error
*
* Note, for a tape, the VolName is the name we give to the
* volume (not really used here), but for a file, the
* In the case of a file, the full name is the device name
* (archive_name) with the VolName concatenated.
*/
-int
+bool
DEVICE::open(DCR *dcr, int omode)
{
int preserve = 0;
if (is_open()) {
if (openmode == omode) {
- return m_fd;
+ return true;
} else {
d_close(m_fd);
clear_opened();
}
state |= preserve; /* reset any important state info */
Dmsg2(100, "preserve=0x%x fd=%d\n", preserve, m_fd);
- return m_fd;
+ return m_fd >= 0;
}
void DEVICE::set_mode(int new_mode)
Mmsg2(errmsg, _("Could not open: %s, ERR=%s\n"), archive_name.c_str(),
be.bstrerror());
Dmsg1(100, "open failed: %s", errmsg);
-// Jmsg1(NULL, M_WARNING, 0, "%s", errmsg);
- } else {
+ }
+ if (m_fd >= 0) {
dev_errno = 0;
file = 0;
file_addr = 0;
void clear_volhdr(); /* in dev.c */
void close(); /* in dev.c */
void close_part(DCR *dcr); /* in dev.c */
- int open(DCR *dcr, int mode); /* in dev.c */
+ bool open(DCR *dcr, int mode); /* in dev.c */
void term(void); /* in dev.c */
ssize_t read(void *buf, size_t len); /* in dev.c */
ssize_t write(const void *buf, size_t len); /* in dev.c */
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2012 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.
mode = OPEN_READ_ONLY;
}
Dmsg0(129, "Opening device.\n");
- if (dev->open(dcr, mode) < 0) {
+ if (!dev->open(dcr, mode)) {
Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg);
ok = false;
goto bail_out;
} else {
mode = OPEN_READ_WRITE;
}
- if (dev->open(dcr, mode) < 0) {
+ if (!dev->open(dcr, mode)) {
/* If polling, ignore the error */
/* If DVD, also ignore the error, very often you cannot open the device
* (when there is no DVD, or when the one inserted is a wrong one) */
}
/* Set old volume name for open if relabeling */
dcr->setVolCatName(volname);
- if (dev->open(dcr, mode) < 0) {
+ if (!dev->open(dcr, mode)) {
dir->fsend(_("3910 Unable to open device \"%s\": ERR=%s\n"),
dev->print_name(), dev->bstrerror());
goto bail_out;
try_autoload_device(jcr, dcr, slot, "");
}
/* We freed the device, so reopen it and wake any waiting threads */
- if (dev->open(dcr, OPEN_READ_ONLY) < 0) {
+ if (!dev->open(dcr, OPEN_READ_ONLY)) {
dir->fsend(_("3901 Unable to open device \"%s\": ERR=%s\n"),
dev->print_name(), dev->bstrerror());
if (dev->blocked() == BST_UNMOUNTED) {
dev->print_name());
}
} else if (dev->is_tape()) {
- if (dev->open(dcr, OPEN_READ_ONLY) < 0) {
+ if (!dev->open(dcr, OPEN_READ_ONLY)) {
dir->fsend(_("3901 Unable to open device \"%s\": ERR=%s\n"),
dev->print_name(), dev->bstrerror());
break;
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2005-2011 Free Software Foundation Europe e.V.
+ Copyright (C) 2005-2012 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.
return -1;
}
}
-
-#ifdef neeeded
- Dmsg2(400, "num_dvd_parts=%d part=%d\n", dev->num_dvd_parts, dev->part);
- make_spooled_dvd_filename(dev, archive_name); /* makes spool name */
-
- /* Check if the next part exists in spool directory . */
- Dmsg1(100, "Check if part on spool: %s\n", archive_name.c_str());
- if ((stat(archive_name.c_str(), &buf) == 0) || (errno != ENOENT)) {
- Dmsg1(29, "======= Part %s is in the way, deleting it...\n", archive_name.c_str());
- /* Then try to unlink it */
- if (unlink(archive_name.c_str()) < 0) {
- berrno be;
- dev->set_part_spooled(false);
- dev->dev_errno = errno;
- Mmsg2(dev->errmsg, _("open_next_part can't unlink existing part %s, ERR=%s\n"),
- archive_name.c_str(), be.bstrerror());
- return -1;
- }
- }
-#endif
}
Dmsg2(400, "Call dev->open(vol=%s, mode=%d)\n", dcr->getVolCatName(),
dev->openmode);
/* Open next part. Note, this sets part_size for part opened. */
- if (dev->open(dcr, OPEN_READ_ONLY) < 0) {
+ if (!dev->open(dcr, OPEN_READ_ONLY)) {
return -1;
}
dev->set_labeled(); /* all next parts are "labeled" */
dev->part = 1;
dev->part_start = 0;
- if (dev->open(dcr, mode) < 0) {
+ if (!dev->open(dcr, mode)) {
Dmsg0(400, "open dev() failed\n");
return false;
}
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-2012 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.
dev->VolHdr.VolumeName[0]?dev->VolHdr.VolumeName:"*NULL*");
if (!dev->is_open()) {
- if (dev->open(dcr, OPEN_READ_ONLY) < 0) {
+ if (!dev->open(dcr, OPEN_READ_ONLY)) {
return VOL_IO_ERROR;
}
}
dev->setVolCatName(VolName);
dcr->setVolCatName(VolName);
Dmsg1(150, "New VolName=%s\n", VolName);
- if (dev->open(dcr, OPEN_READ_WRITE) < 0) {
+ if (!dev->open(dcr, OPEN_READ_WRITE)) {
/* If device is not tape, attempt to create it */
- if (dev->is_tape() || dev->open(dcr, CREATE_READ_WRITE) < 0) {
+ if (dev->is_tape() || !dev->open(dcr, CREATE_READ_WRITE)) {
Jmsg3(dcr->jcr, M_WARNING, 0, _("Open device %s Volume \"%s\" failed: ERR=%s\n"),
dev->print_name(), dcr->VolumeName, dev->bstrerror());
goto bail_out;
DEVICE *dev = dcr->dev;
JCR *jcr = dcr->jcr;
- if (dev->open(dcr, OPEN_READ_WRITE) < 0) {
+ if (!dev->open(dcr, OPEN_READ_WRITE)) {
Jmsg3(jcr, M_WARNING, 0, _("Open device %s Volume \"%s\" failed: ERR=%s\n"),
dev->print_name(), dcr->VolumeName, dev->bstrerror());
return false;
dev->print_name(), dev->print_errmsg());
return false;
}
- if (dev->open(dcr, OPEN_READ_WRITE) < 0) {
+ if (!dev->open(dcr, OPEN_READ_WRITE)) {
Jmsg2(jcr, M_FATAL, 0,
_("Failed to re-open DVD after truncate on device %s: ERR=%s\n"),
dev->print_name(), dev->print_errmsg());
/*
Bacula® - The Network Backup Solution
- Copyright (C) 2002-2010 Free Software Foundation Europe e.V.
+ Copyright (C) 2002-2012 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.
mode = OPEN_READ_WRITE;
}
/* Try autolabel if enabled */
- if (dev->open(dcr, mode) < 0) {
+ if (!dev->open(dcr, mode)) {
try_autolabel(false); /* try to create a new volume label */
}
- while (dev->open(dcr, mode) < 0) {
+ while (!dev->open(dcr, mode)) {
Dmsg1(150, "open_device failed: ERR=%s\n", dev->bstrerror());
if ((dev->is_file() && dev->is_removable()) || dev->is_dvd()) {
bool ok = true;
}
}
if (ok && dev->scan_dir_for_volume(dcr)) {
- if (dev->open(dcr, mode) >= 0) {
+ if (dev->open(dcr, mode)) {
break; /* got a valid volume */
}
}