]> git.sur5r.net Git - bacula/bacula/commitdiff
Apply win32 fixes + add tapetest.c
authorKern Sibbald <kern@sibbald.com>
Tue, 10 Feb 2004 15:54:16 +0000 (15:54 +0000)
committerKern Sibbald <kern@sibbald.com>
Tue, 10 Feb 2004 15:54:16 +0000 (15:54 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@1037 91ce42f0-d328-0410-95d8-f526ca767f89

48 files changed:
bacula/platforms/freebsd/pthreads-fix.txt
bacula/platforms/freebsd/tapetest.c [new file with mode: 0644]
bacula/src/bacula.h
bacula/src/console/conio.c
bacula/src/console/console.c
bacula/src/filed/filed.c
bacula/src/filed/filed.h
bacula/src/filed/filed_conf.c
bacula/src/filed/heartbeat.c
bacula/src/filed/job.c
bacula/src/filed/status.c
bacula/src/filed/win32/winbacula.h
bacula/src/filed/win32/winmain.cpp
bacula/src/filed/win32/winres.rc
bacula/src/filed/win32/winservice.cpp
bacula/src/findlib/attribs.c
bacula/src/findlib/bfile.c
bacula/src/findlib/bfile.h
bacula/src/findlib/create_file.c
bacula/src/findlib/enable_priv.c
bacula/src/findlib/makepath.c
bacula/src/findlib/match.c
bacula/src/findlib/protos.h
bacula/src/findlib/save-cwd.c
bacula/src/findlib/winapi.c
bacula/src/findlib/winapi.h
bacula/src/lib/attr.c
bacula/src/lib/bnet.c
bacula/src/lib/bpipe.c
bacula/src/lib/bshm.c
bacula/src/lib/bsys.c
bacula/src/lib/daemon.c
bacula/src/lib/dlist.h
bacula/src/lib/edit.c
bacula/src/lib/events.c
bacula/src/lib/idcache.c
bacula/src/lib/jcr.c
bacula/src/lib/message.c
bacula/src/lib/parse_conf.c
bacula/src/lib/parse_conf.h
bacula/src/lib/signal.c
bacula/src/lib/util.c
bacula/src/lib/var.c
bacula/src/stored/bextract.c
bacula/src/stored/bls.c
bacula/src/stored/bscan.c
bacula/src/tools/testfind.c
bacula/src/tools/testls.c

index 913d4ee4db86a1ff4c49ddeb948a06a1445adaec..54402f2d7210ac18e2f578796bd3da23d599a83b 100644 (file)
@@ -1,55 +1,7 @@
-From bacula-users-admin@lists.sourceforge.net Mon Oct 20 23:44:13 2003
-Return-Path: <bacula-users-admin@lists.sourceforge.net>
-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 <kern@sibbald.com>; 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 <bacula-users@lists.sourceforge.net>; 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
-       <bacula-users@lists.sourceforge.net>; Mon, 20 Oct 2003 15:25:33 -0400 (EDT)
 From: "Dan Langille" <dan@langille.org>
 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: <mailto:bacula-users-request@lists.sourceforge.net?subject=help>
-List-Post: <mailto:bacula-users@lists.sourceforge.net>
-List-Subscribe:
-       <https://lists.sourceforge.net/lists/listinfo/bacula-users>,
-       <mailto:bacula-users-request@lists.sourceforge.net?subject=subscribe>
-List-Id: Bacula user's email list for support and discussions
-       <bacula-users.lists.sourceforge.net>
-List-Unsubscribe:
-       <https://lists.sourceforge.net/lists/listinfo/bacula-users>,
-       <mailto:bacula-users-request@lists.sourceforge.net?subject=unsubscribe>
-List-Archive:
-       <http://sourceforge.net/mailarchive/forum.php?forum=bacula-users>
 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 (file)
index 0000000..d055ae9
--- /dev/null
@@ -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 <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <string.h>
+#include <strings.h>
+#include <sys/mtio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <ctype.h>
+
+#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<comsize; i++)       /* search for command */
+        if (fstrsch(cmd,  commands[i].key)) {
+           (*commands[i].func)();    /* go execute command */
+           found = 1;
+           break;
+        }
+      if (!found) {
+         printf("%s is an illegal command\n", cmd);
+      }
+      if (quit) {
+        break;
+      }
+   }
+}
+
+static void helpcmd()
+{
+   unsigned int i;
+   usage();
+   printf("  Command    Description\n  =======    ===========\n");
+   for (i=0; i<comsize; i++)
+      printf("  %-10s %s\n", commands[i].key, commands[i].help);
+   printf("\n");
+}
+
+static void usage()
+{
+   fprintf(stderr,
+"Usage: tapetest [-d debug_level] [device_name]\n"
+"       -dnn        set debug level to nn\n"
+"       -?          print this message.\n"  
+"\n");
+
+}
+
+
+
+/*     
+ * Get next input command from terminal.  This
+ * routine is REALLY primitive, and should be enhanced
+ * to have correct backspacing, etc.
+ */
+int 
+get_cmd(char *prompt)
+{
+   int i = 0;
+   int ch;
+   fprintf(stdout, prompt);
+
+   /* We really should turn off echoing and pretty this
+    * up a bit.
+    */
+   cmd[i] = 0;
+   while ((ch = fgetc(stdin)) != EOF) { 
+      if (ch == '\n') {
+        strip_trailing_junk(cmd);
+        return 1;
+      } else if (ch == 4 || ch == 0xd3 || ch == 0x8) {
+        if (i > 0)
+           cmd[--i] = 0;
+        continue;
+      } 
+        
+      cmd[i++] = ch;
+      cmd[i] = 0;
+   }
+   quit = 1;
+   return 0;
+}
index c1ab1928664483631c6c9fe3a19cf68634ed5b8a..35f3c07ea18e1300afaa28da89de69514e65422f 100644 (file)
 #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
 #ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
+#ifdef HAVE_WIN32
+#include <winsock2.h>
+#else
 #include <sys/stat.h>
+#endif
 #include <sys/time.h>
 #if HAVE_SYS_WAIT_H
 #include <sys/wait.h>
index c2f7003e45eb391851b644bcd2330f13723016c7..443ced781234ab5bbf757b0452aea9f37694fa7b 100755 (executable)
@@ -987,7 +987,7 @@ void clrbrk()
 /* Interrupt caught here */
 static void sigintcatcher(int sig)
 {
-   brkflg = 1;
+   brkflg++;
    signal(SIGINT, sigintcatcher);
 }
 
index 3e3dc3cf7bd1ab1658eb99335900d20362e8876b..f61f9e5e58ae8726f0c8db837c84416eac572de2 100644 (file)
@@ -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);
       }
index 4eb34b8ae49abc55a696c47471d66c20f8252dfb..ffc4648c06669444cfbe984777a61f667bb16763 100644 (file)
@@ -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;
index 36a93d2717e7f72a56e3dc6d137a732c860fa766..a4a90910c268f9a6480af5392130ebc7832677c6 100644 (file)
@@ -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 */
index 022d7ba6cb685234687fc205fca237b8d162d5c6..8767ad3733b5ccdd6c31cba56a400a5ec1dd8957 100644 (file)
@@ -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 
index bda617ee11b7466b13f381bb2ff8b07b96edb53a..8e1c033d22ccee69ef689bdb2fa26f2157493afc 100644 (file)
@@ -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 */
index b5f05c13b1e66f344b2465af43149e2ad496cf1a..bc3f09a40e9953311e4419648070359cc70f27d8 100644 (file)
@@ -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)
index 90ebead8f7c92e1bdd7c7d727237ed0291e1527b..17c1e1a48bfe71f36056f63bb09321bda73bf7f5 100755 (executable)
@@ -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 <windows.h>
 
 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);
    
index a9a83dfbb3a0d0985b98536ed0b580205739831f..36dcee03c001080ddc5aa8850f86464ecd492779 100755 (executable)
@@ -31,7 +31,7 @@
 
 // WinUPS header file
 
-#define STRICT
+#define STRICT 1
 #include <windows.h>
 #include <stdio.h>
 #include <process.h>
index 6ab088c8236c200ea56f2a4ded1b35b33cc23215..b839b961f4e997e157a79254995cf03be30ca59e 100755 (executable)
@@ -21,7 +21,9 @@
    Copyright (2000) Kern E. Sibbald
 */
 
+#ifndef HAVE_WIN32
 #define HAVE_CYGWIN 1
+#endif
 
 #include <unistd.h>
 #include <lmcons.h>
@@ -33,7 +35,7 @@
 #include <pthread.h>
 #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);
index df3c35874ef05bdcf2b0a200c02c6e739d116ae0..62b6c566280e3e3e08c45046e24353f505268977 100644 (file)
@@ -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
 
 /////////////////////////////////////////////////////////////////////////////
index 98cb4140dde1bbca04e49eacabd40cc4a9c32b2a..3492da70e68a09786fb37146ee71d7c8bc8efaa9 100755 (executable)
@@ -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) 
index 87514c67c037c127fa997fc819ae1beae9f2630a..6cfcaa640487e2d636f3f1134a2f72d09c2b0296 100755 (executable)
@@ -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)
 {
index 2ade59f41fb7f7737b6fbae8a92b667a1400e9e8..600b6d53491593d648f86d6c7ece4896d75dcf57 100644 (file)
@@ -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;
index 67c9dc1d8490a9b33570cddee75bc767ebd32805..5356182c39a95bbe237cbe869ec64274ede1c358 100644 (file)
@@ -28,7 +28,7 @@
 #ifndef __BFILE_H
 #define __BFILE_H
 
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
 
 #include <windows.h>
 #include "winapi.h"
index 3bf61b4535476c8cd68a49e2569ab962b217de9e..500061d25a1eb343516d9ed41e8f5213d93467b3 100644 (file)
@@ -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:
index f85802a508c4aa5ad1b95170871ff9c72813dcae..4095ef2296175537f58e98341bc133c159721cd9 100755 (executable)
@@ -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);
 
index 03c9b07fafa48ec1285a303974bac6a6806e6cf7..bc1fb33989832a95d368f34aa801a4c931492cc6 100644 (file)
@@ -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;
       }
 
index 823e3b5a1065902927877260fd50a0d56fd1b2b3..4e6f69d157de27df335087ff0289c90a16371717 100644 (file)
 #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 == '\\') {
index 4355b1260780702db664fd052a9e91aa24f6ad69..a77b7644f1a77631bc0af03b9687dab3ce03b420 100644 (file)
@@ -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);
index d5f8184dbb6a7d76d20cbf1cd53a65e109c0ff3e..cd68d394439124427235565e101d243b1dfef0d8 100644 (file)
@@ -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));
index 6715afdca71ed51e4f95121cae93afa92702f04d..bdd7a931a1097ed5df9186c5fac806001f80d54b 100644 (file)
@@ -28,7 +28,7 @@
 #include "bacula.h"
 #include "find.h"
 
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
 
 /* API Pointers */
 
index 0877bc4bc3049da3e61db4aaa5d1cdac2750ac11..4672fdd49fbb44f0df53d3db71c0c9070b7b3d16 100644 (file)
 
 #ifndef __WINAPI_H
 #define __WINAPI_H
-
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_WIN32)
+#include <native.h>
+#include <windef.h>
+#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 */
index dc8362afa07797cc3e9f17abdb6baab58c613ae0..cec5a4d2bbd4a28dd3db988860a348c006de5d7c 100644 (file)
@@ -29,7 +29,7 @@
 #include "bacula.h"
 #include "jcr.h"
 
-extern int win32_client;
+extern const int win32_client;
 
 ATTR *new_attr()
 {
index c55d953c5d22e3c0a4fe6bb481a8a1f8673cac56..6a4a15c0b11b22f72048f06a3ebcc9a7f2e0be72 100644 (file)
@@ -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()
  */
index b5bb3fa0bcf93fa2d624255d52cddb8e85b41b5f..831731d5b57865334eb7f78f529bddab51ccb9ef 100644 (file)
@@ -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<bargc; i++) {
       printf("argc=%d argv=%s:\n", i, bargv[i]);
    }
@@ -92,7 +91,7 @@ BPIPE *open_bpipe(char *prog, int wait, char *mode)
         dup2(readp[1], 1);           /* dup our read to his stdout */
         dup2(readp[1], 2);           /*   and his stderr */
       }
-      for (int i=3; i<=32; i++) {     /* close any open file descriptors */
+      for (i=3; i<=32; i++) {    /* close any open file descriptors */
         close(i);
       }
       execvp(bargv[0], bargv);       /* call the program */
index 89a6274f84baa3ac3b2813955806b5dcf3c4810b..d6c7b3ae8f4ecb49d79e99325c9d14c4c330bafc 100644 (file)
@@ -41,7 +41,7 @@
 
 #include "bacula.h"
 
-#ifndef HAVE_CYGWIN
+#if !defined(HAVE_CYGWIN) && !defined(HAVE_WIN32)
 
 #ifdef NEED_SHARED_MEMORY
 #define SHM_KEY 0x0BACB01           /* key for shared memory */
index b421e2e2e01724594624464748c751b552323e2b..d129747b8971b9b107a9547c7ed3d651337ace24 100644 (file)
@@ -190,7 +190,7 @@ struct tm *localtime_r(const time_t *timep, struct tm *tm)
 #endif /* HAVE_LOCALTIME_R */
 
 #ifndef HAVE_READDIR_R
-
+#ifndef HAVE_WIN32
 #include <dirent.h>
 
 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) {
index 20dc2fdf52fb733cd95b327cb39dfa22d71824eb..65410f34cab9ac20a99e313b3ae5be92a532db90 100644 (file)
@@ -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;
index 11d2f76d7527fd26ad8b9b2442dbbda1ed06654d..e607b776cb115f780f5034d0cc25254e76f025db 100644 (file)
 
 /* 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;
index 23360905e04fa6b85f096c8081589d6f85e6f1ef..11a2e329247165701563ced33ba34a8d4ff16e79 100644 (file)
@@ -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;
 }
 
index 6e602076b9cd5080d3b4e9d61b9b7edbdf7187eb..d9833f3f18b27cbd7552ee9f3b757d1e0143c9c7 100644 (file)
@@ -138,7 +138,7 @@ bailout:
 
 #endif /* IMPLEMENTED */
 
-#ifdef HAVE_CYGWIN
+#if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
 
 #include <windows.h>
 
index 8343df5d0df033e7151bac2b98bd1d540a52529c..1c16780afc8ce977b92a32b4af52a77c135e63eb 100644 (file)
@@ -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;
index aaff694372d03dbab9e5d3e466f2597e81d0eddf..56aa096410dae16528919920e6119f6c916dbd81 100755 (executable)
@@ -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));
index 91701359301c36968f94128e74444ea1dd95c686..0b308fa4e06863c35e23fa634deb1b73b13187f5 100755 (executable)
@@ -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);
+       }
+   }
 }
 
 
index 4e6ee8da8220197f049fdbbf423e3acd86f87971..fddab60bddfca2cfd8cba6d466522d142af93c92 100755 (executable)
@@ -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 */
 
index 5d63dfc0dcbc18914c40aef5302ed86beb580b34..7a406faabf32d315074d49850ed722351a7a2030 100644 (file)
@@ -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);
index 89151fb5bd325bfdc322e45ae9de7b49ec616fc6..3d7d2d1f2b93d7821e9a2f328431c5dce71a55e6 100644 (file)
@@ -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
index 8f91db6c67a44a3e369169963c2503ac57d7c123..3e41d4fd8a7b030eb21d59ee7aff284a7eddf24e 100644 (file)
@@ -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;
                }
index 52d147c787d99f7766d5680d93180f7ae48b7fc4..1f1050e5b9f63f06a783ca6163dda312fbfc41a4 100644 (file)
@@ -37,7 +37,7 @@
 
  */
 
-
+#ifndef HAVE_WIN32
 #include "bacula.h"
 #if defined(HAVE_PCREPOSIX)
 #  include <pcreposix.h>
@@ -2716,3 +2716,4 @@ char *var_strerror(var_t *var, var_rc_t rc)
     }
     return str;
 }
+#endif
index d594de8cdf8cd262c23c1006c5717bec5c22238b..cbf6e513fe4095db0616da56d332797edeeaab60 100644 (file)
 #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);
 
index 380bd598b1ca9a098820ee8cf7c3bfbe2e62a932..1e01be67c2654440db4f499933b30e61c98f1f2a 100644 (file)
 #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);
index 193a03452b3126317b99759348de2cf675dff493..4939581eff47e52c02bbb811dea517e4d69ec5b8 100644 (file)
@@ -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;
index 8ace8a7a817824eeec151ea269c73a683861078d..fca5d95a27ff30d236e854c22125b2a8cbad5686 100644 (file)
 #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;
index 236d3b7d8f27ff302fc029e22ea958e1b2dfaeb4..ccd0577646bbdafb7719580c4214f5ee32d0924c 100755 (executable)
 #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;