From ef04a2edf42f6ad635944cafb4f4d0a140705331 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 27 Jun 2003 15:44:48 +0000 Subject: [PATCH] Final touches to Win32 code git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@615 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/kernstodo | 7 +++ bacula/src/baconfig.h | 1 - bacula/src/filed/backup.c | 4 +- bacula/src/filed/restore.c | 29 +----------- bacula/src/findlib/attribs.c | 30 +++++++----- bacula/src/findlib/bfile.c | 79 ++++++++++++++++++++++++-------- bacula/src/findlib/bfile.h | 7 ++- bacula/src/findlib/create_file.c | 45 +++++++----------- bacula/src/findlib/find_one.c | 4 +- bacula/src/stored/bextract.c | 27 +---------- 10 files changed, 114 insertions(+), 119 deletions(-) diff --git a/bacula/kernstodo b/bacula/kernstodo index 44f036c16b..532387eaaf 100644 --- a/bacula/kernstodo +++ b/bacula/kernstodo @@ -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. diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index 86525db417..f334453666 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -120,7 +120,6 @@ #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). diff --git a/bacula/src/filed/backup.c b/bacula/src/filed/backup.c index fde9eec887..cb0b56be41 100644 --- a/bacula/src/filed/backup.c +++ b/bacula/src/filed/backup.c @@ -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); diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index fc356f09dc..bc50195b7b 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.c @@ -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; diff --git a/bacula/src/findlib/attribs.c b/bacula/src/findlib/attribs.c index 1fb2a7f22b..9e192c0d01 100755 --- a/bacula/src/findlib/attribs.c +++ b/bacula/src/findlib/attribs.c @@ -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 */ diff --git a/bacula/src/findlib/bfile.c b/bacula/src/findlib/bfile.c index 6ba27c29dd..a82c424e2f 100644 --- a/bacula/src/findlib/bfile.c +++ b/bacula/src/findlib/bfile.c @@ -37,6 +37,17 @@ * * =============================================================== */ + +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; diff --git a/bacula/src/findlib/bfile.h b/bacula/src/findlib/bfile.h index 6ed03470e4..67c9dc1d84 100644 --- a/bacula/src/findlib/bfile.h +++ b/bacula/src/findlib/bfile.h @@ -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); diff --git a/bacula/src/findlib/create_file.c b/bacula/src/findlib/create_file.c index fff676d7d8..c947cecf1c 100644 --- a/bacula/src/findlib/create_file.c +++ b/bacula/src/findlib/create_file.c @@ -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; diff --git a/bacula/src/findlib/find_one.c b/bacula/src/findlib/find_one.c index 3fbce57e44..b4d8240d97 100755 --- a/bacula/src/findlib/find_one.c +++ b/bacula/src/findlib/find_one.c @@ -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; diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c index 3a20e5b985..8d063902ea 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -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; -- 2.39.5