]> git.sur5r.net Git - bacula/bacula/commitdiff
Final touches to Win32 code
authorKern Sibbald <kern@sibbald.com>
Fri, 27 Jun 2003 15:44:48 +0000 (15:44 +0000)
committerKern Sibbald <kern@sibbald.com>
Fri, 27 Jun 2003 15:44:48 +0000 (15:44 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@615 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/kernstodo
bacula/src/baconfig.h
bacula/src/filed/backup.c
bacula/src/filed/restore.c
bacula/src/findlib/attribs.c
bacula/src/findlib/bfile.c
bacula/src/findlib/bfile.h
bacula/src/findlib/create_file.c
bacula/src/findlib/find_one.c
bacula/src/stored/bextract.c

index 44f036c16b580ac1ac64ebf392553dfe930b5d53..532387eaaf933d6124f98a8647e95f2e6a6d7346 100644 (file)
@@ -17,6 +17,7 @@ Documentation to do: (any release a little bit at a time)
 - Document need to add "-u root" to most of MySQL script calls
   (./create_mys... ./make_my...).
 - Document c:/working directory better than /working directory.
+- Document all the status codes JobLevel, JobType, JobStatus.
 
           
 Testing to do: (painful)
@@ -32,6 +33,12 @@ Testing to do: (painful)
 - Figure out how to use ssh or stunnel to protect Bacula communications.
 
 For 1.31 release:
+- Non-fatal errors are not correct counting attribs.c:277
+- In Win portable restore the directory is not create    
+   27-Jun-2003 16:52 tibs-fd: kernsrestore.2003-06-27_16.52.20 Error:
+   create_file.c:175 Could not create
+   /tmp/bacula-restores/cygwin/home/kern/bacula/k/src/dird/dird_conf.o: 0
+   ERR=The system cannot find the path specified.
 - Finish Windows implementation (add setting of correct type on restore,
   add Portable Data Format flag).
 - Remove multiple simultaneous devices code in SD.
index 86525db417839a5b01beb6d405e6493b21676053..f334453666d00e63061844dddbbed88f78fd3286 100644 (file)
 #define STREAM_SHA1_SIGNATURE    10    /* SHA1 signature for the file */
 #define STREAM_WIN32_DATA        11    /* Win32 BackupRead data */
 #define STREAM_WIN32_GZIP_DATA   12    /* Gzipped Win32 BackupRead data */
-#define STREAM_WIN32_ATTRIBUTES  13    /* Unix attribs, but WIN32_DATA follows */
 
 /* 
  *  File type (Bacula defined).           
index fde9eec8876aa68ecc3654c649ab86c32be972b8..cb0b56be419d302f6d597fae71eb51758c071434 100644 (file)
@@ -194,7 +194,7 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr)
 
    binit(&ff_pkt->bfd);
    if (ff_pkt->flags & FO_PORTABLE) {
-      set_win32_backup(&ff_pkt->bfd, 0); /* disable Win32 BackupRead() */
+      set_portable_backup(&ff_pkt->bfd); /* disable Win32 BackupRead() */
    }
 
    /* 
@@ -205,7 +205,7 @@ static int save_file(FF_PKT *ff_pkt, void *vjcr)
    if (ff_pkt->type != FT_LNKSAVED && (S_ISREG(ff_pkt->statp.st_mode) && 
         ff_pkt->statp.st_size > 0) || 
         ff_pkt->type == FT_RAW || ff_pkt->type == FT_FIFO ||
-        (is_win32_backup() && ff_pkt->type == FT_DIR)) {
+        (!is_portable_backup(&ff_pkt->bfd) && ff_pkt->type == FT_DIR)) {
       btimer_id tid;   
       if (ff_pkt->type == FT_FIFO) {
         tid = start_thread_timer(pthread_self(), 60);
index fc356f09dc3e65a32c9a5a936d4e08cb107438cc..bc50195b7b4b500f43cb68b712a6e770cc0fea4a 100644 (file)
@@ -188,24 +188,11 @@ void do_restore(JCR *jcr)
         }  
         break;
 
-      /* Windows Backup data stream */
-      case STREAM_WIN32_DATA:  
-        if (!is_win32_backup()) {
-           if (!non_support_data) {
-               Jmsg(jcr, M_ERROR, 0, _("%s stream not supported on this Client.\n"),
-                 stream_to_ascii(stream));
-           }
-           extract = FALSE;
-           non_support_data++;
-           continue;
-        }
-        goto extract_data;
-
       /* Data stream */
       case STREAM_FILE_DATA:
       case STREAM_SPARSE_DATA: 
+      case STREAM_WIN32_DATA:  
 
-extract_data:
         if (extract) {
            if (stream == STREAM_SPARSE_DATA) {
               ser_declare;
@@ -243,22 +230,10 @@ extract_data:
         }
         break;
 
-      /* Windows Backup GZIP data stream */
-      case STREAM_WIN32_GZIP_DATA:  
-        if (!is_win32_backup()) {
-           if (!non_support_attr) {
-               Jmsg(jcr, M_ERROR, 0, _("%s stream not supported on this Client.\n"),
-                 stream_to_ascii(stream));
-           }
-           extract = FALSE;
-           non_support_attr++;
-           continue;
-        }
-        /* Fall through desired */
-
       /* GZIP data stream */
       case STREAM_GZIP_DATA:
       case STREAM_SPARSE_GZIP_DATA:  
+      case STREAM_WIN32_GZIP_DATA:  
 #ifdef HAVE_LIBZ
         if (extract) {
            ser_declare;
index 1fb2a7f22bdc0b84d21685ca84aae9801bb412a5..9e192c0d01afc5e8c47bf1ea3826c743e035adba 100755 (executable)
@@ -34,8 +34,7 @@
 #ifdef HAVE_CYGWIN
 
 /* Forward referenced subroutines */
-static
-int set_win32_attributes(JCR *jcr, ATTR *attr, BFILE *ofd);
+static int set_win32_attributes(JCR *jcr, ATTR *attr, BFILE *ofd);
 void unix_name_to_win32(POOLMEM **win32_name, char *name);
 void win_error(JCR *jcr, char *prefix, POOLMEM *ofile);
 HANDLE bget_handle(BFILE *bfd);
@@ -60,7 +59,7 @@ int select_data_stream(FF_PKT *ff_pkt)
    int stream;
 
    /* Note, no sparse option for win32_data */
-   if (is_win32_backup()) {
+   if (!is_portable_backup(&ff_pkt->bfd)) {
       stream = STREAM_WIN32_DATA;
       ff_pkt->flags &= ~FO_SPARSE;
    } else if (ff_pkt->flags & FO_SPARSE) {
@@ -237,8 +236,19 @@ int set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
    int stat = 1;
 
 #ifdef HAVE_CYGWIN
+   if (attr->data_stream == STREAM_WIN32_DATA ||
+       attr->data_stream == STREAM_WIN32_GZIP_DATA) {
+      if (is_bopen(ofd)) {
+        bclose(ofd); 
+      }
+      return 1;
+   }
+
    if (attr->stream == STREAM_UNIX_ATTRIBUTES_EX &&
        set_win32_attributes(jcr, attr, ofd)) {
+      if (is_bopen(ofd)) {
+        bclose(ofd); 
+      }
       return 1;
    }
    /*
@@ -264,18 +274,18 @@ int set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
    if (attr->type == FT_LNK) {
       /* Change owner of link, not of real file */
       if (lchown(attr->ofname, attr->statp.st_uid, attr->statp.st_gid) < 0) {
-         Jmsg2(jcr, M_WARNING, 0, _("Unable to set file owner %s: ERR=%s\n"),
+         Jmsg2(jcr, M_ERROR, 0, _("Unable to set file owner %s: ERR=%s\n"),
            attr->ofname, strerror(errno));
         stat = 0;
       }
    } else {
       if (chown(attr->ofname, attr->statp.st_uid, attr->statp.st_gid) < 0) {
-         Jmsg2(jcr, M_WARNING, 0, _("Unable to set file owner %s: ERR=%s\n"),
+         Jmsg2(jcr, M_ERROR, 0, _("Unable to set file owner %s: ERR=%s\n"),
            attr->ofname, strerror(errno));
         stat = 0;
       }
       if (chmod(attr->ofname, attr->statp.st_mode) < 0) {
-         Jmsg2(jcr, M_WARNING, 0, _("Unable to set file modes %s: ERR=%s\n"),
+         Jmsg2(jcr, M_ERROR, 0, _("Unable to set file modes %s: ERR=%s\n"),
            attr->ofname, strerror(errno));
         stat = 0;
       }
@@ -283,7 +293,7 @@ int set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
       /* FreeBSD user flags */
 #ifdef HAVE_CHFLAGS
       if (chflags(attr->ofname, attr->statp.st_flags) < 0) {
-         Jmsg2(jcr, M_WARNING, 0, _("Unable to set file flags %s: ERR=%s\n"),
+         Jmsg2(jcr, M_ERROR, 0, _("Unable to set file flags %s: ERR=%s\n"),
            attr->ofname, strerror(errno));
         stat = 0;
       }
@@ -345,7 +355,7 @@ int encode_attribsEx(JCR *jcr, char *attribsEx, FF_PKT *ff_pkt)
 
    attribsEx[0] = 0;                 /* no extended attributes */
 
-   if (!p_GetFileAttributesEx) {
+   if (!p_GetFileAttributesEx) {                                
       return STREAM_UNIX_ATTRIBUTES;
    }
 
@@ -398,8 +408,7 @@ int encode_attribsEx(JCR *jcr, char *attribsEx, FF_PKT *ff_pkt)
  * Returns:  1 on success
  *          0 on failure
  */
-static
-int set_win32_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
+static int set_win32_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
 {
    char *p = attr->attrEx;
    int64_t val;
@@ -449,7 +458,6 @@ int set_win32_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
 
    /* At this point, we have reconstructed the WIN32_FILE_ATTRIBUTE_DATA pkt */
 
-
    if (!is_bopen(ofd)) {
       Dmsg1(100, "File not open: %s\n", attr->ofname);
       bopen(ofd, attr->ofname, O_WRONLY|O_BINARY, 0);  /* attempt to open the file */
index 6ba27c29dd6a7e352150ef17884925073b90579c..a82c424e2f890f04b1a7c57724add08871c000fb 100644 (file)
  *
  * ===============================================================
  */
+
+int is_win32_stream(int stream)
+{
+   switch (stream) {
+   case STREAM_WIN32_DATA:
+   case STREAM_WIN32_GZIP_DATA:
+      return 1;
+   }
+   return 0;
+}
+
 char *stream_to_ascii(int stream)
 {
    static char buf[20];
@@ -46,7 +57,6 @@ char *stream_to_ascii(int stream)
       return "GZIP data";
    case STREAM_SPARSE_GZIP_DATA:
       return "GZIP sparse data";
-   case STREAM_WIN32_ATTRIBUTES:
       return "Win32 attributes";
    case STREAM_WIN32_DATA:
       return "Win32 data";
@@ -89,41 +99,52 @@ void unix_name_to_win32(POOLMEM **win32_name, char *name);
 extern "C" HANDLE get_osfhandle(int fd);
 
 
+
 void binit(BFILE *bfd)
 {
    bfd->fid = -1;
    bfd->mode = BF_CLOSED;
-   bfd->use_backup_api = p_BackupRead && p_BackupWrite;
+   bfd->use_backup_api = have_win32_api();
    bfd->errmsg = NULL;
    bfd->lpContext = NULL;
    bfd->lerror = 0;
 }
 
 /*
- * Enables/disables using the Backup API (win32_data).
+ * Enables using the Backup API (win32_data).
  *   Returns 1 if function worked
  *   Returns 0 if failed (i.e. do not have Backup API on this machine)
  */
-int set_win32_backup(BFILE *bfd, int enable)
+int set_win32_backup(BFILE *bfd
 {
-   if (!enable) {
-      bfd->use_backup_api = 0;
-      return 1;
-   }
    /* We enable if possible here */
-   bfd->use_backup_api = p_BackupRead && p_BackupWrite;
+   bfd->use_backup_api = have_win32_api();
    return bfd->use_backup_api;
 }
 
+
+int set_portable_backup(BFILE *bfd)
+{
+   bfd->use_backup_api = 0;
+   return 1;
+}
+
 /*
- * Return 1 if we can do Win32 backup
- * return 0 if not
+ * Return 1 if we are NOT using Win32 BackupWrite() 
+ * return 0 if are
  */
-int is_win32_backup(void)
+int is_portable_backup(BFILE *bfd) 
+{
+   return !bfd->use_backup_api;
+}
+
+int have_win32_api()
 {
    return p_BackupRead && p_BackupWrite;
 }
 
+
+
 /*
  * Return 1 if we support the stream
  *       0 if we do not support the stream
@@ -137,10 +158,9 @@ int is_stream_supported(int stream)
    case STREAM_SPARSE_GZIP_DATA:
       return 0;
 #endif
-   case STREAM_WIN32_ATTRIBUTES:
    case STREAM_WIN32_DATA:
    case STREAM_WIN32_GZIP_DATA:
-      return is_win32_backup();   /* check if we support BackupRead/Write data */
+      return have_win32_api();
 
    /* Known streams */
 #ifdef HAVE_LIBZ
@@ -194,7 +214,7 @@ 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 = FILE_ALL_ACCESS|WRITE_OWNER|WRITE_DAC|ACCESS_SYSTEM_SECURITY;
+        dwaccess = GENERIC_WRITE|FILE_ALL_ACCESS|WRITE_OWNER|WRITE_DAC|ACCESS_SYSTEM_SECURITY;
         dwflags = FILE_FLAG_BACKUP_SEMANTICS;
       } else {
         dwaccess = GENERIC_WRITE;
@@ -391,14 +411,34 @@ void binit(BFILE *bfd)
    bfd->fid = -1;
 }
 
-int set_win32_backup(BFILE *bfd, int enable)
+int have_win32_api()
+{ 
+   return 0;                         /* no can do */
+} 
+
+/*
+ * Enables using the Backup API (win32_data).
+ *   Returns 1 if function worked
+ *   Returns 0 if failed (i.e. do not have Backup API on this machine)
+ */
+int set_win32_backup(BFILE *bfd) 
+{
+   return 0;                         /* no can do */
+}
+
+
+int set_portable_backup(BFILE *bfd)
 {
-   return !enable;
+   return 1;                         /* no problem */
 }
 
-int is_win32_backup(void)
+/*
+ * Return 1 if we are writing in portable format
+ * return 0 if not
+ */
+int is_portable_backup(BFILE *bfd) 
 {
-   return 0;
+   return 1;                         /* portable by definition */
 }
 
 int is_stream_supported(int stream)
@@ -409,7 +449,6 @@ int is_stream_supported(int stream)
    case STREAM_GZIP_DATA:
    case STREAM_SPARSE_GZIP_DATA:
 #endif
-   case STREAM_WIN32_ATTRIBUTES:
    case STREAM_WIN32_DATA:
    case STREAM_WIN32_GZIP_DATA:
       return 0;
index 6ed03470e47e9d4da7a994f8481f4026a1957156..67c9dc1d8490a9b33570cddee75bc767ebd32805 100644 (file)
@@ -67,9 +67,12 @@ struct BFILE {
 
 void   binit(BFILE *bfd);
 int    is_bopen(BFILE *bfd);
-int    set_win32_backup(BFILE *bfd, int enable);
-int    is_win32_backup();
+int    set_win32_backup(BFILE *bfd);
+int    set_portable_backup(BFILE *bfd);
+int    have_win32_api();
+int    is_portable_backup(BFILE *bfd);
 int    is_stream_supported(int stream);
+int    is_win32_stream(int stream);
 char   *berror(BFILE *bfd);
 int    bopen(BFILE *bfd, const char *fname, int flags, mode_t mode);
 int    bclose(BFILE *bfd);
index fff676d7d8479166c67ed846b5d6db2c4b3458d0..c947cecf1c7d8e7da5b90d4b16e64f08e236d59c 100644 (file)
@@ -61,7 +61,7 @@ static int path_already_seen(char *path, int pnl);
  *     files.
  *
  */
-int create_file(JCR *jcr, ATTR *attr, BFILE *ofd, int replace)
+int create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
 {
    int new_mode, parent_mode, mode;
    uid_t uid;
@@ -70,25 +70,10 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *ofd, int replace)
    bool exists = false;
    struct stat mstatp;
 
-   binit(ofd);
-   /* Set desired writing mode (BackupWrite() or write()) */
-   switch (attr->data_stream) {
-   case 0:
-      break;                         /* use default defined by system */
-
-   /* These streams require using BackupWrite() */
-   case STREAM_WIN32_ATTRIBUTES:
-   case STREAM_WIN32_DATA:
-   case STREAM_WIN32_GZIP_DATA:
-      if (!set_win32_backup(ofd, 1)) { /* use BackupWrite() */
-         Jmsg(jcr, M_ERROR, 0, _("Could not set Win32 output format.\n"));
-        return CF_ERROR;
-      }
-
-   /* All other stream use standard system I/O (portable) */
-   default:
-      set_win32_backup(ofd, 0);       /* Disable using BackupWrite() */
-      break;
+   if (is_win32_stream(attr->data_stream)) { 
+      set_win32_backup(bfd);
+   } else {
+      set_portable_backup(bfd);
    }
 
    new_mode = attr->statp.st_mode;
@@ -167,7 +152,8 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *ofd, int replace)
             * exists. Normally, this should do nothing.
             */
            if (make_path(jcr, attr->ofname, parent_mode, parent_mode, uid, gid, 1, NULL) != 0) {
-               Dmsg1(0, "Could not make path. %s\n", attr->ofname);
+               Dmsg1(10, "Could not make path. %s\n", attr->ofname);
+              attr->ofname[pnl] = savechr;     /* restore full name */
               return CF_ERROR;
            }
         }
@@ -184,9 +170,10 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *ofd, int replace)
            mode |= O_CTG;               /* set contiguous bit if needed */
         }
          Dmsg1(50, "Create file: %s\n", attr->ofname);
-        if ((bopen(ofd, attr->ofname, mode, S_IRUSR | S_IWUSR)) < 0) {
-            Jmsg2(jcr, M_ERROR, 0, _("Could not create %s: ERR=%s\n"), 
-                 attr->ofname, berror(ofd));
+        if ((bopen(bfd, attr->ofname, mode, S_IRUSR | S_IWUSR)) < 0) {
+            Jmsg2(jcr, M_ERROR, 0, _("Could not create %s: %d ERR=%s\n"), 
+                 attr->ofname, berror(bfd));
+
            return CF_ERROR;
         }
         return CF_EXTRACT;
@@ -219,9 +206,9 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *ofd, int replace)
            } else {
               tid = NULL;
            }
-           if ((bopen(ofd, attr->ofname, mode, 0)) < 0) {
+           if ((bopen(bfd, attr->ofname, mode, 0)) < 0) {
                Jmsg2(jcr, M_ERROR, 0, _("Could not open %s: ERR=%s\n"), 
-                    attr->ofname, berror(ofd));
+                    attr->ofname, berror(bfd));
               stop_thread_timer(tid);
               return CF_ERROR;
            }
@@ -261,10 +248,10 @@ int create_file(JCR *jcr, ATTR *attr, BFILE *ofd, int replace)
        *   directory so that the security info will be read
        *   and saved.
        */
-      if (is_win32_backup()) {
-        if ((bopen(ofd, attr->ofname, O_WRONLY|O_BINARY, 0)) < 0) {
+      if (!is_portable_backup(bfd)) {
+        if ((bopen(bfd, attr->ofname, O_WRONLY|O_BINARY, 0)) < 0) {
             Jmsg2(jcr, M_ERROR, 0, _("Could not open %s: ERR=%s\n"), 
-                 attr->ofname, berror(ofd));
+                 attr->ofname, berror(bfd));
            return CF_ERROR;
         }
         return CF_EXTRACT;
index 3fbce57e449123bbd6118a13347c9417cc492f3d..b4d8240d97a99d4687f3524f3c6600b4e81f73ac 100755 (executable)
@@ -206,11 +206,11 @@ find_one_file(JCR *jcr, FF_PKT *ff_pkt, int handle_file(FF_PKT *ff, void *hpkt),
       dev_t our_device = ff_pkt->statp.st_dev;
 
       /*  
-       * If we are using Win32 backup API, don't check
+       * If we are using Win32 (non-portable) backup API, don't check
        *  access as everything is more complicated, and
        *  in principle, we should be able to access everything.
        */
-      if (!is_win32_backup()) {
+      if (!have_win32_api() || (ff_pkt->flags & FO_PORTABLE)) {
         if (access(fname, R_OK) == -1 && geteuid() != 0) {
            /* Could not access() directory */
            ff_pkt->type = FT_NOACCESS;
index 3a20e5b9851be3e1382d6ef952740e15ec781989..8d063902ea4297ab44481f6bc871a08d4b5b9bbe 100644 (file)
@@ -305,24 +305,11 @@ static void record_cb(JCR *jcr, DEVICE *dev, DEV_BLOCK *block, DEV_RECORD *rec)
         }  
       }
 
-   /* Windows Backup data stream */
-   case STREAM_WIN32_DATA:  
-      if (!is_win32_backup()) {
-        if (!non_support_data) {
-            Jmsg(jcr, M_ERROR, 0, _("Win32 backup data not supported on this Client.\n"));
-        }
-        extract = FALSE;
-        non_support_data++;
-        return;
-      }
-      goto extract_data;
-   
-
    /* Data stream and extracting */
    case STREAM_FILE_DATA:
    case STREAM_SPARSE_DATA:
+   case STREAM_WIN32_DATA:  
 
-extract_data:
       if (extract) {
         if (rec->Stream == STREAM_SPARSE_DATA) {
            ser_declare;
@@ -351,21 +338,11 @@ extract_data:
         fileAddr += wsize;
       }
 
-   /* Windows Backup GZIP data stream */
-   case STREAM_WIN32_GZIP_DATA:  
-      if (!is_win32_backup()) {
-        if (!non_support_attr) {
-            Jmsg(jcr, M_ERROR, 0, _("Win32 GZIP backup data not supported on this Client.\n"));
-        }
-        extract = FALSE;
-        non_support_attr++;
-        return;
-      }
-      /* Fall through desired */
 
    /* GZIP data stream */
    case STREAM_GZIP_DATA:
    case STREAM_SPARSE_GZIP_DATA: 
+   case STREAM_WIN32_GZIP_DATA:  
 #ifdef HAVE_LIBZ
       if (extract) {
         uLongf compress_len;