/* * Close the device */ bool DEVICE::close() { bool ok = true; Dmsg4(40, "close_dev vol=%s fd=%d dev=%p dev=%s\n", VolHdr.VolumeName, m_fd, this, print_name()); offline_or_rewind(); if (!is_open()) { Dmsg2(200, "device %s already closed vol=%s\n", print_name(), VolHdr.VolumeName); return true; /* already closed */ } switch (dev_type) { case B_VTL_DEV: case B_VTAPE_DEV: case B_TAPE_DEV: unlock_door(); /* Fall through wanted */ default: if (d_close(m_fd) != 0) { berrno be; dev_errno = errno; Mmsg2(errmsg, _("Error closing device %s. ERR=%s.\n"), print_name(), be.bstrerror()); ok = false; } break; } unmount(1); /* do unmount if required */ /* Clean up device packet so it can be reused */ clear_opened(); /* * Be careful not to clear items needed by the DVD driver * when it is closing a single part. */ state &= ~(ST_LABEL|ST_READ|ST_APPEND|ST_EOT|ST_WEOT|ST_EOF| ST_NOSPACE|ST_MOUNTED|ST_MEDIA|ST_SHORT); label_type = B_BACULA_LABEL; file = block_num = 0; file_size = 0; file_addr = 0; EndFile = EndBlock = 0; openmode = 0; clear_volhdr(); memset(&VolCatInfo, 0, sizeof(VolCatInfo)); if (tid) { stop_thread_timer(tid); tid = 0; } return ok; }
/* * Close the device. */ bool DEVICE::close(DCR *dcr) { bool retval = true; int status; Dmsg1(100, "close_dev %s\n", print_name()); if (!is_open()) { Dmsg2(100, "device %s already closed vol=%s\n", print_name(), VolHdr.VolumeName); goto bail_out; /* already closed */ } if (!norewindonclose) { offline_or_rewind(); } switch (dev_type) { case B_VTL_DEV: case B_TAPE_DEV: unlock_door(); /* * Fall through wanted */ default: status = d_close(m_fd); if (status < 0) { berrno be; Mmsg2(errmsg, _("Unable to close device %s. ERR=%s\n"), print_name(), be.bstrerror()); dev_errno = errno; retval = false; } break; } unmount(dcr, 1); /* do unmount if required */ /* * Clean up device packet so it can be reused. */ clear_opened(); clear_bit(ST_LABEL, state); clear_bit(ST_READREADY, state); clear_bit(ST_APPENDREADY, state); clear_bit(ST_EOT, state); clear_bit(ST_WEOT, state); clear_bit(ST_EOF, state); clear_bit(ST_MOUNTED, state); clear_bit(ST_MEDIA, state); clear_bit(ST_SHORT, state); label_type = B_BAREOS_LABEL; file = block_num = 0; file_size = 0; file_addr = 0; EndFile = EndBlock = 0; open_mode = 0; clear_volhdr(); memset(&VolCatInfo, 0, sizeof(VolCatInfo)); if (tid) { stop_thread_timer(tid); tid = 0; } /* * We closed the device so let any plugin know we did. */ if (dcr) { generate_plugin_event(dcr->jcr, bsdEventDeviceClose, dcr); } bail_out: return retval; }