+/*
+ Bacula® - The Network Backup Solution
+
+ Copyright (C) 2000-2007 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.
+ This program is Free Software; you can redistribute it and/or
+ modify it under the terms of version two of the GNU General Public
+ License as published by the Free Software Foundation plus additions
+ that are listed in the file LICENSE.
+
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Bacula® is a registered trademark of John Walker.
+ The licensor of Bacula is the Free Software Foundation Europe
+ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+ Switzerland, email:ftf@fsfeurope.org.
+*/
/*
*
* dev.c -- low level operations on device (storage device)
* Kern Sibbald, MM
*
* NOTE!!!! None of these routines are reentrant. You must
- * use lock_device() and unlock_device() at a higher level,
+ * use dev->r_dlock() and dev->unlock() at a higher level,
* or use the xxx_device() equivalents. By moving the
* thread synchronization to a higher level, we permit
* the higher level routines to "seize" the device and
*
* Version $Id$
*/
-/*
- Bacula® - The Network Backup Solution
-
- Copyright (C) 2000-2007 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.
- This program is Free Software; you can redistribute it and/or
- modify it under the terms of version two of the GNU General Public
- License as published by the Free Software Foundation plus additions
- that are listed in the file LICENSE.
-
- 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., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA.
-
- Bacula® is a registered trademark of John Walker.
- The licensor of Bacula is the Free Software Foundation Europe
- (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
- Switzerland, email:ftf@fsfeurope.org.
-*/
/*
* Handling I/O errors and end of tape conditions are a bit tricky.
dev->clear_opened();
dev->attached_dcrs = New(dlist(dcr, &dcr->dev_link));
Dmsg2(29, "init_dev: tape=%d dev_name=%s\n", dev->is_tape(), dev->dev_name);
+ dev->initiated = true;
return dev;
}
void DEVICE::block(int why)
{
- lock_device(this);
+ r_dlock(); /* need recursive lock to block */
block_device(this, why);
- unlock();
+ r_dunlock();
}
-void DEVICE::unblock()
-{
- lock();
+void DEVICE::unblock(bool locked)
+{
+ if (!locked) {
+ dlock();
+ }
unblock_device(this);
- unlock();
+ dunlock();
}
+
const char *DEVICE::print_blocked() const
{
switch (m_blocked) {
/* On some systems such as NetBSD, this clears all errors */
get_os_tape_file();
-/* Found on Linux */
+/* Found on Solaris */
#ifdef MTIOCLRERR
{
- struct mtop mt_com;
- mt_com.mt_op = MTIOCLRERR;
- mt_com.mt_count = 1;
- /* Clear any error condition on the tape */
- tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
+ tape_ioctl(m_fd, MTIOCLRERR);
Dmsg0(200, "Did MTIOCLRERR\n");
}
#endif
#endif
}
+
+/*
+ * Clear volume header
+ */
+void DEVICE::clear_volhdr()
+{
+ /* If we have an unused volume associated with this drive, free it */
+ if (vol && !is_busy()) {
+ free_volume(this);
+ }
+ Dmsg1(100, "Clear volhdr vol=%s\n", VolHdr.VolumeName);
+ memset(&VolHdr, 0, sizeof(VolHdr));
+}
+
+
/*
* Close the device
*/
EndFile = EndBlock = 0;
openmode = 0;
Slot = -1; /* unknown slot */
- free_volume(this);
+ clear_volhdr();
memset(&VolCatInfo, 0, sizeof(VolCatInfo));
- memset(&VolHdr, 0, sizeof(VolHdr));
if (tid) {
stop_thread_timer(tid);
tid = 0;
dev->clrerror(MTSETBSIZ);
}
}
-/* Turn this on later when fully tested */
-#if defined(xxxMTIOCSETEOTMODEL)
+#if defined(MTIOCSETEOTMODEL)
uint32_t neof;
if (dev->has_cap(CAP_TWOEOF)) {
neof = 2;