From: Thorsten Engel Date: Mon, 7 Nov 2005 09:29:37 +0000 (+0000) Subject: Win32 BackupStream decomposition "alpha version" X-Git-Tag: Release-1.38.1~27 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=37ac6eb50d35996db4b9c99f99ed05636bca7ed0;p=bacula%2Fbacula Win32 BackupStream decomposition "alpha version" git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2556 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index ae1ff8e00e..1ac1d634a9 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.c @@ -294,7 +294,7 @@ void do_restore(JCR *jcr) if (is_win32_stream(stream) && !have_win32_api()) { set_portable_backup(&bfd); - flags |= FO_WIN32DECOMP; /* "decompose BackupWrite data */ + flags |= FO_WIN32DECOMP; /* "decompose" BackupWrite data */ } if (extract_data(jcr, &bfd, sd->msg, sd->msglen, &fileAddr, flags) < 0) { diff --git a/bacula/src/findlib/bfile.c b/bacula/src/findlib/bfile.c index 43dce6a7e6..e1ca62b992 100644 --- a/bacula/src/findlib/bfile.c +++ b/bacula/src/findlib/bfile.c @@ -93,6 +93,43 @@ const char *stream_to_ascii(int stream) } #ifdef USE_WIN32STREAMEXTRACTION + +void int64_LE2BE(int64_t* pBE, const int64_t v) +{ + /* convert little endian to big endian */ + if (htonl(1) != 1L) { /* no work if on little endian machine */ + memcpy(pBE, &v, sizeof(int64_t)); + } else { + int i; + uint8_t rv[sizeof(int64_t)]; + uint8_t *pv = (uint8_t *) &v; + + for (i = 0; i < 8; i++) { + rv[i] = pv[7 - i]; + } + memcpy(pBE, &rv, sizeof(int64_t)); + } +} + + +void int32_LE2BE(int32_t* pBE, const int32_t v) +{ + /* convert little endian to big endian */ + if (htonl(1) != 1L) { /* no work if on little endian machine */ + memcpy(pBE, &v, sizeof(int32_t)); + } else { + int i; + uint8_t rv[sizeof(int32_t)]; + uint8_t *pv = (uint8_t *) &v; + + for (i = 0; i < 4; i++) { + rv[i] = pv[3 - i]; + } + memcpy(pBE, &rv, sizeof(int32_t)); + } +} + + BOOL processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, size_t dwSize) { /* pByte contains the buffer @@ -102,14 +139,14 @@ BOOL processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, size_t dwSize) */ PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT* pContext = &(bfd->win32DecompContext); - BOOL bContinue = FALSE; - LONGLONG dwDataOffset = 0; - LONGLONG dwDataLen; + bool bContinue = FALSE; + int64_t dwDataOffset = 0; + int64_t dwDataLen; /* Win32 Stream Header size without name of stream. * = sizeof (WIN32_STREAM_ID)- sizeof(WCHAR*); */ - DWORD dwSizeHeader = 20; + int32_t dwSizeHeader = 20; do { if (pContext->liNextHeader >= dwSize) { @@ -129,8 +166,8 @@ BOOL processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, size_t dwSize) } if (pContext->liNextHeader < dwSize) {/* is a header in this block ? */ - DWORD dwOffsetTarget; - DWORD dwOffsetSource; + int32_t dwOffsetTarget; + int32_t dwOffsetSource; if (pContext->liNextHeader < 0) { /* start of header was before this block, so we @@ -145,8 +182,8 @@ BOOL processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, size_t dwSize) dwOffsetSource = pContext->liNextHeader; } - DWORD dwHeaderPartLen = dwSizeHeader-dwOffsetTarget; - BOOL bHeaderIsComplete; + int32_t dwHeaderPartLen = dwSizeHeader-dwOffsetTarget; + bool bHeaderIsComplete; if (dwHeaderPartLen <= dwSize-dwOffsetSource) /* header (or rest of header) is completely available @@ -164,8 +201,15 @@ BOOL processWin32BackupAPIBlock (BFILE *bfd, void *pBuffer, size_t dwSize) /* recalculate position of next header */ if (bHeaderIsComplete) { - dwDataOffset = pContext->liNextHeader+dwSizeHeader+pContext->header_stream.dwStreamNameSize; - pContext->liNextHeader = dwDataOffset+pContext->header_stream.Size.QuadPart; + /* convert stream name size (32 bit little endian) to machine type */ + int32_t dwNameSize; + int32_LE2BE (&dwNameSize, pContext->header_stream.dwStreamNameSize); + dwDataOffset = dwNameSize+pContext->liNextHeader+dwSizeHeader; + + /* convert stream size (64 bit little endian) to machine type */ + int64_LE2BE (&(pContext->liNextHeader), pContext->header_stream.Size); + pContext->liNextHeader += dwDataOffset; + pContext->bIsInData = pContext->header_stream.dwStreamId == BACKUP_DATA; if (dwDataOffset == dwSize) bContinue = FALSE; @@ -257,7 +301,7 @@ bool have_win32_api() */ bool is_stream_supported(int stream) { - /* No Win32 backup on this machine */ + /* With Win32 backup on this machine */ switch (stream) { case STREAM_WIN32_DATA: #ifdef HAVE_ZLIB diff --git a/bacula/src/findlib/bfile.h b/bacula/src/findlib/bfile.h index a3ac4e733b..4a4f69469a 100644 --- a/bacula/src/findlib/bfile.h +++ b/bacula/src/findlib/bfile.h @@ -37,10 +37,24 @@ struct Python_IO { #endif #ifdef USE_WIN32STREAMEXTRACTION + +/* this should physically correspond to WIN32_STREAM_ID + * from winbase.h on Win32. We didn't inlcude cStreamName + * as we don't use it and don't need it for a correct struct size. + */ + +typedef struct _BWIN32_STREAM_ID { + int32_t dwStreamId; + int32_t dwStreamAttributes; + int64_t Size; + int32_t dwStreamNameSize; +} BWIN32_STREAM_ID, *LPBWIN32_STREAM_ID ; + + typedef struct _PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT { - LONGLONG liNextHeader; - BOOL bIsInData; - WIN32_STREAM_ID header_stream; + int64_t liNextHeader; + bool bIsInData; + BWIN32_STREAM_ID header_stream; } PROCESS_WIN32_BACKUPAPIBLOCK_CONTEXT; #endif