]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/dev.c
tweaks
[bacula/bacula] / bacula / src / stored / dev.c
index e6d9563e8242ddd7be4d7f5257f172b1bb614772..474fa45d411518191f24eb9df0370aa50aec828f 100644 (file)
@@ -31,7 +31,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
@@ -192,9 +192,8 @@ init_dev(JCR *jcr, DEVRES *device)
       if (!device->mount_point || stat(device->mount_point, &statp) < 0) {
          berrno be;
          dev->dev_errno = errno;
-         Jmsg2(jcr, M_ERROR, 0, _("Unable to stat mount point %s: ERR=%s\n"), 
+         Jmsg2(jcr, M_ERROR_TERM, 0, _("Unable to stat mount point %s: ERR=%s\n"), 
             device->mount_point, be.strerror());
-         return NULL;
       }
    }
    if (dev->is_dvd()) {
@@ -337,8 +336,10 @@ void DEVICE::open_tape_device(DCR *dcr, int omode)
 {
    file_size = 0;
    int timeout = max_open_wait;
+#if !defined(HAVE_WIN32)
    struct mtop mt_com;
    utime_t start_time = time(NULL);
+#endif
 
 
    Dmsg0(29, "Open dev: device is tape\n");
@@ -519,9 +520,9 @@ void DEVICE::open_dvd_device(DCR *dcr, int omode)
    Dmsg1(100, "Volume=%s\n", VolCatInfo.VolCatName);
 
    if (VolCatInfo.VolCatName[0] == 0) {
-      Dmsg1(10,  "Could not open file device %s. No Volume name given.\n",
+      Dmsg1(10,  "Could not open DVD device %s. No Volume name given.\n",
          print_name());
-      Mmsg(errmsg, _("Could not open file device %s. No Volume name given.\n"),
+      Mmsg(errmsg, _("Could not open DVD device %s. No Volume name given.\n"),
          print_name());
       clear_opened();
       return;
@@ -1324,7 +1325,7 @@ bool DEVICE::fsf(int num)
       mt_com.mt_count = 1;
       while (num-- && !at_eot()) {
          Dmsg0(100, "Doing read before fsf\n");
-         if ((stat = tape_read(fd, (char *)rbuf, rbuf_len)) < 0) {
+         if ((stat = this->read((char *)rbuf, rbuf_len)) < 0) {
             if (errno == ENOMEM) {     /* tape record exceeds buf len */
                stat = rbuf_len;        /* This is OK */
             /*
@@ -1712,32 +1713,32 @@ void DEVICE::clrerror(int func)
    if (errno == ENOTTY || errno == ENOSYS) { /* Function not implemented */
       switch (func) {
       case -1:
-         break;              /* ignore message printed later */
+         break;                  /* ignore message printed later */
       case MTWEOF:
          msg = "WTWEOF";
-         capabilities &= ~CAP_EOF; /* turn off feature */
+         clear_cap(CAP_EOF);     /* turn off feature */
          break;
 #ifdef MTEOM
       case MTEOM:
          msg = "WTEOM";
-         capabilities &= ~CAP_EOM; /* turn off feature */
+         clear_cap(CAP_EOM);     /* turn off feature */
          break;
 #endif
       case MTFSF:
          msg = "MTFSF";
-         capabilities &= ~CAP_FSF; /* turn off feature */
+         clear_cap(CAP_FSF);     /* turn off feature */
          break;
       case MTBSF:
          msg = "MTBSF";
-         capabilities &= ~CAP_BSF; /* turn off feature */
+         clear_cap(CAP_BSF);     /* turn off feature */
          break;
       case MTFSR:
          msg = "MTFSR";
-         capabilities &= ~CAP_FSR; /* turn off feature */
+         clear_cap(CAP_FSR);     /* turn off feature */
          break;
       case MTBSR:
          msg = "MTBSR";
-         capabilities &= ~CAP_BSR; /* turn off feature */
+         clear_cap(CAP_BSR);     /* turn off feature */
          break;
       case MTREW:
          msg = "MTREW";
@@ -2191,6 +2192,63 @@ void DEVICE::edit_mount_codes(POOL_MEM &omsg, const char *imsg)
    }
 }
 
+/* return the last timer interval (ms) */
+btime_t DEVICE::get_timer_count()
+{
+   btime_t old = last_timer;
+   last_timer = get_current_btime();
+   return last_timer - old;
+}
+
+/* read from fd */
+ssize_t DEVICE::read(void *buf, size_t len)
+{
+   ssize_t read_len ;
+
+   get_timer_count();
+
+   if (this->is_tape()) {
+      read_len = tape_read(fd, buf, len);
+   } else {
+      read_len = ::read(fd, buf, len);
+   }
+
+   last_tick = get_timer_count();
+
+   DevReadTime += last_tick;
+   VolCatInfo.VolReadTime += last_tick;
+
+   if (read_len > 0) {          /* skip error */
+      DevReadBytes += read_len;
+   }
+
+   return read_len;   
+}
+
+/* write to fd */
+ssize_t DEVICE::write(const void *buf, size_t len)
+{
+   ssize_t write_len ;
+
+   get_timer_count();
+
+   if (this->is_tape()) {
+      write_len = tape_write(fd, buf, len);
+   } else {
+      write_len = ::write(fd, buf, len);
+   }
+
+   last_tick = get_timer_count();
+
+   DevWriteTime += last_tick;
+   VolCatInfo.VolWriteTime += last_tick;
+
+   if (write_len > 0) {         /* skip error */
+      DevWriteBytes += write_len;
+   }
+
+   return write_len;   
+}
 
 /* Return the resource name for the device */
 const char *DEVICE::name() const
@@ -2369,7 +2427,7 @@ void set_os_device_parameters(DCR *dcr)
 /* Turn this on later when fully tested */
 #if defined(xxxMTIOCSETEOTMODEL) 
    uint32_t neof;
-   if (dev_cap(dev, CAP_TWOEOF)) {
+   if (dev->has_cap(CAP_TWOEOF)) {
       neof = 2;
    } else {
       neof = 1;