#include "stored.h"
/* Forward referenced functions */
+void set_os_device_parameters(DEVICE *dev);
/*
* Allocate and initialize the DEVICE structure
dev->state |= ST_OPENED;
dev->use_count = 1;
update_pos_dev(dev); /* update position */
+ set_os_device_parameters(dev); /* do system dependent stuff */
}
/* Stop any open() timer we started */
if (dev->tid) {
return -1;
}
archive_name = get_pool_memory(PM_FNAME);
- pm_strcpy(&archive_name, dev->dev_name);
+ pm_strcpy(archive_name, dev->dev_name);
if (archive_name[strlen(archive_name)] != '/') {
- pm_strcat(&archive_name, "/");
+ pm_strcat(archive_name, "/");
}
- pm_strcat(&archive_name, VolName);
+ pm_strcat(archive_name, VolName);
Dmsg1(29, "open_dev: device is disk %s\n", archive_name);
if (mode == OPEN_READ_WRITE) {
dev->mode = O_CREAT | O_RDWR | O_BINARY;
clrerror_dev(DEVICE *dev, int func)
{
const char *msg = NULL;
+ struct mtget mt_stat;
dev->dev_errno = errno; /* save errno */
if (errno == EIO) {
Emsg0(M_ERROR, 0, dev->errmsg);
}
}
+ /* On some systems such as NetBSD, this clears all errors */
+ ioctl(dev->fd, MTIOCGET, (char *)&mt_stat);
+
/* Found on Linux */
#ifdef MTIOCLRERR
{
ioctl(dev->fd, MTIOCERRSTAT, (char *)&mt_errstat);
}
#endif
+
+/* Clear Subsystem Exception OSF1 */
+#ifdef MTCSE
+{
+ struct mtop mt_com;
+ mt_com.mt_op = MTCSE;
+ mt_com.mt_count = 1;
+ /* Clear any error condition on the tape */
+ ioctl(dev->fd, MTIOCTOP, (char *)&mt_com);
+ Dmsg0(200, "Did MTCSE\n");
+}
+#endif
}
/*
}
}
-#ifdef xxxx
-/*
- * We attach a jcr to the device so that when
- * the Volume is full during writing, a
- * JobMedia record will be created for this
- * Job.
- */
-void attach_jcr_to_device(DEVICE *dev, JCR *jcr)
-{
- jcr->prev_dev = (JCR *)NULL;
- jcr->next_dev = dev->attached_jcrs;
- if (dev->attached_jcrs) {
- dev->attached_jcrs->prev_dev = jcr;
- }
- dev->attached_jcrs = jcr;
- Dmsg1(100, "Attached Job %s\n", jcr->Job);
-}
-
-void detach_jcr_from_device(DEVICE *dev, JCR *jcr)
-{
- if (!jcr->prev_dev) {
- dev->attached_jcrs = jcr->next_dev;
- } else {
- jcr->prev_dev->next_dev = jcr->next_dev;
- }
- if (jcr->next_dev) {
- jcr->next_dev->prev_dev = jcr->prev_dev;
- }
- jcr->next_dev = jcr->prev_dev = NULL;
- Dmsg1(100, "Detached Job %s\n", jcr->Job);
-}
-
-JCR *next_attached_jcr(DEVICE *dev, JCR *jcr)
-{
- if (jcr == (JCR *)NULL) {
- return dev->attached_jcrs;
- }
- return jcr->next_dev;
-}
-#endif
-
/*
* This routine initializes the device wait timers
*/
}
return true;
}
+
+void set_os_device_parameters(DEVICE *dev)
+{
+#ifdef HAVE_LINUX_OS
+ struct mtop mt_com;
+ if (dev->min_block_size == dev->max_block_size &&
+ dev->min_block_size == 0) { /* variable block mode */
+ mt_com.mt_op = MTSETBLK;
+ mt_com.mt_count = 0;
+ if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
+ clrerror_dev(dev, MTSETBLK);
+ }
+ mt_com.mt_op = MTSETDRVBUFFER;
+ mt_com.mt_count = MT_ST_CLEARBOOLEANS;
+ if (!dev_cap(dev, CAP_TWOEOF)) {
+ mt_com.mt_count |= MT_ST_TWO_FM;
+ }
+ if (dev_cap(dev, CAP_EOM)) {
+ mt_com.mt_count |= MT_ST_FAST_MTEOM;
+ }
+ if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
+ clrerror_dev(dev, MTSETBLK);
+ }
+ }
+ return;
+#endif
+
+#ifdef HAVE_NETBSD_OS
+ struct mtop mt_com;
+ if (dev->min_block_size == dev->max_block_size &&
+ dev->min_block_size == 0) { /* variable block mode */
+ mt_com.mt_op = MTSETBSIZ;
+ mt_com.mt_count = 0;
+ if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
+ clrerror_dev(dev, MTSETBSIZ);
+ }
+ /* Get notified at logical end of tape */
+ mt_com.mt_op = MTEWARN;
+ mt_com.mt_count = 1;
+ if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
+ clrerror_dev(dev, MTEWARN);
+ }
+ }
+ return;
+#endif
+
+#if HAVE_FREEBSD_OS || HAVE_OPENBSD_OS
+ struct mtop mt_com;
+ if (dev->min_block_size == dev->max_block_size &&
+ dev->min_block_size == 0) { /* variable block mode */
+ mt_com.mt_op = MTSETBSIZ;
+ mt_com.mt_count = 0;
+ if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
+ clrerror_dev(dev, MTSETBSIZ);
+ }
+ }
+ return;
+#endif
+
+#ifdef HAVE_SUN_OS
+ struct mtop mt_com;
+ if (dev->min_block_size == dev->max_block_size &&
+ dev->min_block_size == 0) { /* variable block mode */
+ mt_com.mt_op = MTSRSZ;
+ mt_com.mt_count = 0;
+ if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
+ clrerror_dev(dev, MTSRSZ);
+ }
+ }
+ return;
+#endif
+
+}