]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/vtape.c
bacula-web: Changed header.tpl design and links
[bacula/bacula] / bacula / src / stored / vtape.c
index 99e9fdd13559ecea286e9503879702135d41f811..16d9019b860e16644c655badb3f8353627e965d9 100644 (file)
@@ -1,12 +1,12 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
+   Copyright (C) 2008-2010 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.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation, which is 
    listed in the file LICENSE.
 
@@ -15,7 +15,7 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
@@ -67,102 +67,26 @@ Device {
 
 static int dbglevel = 100;
 #define FILE_OFFSET 30
-vtape *ftape_list[FTAPE_MAX_DRIVE];
-
-static vtape *get_tape(int fd)
-{
-   ASSERT(fd >= 0);
-
-   if (fd >= FTAPE_MAX_DRIVE) {
-      /* error */
-      return NULL;
-   }
-
-   return ftape_list[fd];
-}
-
-static bool put_tape(vtape *ftape)
-{
-   ASSERT(ftape != NULL);
-
-   int fd = ftape->get_fd();
-   if (fd >= FTAPE_MAX_DRIVE) {
-      /* error */
-      return false;
-   }
-   ftape_list[fd] = ftape;
-   return true;
-}
 
 void vtape_debug(int level)
 {
    dbglevel = level;
 }
 
-/****************************************************************/
-/* theses function will replace open/read/write/close/ioctl
- * in bacula core
- */
-int vtape_open(const char *pathname, int flags, ...)
+int vtape::d_ioctl(int fd, ioctl_req_t request, char *op)
 {
-   ASSERT(pathname != NULL);
-
-   int fd;
-   vtape *tape = new vtape();
-   fd = tape->open(pathname, flags);
-   if (fd > 0) {
-      put_tape(tape);
-   }
-   return fd;
-}
-
-ssize_t vtape_read(int fd, void *buffer, size_t count)
-{
-   vtape *tape = get_tape(fd);
-   ASSERT(tape != NULL);
-   return tape->read(buffer, count);
-}
-
-ssize_t vtape_write(int fd, const void *buffer, size_t count)
-{
-   vtape *tape = get_tape(fd);
-   ASSERT(tape != NULL);
-   return tape->write(buffer, count);
-}
-
-int vtape_close(int fd)
-{
-   vtape *tape = get_tape(fd);
-   ASSERT(tape != NULL);
-   tape->close();
-   delete tape;
-   return 0;
-}
-
-int vtape_ioctl(int fd, ioctl_req_t request, ...)
-{
-   va_list argp;
    int result = 0;
 
-   vtape *t = get_tape(fd);
-   if (!t) {
-      errno = EBADF;
-      return -1;
-   }
-
-   va_start(argp, request);
-
    if (request == MTIOCTOP) {
-      result = t->tape_op(va_arg(argp, mtop *));
+      result = tape_op((mtop *)op);
    } else if (request == MTIOCGET) {
-      result = t->tape_get(va_arg(argp, mtget *));
+      result = tape_get((mtget *)op);
    } else if (request == MTIOCPOS) {
-      result = t->tape_pos(va_arg(argp, mtpos *));
+      result = tape_pos((mtpos *)op);
    } else {
       errno = ENOTTY;
       result = -1;
    }
-   va_end(argp);
 
    return result;
 }
@@ -417,6 +341,10 @@ int vtape::truncate_file()
    return 0;
 }
 
+vtape::~vtape()
+{
+}
+
 vtape::vtape()
 {
    fd = -1;
@@ -433,11 +361,8 @@ vtape::vtape()
    current_file = 0;
    current_block = -1;
 
-   max_block = 2*1024*2048;      /* 2GB */
-}
-
-vtape::~vtape()
-{
+   max_block = VTAPE_MAX_BLOCK;
+   Dmsg0(0, "I'm a vtape device\n");
 }
 
 int vtape::get_fd()
@@ -451,7 +376,7 @@ int vtape::get_fd()
  * vtape_header = sizeof(data)
  * if vtape_header == 0, this is a EOF
  */
-ssize_t vtape::write(const void *buffer, size_t count)
+ssize_t vtape::d_write(int, const void *buffer, size_t count)
 {
    ASSERT(online);
    ASSERT(current_file >= 0);
@@ -611,7 +536,7 @@ int vtape::fsf()
 bool vtape::read_fm(VT_READ_FM_MODE read_all)
 {
    int ret;
-   uint32_t c;
+   uint32_t c = 0;
    if (read_all == VT_READ_EOF) {
       ::read(fd, &c, sizeof(c));
       if (c != 0) {
@@ -789,6 +714,11 @@ int vtape::bsr(int count)
    return 0;
 }
 
+boffset_t vtape::lseek(int fd, off_t offset, int whence)
+{
+   return ::lseek(fd, offset, whence);
+}
+
 /* BSF => just before last EOF
  * EOF + BSF => just before EOF
  * file 0 + BSF => BOT + errno
@@ -844,7 +774,7 @@ int vtape::offline()
 /* A filemark is automatically written to tape if the last tape operation
  * before close was a write.
  */
-int vtape::close()
+int vtape::d_close(int)
 {
    check_eof();
    ::close(fd);
@@ -860,7 +790,7 @@ int vtape::close()
  * by returning zero bytes for two consecutive read calls.  The third read
  * returns an error.
  */
-ssize_t vtape::read(void *buffer, size_t count)
+ssize_t vtape::d_read(int, void *buffer, size_t count)
 {
    ASSERT(online);
    ASSERT(current_file >= 0);
@@ -928,9 +858,9 @@ ssize_t vtape::read(void *buffer, size_t count)
    return nb;
 }
 
-int vtape::open(const char *pathname, int uflags)
+int vtape::d_open(const char *pathname, int uflags)
 {
-   Dmsg2(dbglevel, "vtape::open(%s, %i)\n", pathname, uflags);
+   Dmsg2(dbglevel, "vtape::d_open(%s, %i)\n", pathname, uflags);
 
    online = true;               /* assume that drive contains a tape */
 
@@ -961,7 +891,9 @@ int vtape::open(const char *pathname, int uflags)
 
    /* If the vtape is empty, start by writing a EOF */
    if (online && !read_fm(VT_READ_EOF)) {
-      weof();
+      lseek(fd, 0, SEEK_SET);          /* rewind */
+      cur_FM = next_FM = last_FM = 0;  /* reset */
+      weof();                          /* write the first EOF */
       last_file = current_file=0;
    }
 
@@ -996,35 +928,4 @@ void vtape::dump()
          atEOF, atEOT, atEOD, atBOT);  
 }
 
-#else  /* USE_VTAPE */
-
-int vtape_ioctl(int fd, ioctl_req_t request, ...)
-{
-   return -1;
-}
-
-int vtape_open(const char *pathname, int flags, ...)
-{
-   return -1;
-}
-
-int vtape_close(int fd)
-{
-   return -1;
-}
-
-void vtape_debug(int level)
-{
-}
-
-ssize_t vtape_read(int fd, void *buffer, size_t count)
-{
-   return -1;
-}
-
-ssize_t vtape_write(int fd, const void *buffer, size_t count)
-{
-   return -1;
-}
-
 #endif  /* ! USE_VTAPE */