]> git.sur5r.net Git - bacula/bacula/commitdiff
- Update all the db update scripts to include the new multiple
authorKern Sibbald <kern@sibbald.com>
Fri, 15 Oct 2004 17:09:21 +0000 (17:09 +0000)
committerKern Sibbald <kern@sibbald.com>
Fri, 15 Oct 2004 17:09:21 +0000 (17:09 +0000)
  key index on File proposed by Martin, and to fix up a few
  minor things with PostgreSQL.
- Apply Christopher Hull's patch for getting the catalog correct
  during a restore.
- Created a patch for 1.34.6 (and code in 1.35) to detect passing
  the A option to the FD, which means enable ACL processing.
  Submitted by Ben Vitale.
- Fix empty files reported by Marin (zero file_size in dev.c).

git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1649 91ce42f0-d328-0410-95d8-f526ca767f89

14 files changed:
bacula/kernstodo
bacula/src/cats/make_mysql_tables.in
bacula/src/cats/make_postgresql_tables.in
bacula/src/cats/make_sqlite_tables.in
bacula/src/cats/sql_create.c
bacula/src/cats/update_mysql_tables.in
bacula/src/cats/update_postgresql_tables.in
bacula/src/cats/update_sqlite_tables.in
bacula/src/dird/ua_restore.c
bacula/src/dird/ua_run.c
bacula/src/filed/job.c
bacula/src/findlib/find.h
bacula/src/stored/bscan.c
bacula/src/stored/dev.c

index 0a9e2dc01d94dbb9e3afa866a0f474a035df3642..ef0aea25eb221b67df2ed2e46dd0ead7a0f55b60 100644 (file)
@@ -11,11 +11,8 @@ Version 1.35                Kern (see below)
 ========================================================
 
 1.35 Items to do for release:
-- Remove documentation for readline.
-- Add File indexes as suggested by Martin -- modify update
-  scripts to add them.
-- Modify postgresql update script to remove bigint FilenameId           
-  reference.
+- Finish recovering from a disaster situation.   
+  - How to get back a catalog.
   
 
 Maybe for 1.35:
@@ -29,6 +26,8 @@ Maybe for 1.35:
 - How to handle backing up portables ...
 - Add "Rerun failed levels = yes/no" to Job resource.
 - Add some sort of guaranteed Interval for upgrading jobs.
+- Can we write the state file after every job terminates? On Win32
+  the system crashes and the state file is not updated.
 
 Documentation to do: (any release a little bit at a time)
 - Doc to do unmount before removing magazine.
@@ -1376,3 +1375,9 @@ Block Position: 0
 - Document a get out of jail procedure if everything breaks if 
   you lost/broke the Catalog -- do the same for "I know my
   file is there how do I get it back?".
+- Fix documentation for readline.
+- Add File indexes as suggested by Martin -- modify update
+  scripts to add them.
+- Modify postgresql update script to remove bigint FilenameId           
+  reference.
+
index b51c33192ec31470eec17f274c6389d5c10913bc..e5da834bbb6f233cd8948d904d0215dd4ae035e9 100644 (file)
@@ -32,6 +32,9 @@ CREATE TABLE File (
    LStat TINYBLOB NOT NULL,
    MD5 TINYBLOB NOT NULL,
    PRIMARY KEY(FileId),
+   INDEX (JobId),
+   INDEX (PathId),
+   INDEX (FilenameId),
    INDEX (JobId, PathId, FilenameId),
    );
 
index 324a14f7827db198c3506431a9ab519da49c2b63..ae642022e252f16d9a5a23b8ef98c08f1d2d929b 100644 (file)
@@ -210,6 +210,9 @@ create table file
     primary key (fileid)
 );
 
+create index file_jobid_idx on file (jobid);
+create index file_pathid_idx on file(pathid);
+create index file_filenameid_idx on file(filenameid);
 create index file_jpfid_idx on file (jobid, pathid, filenameid);
 
 create table jobmedia
index 850b8f1efd54bd01300c72ba972881626f3b2b38..cc2acf219ccb8938945e7fe6fd479416c951aa7a 100644 (file)
@@ -35,7 +35,10 @@ CREATE TABLE File (
    PRIMARY KEY(FileId) 
    );
 
-CREATE INDEX inx3 ON File (JobId, PathId, FileNameId);
+CREATE INDEX inx3 ON File (JobId);
+CREATE INDEX inx4 ON File (PathId);
+CREATE INDEX inx5 ON File (FileNameId);
+CREATE INDEX inx9 ON File (JobId, PathId, FileNameId);
 
 CREATE TABLE Job (
    JobId INTEGER UNSIGNED NOT NULL,
index cc3078a8f89d15f8fb1a00a350e16dbedc5e43d7..61c9a6e2f1aad1e39e475d19f290493980d3a397 100644 (file)
@@ -242,8 +242,9 @@ db_create_media_record(JCR *jcr, B_DB *mdb, MEDIA_DBR *mr)
    Mmsg(mdb->cmd, 
 "INSERT INTO Media (VolumeName,MediaType,PoolId,MaxVolBytes,VolCapacityBytes," 
 "Recycle,VolRetention,VolUseDuration,MaxVolJobs,MaxVolFiles,"
-"VolStatus,Slot,VolBytes,InChanger,VolReadTime,VolWriteTime) "
-"VALUES ('%s','%s',%u,%s,%s,%d,%s,%s,%u,%u,'%s',%d,%s,%d,%s,%s)", 
+"VolStatus,Slot,VolBytes,InChanger,VolReadTime,VolWriteTime," 
+"EndFile,EndBlock "
+"VALUES ('%s','%s',%u,%s,%s,%d,%s,%s,%u,%u,'%s',%d,%s,%d,%s,%s,0,0)", 
                  mr->VolumeName,
                  mr->MediaType, mr->PoolId, 
                  edit_uint64(mr->MaxVolBytes,ed1),
index 380ba8b8b187b6bc23d44dcba636afa54889a81f..5adc8f50fa8587c393c944c894324e3ca3632d68 100755 (executable)
@@ -15,6 +15,8 @@ USE bacula;
 ALTER TABLE Media ADD COLUMN EndFile INTEGER UNSIGNED NOT NULL DEFAULT 0;
 ALTER TABLE Media ADD COLUMN EndBlock INTEGER UNSIGNED NOT NULL DEFAULT 0;
 
+ALTER TABLE File ADD INDEX (JobId, PathId, FilenameId);
+
 UPDATE Filename SET Name='' WHERE Name=' ';
 
 DELETE FROM Version;
index 0a42f018778555fd1ed607d6463152b2b1bae047..c3fe199811a9ffce11db3eebe8ee2b38374b2933 100755 (executable)
@@ -12,14 +12,25 @@ bindir=@SQL_BINDIR@
 if $bindir/psql $* -f - <<END-OF-DATA
 \c bacula
 
-ALTER TABLE Media ADD COLUMN EndFile integer not null default 0;
-ALTER TABLE Media ADD COLUMN EndBlock integer not null default 0;
+ALTER TABLE media ADD COLUMN EndFile integer;
+UPDATE media SET EndFile=0;
+ALTER TABLE media ALTER COLUMN EndFile SET NOT NULL;
+ALTER TABLE media ADD COLUMN EndBlock integer;
+UPDATE media SET EndBlock=0;
+ALTER TABLE media ALTER COLUMN EndBlock SET NOT NULL;
 
 UPDATE Filename SET Name='' WHERE Name=' ';
 
+ALTER TABLE file ALTER COLUMN filenameid SET integer;
+
 DELETE FROM Version;
 INSERT INTO Version (VersionId) VALUES (8);
 
+create index file_jobid_idx on file (jobid);
+create index file_pathid_idx on file(pathid);
+create index file_filenameid_idx on file(filenameid);
+create index file_jpfid_idx on file (jobid, pathid, filenameid);
+
 END-OF-DATA
 then
    echo "Update of Bacula PostgreSQL tables succeeded."
index ae6090a34411bb99950cff74ea2e3131296ad150..7d3610b0617bc53c24d57705a8a23902f9ed9b71 100755 (executable)
@@ -109,6 +109,8 @@ INSERT INTO Media (
 
 DROP TABLE Media_backup;
 
+CREATE INDEX inx9 ON File (JobId, PathId, FileNameId);
+
 COMMIT;
 
 UPDATE Filename SET Name='' WHERE Name=' ';
index 85e9e1001f340c52959c6960c3ed5d5cc11bcfc6..72e4c0e5998336ea51c627cac4494e37164fe4ce 100644 (file)
@@ -208,15 +208,15 @@ int restore_cmd(UAContext *ua, const char *cmd)
    if (rx.where) {
       Mmsg(ua->cmd, 
           "run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s/restore.bsr\""
-          " where=\"%s\" files=%d",
+          " where=\"%s\" files=%d catalog=\"%s\"",
           job->hdr.name, rx.ClientName, rx.store?rx.store->hdr.name:"",
-         working_directory, rx.where, rx.selected_files);
+         working_directory, rx.where, rx.selected_files, ua->catalog->hdr.name);
    } else {
       Mmsg(ua->cmd, 
           "run job=\"%s\" client=\"%s\" storage=\"%s\" bootstrap=\"%s/restore.bsr\""
-          " files=%d",
+          " files=%d catalog=\"%s\"",
           job->hdr.name, rx.ClientName, rx.store?rx.store->hdr.name:"",
-         working_directory, rx.selected_files);
+         working_directory, rx.selected_files, ua->catalog->hdr.name);
    }
    if (find_arg(ua, _("yes")) > 0) {
       pm_strcat(ua->cmd, " yes");    /* pass it on to the run command */
index 592cef898f8554915163205e548cdd9043710d9f..4cdb03f00a09bc02d4eebfb59ccdc07f21b27cdf 100644 (file)
@@ -49,7 +49,7 @@ int run_cmd(UAContext *ua, const char *cmd)
    char *job_name, *level_name, *jid, *store_name, *pool_name;
    char *where, *fileset_name, *client_name, *bootstrap;
    const char *replace;
-   char *when, *verify_job_name;
+   char *when, *verify_job_name, *catalog_name;
    int Priority = 0;
    int i, j, opt, files = 0;
    bool kw_ok;
@@ -77,6 +77,7 @@ int run_cmd(UAContext *ua, const char *cmd)
       N_("yes"),          /* 14 -- if you change this change YES_POS too */
       N_("verifyjob"),                /* 15 */
       N_("files"),                    /* 16 number of files to restore */
+       N_("catalog"),                 /* 17 override catalog */
       NULL};
 
 #define YES_POS 14
@@ -97,6 +98,7 @@ int run_cmd(UAContext *ua, const char *cmd)
    bootstrap = NULL;
    replace = NULL;
    verify_job_name = NULL;
+   catalog_name = NULL;
 
    for (i=1; i<ua->argc; i++) {
       Dmsg2(200, "Doing arg %d = %s\n", i, ua->argk[i]);
@@ -229,6 +231,11 @@ int run_cmd(UAContext *ua, const char *cmd)
               kw_ok = true;
               break;
 
+           case 17: /* catalog */
+              catalog_name = ua->argv[i];
+              kw_ok = true;
+              break;
+
            default:
               break;
            }
@@ -255,6 +262,15 @@ int run_cmd(UAContext *ua, const char *cmd)
             
    Dmsg0(200, "Done scan.\n");
 
+   CAT *catalog = NULL;
+   if (catalog_name != NULL) {
+       catalog = (CAT *)GetResWithName(R_CATALOG, catalog_name);
+       if (catalog == NULL) {
+            bsendmsg(ua, _("Catalog \"%s\" not found\n"), catalog_name);
+          return 1;
+       }
+   }
+
    if (job_name) {
       /* Find Job */
       job = (JOB *)GetResWithName(R_JOB, job_name);
@@ -375,6 +391,9 @@ int run_cmd(UAContext *ua, const char *cmd)
    jcr->fileset = fileset;
    jcr->pool = pool;
    jcr->ExpectedFiles = files;
+   if (catalog != NULL) {
+      jcr->catalog = catalog;
+   }
    if (where) {
       if (jcr->where) {
         free(jcr->where);
@@ -534,16 +553,17 @@ Priority:    %d\n"),
       jcr->JobLevel = L_FULL;     /* default level */
       Dmsg1(20, "JobId to restore=%d\n", jcr->RestoreJobId);
       if (jcr->RestoreJobId == 0) {
-         bsendmsg(ua, _("Run Restore job\n\
-JobName:    %s\n\
-Bootstrap:  %s\n\
-Where:      %s\n\
-Replace:    %s\n\
-FileSet:    %s\n\
-Client:     %s\n\
-Storage:    %s\n\
-When:       %s\n\
-Priority:   %d\n"),
+         bsendmsg(ua, _("Run Restore job\n"
+                        "JobName:    %s\n"
+                        "Bootstrap:  %s\n"
+                        "Where:      %s\n"
+                        "Replace:    %s\n"
+                        "FileSet:    %s\n"
+                        "Client:     %s\n"
+                        "Storage:    %s\n"
+                        "When:       %s\n"
+                        "Catalog:    %s\n"
+                        "Priority:   %d\n"),
              job->hdr.name,
              NPRT(jcr->RestoreBootstrap),
              jcr->where?jcr->where:NPRT(job->RestoreWhere),
@@ -552,18 +572,21 @@ Priority:   %d\n"),
              jcr->client->hdr.name,
              jcr->store->hdr.name, 
              bstrutime(dt, sizeof(dt), jcr->sched_time),
+             jcr->catalog->hdr.name,
              jcr->JobPriority);
       } else {
-         bsendmsg(ua, _("Run Restore job\n\
-JobName:    %s\n\
-Bootstrap:  %s\n\
-Where:      %s\n\
-Replace:    %s\n\
-Client:     %s\n\
-Storage:    %s\n\
-JobId:      %s\n\
-When:       %s\n\
-Priority:   %d\n"),
+         bsendmsg(ua, _("Run Restore job\n"
+                       "JobName:    %s\n"
+                       "Bootstrap:  %s\n"
+                       "Where:      %s\n"
+                       "Replace:    %s\n"
+                       "FileSet:    %s\n"
+                       "Client:     %s\n"
+                       "Storage:    %s\n"
+                       "JobId:      %s\n"
+                       "When:       %s\n"
+                       "Catalog:    %s\n"
+                       "Priority:   %d\n"),
              job->hdr.name,
              NPRT(jcr->RestoreBootstrap),
              jcr->where?jcr->where:NPRT(job->RestoreWhere),
@@ -572,6 +595,7 @@ Priority:   %d\n"),
              jcr->store->hdr.name, 
               jcr->RestoreJobId==0?"*None*":edit_uint64(jcr->RestoreJobId, ec1), 
              bstrutime(dt, sizeof(dt), jcr->sched_time),
+             jcr->catalog->hdr.name,
              jcr->JobPriority);
       }
       break;
index 465ab44c428274c4d615c902a1e7cae334d866c0..9733e0b53713a488662d2da5b678b861d6a5630b 100644 (file)
@@ -885,6 +885,9 @@ static void set_options(findFOPTS *fo, const char *opts)
       case 'k':
         fo->flags |= FO_KEEPATIME;
         break;
+      case 'A':
+        fo->flags |= FO_ACL;
+        break;
       case 'V':                  /* verify options */
         /* Copy Verify Options */
          for (j=0; *p && *p != ':'; p++) {
index 5ca69c57973392fb81348bc3ba2ad069e616462b..dcd438f7bd5988280a554967b3bf2511f5205704 100755 (executable)
@@ -90,7 +90,7 @@ enum {
 #define FO_MTIMEONLY    (1<<11)       /* Use mtime rather than mtime & ctime */
 #define FO_KEEPATIME    (1<<12)       /* Reset access time */
 #define FO_EXCLUDE      (1<<13)       /* Exclude file */
-#define FO_ACL          (1<<14)         /* Backup ACLs */
+#define FO_ACL          (1<<14)       /* Backup ACLs */
 
 struct s_included_file {
    struct s_included_file *next;
index 969c99e83ec81d96896ce44ea667cf8eee3656c7..3a78a0ed2307c3a19a3f03bdeec1a92b913826c3 100644 (file)
@@ -275,7 +275,7 @@ int main (int argc, char *argv[])
    }
 
    do_scan();
-   printf("Records %sadded to catalog:\n%7d Media\n%7d Pool\n%7d Job\n%7d File\n",
+   printf("Records %sadded or updated in the catalog:\n%7d Media\n%7d Pool\n%7d Job\n%7d File\n",
       update_db?"":"would have been ",
       num_media, num_pools, num_jobs, num_files);
 
@@ -1209,4 +1209,3 @@ bool dir_ask_sysop_to_mount_volume(DCR *dcr)
    getchar();  
    return true;
 }
-
index d38c0a3b14bbb276f8f03300ed9cf6f8a031d4ff..d3b36be61adc7c7c3ae7f1c8b25a4c5a856ddc0c 100644 (file)
@@ -254,6 +254,7 @@ open_dev(DEVICE *dev, char *VolName, int mode)
    Dmsg3(29, "open_dev: tape=%d dev_name=%s vol=%s\n", dev_is_tape(dev), 
         dev->dev_name, dev->VolCatInfo.VolCatName);
    dev->state &= ~(ST_LABEL|ST_APPEND|ST_READ|ST_EOT|ST_WEOT|ST_EOF);
+   dev->file_size = 0;
    if (dev->state & (ST_TAPE|ST_FIFO)) {
       int timeout;
       Dmsg0(29, "open_dev: device is tape\n");
@@ -274,17 +275,18 @@ open_dev(DEVICE *dev, char *VolName, int mode)
       }
       /* If busy retry each second for max_open_wait seconds */
       while ((dev->fd = open(dev->dev_name, dev->mode, MODE_RW)) < 0) {
+        berrno be;
         if (errno == EINTR || errno == EAGAIN) {
            continue;
         }
         if (errno == EBUSY && timeout-- > 0) {
-            Dmsg2(100, "Device %s busy. ERR=%s\n", dev->dev_name, strerror(errno));
+            Dmsg2(100, "Device %s busy. ERR=%s\n", dev->dev_name, be.strerror());
            bmicrosleep(1, 0);
            continue;
         }
         dev->dev_errno = errno;
          Mmsg2(&dev->errmsg, _("stored: unable to open device %s: ERR=%s\n"), 
-              dev->dev_name, strerror(dev->dev_errno));
+              dev->dev_name, be.strerror());
         /* Stop any open timer we set */
         if (dev->tid) {
            stop_thread_timer(dev->tid);
@@ -333,8 +335,9 @@ open_dev(DEVICE *dev, char *VolName, int mode)
       }
       /* If creating file, give 0640 permissions */
       if ((dev->fd = open(archive_name, dev->mode, 0640)) < 0) {
+        berrno be;
         dev->dev_errno = errno;
-         Mmsg2(&dev->errmsg, _("Could not open: %s, ERR=%s\n"), archive_name, strerror(dev->dev_errno));
+         Mmsg2(&dev->errmsg, _("Could not open: %s, ERR=%s\n"), archive_name, be.strerror());
         Emsg0(M_FATAL, 0, dev->errmsg);
       } else {
         dev->dev_errno = 0;
@@ -378,6 +381,7 @@ bool rewind_dev(DEVICE *dev)
    }
    dev->state &= ~(ST_EOT|ST_EOF|ST_WEOT);  /* remove EOF/EOT flags */
    dev->block_num = dev->file = 0;
+   dev->file_size = 0;
    dev->file_addr = 0;
    if (dev->state & ST_TAPE) {
       mt_com.mt_op = MTREW;
@@ -389,17 +393,17 @@ bool rewind_dev(DEVICE *dev)
       for (i=dev->max_rewind_wait; ; i -= 5) {
         if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) {
            berrno be;
+           clrerror_dev(dev, MTREW);
            if (i == dev->max_rewind_wait) {
-               Dmsg1(200, "Rewind error, %s. retrying ...\n", strerror(errno));
+               Dmsg1(200, "Rewind error, %s. retrying ...\n", be.strerror());
            }
-           clrerror_dev(dev, MTREW);
            if (dev->dev_errno == EIO && i > 0) {
                Dmsg0(200, "Sleeping 5 seconds.\n");
               bmicrosleep(5, 0);
               continue;
            }
             Mmsg2(&dev->errmsg, _("Rewind error on %s. ERR=%s.\n"),
-              dev->dev_name, be.strerror(dev->dev_errno));
+              dev->dev_name, be.strerror());
            return false;
         }
         break;
@@ -409,7 +413,7 @@ bool rewind_dev(DEVICE *dev)
         berrno be;
         dev->dev_errno = errno;
          Mmsg2(&dev->errmsg, _("lseek error on %s. ERR=%s.\n"),
-           dev->dev_name, be.strerror(dev->dev_errno));
+           dev->dev_name, be.strerror());
         return false;
       }
    }
@@ -435,6 +439,7 @@ eod_dev(DEVICE *dev)
    }
    dev->state &= ~(ST_EOF);  /* remove EOF flags */
    dev->block_num = dev->file = 0;
+   dev->file_size = 0;
    dev->file_addr = 0;
    if (dev->state & (ST_FIFO | ST_PROG)) {
       return 1;
@@ -450,7 +455,7 @@ eod_dev(DEVICE *dev)
       dev->dev_errno = errno;
       berrno be;
       Mmsg2(&dev->errmsg, _("lseek error on %s. ERR=%s.\n"),
-            dev->dev_name, be.strerror(dev->dev_errno));
+            dev->dev_name, be.strerror());
       return 0;
    }
 #ifdef MTEOM
@@ -483,10 +488,10 @@ eod_dev(DEVICE *dev)
       if ((stat=ioctl(dev->fd, MTIOCTOP, (char *)&mt_com)) < 0) {
         berrno be;
         clrerror_dev(dev, mt_com.mt_op);
-         Dmsg1(50, "ioctl error: %s\n", be.strerror(dev->dev_errno));
+         Dmsg1(50, "ioctl error: %s\n", be.strerror());
         update_pos_dev(dev);
          Mmsg2(&dev->errmsg, _("ioctl MTEOM error on %s. ERR=%s.\n"),
-           dev->dev_name, be.strerror(dev->dev_errno));
+           dev->dev_name, be.strerror());
         return 0;
       }
 
@@ -494,7 +499,7 @@ eod_dev(DEVICE *dev)
         berrno be;
         clrerror_dev(dev, -1);
          Mmsg2(&dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"),
-           dev->dev_name, be.strerror(dev->dev_errno));
+           dev->dev_name, be.strerror());
         return 0;
       }
       Dmsg2(100, "EOD file=%d block=%d\n", mt_stat.mt_fileno, mt_stat.mt_blkno);
@@ -585,10 +590,11 @@ bool update_pos_dev(DEVICE *dev)
       dev->file_addr = 0;
       pos = lseek(dev->fd, (off_t)0, SEEK_CUR);
       if (pos < 0) {
-         Pmsg1(000, "Seek error: ERR=%s\n", strerror(dev->dev_errno));
+        berrno be;
         dev->dev_errno = errno;
+         Pmsg1(000, "Seek error: ERR=%s\n", be.strerror());
          Mmsg2(&dev->errmsg, _("lseek error on %s. ERR=%s.\n"),
-           dev->dev_name, strerror(dev->dev_errno));
+           dev->dev_name, be.strerror());
         ok = false;
       } else {
         dev->file_addr = pos;
@@ -628,7 +634,7 @@ uint32_t status_dev(DEVICE *dev)
         berrno be;
         dev->dev_errno = errno;
          Mmsg2(&dev->errmsg, _("ioctl MTIOCGET error on %s. ERR=%s.\n"),
-           dev->dev_name, be.strerror(dev->dev_errno));
+           dev->dev_name, be.strerror());
         return 0;
       }
       Dmsg0(-20, " Device status:");
@@ -704,11 +710,12 @@ bool load_dev(DEVICE *dev)
    berrno be;
    dev->dev_errno = ENOTTY;          /* function not available */
    Mmsg2(&dev->errmsg, _("ioctl MTLOAD error on %s. ERR=%s.\n"),
-        dev->dev_name, be.strerror(dev->dev_errno));      return 0;
+        dev->dev_name, be.strerror());
    return false;
 #else
 
    dev->block_num = dev->file = 0;
+   dev->file_size = 0;
    dev->file_addr = 0;
    mt_com.mt_op = MTLOAD;
    mt_com.mt_count = 1;
@@ -716,7 +723,7 @@ bool load_dev(DEVICE *dev)
       berrno be;
       dev->dev_errno = errno;
       Mmsg2(&dev->errmsg, _("ioctl MTLOAD error on %s. ERR=%s.\n"),
-        dev->dev_name, be.strerror(dev->dev_errno));      return 0;
+        dev->dev_name, be.strerror());
       return false;
    }
    return true;
@@ -744,6 +751,7 @@ bool offline_dev(DEVICE *dev)
 
    dev->state &= ~(ST_APPEND|ST_READ|ST_EOT|ST_EOF|ST_WEOT);  /* remove EOF/EOT flags */
    dev->block_num = dev->file = 0;
+   dev->file_size = 0;
    dev->file_addr = 0;
 #ifdef MTUNLOCK
    mt_com.mt_op = MTUNLOCK;
@@ -756,7 +764,7 @@ bool offline_dev(DEVICE *dev)
       berrno be;
       dev->dev_errno = errno;
       Mmsg2(&dev->errmsg, _("ioctl MTOFFL error on %s. ERR=%s.\n"),
-        dev->dev_name, be.strerror(dev->dev_errno));
+        dev->dev_name, be.strerror());
       return false;
    }
    Dmsg1(100, "Offlined device %s\n", dev->dev_name);
@@ -841,6 +849,7 @@ fsf_dev(DEVICE *dev, int num)
       dev->file = mt_stat.mt_fileno;
       dev->state |= ST_EOF;    /* just read EOF */
       dev->file_addr = 0;
+      dev->file_size = 0;
       return true;
 
    /* 
@@ -874,7 +883,7 @@ fsf_dev(DEVICE *dev, int num)
                Dmsg2(200, "Set ST_EOT read errno=%d. ERR=%s\n", dev->dev_errno,
                  be.strerror());
                Mmsg2(dev->errmsg, _("read error on %s. ERR=%s.\n"),
-                 dev->dev_name, be.strerror(dev->dev_errno));
+                 dev->dev_name, be.strerror());
                Dmsg1(200, "%s", dev->errmsg);
               break;
            }
@@ -891,6 +900,7 @@ fsf_dev(DEVICE *dev, int num)
               dev->state |= ST_EOF;
               dev->file++;
               dev->file_addr = 0;
+              dev->file_size = 0;
               continue;
            }
         } else {                        /* Got data */
@@ -905,13 +915,14 @@ fsf_dev(DEVICE *dev, int num)
             Dmsg0(200, "Set ST_EOT\n");
            clrerror_dev(dev, MTFSF);
             Mmsg2(&dev->errmsg, _("ioctl MTFSF error on %s. ERR=%s.\n"),
-              dev->dev_name, be.strerror(dev->dev_errno));
+              dev->dev_name, be.strerror());
             Dmsg0(200, "Got < 0 for MTFSF\n");
             Dmsg1(200, "%s", dev->errmsg);
         } else {
            dev->state |= ST_EOF;     /* just read EOF */
            dev->file++;
            dev->file_addr = 0;
+           dev->file_size = 0;
         }   
       }
       free_memory(rbuf);
@@ -969,6 +980,7 @@ bsf_dev(DEVICE *dev, int num)
    dev->state &= ~(ST_EOT|ST_EOF);
    dev->file -= num;
    dev->file_addr = 0;
+   dev->file_size = 0;
    mt_com.mt_op = MTBSF;
    mt_com.mt_count = num;
    stat = ioctl(dev->fd, MTIOCTOP, (char *)&mt_com);
@@ -976,7 +988,7 @@ bsf_dev(DEVICE *dev, int num)
       berrno be;
       clrerror_dev(dev, MTBSF);
       Mmsg2(dev->errmsg, _("ioctl MTBSF error on %s. ERR=%s.\n"),
-        dev->dev_name, be.strerror(dev->dev_errno));
+        dev->dev_name, be.strerror());
    }
    update_pos_dev(dev);
    return stat == 0;
@@ -1034,10 +1046,11 @@ fsr_dev(DEVICE *dev, int num)
            dev->file++;
            dev->block_num = 0;
            dev->file_addr = 0;
+           dev->file_size = 0;
         }
       }
       Mmsg2(dev->errmsg, _("ioctl MTFSR error on %s. ERR=%s.\n"),
-        dev->dev_name, be.strerror(dev->dev_errno));
+        dev->dev_name, be.strerror());
    }
    update_pos_dev(dev);
    return stat == 0;
@@ -1080,7 +1093,7 @@ bsr_dev(DEVICE *dev, int num)
       berrno be;
       clrerror_dev(dev, MTBSR);
       Mmsg2(dev->errmsg, _("ioctl MTBSR error on %s. ERR=%s.\n"),
-        dev->dev_name, be.strerror(dev->dev_errno));
+        dev->dev_name, be.strerror());
    }
    update_pos_dev(dev);
    return stat == 0;
@@ -1105,9 +1118,10 @@ reposition_dev(DEVICE *dev, uint32_t file, uint32_t block)
       off_t pos = (((off_t)file)<<32) + block;
       Dmsg1(100, "===== lseek to %d\n", (int)pos);
       if (lseek(dev->fd, pos, SEEK_SET) == (off_t)-1) {
+        berrno be;
         dev->dev_errno = errno;
          Mmsg2(dev->errmsg, _("lseek error on %s. ERR=%s.\n"),
-           dev->dev_name, strerror(dev->dev_errno));
+           dev->dev_name, be.strerror());
         return false;
       }
       dev->file = file;
@@ -1160,6 +1174,7 @@ weof_dev(DEVICE *dev, int num)
       Emsg0(M_FATAL, 0, dev->errmsg);
       return -1;
    }
+   dev->file_size = 0;
 
    if (!(dev_state(dev, ST_TAPE))) {
       return 0;
@@ -1315,6 +1330,7 @@ static void do_close(DEVICE *dev)
    dev->fd = -1;
    dev->state &= ~(ST_OPENED|ST_LABEL|ST_READ|ST_APPEND|ST_EOT|ST_WEOT|ST_EOF);
    dev->file = dev->block_num = 0;
+   dev->file_size = 0;
    dev->file_addr = 0;
    dev->EndFile = dev->EndBlock = 0;
    memset(&dev->VolCatInfo, 0, sizeof(dev->VolCatInfo));
@@ -1373,7 +1389,8 @@ bool truncate_dev(DEVICE *dev)
       /* maybe we should rewind and write and eof ???? */
    }
    if (ftruncate(dev->fd, 0) != 0) {
-      Mmsg1(&dev->errmsg, _("Unable to truncate device. ERR=%s\n"), strerror(errno));
+      berrno be;
+      Mmsg1(&dev->errmsg, _("Unable to truncate device. ERR=%s\n"), be.strerror());
       return false;
    }
    return true;
@@ -1567,5 +1584,4 @@ void set_os_device_parameters(DEVICE *dev)
    }
    return;
 #endif
-
 }