From b4b9797ae1ebe51b00e9a3115697f14efff489b3 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/src/win32/compat/compat.h | 10 +++++++--- bacula/src/win32/dll/bacula.def | 7 ++++++- bacula/src/win32/stored/mtops.cpp | 26 ++++++++++++++++++++++---- bacula/technotes-2.5 | 3 +++ 8 files changed, 71 insertions(+), 30 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/src/win32/compat/compat.h b/bacula/src/win32/compat/compat.h index 5414c0f821..01802706ac 100644 --- a/bacula/src/win32/compat/compat.h +++ b/bacula/src/win32/compat/compat.h @@ -233,11 +233,15 @@ int chmod(const char *, mode_t mode); #define F_GETFL 3 #define F_SETFL 4 -int win32_tape_open(const char *file, int flags, int mode = 0); -int win32_tape_read(int fd, void *buffer, unsigned int count); -int win32_tape_write(int fd, const void *buffer, unsigned int count); +int win32_tape_open(const char *file, int flags, ...); int win32_tape_ioctl(int fd, unsigned long int request, ...); int win32_tape_close(int fd); +ssize_t win32_tape_read(int fd, void *buffer, size_t count); +ssize_t win32_tape_write(int fd, const void *buffer, size_t count); + +ssize_t win32_read(int fd, void *buffer, size_t count); +ssize_t win32_write(int fd, const void *buffer, size_t count); +int win32_ioctl(int fd, unsigned long int req, ...); #define open _open diff --git a/bacula/src/win32/dll/bacula.def b/bacula/src/win32/dll/bacula.def index 6aad607c50..915f05b67e 100644 --- a/bacula/src/win32/dll/bacula.def +++ b/bacula/src/win32/dll/bacula.def @@ -740,7 +740,12 @@ _Z14start_watchdogv _Z17register_watchdogP12s_watchdog_t _Z19unregister_watchdogP12s_watchdog_t watchdog_thread - + +; mtops.o +__Z10win32_readiPvj +__Z11win32_writeiPKvj +__Z11win32_ioctlimz + console_command DATA plugin_list DATA plugin_bopen DATA diff --git a/bacula/src/win32/stored/mtops.cpp b/bacula/src/win32/stored/mtops.cpp index 5275aa8d14..9e9f0d7d38 100644 --- a/bacula/src/win32/stored/mtops.cpp +++ b/bacula/src/win32/stored/mtops.cpp @@ -181,7 +181,7 @@ static int tape_op(int fd, struct mtop *mt_com); static int tape_pos(int fd, struct mtpos *mt_pos); int -win32_tape_open(const char *file, int flags, int mode) +win32_tape_open(const char *file, int flags, ...) { HANDLE hDevice = INVALID_HANDLE_VALUE; char szDeviceName[256] = "\\\\.\\"; @@ -274,8 +274,26 @@ win32_tape_open(const char *file, int flags, int mode) return (int)idxFile + 3; } +ssize_t +win32_read(int fd, void *buffer, size_t count) +{ + return read(fd, buffer, count); +} + +ssize_t +win32_write(int fd, const void *buffer, size_t count) +{ + return write(fd, buffer, count); +} + int -win32_tape_read(int fd, void *buffer, unsigned int count) +ioctl(int d, unsigned long int req, ...) +{ + return -1; +} + +ssize_t +win32_tape_read(int fd, void *buffer, size_t count) { if (buffer == NULL) { errno = EINVAL; @@ -346,8 +364,8 @@ win32_tape_read(int fd, void *buffer, unsigned int count) } } -int -win32_tape_write(int fd, const void *buffer, unsigned int count) +ssize_t +win32_tape_write(int fd, const void *buffer, size_t count) { if (buffer == NULL) { errno = EINVAL; 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