]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Add pseudo WORM support for vtape
authorEric Bollengier <eric@baculasystems.com>
Fri, 9 Nov 2018 14:02:09 +0000 (15:02 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 10 Nov 2018 09:36:58 +0000 (10:36 +0100)
vtape will refuse to write if not at the end of the volume

bacula/src/stored/vtape_dev.c

index bdf880eb95958a1d5a0e263f5abb2ac8342bc14c..9cf182bd3d8f34a9181c673347e18627927906c9 100644 (file)
@@ -385,7 +385,7 @@ ssize_t vtape::d_write(int, const void *buffer, size_t count)
    ASSERT(buffer);
 
    ssize_t nb;
-   Dmsg3(dbglevel*2, "write len=%i %i:%i\n",
+   Dmsg3(0, "write len=%i %i:%i\n",
          count, current_file,current_block);
 
    if (atEOT) {
@@ -394,6 +394,22 @@ ssize_t vtape::d_write(int, const void *buffer, size_t count)
       return -1;
    }
 
+   if (m_is_worm) {
+      /* The start of the vtape volume has a WEOF */
+      int64_t size = ::lseek(fd, 0, SEEK_END);
+      if (size < 100) {
+         size = 0;
+      }
+      int64_t pos = DEVICE::get_full_addr(current_file, current_block);
+      if ( pos < size ) {
+         Dmsg2(0, "WORM detected. Cannot write at %lld with current size at %lld\n", pos, size -20);
+         errno = EIO;
+         return -1;
+      }
+   } else {
+      Dmsg0(0, "Not worm!\n");
+   }
+
    if (!atEOD) {                /* if not at the end of the data */
       truncate_file();
    }