From: Kern Sibbald Date: Sat, 16 Aug 2003 17:31:50 +0000 (+0000) Subject: Do MTIOCERRSTAT after weof on FreeBSD X-Git-Tag: Release-1.32~51 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7a01aa2757da7bbdd36c09b9b8704eebbd0582ab;p=bacula%2Fbacula Do MTIOCERRSTAT after weof on FreeBSD git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@668 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index 50a7cfa955..ca96d6d394 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -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;