From 488a484b4fb8b6820208d6734b280b9607f2e127 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 15 Oct 2004 17:09:21 +0000 Subject: [PATCH] - Update all the db update scripts to include the new multiple 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 --- bacula/kernstodo | 15 +++-- bacula/src/cats/make_mysql_tables.in | 3 + bacula/src/cats/make_postgresql_tables.in | 3 + bacula/src/cats/make_sqlite_tables.in | 5 +- bacula/src/cats/sql_create.c | 5 +- bacula/src/cats/update_mysql_tables.in | 2 + bacula/src/cats/update_postgresql_tables.in | 15 ++++- bacula/src/cats/update_sqlite_tables.in | 2 + bacula/src/dird/ua_restore.c | 8 +-- bacula/src/dird/ua_run.c | 66 ++++++++++++++------- bacula/src/filed/job.c | 3 + bacula/src/findlib/find.h | 2 +- bacula/src/stored/bscan.c | 3 +- bacula/src/stored/dev.c | 66 +++++++++++++-------- 14 files changed, 135 insertions(+), 63 deletions(-) diff --git a/bacula/kernstodo b/bacula/kernstodo index 0a9e2dc01d..ef0aea25eb 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -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. + diff --git a/bacula/src/cats/make_mysql_tables.in b/bacula/src/cats/make_mysql_tables.in index b51c33192e..e5da834bbb 100644 --- a/bacula/src/cats/make_mysql_tables.in +++ b/bacula/src/cats/make_mysql_tables.in @@ -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), ); diff --git a/bacula/src/cats/make_postgresql_tables.in b/bacula/src/cats/make_postgresql_tables.in index 324a14f782..ae642022e2 100644 --- a/bacula/src/cats/make_postgresql_tables.in +++ b/bacula/src/cats/make_postgresql_tables.in @@ -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 diff --git a/bacula/src/cats/make_sqlite_tables.in b/bacula/src/cats/make_sqlite_tables.in index 850b8f1efd..cc2acf219c 100644 --- a/bacula/src/cats/make_sqlite_tables.in +++ b/bacula/src/cats/make_sqlite_tables.in @@ -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, diff --git a/bacula/src/cats/sql_create.c b/bacula/src/cats/sql_create.c index cc3078a8f8..61c9a6e2f1 100644 --- a/bacula/src/cats/sql_create.c +++ b/bacula/src/cats/sql_create.c @@ -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), diff --git a/bacula/src/cats/update_mysql_tables.in b/bacula/src/cats/update_mysql_tables.in index 380ba8b8b1..5adc8f50fa 100755 --- a/bacula/src/cats/update_mysql_tables.in +++ b/bacula/src/cats/update_mysql_tables.in @@ -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; diff --git a/bacula/src/cats/update_postgresql_tables.in b/bacula/src/cats/update_postgresql_tables.in index 0a42f01877..c3fe199811 100755 --- a/bacula/src/cats/update_postgresql_tables.in +++ b/bacula/src/cats/update_postgresql_tables.in @@ -12,14 +12,25 @@ bindir=@SQL_BINDIR@ if $bindir/psql $* -f - <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 */ diff --git a/bacula/src/dird/ua_run.c b/bacula/src/dird/ua_run.c index 592cef898f..4cdb03f00a 100644 --- a/bacula/src/dird/ua_run.c +++ b/bacula/src/dird/ua_run.c @@ -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; iargc; 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; diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index 465ab44c42..9733e0b537 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -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++) { diff --git a/bacula/src/findlib/find.h b/bacula/src/findlib/find.h index 5ca69c5797..dcd438f7bd 100755 --- a/bacula/src/findlib/find.h +++ b/bacula/src/findlib/find.h @@ -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; diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index 969c99e83e..3a78a0ed23 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -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; } - diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index d38c0a3b14..d3b36be61a 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -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 - } -- 2.39.2