General:
Changes to 1.37.22:
+14Jun05
+- Fix the same state variable problem in open_next_part().
+- C++ify the SD code a bit more.
13Jun05
- Add more debug code and clarify debug code for DVDs.
- Do not save and restore state in open_first_part()
}
if (dev->is_dvd()) {
- vol_label_status = read_dev_volume_label_guess(dcr, 0);
+ vol_label_status = read_dvd_volume_label(dcr, /*read*/false);
} else {
vol_label_status = read_dev_volume_label(dcr);
}
}
if (stat == 0) {
if (dev->at_eof()) {
- dev->state |= ST_EOT;
+ dev->set_eot(); /* second eof, set eot bit */
Dmsg0(100, "EOM on ANSI label\n");
Mmsg0(jcr->errmsg, _("Insane! End of tape while reading ANSI label.\n"));
return VOL_LABEL_ERROR; /* at EOM this shouldn't happen */
} else {
- dev->set_eof();
+ dev->set_ateof(); /* set eof state */
}
}
switch (i) {
ASSERT(block->binbuf == ((uint32_t) (block->bufp - block->buf)));
/* dump_block(block, "before write"); */
- if (dev->state & ST_WEOT) {
+ if (dev->at_weot()) {
Dmsg0(100, "return write_block_to_dev with ST_WEOT\n");
dev->dev_errno = ENOSPC;
Jmsg(jcr, M_FATAL, 0, _("Cannot write block. Device at EOM.\n"));
Jmsg(dcr->jcr, M_ERROR, 0, "%s", dev->errmsg);
}
bail_out:
- dev->set_eot(); /* no more writing this tape */
+ dev->set_ateot(); /* no more writing this tape */
Dmsg1(100, "Leave terminate_writing_volume -- %s\n", ok?"OK":"ERROR");
return ok;
}
JCR *jcr = dcr->jcr;
DEV_BLOCK *block = dcr->block;
- /* Limit maximum part size to value specified by user (not applicable to tapes/fifos) */
- if (!(dev->state & (ST_TAPE|ST_FIFO)) && dev->max_part_size > 0 &&
+ /* Limit maximum part size to value specified by user
+ * (not applicable to tapes/fifos)
+ */
+ if (!(dev->is_tape() || dev->is_fifo()) && dev->max_part_size > 0 &&
(dev->part_size + block->binbuf) >= dev->max_part_size) {
if (dev->part < dev->num_parts) {
Jmsg3(dcr->jcr, M_FATAL, 0, _("Error while writing, current part number is less than the total number of parts (%d/%d, device=%s)\n"),
dev->file, dev->block_num, dev->dev_name, be.strerror());
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
if (dev->at_eof()) { /* EOF just seen? */
- dev->state |= ST_EOT; /* yes, error => EOT */
+ dev->set_eot(); /* yes, error => EOT */
}
return false;
}
Mmsg3(dev->errmsg, _("Read zero bytes at %u:%u on device %s.\n"),
dev->file, dev->block_num, dev->dev_name);
if (dev->at_eof()) { /* EOF already read? */
- dev->state |= ST_EOT; /* yes, 2 EOFs => EOT */
+ dev->set_eot(); /* yes, 2 EOFs => EOT */
return 0;
}
- dev->set_eof();
+ dev->set_ateof();
return false; /* return eof */
}
/* Continue here for successful read */
Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Very short block of %d bytes on device %s discarded.\n"),
dev->file, dev->block_num, block->read_len, dev->dev_name);
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
- dev->state |= ST_SHORT; /* set short block */
+ dev->set_short_block();
block->read_len = block->binbuf = 0;
return false; /* return error */
}
Mmsg4(dev->errmsg, _("Volume data error at %u:%u! Short block of %d bytes on device %s discarded.\n"),
dev->file, dev->block_num, block->read_len, dev->dev_name);
Jmsg(jcr, M_ERROR, 0, "%s", dev->errmsg);
- dev->state |= ST_SHORT; /* set short block */
+ dev->set_short_block();
block->read_len = block->binbuf = 0;
return false; /* return error */
}
- dev->state &= ~(ST_EOF|ST_SHORT); /* clear EOF and short block */
+ dev->clear_short_block();
+ dev->clear_eof();
dev->VolCatInfo.VolCatReads++;
dev->VolCatInfo.VolCatRBytes += block->read_len;
dev->file, dev->print_name(), dcr->VolumeName);
Dmsg0(20, "read_record got eof. try again\n");
continue;
- } else if (dev->state & ST_SHORT) {
+ } else if (dev->is_short_block()) {
Jmsg(jcr, M_INFO, 0, "%s", dev->errmsg);
continue;
} else {
return NULL;
}
- dev = init_dev(jcr, NULL, device);
+ dev = init_dev(jcr, device);
if (!dev) {
Jmsg1(jcr, M_FATAL, 0, _("Cannot init device %s\n"), dev_name);
return NULL;
Copyright (C) 2000-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 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 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 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.
*/
*
*/
DEVICE *
-init_dev(JCR *jcr, DEVICE *dev, DEVRES *device)
+init_dev(JCR *jcr, DEVRES *device)
{
struct stat statp;
bool tape, fifo;
int errstat;
DCR *dcr = NULL;
+ DEVICE *dev;
/* Check that device is available */
if (stat(device->device_name, &statp) < 0) {
berrno be;
- if (dev) {
- dev->dev_errno = errno;
- }
Jmsg2(jcr, M_ERROR, 0, _("Unable to stat device %s: ERR=%s\n"),
device->device_name, be.strerror());
return NULL;
} else if (S_ISFIFO(statp.st_mode)) {
fifo = true;
} else if (!(device->cap_bits & CAP_REQMOUNT)) {
- if (dev) {
- dev->dev_errno = ENODEV;
- }
Jmsg2(jcr, M_ERROR, 0, _("%s is an unknown device type. Must be tape or directory. st_mode=%x\n"),
device->device_name, statp.st_mode);
return NULL;
}
- if (!dev) {
- dev = (DEVICE *)get_memory(sizeof(DEVICE));
- memset(dev, 0, sizeof(DEVICE));
- dev->state = ST_MALLOC;
- } else {
- memset(dev, 0, sizeof(DEVICE));
- }
+
+ dev = (DEVICE *)get_memory(sizeof(DEVICE));
+ memset(dev, 0, sizeof(DEVICE));
+ dev->state = ST_MALLOC;
/* Copy user supplied device parameters from Resource */
dev->dev_name = get_memory(strlen(device->device_name)+1);
* Called to indicate that we have just read an
* EOF from the device.
*/
-void DEVICE::set_eof()
+void DEVICE::set_ateof()
{
- state |= ST_EOF;
+ set_eof();
file++;
file_addr = 0;
file_size = 0;
* Called to indicate we are now at the end of the tape, and
* writing is not possible.
*/
-void DEVICE::set_eot()
+void DEVICE::set_ateot()
{
+ /* Make tape effectively read-only */
state |= (ST_EOF|ST_EOT|ST_WEOT);
- state &= ~ST_APPEND; /* make tape read-only */
+ clear_append();
}
/*
return false;
}
Dmsg2(100, "EOD file=%d block=%d\n", mt_stat.mt_fileno, mt_stat.mt_blkno);
- dev->set_eof();
+ dev->set_ateof();
dev->file = mt_stat.mt_fileno;
} else {
#else
Dmsg1(100, "fsf_dev did not advance from file %d\n", file_num);
if (dev_get_os_pos(dev, &mt_stat)) {
Dmsg2(100, "Adjust file from %d to %d\n", dev->file , mt_stat.mt_fileno);
- dev->set_eof();
+ dev->set_ateof();
dev->file = mt_stat.mt_fileno;
}
return false;
return false;
}
Dmsg2(200, "fsf file=%d block=%d\n", mt_stat.mt_fileno, mt_stat.mt_blkno);
- dev->set_eof();
+ dev->set_ateof();
dev->file = mt_stat.mt_fileno;
return true;
Dmsg0(100, "Set ST_EOT\n");
break;
} else {
- dev->set_eof();
+ dev->set_ateof();
continue;
}
} else { /* Got data */
Dmsg0(100, "Got < 0 for MTFSF\n");
Dmsg1(100, "%s", dev->errmsg);
} else {
- dev->set_eof();
+ dev->set_ateof();
}
}
free_memory(rbuf);
block_num = mt_stat.mt_blkno;
} else {
if (at_eof()) {
- state |= ST_EOT;
+ set_eot();
} else {
- set_eof();
+ set_ateof();
}
}
Mmsg3(errmsg, _("ioctl MTFSR %d error on %s. ERR=%s.\n"),
int is_open() const { return state & ST_OPENED; }
int is_offline() const { return state & ST_OFFLINE; }
int is_labeled() const { return state & ST_LABEL; }
+ int is_mounted() const { return state & ST_MOUNTED; }
+ int is_short_block() const { return state & ST_SHORT; }
int is_busy() const { return state & ST_READ || num_writers || reserved_device; }
int at_eof() const { return state & ST_EOF; }
int at_eot() const { return state & ST_EOT; }
const char *archive_name() const;
const char *name() const;
const char *print_name() const; /* Name for display purposes */
- void set_eof(); /* in dev.c */
- void set_eot(); /* in dev.c */
+ void set_ateof(); /* in dev.c */
+ void set_ateot(); /* in dev.c */
+ void set_eot() { state |= ST_EOT; };
+ void set_eof() { state |= ST_EOF; };
void set_append() { state |= ST_APPEND; };
void set_labeled() { state |= ST_LABEL; };
void set_read() { state |= ST_READ; };
void set_offline() { state |= ST_OFFLINE; };
+ void set_opened() { state |= ST_OPENED; };
+ void set_mounted() { state |= ST_MOUNTED; };
+ void set_short_block() { state |= ST_SHORT; };
+ void set_mounted(int val) { if (val) state |= ST_MOUNTED; \
+ else state &= ~ST_MOUNTED; };
void clear_append() { state &= ~ST_APPEND; };
void clear_read() { state &= ~ST_READ; };
void clear_labeled() { state &= ~ST_LABEL; };
void clear_offline() { state &= ~ST_OFFLINE; };
void clear_eot() { state &= ~ST_EOT; };
void clear_eof() { state &= ~ST_EOF; };
+ void clear_opened() { state &= ~ST_OPENED; };
+ void clear_mounted() { state &= ~ST_MOUNTED; };
+ void clear_short_block() { state &= ~ST_SHORT; };
void block(int why); /* in dev.c */
void unblock(); /* in dev.c */
void close(); /* in dev.c */
+
+ void set_blocked(int block) { dev_blocked = block; };
+ int get_blocked() const { return dev_blocked; };
};
/* Note, these return int not bool! */
Jmsg1(jcr, M_ERROR, 0, "%s", jcr->errmsg);
}
/* Set new start/end positions */
- if (dev_state(dev, ST_TAPE)) {
+ if (dev->is_tape()) {
dcr->StartBlock = dev->block_num;
dcr->StartFile = dev->file;
} else {
DEVICE *dev = dcr->dev;
/* Set new start/end positions */
- if (dev_state(dev, ST_TAPE)) {
+ if (dev->is_tape()) {
dcr->StartBlock = dev->block_num;
dcr->StartFile = dev->file;
} else {
void _block_device(const char *file, int line, DEVICE *dev, int state)
{
Dmsg3(500, "block set %d from %s:%d\n", state, file, line);
- ASSERT(dev->dev_blocked == BST_NOT_BLOCKED);
- dev->dev_blocked = state; /* make other threads wait */
+ ASSERT(dev->get_blocked() == BST_NOT_BLOCKED);
+ dev->set_blocked(state); /* make other threads wait */
dev->no_wait_id = pthread_self(); /* allow us to continue */
}
{
Dmsg3(500, "unblock %d from %s:%d\n", dev->dev_blocked, file, line);
ASSERT(dev->dev_blocked);
- dev->dev_blocked = BST_NOT_BLOCKED;
+ dev->set_blocked(BST_NOT_BLOCKED);
dev->no_wait_id = 0;
if (dev->num_waiting > 0) {
pthread_cond_broadcast(&dev->wait); /* wake them up */
{
Dmsg4(500, "steal lock. old=%d new=%d from %s:%d\n", dev->dev_blocked, state,
file, line);
- hold->dev_blocked = dev->dev_blocked;
+ hold->dev_blocked = dev->get_blocked();
hold->dev_prev_blocked = dev->dev_prev_blocked;
hold->no_wait_id = dev->no_wait_id;
- dev->dev_blocked = state;
+ dev->set_blocked(state);
dev->no_wait_id = pthread_self();
V(dev->mutex);
}
/* See what we have for a Volume */
if (dev->is_dvd()) {
- label_status = read_dev_volume_label_guess(dcr, 1);
+ label_status = read_dvd_volume_label(dcr, /*write*/true);
} else {
label_status = read_dev_volume_label(dcr);
}
/* Find resource, and make sure we were able to open it */
if (fnmatch(device->hdr.name, devname.c_str(), 0) == 0) {
if (!device->dev) {
- device->dev = init_dev(jcr, NULL, device);
+ device->dev = init_dev(jcr, device);
}
if (!device->dev) {
Jmsg(jcr, M_WARNING, 0, _("\n"
foreach_alist(device, changer->device) {
Dmsg1(100, "Try changer device %s\n", device->hdr.name);
if (!device->dev) {
- device->dev = init_dev(jcr, NULL, device);
+ device->dev = init_dev(jcr, device);
}
if (!device->dev) {
Dmsg1(100, "Device %s could not be opened. Skipped\n", devname.c_str());
*/
int mount_dev(DEVICE* dev, int timeout)
{
- if (dev->state & ST_MOUNTED) {
+ if (dev->is_mounted()) {
Dmsg0(100, "mount_dev: Device already mounted\n");
return 0;
} else if (dev_cap(dev, CAP_REQMOUNT)) {
*/
int unmount_dev(DEVICE *dev, int timeout)
{
- if (dev->state & ST_MOUNTED) {
+ if (dev->is_mounted()) {
return do_mount_dev(dev, 0, timeout);
}
Dmsg0(100, "mount_dev: Device already unmounted\n");
}
/* (Un)mount the device */
-static int do_mount_dev(DEVICE* dev, int mount, int dotimeout) {
+static int do_mount_dev(DEVICE* dev, int mount, int dotimeout)
+{
POOL_MEM ocmd(PM_FNAME);
POOLMEM* results;
results = get_pool_memory(PM_MESSAGE);
edit_device_codes_dev(dev, ocmd.c_str(), icmd);
- Dmsg2(29, "do_mount_dev: cmd=%s state=%d\n", ocmd.c_str(), dev->state & ST_MOUNTED);
+ Dmsg2(29, "do_mount_dev: cmd=%s state=%d\n", ocmd.c_str(), dev->is_mounted());
if (dotimeout) {
/* Try at most 5 times to (un)mount the device. This should perhaps be configurable. */
timeout = 0;
}
/* If busy retry each second */
- while ((status = run_program_full_output(ocmd.c_str(), dev->max_open_wait/2, results)) != 0) {
+ while ((status = run_program_full_output(ocmd.c_str(),
+ dev->max_open_wait/2, results)) != 0) {
if (--timeout > 0) {
Dmsg2(40, "Device %s cannot be (un)mounted. Retrying... ERR=%s\n", dev->dev_name, results);
/* Sometimes the device cannot be mounted because it is already mounted.
return -1;
}
- if (mount) {
- dev->state |= ST_MOUNTED;
- } else {
- dev->state &= ~ST_MOUNTED;
- }
+ dev->set_mounted(mount); /* set/clear mounted flag */
+
free_pool_memory(results);
- Dmsg1(29, "do_mount_dev: end_state=%d\n", dev->state & ST_MOUNTED);
+ Dmsg1(29, "do_mount_dev: end_state=%d\n", dev->is_mounted());
return 0;
}
/* Only for devices that require a mount.
- * Try to find the volume name of the loaded device, and open the
+ * Try to find the Volume name of the loaded device, and open the
* first part of this volume.
*
* Returns 0 if read_dev_volume_label can now read the label,
- * -1 if an error occured, and read_dev_volume_label_guess must abort with an IO_ERROR.
+ * -1 if an error occured, and read_dvd_volume_label
+ * must abort with an IO_ERROR.
+ *
+ * To find the Volume name, it lists all the files on the DVD,
+ * and searches for a file which has a minimum size (500 bytes).
+ * If this file has a numeric extension, like part files, try to
+ * open the file which has no extension (e.g. the first part
+ * file).
*
- * To guess the device name, it lists all the files on the DVD, and searches for a
- * file which has a minimum size (500 bytes). If this file has a numeric extension,
- * like part files, try to open the file which has no extension (e.g. the first
- * part file).
* So, if the DVD does not contains a Bacula volume, a random file is opened,
* and no valid label could be read from this file.
*
* the label name of the current volume. We can also check that the currently
* mounted disk is writable. (See also read_dev_volume_label_guess in label.c).
*
- * Note that if the right volume is mounted, open_guess_name_dev returns the same
- * result as an usual open_dev.
+ * Note that if the right volume is mounted, open_mounted_dev returns
+ * the same result as an usual open_dev.
*/
-int open_guess_name_dev(DEVICE *dev)
+int open_mounted_dev(DEVICE *dev)
{
- Dmsg1(29, "open_guess_name_dev: dev=%s\n", dev->dev_name);
+ Dmsg1(29, "open_mounted_dev: dev=%s\n", dev->dev_name);
POOL_MEM guessedname(PM_FNAME);
DIR* dp;
struct dirent *entry, *result;
int name_max;
if (!dev->is_dvd()) {
- Dmsg1(100, "open_guess_name_dev: device does not require mount, returning 0. dev=%s\n", dev->dev_name);
+ Dmsg1(100, "open_mounted_dev: device does not require mount, returning 0. dev=%s\n", dev->dev_name);
return 0;
}
#ifndef HAVE_DIRENT_H
- Dmsg0(29, "open_guess_name_dev: readdir not available, cannot guess volume name\n");
+ Dmsg0(29, "open_mounted_dev: readdir not available, cannot guess volume name\n");
return 0;
#endif
if (mount_dev(dev, 1) < 0) {
/* If the device cannot be mounted, check if it is writable */
if (dev->free_space_errno >= 0) {
- Dmsg1(100, "open_guess_name_dev: device cannot be mounted, but it seems to be writable, returning 0. dev=%s\n", dev->dev_name);
+ Dmsg1(100, "open_mounted_dev: device cannot be mounted, but it seems to be writable, returning 0. dev=%s\n", dev->dev_name);
return 0;
} else {
- Dmsg1(100, "open_guess_name_dev: device cannot be mounted, and is not writable, returning -1. dev=%s\n", dev->dev_name);
+ Dmsg1(100, "open_mounted_dev: device cannot be mounted, and is not writable, returning -1. dev=%s\n", dev->dev_name);
return -1;
}
}
if (!(dp = opendir(dev->device->mount_point))) {
berrno be;
dev->dev_errno = errno;
- Dmsg3(29, "open_guess_name_dev: failed to open dir %s (dev=%s), ERR=%s\n", dev->device->mount_point, dev->dev_name, be.strerror());
+ Dmsg3(29, "open_mounted_dev: failed to open dir %s (dev=%s), ERR=%s\n", dev->device->mount_point, dev->dev_name, be.strerror());
return -1;
}
while (1) {
if ((readdir_r(dp, entry, &result) != 0) || (result == NULL)) {
dev->dev_errno = ENOENT;
- Dmsg2(29, "open_guess_name_dev: failed to find suitable file in dir %s (dev=%s)\n", dev->device->mount_point, dev->dev_name);
+ Dmsg2(29, "open_mounted_dev: failed to find suitable file in dir %s (dev=%s)\n", dev->device->mount_point, dev->dev_name);
closedir(dp);
return -1;
}
if (stat(guessedname.c_str(), &statp) < 0) {
berrno be;
- Dmsg3(29, "open_guess_name_dev: failed to stat %s (dev=%s), ERR=%s\n",
+ Dmsg3(29, "open_mounted_dev: failed to stat %s (dev=%s), ERR=%s\n",
guessedname.c_str(), dev->dev_name, be.strerror());
continue;
}
if (!S_ISREG(statp.st_mode) || (statp.st_size < 500)) {
- Dmsg2(100, "open_guess_name_dev: %s is not a regular file, or less than 500 bytes (dev=%s)\n",
+ Dmsg2(100, "open_mounted_dev: %s is not a regular file, or less than 500 bytes (dev=%s)\n",
guessedname.c_str(), dev->dev_name);
continue;
}
if ((stat(guessedname.c_str(), &statp) < 0) || (statp.st_size < 500)) {
/* The file with extension truncated does not exists or is too small, so use it with its extension. */
berrno be;
- Dmsg3(100, "open_guess_name_dev: failed to stat %s (dev=%s), using the file with its extension, ERR=%s\n",
+ Dmsg3(100, "open_mounted_dev: failed to stat %s (dev=%s), using the file with its extension, ERR=%s\n",
guessedname.c_str(), dev->dev_name, be.strerror());
pm_strcpy(guessedname, dev->device->mount_point);
if (guessedname.c_str()[strlen(guessedname.c_str())-1] != '/') {
if ((dev->fd = open(guessedname.c_str(), O_RDONLY | O_BINARY)) < 0) {
berrno be;
dev->dev_errno = errno;
- Dmsg3(29, "open_guess_name_dev: failed to open %s (dev=%s), ERR=%s\n",
+ Dmsg3(29, "open_mounted_dev: failed to open %s (dev=%s), ERR=%s\n",
guessedname.c_str(), dev->dev_name, be.strerror());
if (open_first_part(dev) < 0) {
berrno be;
dev->part_start = 0;
dev->part_size = statp.st_size;
dev->part = 0;
- dev->state |= ST_OPENED;
+ dev->set_opened();
dev->use_count = 1;
- Dmsg2(29, "open_guess_name_dev: %s opened (dev=%s)\n", guessedname.c_str(), dev->dev_name);
+ Dmsg2(29, "open_mounted_dev: %s opened (dev=%s)\n", guessedname.c_str(), dev->dev_name);
return 0;
}
* - Increment part number
* - Reopen the device
*/
-int open_next_part(DEVICE *dev) {
- int state;
+int open_next_part(DEVICE *dev)
+{
Dmsg3(29, "open_next_part %s %s %d\n", dev->dev_name, dev->VolCatInfo.VolCatName, dev->openmode);
/* When appending, do not open a new part if the current is empty */
}
dev->fd = -1;
-
- state = dev->state;
- dev->state &= ~ST_OPENED;
+ dev->clear_opened();
if (dev->is_dvd() && (dev->part == dev->num_parts) && dev->can_append()) {
if (dvd_write_part(dev) < 0) {
}
}
+ Dmsg2(50, "Call open_dev(dev, vol=%s, mode=%d", dev->VolCatInfo.VolCatName,
+ dev->openmode);
if (open_dev(dev, dev->VolCatInfo.VolCatName, dev->openmode) < 0) {
return -1;
}
- dev->state = state;
return dev->fd;
}
close(dev->fd);
}
dev->fd = -1;
- dev->state &= ~ST_OPENED;
+ dev->clear_opened();
dev->part_start = 0;
dev->part = 0;
- Dmsg2(50, "Call open_dev(dev, vol=%s, mode=%d",
- dev->VolCatInfo.VolCatName, dev->openmode);
+ Dmsg2(50, "Call open_dev(dev, vol=%s, mode=%d", dev->VolCatInfo.VolCatName,
+ dev->openmode);
if (open_dev(dev, dev->VolCatInfo.VolCatName, dev->openmode) < 0) {
Dmsg0(50, "open_dev() failed\n");
return -1;
for (p=imsg; *p; p++) {
if (*p == '%') {
switch (*++p) {
- case '%':
- str = "%";
- break;
- case 'n':
- bsnprintf(add, sizeof(add), "%d", dev->part);
- str = add;
- break;
- case 'a':
- str = dev->dev_name;
- break;
- case 'm':
- str = dev->device->mount_point;
- break;
- case 'v':
- str = archive_name.c_str();
- break;
- default:
- add[0] = '%';
- add[1] = *p;
- add[2] = 0;
- str = add;
- break;
+ case '%':
+ str = "%";
+ break;
+ case 'n':
+ bsnprintf(add, sizeof(add), "%d", dev->part);
+ str = add;
+ break;
+ case 'a':
+ str = dev->dev_name;
+ break;
+ case 'm':
+ str = dev->device->mount_point;
+ break;
+ case 'v':
+ str = archive_name.c_str();
+ break;
+ default:
+ add[0] = '%';
+ add[1] = *p;
+ add[2] = 0;
+ str = add;
+ break;
}
} else {
add[0] = *p;
/* Find resource, and make sure we were able to open it */
if (fnmatch(dev_name.c_str(), device->hdr.name, 0) == 0) {
if (!device->dev) {
- device->dev = init_dev(jcr, NULL, device);
+ device->dev = init_dev(jcr, device);
}
if (!device->dev) {
break;
return VOL_OK; /* label already read */
}
- dev->state &= ~(ST_LABEL|ST_APPEND|ST_READ); /* set no label, no append */
+ dev->clear_labeled();
+ dev->clear_append();
+ dev->clear_read();
dev->label_type = B_BACULA_LABEL;
if (!rewind_dev(dev)) {
* Writing : returns the label of the current file (on the harddisk).
* Reading : returns an error
*/
-int read_dev_volume_label_guess(DCR *dcr, bool write)
+int read_dvd_volume_label(DCR *dcr, bool write)
{
int vol_label_status;
DEVICE *dev = dcr->dev;
JCR *jcr = dcr->jcr;
- Dmsg3(100, "Enter read_dev_volume_label_guess device=%s vol=%s dev_Vol=%s\n",
+ Dmsg3(100, "Enter read_dvd_volume_label device=%s vol=%s dev_Vol=%s\n",
dev->print_name(), dcr->VolumeName, dev->VolHdr.VolName);
- if (!dev->is_dvd()) {
- Dmsg0(100, "Leave read_dev_volume_label_guess !CAP_REQMOUNT\n");
- return read_dev_volume_label(dcr);
+ if (!dev->is_dvd()) {
+ Jmsg1(jcr, M_ABORT, 0, _("Device %s is not a DVD.\n"), dev->print_name());
+ return -1; /* for compiler, won't get here */
}
if (!write && (dcr->VolCatInfo.VolCatParts == 0)) {
- Dmsg0(100, "Leave read_dev_volume_label_guess !writing, and VolCatParts == 0\n");
+ Dmsg0(100, "Leave read_dvd_volume_label !writing, and VolCatParts == 0\n");
return read_dev_volume_label(dcr);
}
- /* For mounted devices, tries to guess the volume name, and read the label if possible.
- */
- if (open_guess_name_dev(dev) < 0) {
+ /*
+ * For mounted devices, try to guess the Volume name
+ * and read the label if possible.
+ */
+ if (open_mounted_dev(dev) < 0) {
if (!write || dcr->VolCatInfo.VolCatParts > 0) {
Mmsg2(jcr->errmsg, _("Requested Volume \"%s\" on %s is not a Bacula labeled Volume."),
dev->print_name(), dcr->VolumeName);
- Dmsg0(100, "Leave read_dev_volume_label_guess VOL_NO_LABEL (!open_guess_name_dev)\n");
+ Dmsg0(100, "Leave read_dvd_volume_label VOL_NO_LABEL (!open_mounted_dev)\n");
return VOL_NO_LABEL;
}
if (write && dev->free_space_errno < 0) {
- Dmsg0(100, "Leave read_dev_volume_label_guess !free_space VOL_NO_MEDIA\n");
+ Dmsg0(100, "Leave read_dvd_volume_label !free_space VOL_NO_MEDIA\n");
Mmsg2(jcr->errmsg, _("free_space error on %s. The current medium is probably not writable: ERR=%s.\n"),
dev->print_name(), dev->errmsg);
return VOL_NO_MEDIA;
}
- /* If we can't guess the name, and we are writing, just reopen the right file with open_first_part. */
+ /*
+ * If we can't guess the name, and we are writing,
+ * just reopen the right file with open_first_part.
+ */
if (open_first_part(dev) < 0) {
berrno be;
Mmsg2(jcr->errmsg, _("open_first_part error on %s: ERR=%s.\n"),
dev->print_name(), be.strerror());
- Dmsg0(100, "Leave read_dev_volume_label_guess VOL_IO_ERROR (!open_guess_name_dev && !open_first_part)\n");
+ Dmsg0(100, "Leave read_dvd_volume_label VOL_IO_ERROR (!open_mounted_dev && !open_first_part)\n");
return VOL_IO_ERROR;
}
- Dmsg0(100, "Leave read_dev_volume_label_guess !open_guess_name_dev\n");
+ Dmsg0(100, "Leave read_dvd_volume_label !open_mounted_dev\n");
return read_dev_volume_label(dcr);
} else {
if (write && dcr->dev->free_space_errno < 0) {
- Dmsg0(100, "Leave read_dev_volume_label_guess !free_space VOL_NO_MEDIA\n");
+ Dmsg0(100, "Leave read_dvd_volume_label !free_space VOL_NO_MEDIA\n");
Mmsg2(jcr->errmsg, _("free_space error on %s. The current medium is probably not writable: ERR=%s.\n"),
dev->print_name(), dev->errmsg);
return VOL_NO_MEDIA;
vol_label_status = read_dev_volume_label(dcr);
if (!write || dcr->VolCatInfo.VolCatParts > 0) {
- Dmsg0(100, "Leave read_dev_volume_label_guess (open_guess_name_dev && (!write || dcr->VolCatInfo.VolCatParts > 0))\n");
+ Dmsg0(100, "Leave read_dvd_volume_label (open_mounted_dev && (!write || dcr->VolCatInfo.VolCatParts > 0))\n");
return vol_label_status;
}
berrno be;
Mmsg2(jcr->errmsg, _("open_first_part error on %s: ERR=%s.\n"),
dev->print_name(), be.strerror());
- Dmsg0(100, "Leave read_dev_volume_label_guess VOL_IO_ERROR (open_guess_name_dev && !open_first_part)\n");
+ Dmsg0(100, "Leave read_dvd_volume_label VOL_IO_ERROR (open_mounted_dev && !open_first_part)\n");
return VOL_IO_ERROR;
}
- /* When writing, if the guessed volume name is no the right volume name,
+ /* When writing, if the guessed volume name is not the right volume name,
* report the error, otherwise, just continue with the right file.
*/
if (vol_label_status != VOL_NAME_ERROR) {
- Dmsg0(100, "Leave read_dev_volume_label_guess (open_guess_name_dev && !VOL_NAME_ERROR)\n");
+ Dmsg0(100, "Leave read_dvd_volume_label (open_mounted_dev && !VOL_NAME_ERROR)\n");
dev->clear_labeled();
return read_dev_volume_label(dcr);
} else {
- Dmsg0(100, "Leave read_dev_volume_label_guess (open_guess_name_dev && VOL_NAME_ERROR)\n");
+ Dmsg0(100, "Leave read_dvd_volume_label (open_mounted_dev && VOL_NAME_ERROR)\n");
return vol_label_status;
}
}
rewind_dev(dev);
return false;
}
- } else if (!write_ansi_ibm_labels (dcr, ANSI_VOL_LABEL, dev->VolHdr.VolName)) {
+ } else if (!write_ansi_ibm_labels(dcr, ANSI_VOL_LABEL, dev->VolHdr.VolName)) {
return false;
}
create_volume_label(dev, dcr->VolumeName, "Default");
dev->VolHdr.LabelType = PRE_LABEL;
} else if (dev->is_dvd()) {
- vol_label_status = read_dev_volume_label_guess(dcr, 1);
+ vol_label_status = read_dvd_volume_label(dcr, /*write*/true);
} else {
vol_label_status = read_dev_volume_label(dcr);
}
free_volume(dev);
memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
/* Force re-read of label */
- dev->state &= ~(ST_LABEL|ST_READ|ST_APPEND);
+ dev->clear_labeled();
+ dev->clear_read();
+ dev->clear_append();
dev->label_type = B_BACULA_LABEL;
dcr->VolumeName[0] = 0;
/* From dev.c */
-DEVICE *init_dev(JCR *jcr, DEVICE *dev, DEVRES *device);
+DEVICE *init_dev(JCR *jcr, DEVRES *device);
int open_dev(DEVICE *dev, char *VolName, int mode);
off_t lseek_dev(DEVICE *dev, off_t offset, int whence);
int open_first_part(DEVICE *dev);
int open_next_part(DEVICE *dev);
-int open_guess_name_dev(DEVICE *dev);
+int open_mounted_dev(DEVICE *dev);
bool truncate_dev(DEVICE *dev);
void term_dev(DEVICE *dev);
char * strerror_dev(DEVICE *dev);
/* From label.c */
int read_dev_volume_label(DCR *dcr);
-int read_dev_volume_label_guess(DCR *dcr, bool write);
+int read_dvd_volume_label(DCR *dcr, bool write);
void create_session_label(DCR *dcr, DEV_RECORD *rec, int label);
void create_volume_label(DEVICE *dev, const char *VolName, const char *PoolName);
bool write_new_volume_label_to_dev(DCR *dcr, const char *VolName, const char *PoolName);
Dmsg3(200, "Got EOF at file %u on device %s, Volume \"%s\"\n",
dev->file, dev->print_name(), dcr->VolumeName);
continue;
- } else if (dev_state(dev, ST_SHORT)) {
+ } else if (dev->is_short_block()) {
Jmsg1(jcr, M_ERROR, 0, "%s", dev->errmsg);
continue;
} else {
if (!dev->at_eot()) {
/* Set EOT flag to force mount of next Volume */
jcr->mount_next_volume = true;
- dev->state |= ST_EOT;
+ dev->set_eot();
}
rec->Block = 0;
return true;
DCR *dcr;
const int name_len = MAX_NAME_LENGTH;
if (!rctx.device->dev) {
- rctx.device->dev = init_dev(rctx.jcr, NULL, rctx.device);
+ rctx.device->dev = init_dev(rctx.jcr, rctx.device);
}
if (!rctx.device->dev) {
if (rctx.device->changer_res) {
foreach_res(device, R_DEVICE) {
Dmsg1(90, "calling init_dev %s\n", device->device_name);
- device->dev = init_dev(NULL, NULL, device);
+ device->dev = init_dev(NULL, device);
Dmsg1(10, "SD init done %s\n", device->device_name);
if (!device->dev) {
Jmsg1(NULL, M_ERROR, 0, _("Could not initialize %s\n"), device->device_name);
if (!unmounted) {
dev->dev_prev_blocked = dev->dev_blocked;
- dev->dev_blocked = BST_WAITING_FOR_SYSOP; /* indicate waiting for mount */
+ dev->set_blocked(BST_WAITING_FOR_SYSOP); /* indicate waiting for mount */
}
for ( ; !job_canceled(jcr); ) {
}
if (!unmounted) {
- dev->dev_blocked = dev->dev_prev_blocked; /* restore entry state */
+ dev->set_blocked(dev->dev_prev_blocked); /* restore entry state */
}
V(dev->mutex);
return stat;