* Version $Id$
*/
/*
- Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+ Copyright (C) 2000-2003 Kern Sibbald and John Walker
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
dev->volume_capacity = device->volume_capacity;
dev->max_rewind_wait = device->max_rewind_wait;
dev->max_open_wait = device->max_open_wait;
+ dev->max_open_vols = device->max_open_vols;
dev->device = device;
if (tape) {
dev->use_count++;
Mmsg2(&dev->errmsg, _("WARNING!!!! device %s opened %d times!!!\n"),
dev->dev_name, dev->use_count);
- Emsg0(M_WARNING, 0, dev->errmsg);
+ Emsg1(M_WARNING, 0, "%s", dev->errmsg);
return dev->fd;
}
if (VolName) {
if (dev->state & (ST_TAPE|ST_FIFO)) {
int timeout;
Dmsg0(29, "open_dev: device is tape\n");
- if (mode == READ_WRITE) {
+ if (mode == OPEN_READ_WRITE) {
dev->mode = O_RDWR | O_BINARY;
- } else {
+ } else if (mode == OPEN_READ_ONLY) {
dev->mode = O_RDONLY | O_BINARY;
+ } else if (mode == OPEN_WRITE_ONLY) {
+ dev->mode = O_WRONLY | O_BINARY;
+ } else {
+ Emsg0(M_ABORT, 0, _("Illegal mode given to open_dev.\n"));
}
timeout = dev->max_open_wait;
errno = 0;
+ if (dev->state & ST_FIFO && timeout) {
+ /* Set open timer */
+ dev->tid = start_thread_timer(pthread_self(), timeout);
+ }
+ /* If busy retry each second for max_open_wait seconds */
while ((dev->fd = open(dev->dev_name, dev->mode, MODE_RW)) < 0) {
+ if (errno == EAGAIN) {
+ continue;
+ }
if (errno == EBUSY && timeout-- > 0) {
Dmsg2(100, "Device %s busy. ERR=%s\n", dev->dev_name, strerror(errno));
sleep(1);
dev->dev_errno = errno;
Mmsg2(&dev->errmsg, _("stored: unable to open device %s: ERR=%s\n"),
dev->dev_name, strerror(dev->dev_errno));
+ /* Stop any open timer we set */
+ if (dev->tid) {
+ stop_thread_timer(dev->tid);
+ dev->tid = 0;
+ }
Emsg0(M_FATAL, 0, dev->errmsg);
break;
}
dev->use_count++;
update_pos_dev(dev); /* update position */
}
+ /* Stop any open() timer we started */
+ if (dev->tid) {
+ stop_thread_timer(dev->tid);
+ dev->tid = 0;
+ }
Dmsg1(29, "open_dev: tape %d opened\n", dev->fd);
} else {
/*
}
pm_strcat(&archive_name, VolName);
Dmsg1(29, "open_dev: device is disk %s\n", archive_name);
- if (mode == READ_WRITE) {
+ if (mode == OPEN_READ_WRITE) {
dev->mode = O_CREAT | O_RDWR | O_BINARY;
- } else {
+ } else if (mode == OPEN_READ_ONLY) {
dev->mode = O_RDONLY | O_BINARY;
+ } else if (mode == OPEN_WRITE_ONLY) {
+ dev->mode = O_WRONLY | O_BINARY;
+ } else {
+ Emsg0(M_ABORT, 0, _("Illegal mode given to open_dev.\n"));
}
- if ((dev->fd = open(archive_name, dev->mode, MODE_RW)) < 0) {
+ /* If creating file, give 0640 permissions */
+ if ((dev->fd = open(archive_name, dev->mode, 0640)) < 0) {
dev->dev_errno = errno;
Mmsg2(&dev->errmsg, _("Could not open: %s, ERR=%s\n"), archive_name, strerror(dev->dev_errno));
Emsg0(M_FATAL, 0, dev->errmsg);
memset(&dev->VolCatInfo, 0, sizeof(dev->VolCatInfo));
memset(&dev->VolHdr, 0, sizeof(dev->VolHdr));
dev->use_count--;
+ if (dev->tid) {
+ stop_thread_timer(dev->tid);
+ dev->tid = 0;
+ }
}
/*
Emsg0(M_FATAL, 0, dev->errmsg);
return;
}
- close_dev(dev);
+ do_close(dev);
Dmsg0(29, "term_dev\n");
if (dev->dev_name) {
free_memory(dev->dev_name);