---- src/stored/faketape.c (revision 7097)
-+++ src/stored/faketape.c (working copy)
-@@ -170,6 +170,7 @@
- int faketape::tape_op(struct mtop *mt_com)
- {
- int result=0;
-+ int count = mt_com->mt_count;
-
- if (!online) {
- errno = ENOMEDIUM;
-@@ -193,11 +194,15 @@
- break;
-
- case MTFSF: /* Forward space over mt_count filemarks. */
-- result = fsf(mt_com->mt_count);
-+ do {
-+ result = fsf();
-+ } while (--count > 0 && result == 0);
- break;
-
- case MTBSF: /* Backward space over mt_count filemarks. */
-- result = bsf(mt_com->mt_count);
-+ do {
-+ result = bsf();
-+ } while (--count > 0 && result == 0);
- break;
-
- case MTFSR: /* Forward space over mt_count records (tape blocks). */
-@@ -222,16 +227,20 @@
- break;
-
- case MTWEOF: /* Write mt_count filemarks. */
-- result = weof(mt_com->mt_count);
-+ do {
-+ result = weof();
-+ } while (result == 0 && --count > 0);
- break;
-
- case MTREW: /* Rewind. */
- Dmsg0(dbglevel, "rewind faketape\n");
-+ check_eof();
- atEOF = atEOD = false;
- atBOT = true;
- current_file = 0;
- current_block = 0;
-- seek_file();
-+ lseek(fd, 0, SEEK_SET);
-+ read_next_fm(true);
- break;
-
- case MTOFFL: /* put tape offline */
-@@ -253,19 +262,30 @@
- break;
-
- case MTEOM:/* Go to the end of the recorded media (for appending files). */
-+ while (next_FM) {
-+ lseek(fd, next_FM, SEEK_SET);
-+ if (read_next_fm(true)) {
-+ current_file++;
-+ }
-+ }
-+ off_t l;
-+ while (::read(fd, &l, sizeof(l)) > 0) {
-+ if (l) {
-+ lseek(fd, l, SEEK_CUR);
-+ } else {
-+ ASSERT(0);
-+ }
-+ Dmsg0(dbglevel, "skip 1 block\n");
-+ }
-+ current_block = -1;
-+ atEOF = false;
-+ atEOD = true;
-+
- /*
- file number = 3
- block number = -1
- */
- /* Can be at EOM */
-- atBOT = false;
-- atEOF = false;
-- atEOD = true;
-- atEOT = false;
--
-- current_file = last_file;
-- current_block = -1;
-- seek_file();
- break;
-
- case MTERASE: /* not used by bacula */
-@@ -275,7 +295,8 @@
-
- current_file = 0;
- current_block = -1;
-- seek_file();
-+ lseek(fd, 0, SEEK_SET);
-+ read_next_fm(true);
- truncate_file();
- break;
-
-@@ -405,8 +426,8 @@
- atEOT = false;
- atEOD = false;
- online = false;
-- inplace = false;
- needEOF = false;
-+ eot_count = 0;
-
- file_block = 0;
- last_file = 0;
-@@ -444,8 +465,6 @@
- return -1;
- }
-
-- check_inplace();
--
- if (!atEOD) { /* if not at the end of the data */
- truncate_file();
- }
-@@ -460,14 +479,6 @@
-
- needEOF = true; /* next operation need EOF mark */
-
--// if ((count + file_size) > max_size) {
--// Dmsg2(dbglevel,
--// "EOT writing only %i of %i requested\n",
--// max_size - file_size, count);
--// count = max_size - file_size;
--// atEOT = true;
--// }
--
- uint32_t size = count;
- ::write(fd, &size, sizeof(uint32_t));
- nb = ::write(fd, buffer, count);
-@@ -484,43 +495,67 @@
- return nb;
- }
-
--int faketape::weof(int count)
-+/*
-+ * +---+---------+---+------------------+---+-------------------+
-+ * |00N| DATA |0LN| DATA |0LC| DATA |
-+ * +---+---------+---+------------------+---+-------------------+
-+ *
-+ * 0 : zero
-+ * L : Last FileMark offset
-+ * N : Next FileMark offset
-+ * C : Current FileMark Offset
-+ */
-+int faketape::weof()
- {
- ASSERT(online);
- ASSERT(current_file >= 0);
- Dmsg3(dbglevel, "Writing EOF %i:%i last=%i\n",
- current_file, current_block,last_file);
-+
-+ off_t cur_FM;
-+
- if (atEOT) {
- errno = ENOSPC;
- current_block = -1;
- return -1;
- }
-- needEOF = false;
-
-- check_inplace();
-- truncate_file(); /* nothing after this point */
-+ if (!atEOD) {
-+ truncate_file(); /* nothing after this point */
-+ }
-+
-+ cur_FM = lseek(fd, 0, SEEK_CUR); // current position
-
-+ /* update previous next_FM */
-+ lseek(fd, last_FM + sizeof(uint32_t)+sizeof(off_t), SEEK_SET);
-+ ::write(fd, &cur_FM, sizeof(off_t));
-+ lseek(fd, cur_FM, SEEK_SET);
-+
-+ last_FM = cur_FM;
-+ next_FM = 0;
-+
- uint32_t c=0;
-- ::write(fd, &c, sizeof(uint32_t));
-+ ::write(fd, &c, sizeof(uint32_t)); // EOF
-+ ::write(fd, &last_FM, sizeof(last_FM)); // F-1
-+ ::write(fd, &next_FM, sizeof(next_FM)); // F (will be updated next time)
-
-- current_file += count;
-+ current_file++;
- current_block = 0;
-- seek_file();
-
-- c=0;
-- ::write(fd, &c, sizeof(uint32_t));
-- lseek(fd, lseek(fd, 0, SEEK_CUR) - sizeof(uint32_t), SEEK_SET);
+--- src/baconfig.h (revision 7116)
++++ src/baconfig.h (working copy)
+@@ -86,12 +86,6 @@
+ void InitWinAPIWrapper();
+
+ #define OSDependentInit() InitWinAPIWrapper()
+-#define tape_open win32_tape_open
+-#define tape_ioctl win32_tape_ioctl
+-#define tape_read win32_tape_read
+-#define tape_write win32_tape_write
+-#define tape_close win32_tape_close
+-#define IS_TAPE(x) S_ISCHR(x)
+
+ #define sbrk(x) 0
+
+@@ -117,22 +111,6 @@
+
+ #define OSDependentInit()
+
+-#if defined(USE_FAKETAPE)
+-# define tape_open faketape_open
+-# define tape_ioctl faketape_ioctl
+-# define tape_read faketape_read
+-# define tape_write faketape_write
+-# define tape_close faketape_close
+-# define IS_TAPE(x) S_ISREG(x)
+-#else /* UNIX && !FAKETAPE */
+-# define tape_open ::open
+-# define tape_ioctl ::ioctl
+-# define tape_read ::read
+-# define tape_write ::write
+-# define tape_close ::close
+-# define IS_TAPE(x) S_ISCHR(x)
+-#endif