]> git.sur5r.net Git - bacula/bacula/commitdiff
Do MTIOCERRSTAT after weof on FreeBSD
authorKern Sibbald <kern@sibbald.com>
Sat, 16 Aug 2003 17:31:50 +0000 (17:31 +0000)
committerKern Sibbald <kern@sibbald.com>
Sat, 16 Aug 2003 17:31:50 +0000 (17:31 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@668 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/stored/block.c

index 50a7cfa95506334f84738f557e1cf994bccb6121..ca96d6d3943c1fff30a146b59636a78e5b68bf3e 100644 (file)
@@ -405,7 +405,18 @@ int write_block_to_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
        * simulate an End of Medium.
        */
       if (stat == -1) {
+        /* I have added the ifdefing here because it appears on
+         * FreeBSD where MTIOCERRSTAT is defined, this not only
+         * clears the error but clears the residual unwritten
+         * buffers -> data loss. As a consequence, on those
+         * systems (FreeBSD like), do the clrerror() only after
+         * the weof_dev() call.
+         */
+#ifndef MTIOCERRSTAT
         clrerror_dev(dev, -1);
+#else
+        dev->dev_errno = errno;      /* save errno */
+#endif
         if (dev->dev_errno == 0) {
            dev->dev_errno = ENOSPC;        /* out of space */
         }
@@ -423,6 +434,9 @@ int write_block_to_dev(JCR *jcr, DEVICE *dev, DEV_BLOCK *block)
       block->write_failed = true;
       weof_dev(dev, 1);              /* end the tape */
       weof_dev(dev, 1);              /* write second eof */
+#ifdef MTIOCERRSTAT
+      clrerror_dev(dev, -1);
+#endif
       dev->state |= (ST_EOF | ST_EOT | ST_WEOT);
        
       ok = TRUE;