From 4d921f858d1f0769863b4e1a30db45316719dc67 Mon Sep 17 00:00:00 2001 From: Eric Bollengier Date: Sat, 14 Jun 2008 10:29:32 +0000 Subject: [PATCH] ebl Fix vtape on win32 and debian. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@7137 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/stored/dev.c | 27 +++++++++++++++++++-------- bacula/src/stored/dev.h | 4 ++-- bacula/src/stored/vtape.c | 16 ++++++++-------- bacula/src/stored/vtape.h | 8 ++++---- bacula/technotes-2.5 | 3 +++ 5 files changed, 36 insertions(+), 22 deletions(-) diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 9e4f713ec8..ed6fdfefb7 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -275,29 +275,40 @@ init_dev(JCR *jcr, DEVRES *device) /* Choose the right backend */ void DEVICE::init_backend() { - if (is_vtape()) { - d_open = vtape_open; - d_write = vtape_write; - d_close = vtape_close; - d_ioctl = vtape_ioctl; - d_read = vtape_read; #ifdef HAVE_WIN32 - } else if (is_tape()) { + if (is_tape()) { d_open = win32_tape_open; d_write = win32_tape_write; d_close = win32_tape_close; d_ioctl = win32_tape_ioctl; d_read = win32_tape_read; -#endif } else { + d_open = ::open; + d_close = ::close; + d_ioctl = win32_ioctl; /* dummy function */ + d_write = win32_write; /* win32 read/write are not POSIX */ + d_read = win32_read; + } + +#else /* POSIX / UNIX Interface */ + + if (is_vtape()) { /* test backend */ + d_open = vtape_open; /* vtape isn't available for WIN32 */ + d_write = vtape_write; + d_close = vtape_close; + d_ioctl = vtape_ioctl; + d_read = vtape_read; + + } else { /* tape and file are using normal io */ d_open = ::open; d_write = ::write; d_close = ::close; d_ioctl = ::ioctl; d_read = ::read; } +#endif } /* diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 0bf6682ca0..9ef62f0d74 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -432,10 +432,10 @@ public: /* low level operations */ void init_backend(); int (*d_open)(const char *pathname, int flags, ...); - int (*d_read)(int fd, void *buffer, unsigned int count); - int (*d_write)(int fd, const void *buffer, unsigned int count); int (*d_close)(int fd); int (*d_ioctl)(int fd, unsigned long int request, ...); + ssize_t (*d_read)(int fd, void *buffer, size_t count); + ssize_t (*d_write)(int fd, const void *buffer, size_t count); /* * Locking and blocking calls diff --git a/bacula/src/stored/vtape.c b/bacula/src/stored/vtape.c index 68b32128f1..e5c0b763f0 100644 --- a/bacula/src/stored/vtape.c +++ b/bacula/src/stored/vtape.c @@ -113,14 +113,14 @@ int vtape_open(const char *pathname, int flags, ...) return fd; } -int vtape_read(int fd, void *buffer, unsigned int count) +ssize_t vtape_read(int fd, void *buffer, size_t count) { vtape *tape = get_tape(fd); ASSERT(tape != NULL); return tape->read(buffer, count); } -int vtape_write(int fd, const void *buffer, unsigned int count) +ssize_t vtape_write(int fd, const void *buffer, size_t count) { vtape *tape = get_tape(fd); ASSERT(tape != NULL); @@ -450,14 +450,14 @@ int vtape::get_fd() * vtape_header = sizeof(data) * if vtape_header == 0, this is a EOF */ -int vtape::write(const void *buffer, unsigned int count) +ssize_t vtape::write(const void *buffer, size_t count) { ASSERT(online); ASSERT(current_file >= 0); ASSERT(count > 0); ASSERT(buffer); - unsigned int nb; + ssize_t nb; Dmsg3(dbglevel*2, "write len=%i %i:%i\n", count, current_file,current_block); @@ -485,7 +485,7 @@ int vtape::write(const void *buffer, unsigned int count) ::write(fd, &size, sizeof(uint32_t)); nb = ::write(fd, buffer, count); - if (nb != count) { + if (nb != (ssize_t)count) { atEOT = true; Dmsg2(dbglevel, "Not enough space writing only %i of %i requested\n", @@ -859,11 +859,11 @@ int vtape::close() * by returning zero bytes for two consecutive read calls. The third read * returns an error. */ -int vtape::read(void *buffer, unsigned int count) +ssize_t vtape::read(void *buffer, size_t count) { ASSERT(online); ASSERT(current_file >= 0); - unsigned int nb; + ssize_t nb; uint32_t s; Dmsg2(dbglevel*2, "read %i:%i\n", current_file, current_block); @@ -912,7 +912,7 @@ int vtape::read(void *buffer, unsigned int count) /* reading data itself */ nb = ::read(fd, buffer, s); - if (s != nb) { /* read error */ + if (nb != (ssize_t)s) { /* read error */ errno=EIO; atEOT=true; current_block = -1; diff --git a/bacula/src/stored/vtape.h b/bacula/src/stored/vtape.h index 0bef45fe00..0b5a94b109 100644 --- a/bacula/src/stored/vtape.h +++ b/bacula/src/stored/vtape.h @@ -44,11 +44,11 @@ * Theses functions will replace open/read/write */ int vtape_open(const char *pathname, int flags, ...); -int vtape_read(int fd, void *buffer, unsigned int count); -int vtape_write(int fd, const void *buffer, unsigned int count); int vtape_close(int fd); int vtape_ioctl(int fd, unsigned long int request, ...); void vtape_debug(int level); +ssize_t vtape_read(int fd, void *buffer, size_t count); +ssize_t vtape_write(int fd, const void *buffer, size_t count); typedef enum { VT_READ_EOF, /* Need to read the entire EOF struct */ @@ -97,8 +97,8 @@ public: int get_fd(); void dump(); int open(const char *pathname, int flags); - int read(void *buffer, unsigned int count); - int write(const void *buffer, unsigned int count); + ssize_t read(void *buffer, size_t count); + ssize_t write(const void *buffer, size_t count); int close(); int tape_op(struct mtop *mt_com); diff --git a/bacula/technotes-2.5 b/bacula/technotes-2.5 index ad48a2c915..d7e0ae3d50 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -25,6 +25,9 @@ vtape driver General: +14Jun08 +ebl Fix vtape on win32 and debian. +ebl Fix autoselect patch (cause segfault). 13Jun08 ebl Fix autoselect option broken for a while. Fix #1089. Need some work with StorageId to be able to use a particular drive in a -- 2.39.5