From 1f8e3782a71647390e1963a0662eb8cf866be3a2 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Tue, 10 Feb 2004 15:54:16 +0000 Subject: [PATCH] Apply win32 fixes + add tapetest.c git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1037 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/platforms/freebsd/pthreads-fix.txt | 64 --- bacula/platforms/freebsd/tapetest.c | 601 ++++++++++++++++++++++ bacula/src/bacula.h | 10 + bacula/src/console/conio.c | 2 +- bacula/src/console/console.c | 18 +- bacula/src/filed/filed.c | 9 +- bacula/src/filed/filed.h | 2 +- bacula/src/filed/filed_conf.c | 7 + bacula/src/filed/heartbeat.c | 2 +- bacula/src/filed/job.c | 6 +- bacula/src/filed/status.c | 13 +- bacula/src/filed/win32/winbacula.h | 2 +- bacula/src/filed/win32/winmain.cpp | 10 +- bacula/src/filed/win32/winres.rc | 29 +- bacula/src/filed/win32/winservice.cpp | 8 +- bacula/src/findlib/attribs.c | 8 +- bacula/src/findlib/bfile.c | 8 +- bacula/src/findlib/bfile.h | 2 +- bacula/src/findlib/create_file.c | 4 +- bacula/src/findlib/enable_priv.c | 4 +- bacula/src/findlib/makepath.c | 16 +- bacula/src/findlib/match.c | 11 +- bacula/src/findlib/protos.h | 1 - bacula/src/findlib/save-cwd.c | 6 +- bacula/src/findlib/winapi.c | 2 +- bacula/src/findlib/winapi.h | 23 +- bacula/src/lib/attr.c | 2 +- bacula/src/lib/bnet.c | 15 +- bacula/src/lib/bpipe.c | 5 +- bacula/src/lib/bshm.c | 2 +- bacula/src/lib/bsys.c | 11 +- bacula/src/lib/daemon.c | 2 +- bacula/src/lib/dlist.h | 8 +- bacula/src/lib/edit.c | 7 + bacula/src/lib/events.c | 2 +- bacula/src/lib/idcache.c | 11 +- bacula/src/lib/jcr.c | 2 +- bacula/src/lib/message.c | 47 +- bacula/src/lib/parse_conf.c | 10 +- bacula/src/lib/parse_conf.h | 6 +- bacula/src/lib/signal.c | 3 +- bacula/src/lib/util.c | 3 +- bacula/src/lib/var.c | 3 +- bacula/src/stored/bextract.c | 3 +- bacula/src/stored/bls.c | 3 +- bacula/src/stored/bscan.c | 2 +- bacula/src/tools/testfind.c | 7 + bacula/src/tools/testls.c | 6 + 48 files changed, 842 insertions(+), 186 deletions(-) create mode 100644 bacula/platforms/freebsd/tapetest.c diff --git a/bacula/platforms/freebsd/pthreads-fix.txt b/bacula/platforms/freebsd/pthreads-fix.txt index 913d4ee4db..54402f2d72 100644 --- a/bacula/platforms/freebsd/pthreads-fix.txt +++ b/bacula/platforms/freebsd/pthreads-fix.txt @@ -1,55 +1,7 @@ -From bacula-users-admin@lists.sourceforge.net Mon Oct 20 23:44:13 2003 -Return-Path: -Received: from sc8-sf-list2.sourceforge.net (lists.sourceforge.net - [66.35.250.206]) by matou.sibbald.com (8.11.6/8.11.6) with ESMTP id - h9KLiDY13657 for ; Mon, 20 Oct 2003 23:44:13 +0200 -Received: from sc8-sf-list1-b.sourceforge.net ([10.3.1.13] - helo=sc8-sf-list1.sourceforge.net) by sc8-sf-list2.sourceforge.net with - esmtp (Exim 3.31-VA-mm2 #1 (Debian)) id 1ABhpS-00013k-00; Mon, 20 Oct 2003 - 14:44:42 -0700 -Received: from sc8-sf-mx1-b.sourceforge.net ([10.3.1.11] - helo=sc8-sf-mx1.sourceforge.net) by sc8-sf-list1.sourceforge.net with esmtp - (Cipher TLSv1:DES-CBC3-SHA:168) (Exim 3.31-VA-mm2 #1 (Debian)) id - 1ABhnp-0007qu-00 for ; Mon, 20 Oct 2003 - 14:43:01 -0700 -Received: from bast.unixathome.org ([66.11.174.150] ident=postfix) by - sc8-sf-mx1.sourceforge.net with esmtp (Exim 4.22) id 1ABfiR-0002Iv-Q8 for - bacula-users@lists.sourceforge.net; Mon, 20 Oct 2003 12:29:19 -0700 -Received: from wocker (wocker.unixathome.org [192.168.0.99]) by - bast.unixathome.org (Postfix) with ESMTP id 258913F53 for - ; Mon, 20 Oct 2003 15:25:33 -0400 (EDT) From: "Dan Langille" To: bacula-users@lists.sourceforge.net -MIME-Version: 1.0 -Message-ID: <3F93FF4E.14552.13ACB682@localhost> -Priority: normal -X-mailer: Pegasus Mail for Windows (v4.02a) -Content-type: text/plain; charset=US-ASCII -Content-description: Mail message body -X-Spam-Score: 0.0 (/) -X-Spam-Report: 0.0/5.0 Spam Filtering performed by sourceforge.net. See - http://spamassassin.org/tag/ for more details. Report problems to - https://sf.net/tracker/?func=add&group_id=1&atid=200001 Subject: [Bacula-users] FreeBSD - large backups to tape -Sender: bacula-users-admin@lists.sourceforge.net -Errors-To: bacula-users-admin@lists.sourceforge.net -X-BeenThere: bacula-users@lists.sourceforge.net -X-Mailman-Version: 2.0.9-sf.net -Precedence: bulk -List-Help: -List-Post: -List-Subscribe: - , - -List-Id: Bacula user's email list for support and discussions - -List-Unsubscribe: - , - -List-Archive: - Date: Mon, 20 Oct 2003 15:29:18 -0400 -Content-Transfer-Encoding: 8bit Kern and I have been working on a FreeBSD/Bacula problem. He's asked me to post this to the list. The problem was within the @@ -175,19 +127,3 @@ I suggest running tapetest on your patched system and then conducting a backup which spans two tapes. Restore the data and compare to the original. If not identical, please let us know. -Thanks - --- -Dan Langille : http://www.langille.org/ - - - -------------------------------------------------------- -This SF.net email is sponsored by OSDN developer relations -Here's your chance to show off your extensive product knowledge -We want to know what you know. Tell us and you have a chance to win $100 -http://www.zoomerang.com/survey.zgi?HRPT1X3RYQNC5V4MLNSV3E54 -_______________________________________________ -Bacula-users mailing list -Bacula-users@lists.sourceforge.net -https://lists.sourceforge.net/lists/listinfo/bacula-users diff --git a/bacula/platforms/freebsd/tapetest.c b/bacula/platforms/freebsd/tapetest.c new file mode 100644 index 0000000000..d055ae9d2d --- /dev/null +++ b/bacula/platforms/freebsd/tapetest.c @@ -0,0 +1,601 @@ +/* + * + * Program to test loss of data at EOM on + * FreeBSD systems. + * + * Kern Sibbald, August 2003 + * + * If you build this program with: + * + * c++ -g -O2 -Wall -c tapetest.c + * c++ -g -O2 -Wall tapetest.o -o tapetest + * + * Procedure for testing tape + * ./tapetest /dev/your-tape-device + * rewind + * rawfill + * rewind + * scan + * + * The output will be: + * + * ======== + * Rewound /dev/nsa0 + * *Begin writing blocks of 64512 bytes. + * ++++++++++++++++++++ ... + * Write failed. Last block written=17294. stat=0 ERR=Unknown error: 0 + * weof_dev + * Wrote EOF to /dev/nsa0 + * *Rewound /dev/nsa0 + * *Starting scan at file 0 + * 17294 blocks of 64512 bytes in file 0 + * End of File mark. + * End of File mark. + * End of tape + * Total files=1, blocks=17294, bytes = 1115670528 + * ======== + * + * which is correct. Notice that the return status is + * 0, while in the example below, which fails, the return + * status is -1. + * + + * If you build this program with: + * + * c++ -g -O2 -Wall -pthread -c tapetest.c + * c++ -g -O2 -Wall -pthread tapetest.o -o tapetest + * Note, we simply added -pthread compared to the + * previous example. + * + * Procedure for testing tape + * ./tapetest /dev/your-tape-device + * rewind + * rawfill + * rewind + * scan + * + * The output will be: + * + * ======== + * Rewound /dev/nsa0 + * *Begin writing blocks of 64512 bytes. + * +++++++++++++++++++++++++++++ ... + * Write failed. Last block written=17926. stat=-1 ERR=No space left on device + * weof_dev + * Wrote EOF to /dev/nsa0 + * *Rewound /dev/nsa0 + * *Starting scan at file 0 + * 17913 blocks of 64512 bytes in file 0 + * End of File mark. + * End of File mark. + * End of tape + * Total files=1, blocks=17913, bytes = 1155603456 + * ======== + * + * which is incroorect because it wrote 17,926 blocks but read + * back only 17,913 blocks. + * + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define FALSE 0 +#define TRUE 1 + +#define dev_state(dev, state) ((dev)->state & (state)) + +/* Device state bits */ +#define ST_OPENED (1<<0) /* set when device opened */ +#define ST_TAPE (1<<1) /* is a tape device */ +#define ST_FILE (1<<2) /* is a file device */ +#define ST_FIFO (1<<3) /* is a fifo device */ +#define ST_PROG (1<<4) /* is a program device */ +#define ST_LABEL (1<<5) /* label found */ +#define ST_MALLOC (1<<6) /* dev packet malloc'ed in init_dev() */ +#define ST_APPEND (1<<7) /* ready for Bacula append */ +#define ST_READ (1<<8) /* ready for Bacula read */ +#define ST_EOT (1<<9) /* at end of tape */ +#define ST_WEOT (1<<10) /* Got EOT on write */ +#define ST_EOF (1<<11) /* Read EOF i.e. zero bytes */ +#define ST_NEXTVOL (1<<12) /* Start writing on next volume */ +#define ST_SHORT (1<<13) /* Short block read */ + +#define BLOCK_SIZE (512 * 126) + + +/* Exported variables */ +int quit = 0; +char buf[100000]; +int verbose = 0; +int debug_level = 0; +int fd = 0; + +struct DEVICE { + int fd; + int dev_errno; + int file; + int block_num; + int state; + char *buf; + int buf_len; + char *dev_name; + int file_addr; +}; + +DEVICE *dev; + +#define uint32_t unsigned long +#define uint64_t unsigned long long + +/* Forward referenced subroutines */ +static void do_tape_cmds(); +static void helpcmd(); +static void scancmd(); +static void rewindcmd(); +static void rawfill_cmd(); + + +/* Static variables */ + +static char cmd[1000]; + +static void usage(); +int get_cmd(char *prompt); + + +/********************************************************************* + * + * Main Bacula Pool Creation Program + * + */ +int main(int argc, char *argv[]) +{ + int ch; + + while ((ch = getopt(argc, argv, "d:v?")) != -1) { + switch (ch) { + case 'd': /* set debug level */ + debug_level = atoi(optarg); + if (debug_level <= 0) { + debug_level = 1; + } + break; + + case 'v': + verbose++; + break; + + case '?': + default: + helpcmd(); + exit(0); + + } + } + argc -= optind; + argv += optind; + + + /* See if we can open a device */ + if (argc == 0) { + printf("No archive name specified.\n"); + usage(); + exit(1); + } else if (argc != 1) { + printf("Improper number of arguments specified.\n"); + usage(); + exit(1); + } + + fd = open(argv[0], O_RDWR); + if (fd < 0) { + printf("Error opening %s ERR=%s\n", argv[0], strerror(errno)); + exit(1); + } + dev = (DEVICE *)malloc(sizeof(DEVICE)); + memset(dev, 0, sizeof(DEVICE)); + dev->fd = fd; + dev->dev_name = strdup(argv[0]); + dev->buf_len = BLOCK_SIZE; + dev->buf = (char *)malloc(BLOCK_SIZE); + + do_tape_cmds(); + return 0; +} + + +int rewind_dev(DEVICE *dev) +{ + struct mtop mt_com; + + if (dev->fd < 0) { + dev->dev_errno = EBADF; + printf("Bad call to rewind_dev. Device %s not open\n", + dev->dev_name); + return 0; + } + dev->state &= ~(ST_APPEND|ST_READ|ST_EOT|ST_EOF|ST_WEOT); /* remove EOF/EOT flags */ + dev->block_num = dev->file = 0; + mt_com.mt_op = MTREW; + mt_com.mt_count = 1; + if (ioctl(dev->fd, MTIOCTOP, (char *)&mt_com) < 0) { + dev->dev_errno = errno; + printf("Rewind error on %s. ERR=%s.\n", + dev->dev_name, strerror(dev->dev_errno)); + return 0; + } + return 1; +} + +/* + * Write an end of file on the device + * Returns: 0 on success + * non-zero on failure + */ +int +weof_dev(DEVICE *dev, int num) +{ + struct mtop mt_com; + int stat; + + if (dev->fd < 0) { + dev->dev_errno = EBADF; + printf("Bad call to fsf_dev. Archive not open\n"); + return -1; + } + + dev->state &= ~(ST_EOT | ST_EOF); /* remove EOF/EOT flags */ + dev->block_num = 0; + printf("weof_dev\n"); + mt_com.mt_op = MTWEOF; + mt_com.mt_count = num; + stat = ioctl(dev->fd, MTIOCTOP, (char *)&mt_com); + if (stat == 0) { + dev->file++; + dev->file_addr = 0; + } else { + dev->dev_errno = errno; + printf("ioctl MTWEOF error on %s. ERR=%s.\n", + dev->dev_name, strerror(dev->dev_errno)); + } + return stat; +} + + + + + +void quitcmd() +{ + quit = 1; +} + + +/* + * Rewind the tape. + */ +static void rewindcmd() +{ + if (!rewind_dev(dev)) { + printf("Bad status from rewind. ERR=%s\n", strerror(dev->dev_errno)); + } else { + printf("Rewound %s\n", dev->dev_name); + } +} + +/* + * Write and end of file on the tape + */ +static void weofcmd() +{ + int stat; + + if ((stat = weof_dev(dev, 1)) < 0) { + printf("Bad status from weof %d. ERR=%s\n", stat, strerror(dev->dev_errno)); + return; + } else { + printf("Wrote EOF to %s\n", dev->dev_name); + } +} + + +/* + * Read a record from the tape + */ +static void rrcmd() +{ + char *buf; + int stat, len; + + if (!get_cmd("Enter length to read: ")) { + return; + } + len = atoi(cmd); + if (len < 0 || len > 1000000) { + printf("Bad length entered, using default of 1024 bytes.\n"); + len = 1024; + } + buf = (char *)malloc(len); + stat = read(fd, buf, len); + if (stat > 0 && stat <= len) { + errno = 0; + } + printf("Read of %d bytes gives stat=%d. ERR=%s\n", + len, stat, strerror(errno)); + free(buf); +} + +/* + * Write a record to the tape + */ +static void wrcmd() +{ + int stat; + int rfd; + + rfd = open("/dev/urandom", O_RDONLY); + if (rfd) { + read(rfd, dev->buf, dev->buf_len); + } else { + printf("Cannot open /dev/urandom.\n"); + return; + } + printf("Write one block of %u bytes.\n", dev->buf_len); + stat = write(dev->fd, dev->buf, dev->buf_len); + if (stat != (int)dev->buf_len) { + if (stat == -1) { + printf("Bad status from write. ERR=%s\n", strerror(errno)); + } else { + printf("Expected to write %d bytes but wrote only %d.\n", + dev->buf_len, stat); + } + } +} + + + +/* + * Scan tape by reading block by block. Report what is + * on the tape. Note, this command does raw reads, and as such + * will not work with fixed block size devices. + */ +static void scancmd() +{ + int stat; + int blocks, tot_blocks, tot_files; + int block_size; + uint64_t bytes; + + + blocks = block_size = tot_blocks = 0; + bytes = 0; + if (dev->state & ST_EOT) { + printf("End of tape\n"); + return; + } + tot_files = dev->file; + printf("Starting scan at file %u\n", dev->file); + for (;;) { + if ((stat = read(dev->fd, buf, sizeof(buf))) < 0) { + dev->dev_errno = errno; + printf("Bad status from read %d. ERR=%s\n", stat, strerror(dev->dev_errno)); + if (blocks > 0) + printf("%d block%s of %d bytes in file %d\n", + blocks, blocks>1?"s":"", block_size, dev->file); + return; + } + if (stat != block_size) { + if (blocks > 0) { + printf("%d block%s of %d bytes in file %d\n", + blocks, blocks>1?"s":"", block_size, dev->file); + blocks = 0; + } + block_size = stat; + } + if (stat == 0) { /* EOF */ + printf("End of File mark.\n"); + /* Two reads of zero means end of tape */ + if (dev->state & ST_EOF) + dev->state |= ST_EOT; + else { + dev->state |= ST_EOF; + dev->file++; + } + if (dev->state & ST_EOT) { + printf("End of tape\n"); + break; + } + } else { /* Got data */ + dev->state &= ~ST_EOF; + blocks++; + tot_blocks++; + bytes += stat; + } + } + tot_files = dev->file - tot_files; + printf("Total files=%d, blocks=%d, bytes = %d\n", tot_files, tot_blocks, + (int)bytes); +} + + +static void rawfill_cmd() +{ + int stat; + int rfd; + uint32_t block_num = 0; + uint32_t *p; + int my_errno; + + rfd = open("/dev/urandom", O_RDONLY); + if (rfd) { + read(rfd, dev->buf, dev->buf_len); + } else { + printf("Cannot open /dev/urandom.\n"); + return; + } + p = (uint32_t *)dev->buf; + printf("Begin writing blocks of %u bytes.\n", dev->buf_len); + for ( ;; ) { + *p = block_num; + stat = write(dev->fd, dev->buf, dev->buf_len); + if (stat == (int)dev->buf_len) { + if ((block_num++ % 100) == 0) { + printf("+"); + fflush(stdout); + } + continue; + } + break; + } + my_errno = errno; + printf("\n"); + weofcmd(); + printf("Write failed. Last block written=%d. stat=%d ERR=%s\n", (int)block_num, stat, + strerror(my_errno)); + +} + +/* Strip any trailing junk from the command */ +void strip_trailing_junk(char *cmd) +{ + char *p; + p = cmd + strlen(cmd) - 1; + + /* strip trailing junk from command */ + while ((p >= cmd) && (*p == '\n' || *p == '\r' || *p == ' ')) + *p-- = 0; +} + +/* folded search for string - case insensitive */ +int +fstrsch(char *a, char *b) /* folded case search */ +{ + register char *s1,*s2; + register char c1=0, c2=0; + + s1=a; + s2=b; + while (*s1) { /* do it the fast way */ + if ((*s1++ | 0x20) != (*s2++ | 0x20)) + return 0; /* failed */ + } + while (*a) { /* do it over the correct slow way */ + if (isupper(c1 = *a)) { + c1 = tolower((int)c1); + } + if (isupper(c2 = *b)) { + c2 = tolower((int)c2); + } + if (c1 != c2) { + return 0; + } + a++; + b++; + } + return 1; +} + + +struct cmdstruct { char *key; void (*func)(); char *help; }; +static struct cmdstruct commands[] = { + {"help", helpcmd, "print this command"}, + {"quit", quitcmd, "quit tapetest"}, + {"rawfill", rawfill_cmd, "use write() to fill tape"}, + {"rewind", rewindcmd, "rewind the tape"}, + {"rr", rrcmd, "raw read the tape"}, + {"wr", wrcmd, "raw write one block to the tape"}, + {"scan", scancmd, "read() tape block by block to EOT and report"}, + {"weof", weofcmd, "write an EOF on the tape"}, + }; +#define comsize (sizeof(commands)/sizeof(struct cmdstruct)) + +static void +do_tape_cmds() +{ + unsigned int i; + int found; + + while (get_cmd("*")) { + found = 0; + for (i=0; i 0) + cmd[--i] = 0; + continue; + } + + cmd[i++] = ch; + cmd[i] = 0; + } + quit = 1; + return 0; +} diff --git a/bacula/src/bacula.h b/bacula/src/bacula.h index c1ab192866..35f3c07ea1 100644 --- a/bacula/src/bacula.h +++ b/bacula/src/bacula.h @@ -27,8 +27,14 @@ #ifndef _BACULA_H #define _BACULA_H 1 +#ifdef HAVE_WIN32 +#include "winconfig.h" +#include "winhost.h" +#else #include "config.h" #include "host.h" +#endif + #define _REENTRANT 1 #define _THREAD_SAFE 1 @@ -84,7 +90,11 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif +#ifdef HAVE_WIN32 +#include +#else #include +#endif #include #if HAVE_SYS_WAIT_H #include diff --git a/bacula/src/console/conio.c b/bacula/src/console/conio.c index c2f7003e45..443ced7812 100755 --- a/bacula/src/console/conio.c +++ b/bacula/src/console/conio.c @@ -987,7 +987,7 @@ void clrbrk() /* Interrupt caught here */ static void sigintcatcher(int sig) { - brkflg = 1; + brkflg++; signal(SIGINT, sigintcatcher); } diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index 3e3dc3cf7b..f61f9e5e58 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -196,10 +196,19 @@ static void read_and_process_input(FILE *input, BSOCK *UA_sock) } if (tty_input) { stat = get_cmd(input, prompt, UA_sock, 30); - clrbrk(); + if (usrbrk() == 1) { + clrbrk(); + } + if (usrbrk()) { + break; + } } else { + /* Reading input from a file */ int len = sizeof_pool_memory(UA_sock->msg) - 1; - if (fgets(UA_sock->msg, len, input) == NULL || usrbrk()) { + if (usrbrk()) { + break; + } + if (fgets(UA_sock->msg, len, input) == NULL) { stat = -1; } else { sendit(UA_sock->msg); /* echo to terminal */ @@ -245,6 +254,11 @@ static void read_and_process_input(FILE *input, BSOCK *UA_sock) sendit(UA_sock->msg); } } + if (usrbrk() > 1) { + break; + } else { + clrbrk(); + } if (!stop) { fflush(stdout); } diff --git a/bacula/src/filed/filed.c b/bacula/src/filed/filed.c index 4eb34b8ae4..ffc4648c06 100644 --- a/bacula/src/filed/filed.c +++ b/bacula/src/filed/filed.c @@ -41,10 +41,10 @@ char OK_msg[] = "2000 OK\n"; char TERM_msg[] = "2999 Terminate\n"; -#ifdef HAVE_CYGWIN -int win32_client = 1; +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +const int win32_client = 1; #else -int win32_client = 0; +const int win32_client = 0; #endif @@ -81,9 +81,10 @@ static void usage() * Main Bacula Unix Client Program * */ -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) #define main BaculaMain #endif + int main (int argc, char *argv[]) { int ch; diff --git a/bacula/src/filed/filed.h b/bacula/src/filed/filed.h index 36a93d2717..a4a90910c2 100644 --- a/bacula/src/filed/filed.h +++ b/bacula/src/filed/filed.h @@ -36,6 +36,6 @@ #define uLongf uint32_t #endif -extern int win32_client; /* Are we running on Windows? */ +extern const int win32_client; /* Are we running on Windows? */ extern CLIENT *me; /* "Global" Client resource */ diff --git a/bacula/src/filed/filed_conf.c b/bacula/src/filed/filed_conf.c index 022d7ba6cb..8767ad3733 100644 --- a/bacula/src/filed/filed_conf.c +++ b/bacula/src/filed/filed_conf.c @@ -61,8 +61,15 @@ pthread_mutex_t res_mutex = PTHREAD_MUTEX_INITIALIZER; * then move it to allocated memory when the resource * scan is complete. */ +#if defined(HAVE_WIN32) && !defined(HAVE_CYGWIN) +extern "C" { // work around visual compiler mangling variables + URES res_all; + int res_all_size = sizeof(res_all); +} +#else URES res_all; int res_all_size = sizeof(res_all); +#endif /* Definition of records permitted within each * resource with the routine to process the record diff --git a/bacula/src/filed/heartbeat.c b/bacula/src/filed/heartbeat.c index bda617ee11..8e1c033d22 100644 --- a/bacula/src/filed/heartbeat.c +++ b/bacula/src/filed/heartbeat.c @@ -31,7 +31,7 @@ #include "bacula.h" #include "filed.h" -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) /* pthread_kill() dies on Cygwin, so disable it */ #define pthread_kill(x, y) /* Use shorter wait interval on Cygwin because no kill */ diff --git a/bacula/src/filed/job.c b/bacula/src/filed/job.c index b5f05c13b1..bc3f09a40e 100644 --- a/bacula/src/filed/job.c +++ b/bacula/src/filed/job.c @@ -114,7 +114,7 @@ static char OKverify[] = "2000 OK verify\n"; static char OKrestore[] = "2000 OK restore\n"; static char OKsession[] = "2000 OK session\n"; static char OKstore[] = "2000 OK storage\n"; -static char OKjob[] = "2000 OK Job " HOST_OS "," DISTNAME "," DISTVER; +static char OKjob[] = "2000 OK Job %s,%s,%s"; static char OKsetdebug[] = "2000 OK setdebug=%d\n"; static char BADjob[] = "2901 Bad Job\n"; static char EndJob[] = "2800 End Job TermCode=%d JobFiles=%u ReadBytes=%s JobBytes=%s Errors=%u\n"; @@ -257,7 +257,7 @@ static int cancel_cmd(JCR *jcr) P(cjcr->mutex); cjcr->store_bsock->timed_out = 1; cjcr->store_bsock->terminated = 1; -#ifndef HAVE_CYGWIN +#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) pthread_kill(cjcr->my_thread_id, TIMEOUT_SIGNAL); #endif V(cjcr->mutex); @@ -333,7 +333,7 @@ static int job_cmd(JCR *jcr) jcr->sd_auth_key = bstrdup(sd_auth_key); free_pool_memory(sd_auth_key); Dmsg2(120, "JobId=%d Auth=%s\n", jcr->JobId, jcr->sd_auth_key); - return bnet_fsend(dir, OKjob); + return bnet_fsend(dir, OKjob, HOST_OS, DISTNAME, DISTVER); } static int runbefore_cmd(JCR *jcr) diff --git a/bacula/src/filed/status.c b/bacula/src/filed/status.c index 90ebead8f7..17c1e1a48b 100755 --- a/bacula/src/filed/status.c +++ b/bacula/src/filed/status.c @@ -39,7 +39,7 @@ static void bsock_sendit(char *msg, int len, void *arg); static char *level_to_str(int level); -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) static int privs = 0; #endif @@ -63,7 +63,7 @@ static void do_status(void sendit(char *msg, int len, void *sarg), void *arg) len = Mmsg(&msg, _("Daemon started %s, %d Job%s run.\n"), dt, last_job.NumJobs, last_job.NumJobs == 1 ? "" : "s"); sendit(msg, len, arg); -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) if (debug_level > 0) { if (!privs) { privs = enable_backup_privileges(NULL, 1); @@ -319,7 +319,7 @@ static char *level_to_str(int level) } -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) #include static char buf[100]; @@ -338,7 +338,12 @@ static void win32_sendit(char *msg, int len, void *marg) struct s_win32_arg *arg = (struct s_win32_arg *)marg; if (len > 0 && msg[len-1] == '\n') { - msg[len-1] = 0; /* eliminate newline */ + // when compiling with visual studio some strings are read-only + // and cause access violations. So we creat a tmp copy. + char *_msg = (char *)alloca(len); + strncpy(_msg, msg, len-1); + _msg[len-1] = 0; + msg = _msg; } SendDlgItemMessage(arg->hwnd, arg->idlist, LB_ADDSTRING, 0, (LONG)msg); diff --git a/bacula/src/filed/win32/winbacula.h b/bacula/src/filed/win32/winbacula.h index a9a83dfbb3..36dcee03c0 100755 --- a/bacula/src/filed/win32/winbacula.h +++ b/bacula/src/filed/win32/winbacula.h @@ -31,7 +31,7 @@ // WinUPS header file -#define STRICT +#define STRICT 1 #include #include #include diff --git a/bacula/src/filed/win32/winmain.cpp b/bacula/src/filed/win32/winmain.cpp index 6ab088c823..b839b961f4 100755 --- a/bacula/src/filed/win32/winmain.cpp +++ b/bacula/src/filed/win32/winmain.cpp @@ -21,7 +21,9 @@ Copyright (2000) Kern E. Sibbald */ +#ifndef HAVE_WIN32 #define HAVE_CYGWIN 1 +#endif #include #include @@ -33,7 +35,7 @@ #include #include "../../findlib/winapi.h" -extern int BaculaMain(int argc, char **argv); +extern int BaculaMain(int argc, char *argv[]); extern int terminate_filed(int sig); extern DWORD g_error; extern BOOL ReportStatus(DWORD state, DWORD exitcode, DWORD waithint); @@ -315,7 +317,9 @@ int BaculaAppMain() { // DWORD dwThreadID; pthread_t tid; - +#ifdef HAVE_WIN32 + WSA_Init(); +#endif HINSTANCE hLib = LoadLibrary("KERNEL32.DLL"); if (hLib) { p_GetFileAttributesEx = (t_GetFileAttributesEx) @@ -361,7 +365,7 @@ int BaculaAppMain() // Create a thread to handle the Windows messages // (void)CreateThread(NULL, 0, Main_Msg_Loop, NULL, 0, &dwThreadID); - pthread_create(&tid, NULL, Main_Msg_Loop, (void *)0); + pthread_create(&tid, NULL, Main_Msg_Loop, (void *)0); // Call the "real" Bacula BaculaMain(num_command_args, command_args); diff --git a/bacula/src/filed/win32/winres.rc b/bacula/src/filed/win32/winres.rc index df3c35874e..62b6c56628 100644 --- a/bacula/src/filed/win32/winres.rc +++ b/bacula/src/filed/win32/winres.rc @@ -128,21 +128,20 @@ BEGIN DEFPUSHBUTTON "OK",IDOK,190,120,50,15 // CONTROL "\3", IDC_BACULABMP,"Static",SS_ICON | SS_CENTERIMAGE | // SS_SUNKEN,7,5,73,65 - CONTROL "a", IDB_BACULABMP,"Static",SS_BITMAP|SS_SUNKEN,7,5,73,65 - LTEXT "Bacula Version " VERSION " (" BDATE ")", IDC_VERSION,90,10,239,10 - LTEXT " by Kern Sibbald",IDC_NAME,90,20,239,10 - LTEXT "For more information, see:", - IDC_WWW,90,40,239,10 - LTEXT " www.sibbald.com/bacula", - IDC_WWW,90,50,239,10 - LTEXT " ", - IDC_WWW,90,60,239,10 - LTEXT " ", - IDC_WWW,90,70,239,10 - LTEXT "Copyright (C) 1999-2004, Kern Sibbald", - IDC_COPYRIGHT,7,120,175,10 - LTEXT "Licensed under GNU GPL 2.0.", - IDC_TRADEMARK,7,130,175,10 + CONTROL IDB_BACULABMP,IDB_BACULABMP,"Static",SS_BITMAP|SS_SUNKEN,7,5,32,32 + + LTEXT " by Kern Sibbald",IDC_NAME,134,38,78,10 + LTEXT "For more information, see:",-1,115,60,100,10 + LTEXT " www.sibbald.com/bacula",IDC_WWW,115,70,100,10 +// LTEXT " ",-1,69,81,100,10 +// LTEXT " ",-1,90,70,100,10 + LTEXT "Copyright (C) 1999-2003, Kern Sibbald",IDC_COPYRIGHT,7,120,175,10 + LTEXT "Licensed under GNU GPL 2.0.",IDC_TRADEMARK,7,130,175,10 + RTEXT "Build Date:",-1,108,24,42,8 + RTEXT "Bacula Version:",-1,100,9,50,8 + LTEXT VERSION,IDC_VERSION,159,10,65,8 + LTEXT BDATE,-1,159,24,65,10 + END ///////////////////////////////////////////////////////////////////////////// diff --git a/bacula/src/filed/win32/winservice.cpp b/bacula/src/filed/win32/winservice.cpp index 98cb4140dd..3492da70e6 100755 --- a/bacula/src/filed/win32/winservice.cpp +++ b/bacula/src/filed/win32/winservice.cpp @@ -289,8 +289,8 @@ bacService::BaculaServiceMain() } // And find the RegisterServiceProcess function - DWORD WINAPI (*RegisterService)(DWORD, DWORD); - RegisterService = (DWORD (*)(DWORD, DWORD)) + DWORD (WINAPI *RegisterService)(DWORD, DWORD); + RegisterService = (DWORD (WINAPI *)(DWORD, DWORD)) GetProcAddress(kerneldll, "RegisterServiceProcess"); if (RegisterService == NULL) { MessageBox(NULL, "Registry service not found: Bacula service not started", @@ -426,7 +426,7 @@ bacService::InstallService() // Append the service-start flag to the end of the path: if ((int)strlen(path) + 20 + (int)strlen(BaculaRunService) < pathlength) { - sprintf(servicecmd, "\"%s\" %s -c %s", path, BaculaRunService, path); + sprintf(servicecmd, "\"%s\" %s -c \"%s\"", path, BaculaRunService, path); len = strlen(servicecmd) - 1; for ( ; len > 0; len--) { if (servicecmd[len] == '\\') { @@ -781,7 +781,7 @@ void LogErrorMsg(char *message, char *fname, int lineno) } LocalFree(msg); } -typedef BOOL WINAPI (*WinAPI)(SC_HANDLE, DWORD, LPVOID); +typedef BOOL (WINAPI * WinAPI)(SC_HANDLE, DWORD, LPVOID); void set_service_description(SC_HANDLE hSCManager, SC_HANDLE hService, LPSTR lpDesc) diff --git a/bacula/src/findlib/attribs.c b/bacula/src/findlib/attribs.c index 87514c67c0..6cfcaa6404 100755 --- a/bacula/src/findlib/attribs.c +++ b/bacula/src/findlib/attribs.c @@ -31,7 +31,7 @@ #include "bacula.h" #include "find.h" -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) /* Forward referenced subroutines */ static int set_win32_attributes(JCR *jcr, ATTR *attr, BFILE *ofd); @@ -277,7 +277,7 @@ int set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd) mode_t old_mask; int stat = 1; -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) if (attr->data_stream == STREAM_WIN32_DATA || attr->data_stream == STREAM_WIN32_GZIP_DATA) { if (is_bopen(ofd)) { @@ -363,7 +363,7 @@ int set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd) /* */ /*=============================================================*/ -#ifndef HAVE_CYGWIN +#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) /* * It is possible to piggyback additional data e.g. ACLs on @@ -390,7 +390,7 @@ int encode_attribsEx(JCR *jcr, char *attribsEx, FF_PKT *ff_pkt) /* */ /*=============================================================*/ -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) int encode_attribsEx(JCR *jcr, char *attribsEx, FF_PKT *ff_pkt) { diff --git a/bacula/src/findlib/bfile.c b/bacula/src/findlib/bfile.c index 2ade59f41f..600b6d5349 100644 --- a/bacula/src/findlib/bfile.c +++ b/bacula/src/findlib/bfile.c @@ -92,7 +92,7 @@ char *stream_to_ascii(int stream) * =============================================================== */ -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) void unix_name_to_win32(POOLMEM **win32_name, char *name); extern "C" HANDLE get_osfhandle(int fd); @@ -213,7 +213,11 @@ int bopen(BFILE *bfd, const char *fname, int flags, mode_t mode) } else if (flags & O_WRONLY) { /* Open existing for write */ if (bfd->use_backup_api) { - dwaccess = GENERIC_WRITE|FILE_ALL_ACCESS|WRITE_OWNER|WRITE_DAC|ACCESS_SYSTEM_SECURITY; +#ifdef HAVE_WIN32 + dwaccess = GENERIC_WRITE|/*FILE_ALL_ACCESS|*/WRITE_OWNER|WRITE_DAC/*|ACCESS_SYSTEM_SECURITY*/; +#else + dwaccess = GENERIC_WRITE|FILE_ALL_ACCESS|WRITE_OWNER|WRITE_DAC|ACCESS_SYSTEM_SECURITY; +#endif dwflags = FILE_FLAG_BACKUP_SEMANTICS; } else { dwaccess = GENERIC_WRITE; diff --git a/bacula/src/findlib/bfile.h b/bacula/src/findlib/bfile.h index 67c9dc1d84..5356182c39 100644 --- a/bacula/src/findlib/bfile.h +++ b/bacula/src/findlib/bfile.h @@ -28,7 +28,7 @@ #ifndef __BFILE_H #define __BFILE_H -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) #include #include "winapi.h" diff --git a/bacula/src/findlib/create_file.c b/bacula/src/findlib/create_file.c index 3bf61b4535..500061d25a 100644 --- a/bacula/src/findlib/create_file.c +++ b/bacula/src/findlib/create_file.c @@ -179,7 +179,7 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) return CF_ERROR; } return CF_EXTRACT; - +#ifndef HAVE_WIN32 // none of these exists on MS Windows case FT_RAW: /* Bacula raw device e.g. /dev/sda1 */ case FT_FIFO: /* Bacula fifo to save data */ case FT_SPEC: @@ -240,7 +240,7 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace) return CF_ERROR; } return CF_CREATED; - +#endif } /* End inner switch */ case FT_DIR: diff --git a/bacula/src/findlib/enable_priv.c b/bacula/src/findlib/enable_priv.c index f85802a508..4095ef2296 100755 --- a/bacula/src/findlib/enable_priv.c +++ b/bacula/src/findlib/enable_priv.c @@ -37,7 +37,7 @@ /* */ /*=============================================================*/ -#ifndef HAVE_CYGWIN +#if !defined(HAVE_CYGWIN) && !defined(WIN32) int enable_backup_privileges(JCR *jcr, int ignore_errors) { return 0; } @@ -53,7 +53,7 @@ int enable_backup_privileges(JCR *jcr, int ignore_errors) /* */ /*=============================================================*/ -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(WIN32) void win_error(JCR *jcr, char *prefix, DWORD lerror); diff --git a/bacula/src/findlib/makepath.c b/bacula/src/findlib/makepath.c index 03c9b07faf..bc1fb33989 100644 --- a/bacula/src/findlib/makepath.c +++ b/bacula/src/findlib/makepath.c @@ -130,6 +130,18 @@ make_dir(JCR *jcr, const char *dir, const char *dirpath, mode_t mode, int *creat return fail; } +/* return non-zero if path is absolute or zero if relative. */ + +int +isAbsolute(const char *path) +{ +#if defined(HAVE_CYGWIN) || defined(WIN32) + return path[1] == ':' || *path == '/' || *path == '\\'; /* drivespec:/blah is absolute */ +#else + return *path == '/'; +#endif +} + /* Ensure that the directory ARGPATH exists. Remove any trailing slashes from ARGPATH before calling this function. @@ -200,7 +212,7 @@ make_path( re_protect = 0; } -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) /* Because of silly Win32 security, we allow everything */ tmp_mode = S_IRWXUGO; re_protect = 0; @@ -213,7 +225,7 @@ make_path( /* If we've saved the cwd and DIRPATH is an absolute pathname, we must chdir to `/' in order to enable the chdir optimization. So if chdir ("/") fails, turn off the optimization. */ - if (cwd.do_chdir && *dirpath == '/' && chdir ("/") < 0) { + if (cwd.do_chdir && isAbsolute(dirpath) && chdir ("/") < 0) { cwd.do_chdir = 0; } diff --git a/bacula/src/findlib/match.c b/bacula/src/findlib/match.c index 823e3b5a10..4e6f69d157 100644 --- a/bacula/src/findlib/match.c +++ b/bacula/src/findlib/match.c @@ -39,12 +39,7 @@ #undef bmalloc #define bmalloc(x) sm_malloc(__FILE__, __LINE__, x) -#ifdef HAVE_CYGWIN -static int win32_client = 1; -#else -static int win32_client = 0; -#endif - +extern const int win32_client; /* * Initialize structures for filename matching @@ -178,7 +173,7 @@ void add_fname_to_include_list(FF_PKT *ff, int prefixed, char *fname) break; } } -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) /* Convert any \'s into /'s */ for (p=inc->fname; *p; p++) { if (*p == '\\') { @@ -210,7 +205,7 @@ void add_fname_to_exclude_list(FF_PKT *ff, char *fname) int len; struct s_excluded_file *exc, **list; -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) /* Convert any \'s into /'s */ for (char *p=fname; *p; p++) { if (*p == '\\') { diff --git a/bacula/src/findlib/protos.h b/bacula/src/findlib/protos.h index 4355b12607..a77b7644f1 100644 --- a/bacula/src/findlib/protos.h +++ b/bacula/src/findlib/protos.h @@ -22,7 +22,6 @@ MA 02111-1307, USA. */ - /* from attribs.c */ void encode_stat (char *buf, FF_PKT *ff_pkt, int data_stream); int decode_stat (char *buf, struct stat *statp, int32_t *LinkFI); diff --git a/bacula/src/findlib/save-cwd.c b/bacula/src/findlib/save-cwd.c index d5f8184dbb..cd68d39443 100644 --- a/bacula/src/findlib/save-cwd.c +++ b/bacula/src/findlib/save-cwd.c @@ -71,7 +71,11 @@ save_cwd(struct saved_cwd *cwd) } if (!have_working_fchdir) { - POOLMEM *buf = get_pool_memory(PM_FNAME); +#ifdef HAVE_WIN32 + POOLMEM *buf = get_memory(MAX_PATH); +#else + POOLMEM *buf = get_memory(5000); +#endif cwd->name = (POOLMEM *)getcwd(buf, sizeof_pool_memory(buf)); if (cwd->name == NULL) { Emsg1(M_ERROR, 0, "Cannot get current directory: %s\n", strerror(errno)); diff --git a/bacula/src/findlib/winapi.c b/bacula/src/findlib/winapi.c index 6715afdca7..bdd7a931a1 100644 --- a/bacula/src/findlib/winapi.c +++ b/bacula/src/findlib/winapi.c @@ -28,7 +28,7 @@ #include "bacula.h" #include "find.h" -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) /* API Pointers */ diff --git a/bacula/src/findlib/winapi.h b/bacula/src/findlib/winapi.h index 0877bc4bc3..4672fdd49f 100644 --- a/bacula/src/findlib/winapi.h +++ b/bacula/src/findlib/winapi.h @@ -27,30 +27,35 @@ #ifndef __WINAPI_H #define __WINAPI_H - -#ifdef HAVE_CYGWIN +#if defined(HAVE_WIN32) +#include +#include +#endif +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) /* In ADVAPI32.DLL */ -typedef BOOL WINAPI (*t_OpenProcessToken)(HANDLE, DWORD, PHANDLE); -typedef BOOL WINAPI (*t_AdjustTokenPrivileges)(HANDLE, BOOL, + +typedef BOOL (WINAPI * t_OpenProcessToken)(HANDLE, DWORD, PHANDLE); +typedef BOOL (WINAPI * t_AdjustTokenPrivileges)(HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD); -typedef BOOL WINAPI (*t_LookupPrivilegeValue)(LPCTSTR, LPCTSTR, PLUID); +typedef BOOL (WINAPI * t_LookupPrivilegeValue)(LPCTSTR, LPCTSTR, PLUID); extern t_OpenProcessToken p_OpenProcessToken; extern t_AdjustTokenPrivileges p_AdjustTokenPrivileges; extern t_LookupPrivilegeValue p_LookupPrivilegeValue; /* In KERNEL32.DLL */ -typedef BOOL WINAPI (*t_GetFileAttributesEx)(LPCTSTR, GET_FILEEX_INFO_LEVELS, +typedef BOOL (WINAPI * t_GetFileAttributesEx)(LPCTSTR, GET_FILEEX_INFO_LEVELS, LPVOID); -typedef BOOL WINAPI (*t_SetProcessShutdownParameters)(DWORD, DWORD); -typedef BOOL WINAPI (*t_BackupRead)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*); -typedef BOOL WINAPI (*t_BackupWrite)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*); +typedef BOOL (WINAPI * t_SetProcessShutdownParameters)(DWORD, DWORD); +typedef BOOL (WINAPI * t_BackupRead)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*); +typedef BOOL (WINAPI * t_BackupWrite)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*); extern t_GetFileAttributesEx p_GetFileAttributesEx; extern t_SetProcessShutdownParameters p_SetProcessShutdownParameters; extern t_BackupRead p_BackupRead; extern t_BackupWrite p_BackupWrite; + #endif #endif /* __WINAPI_H */ diff --git a/bacula/src/lib/attr.c b/bacula/src/lib/attr.c index dc8362afa0..cec5a4d2bb 100644 --- a/bacula/src/lib/attr.c +++ b/bacula/src/lib/attr.c @@ -29,7 +29,7 @@ #include "bacula.h" #include "jcr.h" -extern int win32_client; +extern const int win32_client; ATTR *new_attr() { diff --git a/bacula/src/lib/bnet.c b/bacula/src/lib/bnet.c index c55d953c5d..6a4a15c0b1 100644 --- a/bacula/src/lib/bnet.c +++ b/bacula/src/lib/bnet.c @@ -42,7 +42,13 @@ extern time_t watchdog_time; #define ENODATA EPIPE #endif - +#ifdef HAVE_WIN32 +#define socketRead(fd, buf, len) recv(fd, buf, len, 0) +#define socketWrite(fd, buf, len) send(fd, buf, len, 0) +#else +#define socketRead(fd, buf, len) read(fd, buf, len) +#define socketWrite(fd, buf, len) write(fd, buf, len) +#endif /* @@ -59,7 +65,7 @@ static int32_t read_nbytes(BSOCK *bsock, char *ptr, int32_t nbytes) while (nleft > 0) { do { errno = 0; - nread = read(bsock->fd, ptr, nleft); + nread = socketRead(bsock->fd, ptr, nleft); if (bsock->timed_out || bsock->terminated) { return nread; } @@ -95,7 +101,7 @@ static int32_t write_nbytes(BSOCK *bsock, char *ptr, int32_t nbytes) while (nleft > 0) { do { errno = 0; - nwritten = write(bsock->fd, ptr, nleft); + nwritten = socketWrite(bsock->fd, ptr, nleft); if (bsock->timed_out || bsock->terminated) { return nwritten; } @@ -490,8 +496,9 @@ bnet_wait_data_intr(BSOCK *bsock, int sec) #define NO_DATA 4 /* Valid name, no data record of requested type. */ #endif +#ifndef HAVE_WIN32 extern int h_errno; /* On error has one of the above */ - +#endif /* * Get human readable error for gethostbyname() */ diff --git a/bacula/src/lib/bpipe.c b/bacula/src/lib/bpipe.c index b5bb3fa0bc..831731d5b5 100644 --- a/bacula/src/lib/bpipe.c +++ b/bacula/src/lib/bpipe.c @@ -44,7 +44,7 @@ static void build_argc_argv(char *cmd, int *bargc, char *bargv[], int max_arg); BPIPE *open_bpipe(char *prog, int wait, char *mode) { char *bargv[MAX_ARGV]; - int bargc; + int bargc, i; int readp[2], writep[2]; POOLMEM *tprog; int mode_read, mode_write; @@ -60,7 +60,6 @@ BPIPE *open_bpipe(char *prog, int wait, char *mode) build_argc_argv(mp_chr(tprog), &bargc, bargv, MAX_ARGV); #ifdef xxxxxx printf("argc=%d\n", bargc); - int i; for (i=0; i int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) @@ -217,8 +217,9 @@ int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) } V(mutex); return stat; -} +} +#endif #endif /* HAVE_READDIR_R */ #ifdef xxxxxxxxxx_STRERROR_R @@ -282,7 +283,7 @@ void _v(char *file, int line, pthread_mutex_t *m) } #endif /* DEBUG_MUTEX */ -#ifndef HAVE_CYGWIN +#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) static int del_pid_file_ok = FALSE; #endif @@ -291,7 +292,7 @@ static int del_pid_file_ok = FALSE; */ void create_pid_file(char *dir, char *progname, int port) { -#ifndef HAVE_CYGWIN +#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) int pidfd, len; int oldpid; char pidbuf[20]; @@ -333,7 +334,7 @@ void create_pid_file(char *dir, char *progname, int port) */ int delete_pid_file(char *dir, char *progname, int port) { -#ifndef HAVE_CYGWIN +#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) POOLMEM *fname = get_pool_memory(PM_FNAME); if (!del_pid_file_ok) { diff --git a/bacula/src/lib/daemon.c b/bacula/src/lib/daemon.c index 20dc2fdf52..65410f34ca 100644 --- a/bacula/src/lib/daemon.c +++ b/bacula/src/lib/daemon.c @@ -39,7 +39,7 @@ void daemon_start() { -#ifndef HAVE_CYGWIN +#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32) int i; pid_t cpid; mode_t oldmask; diff --git a/bacula/src/lib/dlist.h b/bacula/src/lib/dlist.h index 11d2f76d75..e607b776cb 100644 --- a/bacula/src/lib/dlist.h +++ b/bacula/src/lib/dlist.h @@ -30,18 +30,24 @@ /* In case you want to specifically specify the offset to the link */ #define OFFSET(item, link) ((char *)(link) - (char *)(item)) - +#ifdef HAVE_WIN32 +/* Extra ***& workaround for VisualC Studio */ +#define foreach_dlist(var, list) \ + for((var)=NULL; (*((void **)&(var))=(void*)((list)->next(var))); ) +#else /* * Loop var through each member of list */ #define foreach_dlist(var, list) \ for((var)=NULL; (((void *)(var))=(list)->next(var)); ) +#endif struct dlink { void *next; void *prev; }; + class dlist { void *head; void *tail; diff --git a/bacula/src/lib/edit.c b/bacula/src/lib/edit.c index 23360905e0..11a2e32924 100644 --- a/bacula/src/lib/edit.c +++ b/bacula/src/lib/edit.c @@ -262,9 +262,16 @@ int size_to_uint64(char *str, int str_len, uint64_t *rtn_value) if (errno != 0 || value < 0) { return 0; } +#if defined(HAVE_WIN32) + /* work around microsofts non handling of uint64 to double cvt*/ + *rtn_value = (uint64_t)(value * (__int64)mult[i]); + Dmsg2(400, "Full value = %lf %" lld "\n", value * (__int64)mult[i], + (uint64_t)(value * (__int64)mult[i])); +#else *rtn_value = (uint64_t)(value * mult[i]); Dmsg2(400, "Full value = %lf %" lld "\n", value * mult[i], (uint64_t)(value * mult[i])); +#endif return 1; } diff --git a/bacula/src/lib/events.c b/bacula/src/lib/events.c index 6e602076b9..d9833f3f18 100644 --- a/bacula/src/lib/events.c +++ b/bacula/src/lib/events.c @@ -138,7 +138,7 @@ bailout: #endif /* IMPLEMENTED */ -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) #include diff --git a/bacula/src/lib/idcache.c b/bacula/src/lib/idcache.c index 8343df5d0d..1c16780afc 100644 --- a/bacula/src/lib/idcache.c +++ b/bacula/src/lib/idcache.c @@ -52,12 +52,17 @@ char *getuser(uid_t uid) pwent = getpwuid(uid); tail = (struct userid *)malloc(sizeof (struct userid)); tail->id.u = uid; +#ifndef HAVE_WIN32 if (pwent == 0 || strcmp(pwent->pw_name, "????????") == 0) { sprintf(usernum_string, "%u", (uint32_t)uid); tail->name = bstrdup(usernum_string); } else { tail->name = bstrdup(pwent->pw_name); } +#else + sprintf(usernum_string, "%u", (uint32_t)uid); + tail->name = bstrdup(usernum_string); +#endif /* Add to the head of the list, so most recently used is first. */ tail->next = user_alist; @@ -102,13 +107,17 @@ char *getgroup(gid_t gid) grent = getgrgid(gid); tail = (struct userid *)malloc(sizeof (struct userid)); tail->id.g = gid; +#ifndef HAVE_WIN32 if (grent == 0 || strcmp(grent->gr_name, "????????") == 0) { sprintf (groupnum_string, "%u", (uint32_t)gid); tail->name = bstrdup(groupnum_string); } else { tail->name = bstrdup(grent->gr_name); } - +#else + sprintf (groupnum_string, "%u", (uint32_t)gid); + tail->name = bstrdup(groupnum_string); +#endif /* Add to the head of the list, so most recently used is first. */ tail->next = group_alist; group_alist = tail; diff --git a/bacula/src/lib/jcr.c b/bacula/src/lib/jcr.c index aaff694372..56aa096410 100755 --- a/bacula/src/lib/jcr.c +++ b/bacula/src/lib/jcr.c @@ -49,7 +49,7 @@ static brwlock_t lock; /* lock for last jobs and JCR chain */ void init_last_jobs_list() { int errstat; - struct s_last_job *job_entry; + struct s_last_job *job_entry = NULL; if (!last_jobs) { last_jobs = new dlist(job_entry, &job_entry->link); memset(&last_job, 0, sizeof(last_job)); diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index 9170135930..0b308fa4e0 100755 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -65,9 +65,9 @@ char catalog_db[] = "Internal"; #endif #endif -char *host_os = HOST_OS; -char *distname = DISTNAME; -char *distver = DISTVER; +const char *host_os = HOST_OS; +const char *distname = DISTNAME; +const char *distver = DISTVER; /* Forward referenced functions */ @@ -107,7 +107,7 @@ void my_name_is(int argc, char *argv[], char *name) l++; } else { l = argv[0]; -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) /* On Windows allow c: junk */ if (l[1] == ':') { l += 2; @@ -162,12 +162,13 @@ void init_msg(JCR *jcr, MSGS *msg) { DEST *d, *dnew, *temp_chain = NULL; - int i, fd; + int i; if (jcr == NULL && msg == NULL) { init_last_jobs_list(); } +#ifndef HAVE_WIN32 /* * Make sure we have fd's 0, 1, 2 open * If we don't do this one of our sockets may open @@ -175,6 +176,7 @@ init_msg(JCR *jcr, MSGS *msg) * send total garbage to our socket. * */ + int fd; fd = open("/dev/null", O_RDONLY, 0644); if (fd > 2) { close(fd); @@ -184,7 +186,7 @@ init_msg(JCR *jcr, MSGS *msg) } } - +#endif /* * If msg is NULL, initialize global chain for STDOUT and syslog */ @@ -741,18 +743,22 @@ d_msg(char *file, int line, int level, char *fmt,...) } if (level <= debug_level) { +#ifdef HAVE_WIN32 +#define SEND_DMSG_TO_FILE +#endif #ifdef SEND_DMSG_TO_FILE if (!trace_fd) { - bsnprintf(buf, sizeof(buf), "%s/bacula.trace", working_directory); + bsnprintf(buf, sizeof(buf), "%s/bacula.trace", working_directory ? working_directory : "."); trace_fd = fopen(buf, "a+"); - if (!trace_fd) { - Emsg2(M_ABORT, 0, _("Cannot open trace file \"%s\": ERR=%s\n"), - buf, strerror(errno)); - } } #endif #ifdef FULL_LOCATION if (details) { + /* visual studio passes the whole path to the file as well + * which makes for very long lines + */ + char *f = strrchr(file, '\\'); + if (f) file = f + 1; len = bsnprintf(buf, sizeof(buf), "%s: %s:%d ", my_name, file, line); } else { len = 0; @@ -765,8 +771,10 @@ d_msg(char *file, int line, int level, char *fmt,...) va_end(arg_ptr); #ifdef SEND_DMSG_TO_FILE - fputs(buf, trace_fd); - fflush(trace_fd); + if (trace_fd) { + fputs(buf, trace_fd); + fflush(trace_fd); + } #else fputs(buf, stdout); #endif @@ -831,10 +839,6 @@ t_msg(char *file, int line, int level, char *fmt,...) if (!trace_fd) { bsnprintf(buf, sizeof(buf), "%s/bacula.trace", working_directory); trace_fd = fopen(buf, "a+"); - if (!trace_fd) { - Emsg2(M_ABORT, 0, _("Cannot open trace file \"%s\": ERR=%s\n"), - buf, strerror(errno)); - } } #ifdef FULL_LOCATION @@ -849,10 +853,11 @@ t_msg(char *file, int line, int level, char *fmt,...) va_start(arg_ptr, fmt); bvsnprintf(buf+len, sizeof(buf)-len, (char *)fmt, arg_ptr); va_end(arg_ptr); - - fputs(buf, trace_fd); - fflush(trace_fd); - } + if (trace_fd != NULL) { + fputs(buf, trace_fd); + fflush(trace_fd); + } + } } diff --git a/bacula/src/lib/parse_conf.c b/bacula/src/lib/parse_conf.c index 4e6ee8da82..fddab60bdd 100755 --- a/bacula/src/lib/parse_conf.c +++ b/bacula/src/lib/parse_conf.c @@ -66,8 +66,16 @@ extern int r_first; extern int r_last; extern pthread_mutex_t res_mutex; extern struct s_res resources[]; -extern CURES res_all; +#ifdef HAVE_WIN32 +// work around visual studio name manling preventing external linkage since res_all +// is declared as a different type when instantiated. +extern "C" CURES res_all; +extern "C" int res_all_size; +#else +extern CURES res_all; extern int res_all_size; +#endif + static bool res_locked = false; /* set when resource chains locked */ diff --git a/bacula/src/lib/parse_conf.h b/bacula/src/lib/parse_conf.h index 5d63dfc0dc..7a406faabf 100644 --- a/bacula/src/lib/parse_conf.h +++ b/bacula/src/lib/parse_conf.h @@ -111,9 +111,13 @@ void init_resource(int type, struct res_items *item); void save_resource(int type, struct res_items *item, int pass); char *res_to_str(int rcode); /* Loop through each resource of type, returning in var */ +#ifdef HAVE_WIN32 +#define foreach_res(var, type) \ + for(var=NULL; *((void **)&(var))=(void *)GetNextRes((type), (RES *)var);) +#else #define foreach_res(var, type) \ for((var)=NULL; (((void *)(var))=GetNextRes((type), (RES *)var));) - +#endif void store_str(LEX *lc, struct res_items *item, int index, int pass); diff --git a/bacula/src/lib/signal.c b/bacula/src/lib/signal.c index 89151fb5bd..3d7d2d1f2b 100644 --- a/bacula/src/lib/signal.c +++ b/bacula/src/lib/signal.c @@ -34,7 +34,7 @@ */ - +#ifndef HAVE_WIN32 #include "bacula.h" #ifndef _NSIG @@ -320,3 +320,4 @@ void init_signals(void terminate(int sig)) sigaction(SIGLOST, &sighandle, NULL); #endif } +#endif diff --git a/bacula/src/lib/util.c b/bacula/src/lib/util.c index 8f91db6c67..3e41d4fd8a 100644 --- a/bacula/src/lib/util.c +++ b/bacula/src/lib/util.c @@ -498,6 +498,7 @@ POOLMEM *edit_job_codes(JCR *jcr, char *omsg, char *imsg, char *to) char *p, *str; char add[20]; char name[MAX_NAME_LENGTH]; + int i; *omsg = 0; Dmsg1(200, "edit_job_codes: %s\n", imsg); @@ -532,7 +533,7 @@ POOLMEM *edit_job_codes(JCR *jcr, char *omsg, char *imsg, char *to) case 'n': bstrncpy(name, jcr->Job, sizeof(name)); /* There are three periods after the Job name */ - for (int i=0; i<3; i++) { + for (i=0; i<3; i++) { if ((str=strrchr(name, '.')) != NULL) { *str = 0; } diff --git a/bacula/src/lib/var.c b/bacula/src/lib/var.c index 52d147c787..1f1050e5b9 100644 --- a/bacula/src/lib/var.c +++ b/bacula/src/lib/var.c @@ -37,7 +37,7 @@ */ - +#ifndef HAVE_WIN32 #include "bacula.h" #if defined(HAVE_PCREPOSIX) # include @@ -2716,3 +2716,4 @@ char *var_strerror(var_t *var, var_rc_t rc) } return str; } +#endif diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c index d594de8cdf..cbf6e513fe 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -31,13 +31,12 @@ #include "stored.h" #include "findlib/find.h" -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) int win32_client = 1; #else int win32_client = 0; #endif - static void do_extract(char *fname); static int record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec); diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index 380bd598b1..1e01be67c2 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -28,13 +28,12 @@ #include "stored.h" #include "findlib/find.h" -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) int win32_client = 1; #else int win32_client = 0; #endif - static void do_blocks(char *infname); static void do_jobs(char *infname); static void do_ls(char *fname); diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index 193a03452b..4939581eff 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -55,7 +55,7 @@ static int update_SIG_record(B_DB *db, char *SIGbuf, DEV_RECORD *rec, int type); /* Global variables */ STORES *me; -#ifdef HAVE_CYGWIN +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) int win32_client = 1; #else int win32_client = 0; diff --git a/bacula/src/tools/testfind.c b/bacula/src/tools/testfind.c index 8ace8a7a81..fca5d95a27 100644 --- a/bacula/src/tools/testfind.c +++ b/bacula/src/tools/testfind.c @@ -26,6 +26,13 @@ #include "findlib/find.h" +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +int win32_client = 1; +#else +int win32_client = 0; +#endif + + /* Global variables */ static int num_files = 0; static int max_file_len = 0; diff --git a/bacula/src/tools/testls.c b/bacula/src/tools/testls.c index 236d3b7d8f..ccd0577646 100755 --- a/bacula/src/tools/testls.c +++ b/bacula/src/tools/testls.c @@ -25,6 +25,12 @@ #include "bacula.h" #include "findlib/find.h" +#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32) +int win32_client = 1; +#else +int win32_client = 0; +#endif + /* Global variables */ int attrs = 0; -- 2.39.5