]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/btape.c
Add mac.c file
[bacula/bacula] / bacula / src / stored / btape.c
index dd73797be5533115b5e70d0f8ada746e0d9dfbe0..aca4acc047fd7579ddf994d5ac47f3052401231d 100644 (file)
@@ -14,7 +14,7 @@
  *
  */
 /*
-   Copyright (C) 2000-2005 Kern Sibbald
+   Copyright (C) 2000-2006 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
@@ -328,14 +328,12 @@ static bool open_the_device()
 
    block = new_block(dev);
    lock_device(dev);
-   if (!dev->is_open()) {
-      Dmsg1(200, "Opening device %s\n", dcr->VolumeName);
-      if (dev->open(dcr, OPEN_READ_WRITE) < 0) {
-         Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg);
-         unlock_device(dev);
-         free_block(block);
-         return false;
-      }
+   Dmsg1(200, "Opening device %s\n", dcr->VolumeName);
+   if (dev->open(dcr, OPEN_READ_WRITE) < 0) {
+      Emsg1(M_FATAL, 0, _("dev open failed: %s\n"), dev->errmsg);
+      unlock_device(dev);
+      free_block(block);
+      return false;
    }
    Pmsg1(000, _("open device %s: OK\n"), dev->print_name());
    dev->set_append();                 /* put volume in append mode */
@@ -368,7 +366,7 @@ static void labelcmd()
          Pmsg1(0, _("Device open failed. ERR=%s\n"), strerror_dev(dev));
       }
    }
-   rewind_dev(dev);
+   dev->rewind(dcr);
    write_new_volume_label_to_dev(dcr, cmd, "Default");
    Pmsg1(-1, _("Wrote Volume label for volume \"%s\".\n"), cmd);
 }
@@ -433,7 +431,7 @@ static void loadcmd()
  */
 static void rewindcmd()
 {
-   if (!rewind_dev(dev)) {
+   if (!dev->rewind(dcr)) {
       Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), strerror_dev(dev));
       clrerror_dev(dev, -1);
    } else {
@@ -485,7 +483,7 @@ static void weofcmd()
  */
 static void eomcmd()
 {
-   if (!eod_dev(dev)) {
+   if (!dev->eod()) {
       Pmsg1(0, "%s", strerror_dev(dev));
       return;
    } else {
@@ -515,7 +513,7 @@ static void bsfcmd()
       num = 1;
    }
 
-   if (!bsf_dev(dev, num)) {
+   if (!dev->bsf(num)) {
       Pmsg1(0, _("Bad status from bsf. ERR=%s\n"), strerror_dev(dev));
    } else {
       Pmsg2(0, _("Backspaced %d file%s.\n"), num, num==1?"":"s");
@@ -701,12 +699,12 @@ static int re_read_block_test()
    if (dev_cap(dev, CAP_TWOEOF)) {
       weofcmd();
    }
-   if (!bsf_dev(dev, 1)) {
+   if (!dev->bsf(1)) {
       Pmsg1(0, _("Backspace file failed! ERR=%s\n"), strerror_dev(dev));
       goto bail_out;
    }
    if (dev_cap(dev, CAP_TWOEOF)) {
-      if (!bsf_dev(dev, 1)) {
+      if (!dev->bsf(1)) {
          Pmsg1(0, _("Backspace file failed! ERR=%s\n"), strerror_dev(dev));
          goto bail_out;
       }
@@ -773,7 +771,7 @@ static int write_read_test()
       "This is an *essential* feature ...\n\n"));
    block = dcr->block;
    rec = new_record();
-   if (!rewind_dev(dev)) {
+   if (!dev->rewind(dcr)) {
       Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), strerror_dev(dev));
       goto bail_out;
    }
@@ -815,7 +813,7 @@ static int write_read_test()
    if (dev_cap(dev, CAP_TWOEOF)) {
       weofcmd();
    }
-   if (!rewind_dev(dev)) {
+   if (!dev->rewind(dcr)) {
       Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), strerror_dev(dev));
       goto bail_out;
    } else {
@@ -885,7 +883,7 @@ static int position_test()
       "This is an *essential* feature ...\n\n"));
    empty_block(block);
    rec = new_record();
-   if (!rewind_dev(dev)) {
+   if (!dev->rewind(dcr)) {
       Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), strerror_dev(dev));
       goto bail_out;
    }
@@ -927,7 +925,7 @@ static int position_test()
    if (dev_cap(dev, CAP_TWOEOF)) {
       weofcmd();
    }
-   if (!rewind_dev(dev)) {
+   if (!dev->rewind(dcr)) {
       Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), strerror_dev(dev));
       goto bail_out;
    } else {
@@ -1055,7 +1053,7 @@ static int append_test()
    if (dev_cap(dev, CAP_TWOEOF)) {
       weofcmd();
    }
-   force_close_device(dev);              /* release device */
+   dev->close();              /* release device */
    if (!open_the_device()) {
       return -1;
    }
@@ -1149,9 +1147,8 @@ try_again:
    Dmsg1(100, "Results from loaded query=%s\n", results);
    if (loaded) {
       dcr->VolCatInfo.Slot = loaded;
-      offline_or_rewind_dev(dev);
       /* We are going to load a new tape, so close the device */
-      force_close_device(dev);
+      dev->close();
       Pmsg2(-1, _("3302 Issuing autochanger \"unload %d %d\" command.\n"),
          loaded, dev->drive_index);
       changer = edit_device_codes(dcr, changer, 
@@ -1176,7 +1173,7 @@ try_again:
    changer = edit_device_codes(dcr, changer, 
                 dcr->device->changer_command, "load");
    Dmsg1(100, "Changer=%s\n", changer);
-   force_close_device(dev);
+   dev->close();
    status = run_program(changer, timeout, results);
    if (status == 0) {
       Pmsg2(-1,  _("3303 Autochanger \"load %d %d\" status is OK.\n"),
@@ -1196,7 +1193,7 @@ try_again:
     * a failure.
     */
    bmicrosleep(sleep_time, 0);
-   if (!rewind_dev(dev) || weof_dev(dev,1) < 0) {
+   if (!dev->rewind(dcr) || weof_dev(dev,1) < 0) {
       Pmsg1(0, _("Bad status from rewind. ERR=%s\n"), strerror_dev(dev));
       clrerror_dev(dev, -1);
       Pmsg0(-1, _("\nThe test failed, probably because you need to put\n"
@@ -1663,6 +1660,7 @@ static void scan_blocks()
    uint64_t bytes;
    DEV_BLOCK *block = dcr->block;
    char ec1[50];
+   char buf1[100], buf2[100];
 
    blocks = block_size = tot_blocks = 0;
    bytes = 0;
@@ -1737,8 +1735,8 @@ static void scan_blocks()
          read_record_from_block(block, rec);
          Pmsg8(-1, _("Blk_block: %u dev_blk=%u blen=%u First rec FI=%s SessId=%u SessTim=%u Strm=%s rlen=%d\n"),
               block->BlockNumber, dev->block_num, block->block_len,
-              FI_to_ascii(rec->FileIndex), rec->VolSessionId, rec->VolSessionTime,
-              stream_to_ascii(rec->Stream, rec->FileIndex), rec->data_len);
+              FI_to_ascii(buf1, rec->FileIndex), rec->VolSessionId, rec->VolSessionTime,
+              stream_to_ascii(buf2, rec->Stream, rec->FileIndex), rec->data_len);
          rec->remainder = 0;
          free_record(rec);
       } else if (verbose > 1) {
@@ -1774,9 +1772,11 @@ static void fillcmd()
    DEV_RECORD rec;
    DEV_BLOCK  *block = dcr->block;
    char ec1[50];
+   char buf1[100], buf2[100];
    int fd;
    uint32_t i;
    uint32_t min_block_size;
+   struct tm tm;
 
    ok = true;
    stop = 0;
@@ -1823,7 +1823,7 @@ static void fillcmd()
    dev->min_block_size = dev->max_block_size;
    set_volume_name("TestVolume1", 1);
 
-   if (!dev->rewind()) {
+   if (!dev->rewind(dcr)) {
       Pmsg0(000, _("Rewind failed.\n"));
    }
    if (!dev->weof()) {
@@ -1882,10 +1882,12 @@ static void fillcmd()
     */
    jcr->dcr->VolFirstIndex = 0;
    time(&jcr->run_time);              /* start counting time for rates */
+   localtime_r(&jcr->run_time, &tm);
+   strftime(buf1, sizeof(buf1), "%T", &tm);
    if (simple) {
-      Pmsg0(-1, _("Begin writing Bacula records to tape ...\n"));
+      Pmsg1(-1, _("%s Begin writing Bacula records to tape ...\n"), buf1);
    } else {
-      Pmsg0(-1, _("Begin writing Bacula records to first tape ...\n"));
+      Pmsg1(-1, _("%s Begin writing Bacula records to first tape ...\n"), buf1);
    }
    for (file_index = 0; ok && !job_canceled(jcr); ) {
       rec.VolSessionId = jcr->VolSessionId;
@@ -1901,7 +1903,8 @@ static void fillcmd()
       }
 
       Dmsg4(250, "before write_rec FI=%d SessId=%d Strm=%s len=%d\n",
-         rec.FileIndex, rec.VolSessionId, stream_to_ascii(rec.Stream, rec.FileIndex),
+         rec.FileIndex, rec.VolSessionId, 
+         stream_to_ascii(buf1, rec.Stream, rec.FileIndex),
          rec.data_len);
 
       while (!write_record_to_block(block, &rec)) {
@@ -1929,10 +1932,13 @@ static void fillcmd()
                block->BlockNumber, dev->block_num,
                edit_uint64_with_commas(dev->VolCatInfo.VolCatBytes, ec1), (float)kbs);
          }
-         /* Every 15000 blocks (approx 1GB) write an EOF.
+         /* Every 32000 blocks (approx 2GB) write an EOF.
           */
-         if ((block->BlockNumber % 15000) == 0) {
-            Pmsg0(-1, _("Flush block, write EOF\n"));
+         if ((block->BlockNumber % 32000) == 0) {
+            now = time(NULL);
+            localtime_r(&now, &tm);
+            strftime(buf1, sizeof(buf1), "%T", &tm);
+            Pmsg1(-1, _("%s Flush block, write EOF\n"), buf1);
             flush_block(block, 0);
             weof_dev(dev, 1);
          }
@@ -1948,8 +1954,8 @@ static void fillcmd()
       }
       jcr->JobBytes += rec.data_len;   /* increment bytes this job */
       Dmsg4(190, "write_record FI=%s SessId=%d Strm=%s len=%d\n",
-         FI_to_ascii(rec.FileIndex), rec.VolSessionId,
-         stream_to_ascii(rec.Stream, rec.FileIndex), rec.data_len);
+         FI_to_ascii(buf1, rec.FileIndex), rec.VolSessionId,
+         stream_to_ascii(buf2, rec.Stream, rec.FileIndex), rec.data_len);
 
       /* Get out after writing 10 blocks to the second tape */
       if (BlockNumber > 10 && stop != 0) {      /* get out */
@@ -2006,13 +2012,16 @@ static void fillcmd()
                  be.strerror());
    }
 
+   now = time(NULL);
+   localtime_r(&now, &tm);
+   strftime(buf1, sizeof(buf1), "%T", &tm);
    if (simple) {
-      Pmsg2(-1, _("\n\nDone filling tape at %d:%d. Now beginning re-read of tape ...\n"),
-         jcr->dcr->dev->file, jcr->dcr->dev->block_num);
+      Pmsg3(-1, _("\n\n%s Done filling tape at %d:%d. Now beginning re-read of tape ...\n"),
+         buf1, jcr->dcr->dev->file, jcr->dcr->dev->block_num);
    }
    else {
-      Pmsg2(-1, _("\n\nDone filling tapes at %d:%d. Now beginning re-read of first tape ...\n"),
-         jcr->dcr->dev->file, jcr->dcr->dev->block_num);
+      Pmsg3(-1, _("\n\n%s Done filling tapes at %d:%d. Now beginning re-read of first tape ...\n"),
+         buf1, jcr->dcr->dev->file, jcr->dcr->dev->block_num);
    }
 
    jcr->dcr->block = block;
@@ -2093,11 +2102,11 @@ static void do_unfill()
       /* Multiple Volume tape */
       /* Close device so user can use autochanger if desired */
       if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
-         offline_dev(dev);
+         dev->offline();
       }
       autochanger = autoload_device(dcr, 1, NULL);
       if (!autochanger) {
-         force_close_device(dev);
+         dev->close();
          get_cmd(_("Mount first tape. Press enter when ready: "));
       }
       free_restore_volume_list(jcr);
@@ -2105,8 +2114,7 @@ static void do_unfill()
       set_volume_name("TestVolume1", 1);
       jcr->bsr = NULL;
       create_restore_volume_list(jcr);
-      close_device(dev);
-      dev->state &= ~(ST_READ|ST_APPEND);
+      dev->close();
       dev->num_writers = 0;
       if (!acquire_device_for_read(dcr)) {
          Pmsg1(-1, "%s", dev->errmsg);
@@ -2118,11 +2126,13 @@ static void do_unfill()
     * Note, re-reading last block may have caused us to
     *   loose track of where we are (block number unknown).
     */
-   if (!rewind_dev(dev)) {                /* get to a known place on tape */
+   Pmsg0(-1, _("Rewinding.\n"));
+   if (!dev->rewind(dcr)) {                /* get to a known place on tape */
       goto bail_out;
    }
    /* Read the first 10000 records */
-   Pmsg0(-1, _("Reading the first 10000 records.\n"));
+   Pmsg2(-1, _("Reading the first 10000 records from %u:%u.\n"),
+      dev->file, dev->block_num);
    quickie_count = 0;
    read_records(dcr, quickie_cb, my_mount_next_read_volume);
    Pmsg4(-1, _("Reposition from %u:%u to %u:%u\n"), dev->file, dev->block_num,
@@ -2155,7 +2165,7 @@ static void do_unfill()
    /* Multiple Volume tape */
    /* Close device so user can use autochanger if desired */
    if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
-      offline_dev(dev);
+      dev->offline();
    }
 
    free_restore_volume_list(jcr);
@@ -2164,7 +2174,7 @@ static void do_unfill()
    create_restore_volume_list(jcr);
    autochanger = autoload_device(dcr, 1, NULL);
    if (!autochanger) {
-      force_close_device(dev);
+      dev->close();
       get_cmd(_("Mount second tape. Press enter when ready: "));
    }
 
@@ -2217,14 +2227,9 @@ bail_out:
 static bool quickie_cb(DCR *dcr, DEV_RECORD *rec)
 {
    DEVICE *dev = dcr->dev;
-   if (dev->file != 0) {
-      Pmsg3(-1, _("ERROR! device at %d:%d count=%d\n"), dev->file, dev->block_num,
-         quickie_count);
-      return false;
-   }
    quickie_count++;
    if (quickie_count == 10000) {
-      Pmsg2(-1, _("1000 records read now at %d:%d\n"), dev->file, dev->block_num);
+      Pmsg2(-1, _("10000 records read now at %d:%d\n"), dev->file, dev->block_num);
    }
    return quickie_count < 10000;
 }
@@ -2670,11 +2675,7 @@ bool dir_ask_sysop_to_mount_volume(DCR *dcr)
    if (dcr->VolumeName[0] == 0) {
       return dir_ask_sysop_to_create_appendable_volume(dcr);
    }
-   /* Close device so user can use autochanger if desired */
-   if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
-      offline_dev(dev);
-   }
-   force_close_device(dev);
+   dev->close();
    Pmsg1(-1, "%s", dev->errmsg);           /* print reason */
    if (dcr->VolumeName[0] == 0 || strcmp(dcr->VolumeName, "TestVolume2") == 0) {
       fprintf(stderr, _("Mount second Volume on device %s and press return when ready: "),
@@ -2699,11 +2700,11 @@ bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr)
    }
    /* Close device so user can use autochanger if desired */
    if (dev_cap(dev, CAP_OFFLINEUNMOUNT)) {
-      offline_dev(dev);
+      dev->offline();
    }
    autochanger = autoload_device(dcr, 1, NULL);
    if (!autochanger) {
-      force_close_device(dev);
+      dev->close();
       fprintf(stderr, _("Mount blank Volume on device %s and press return when ready: "),
          dev->print_name());
       getchar();
@@ -2746,8 +2747,7 @@ static bool my_mount_next_read_volume(DCR *dcr)
    set_volume_name("TestVolume2", 2);
    jcr->bsr = NULL;
    create_restore_volume_list(jcr);
-   close_device(dev);
-   dev->clear_read();
+   dev->close();
    if (!acquire_device_for_read(dcr)) {
       Pmsg2(0, _("Cannot open Dev=%s, Vol=%s\n"), dev->print_name(), dcr->VolumeName);
       return false;