diff -rud partimage-0.6.4/configure.ac partimage-0.6.4-lzma/configure.ac --- partimage-0.6.4/configure.ac 2007-11-21 12:37:33.000000000 -0500 +++ partimage-0.6.4-lzma/configure.ac 2007-11-21 11:19:24.000000000 -0500 @@ -97,6 +97,8 @@ fi AC_CHECK_LIB([bz2], [BZ2_bzopen], [], AC_MSG_ERROR([*** bzip2 library (libbz2) not found or too old: version 1.0.0 or more recent is need])) +AC_CHECK_LIB([lzmadec], [lzmadec_open], [], + AC_MSG_ERROR([*** lzmadec library not found or too old])) AC_CHECK_LIB([newt], [newtCenteredWindow], [], AC_MSG_ERROR([*** newt library (libnewt) not found])) AC_CHECK_LIB([z], [gzwrite], [], diff -rud partimage-0.6.4/src/client/gui_text.cpp partimage-0.6.4-lzma/src/client/gui_text.cpp --- partimage-0.6.4/src/client/gui_text.cpp 2007-11-21 12:37:33.000000000 -0500 +++ partimage-0.6.4-lzma/src/client/gui_text.cpp 2007-11-21 11:19:23.000000000 -0500 @@ -869,6 +869,9 @@ case COMPRESS_LZO: SNPRINTF(szTemp, i18n("Compression level:................lzo")); break; + case COMPRESS_LZMA: + SNPRINTF(szTemp, i18n("Compression level:................lzma")); + break; default: memset(szTemp, 0, sizeof(szTemp)); } diff -rud partimage-0.6.4/src/client/image_net.h partimage-0.6.4-lzma/src/client/image_net.h --- partimage-0.6.4/src/client/image_net.h 2007-11-21 12:37:33.000000000 -0500 +++ partimage-0.6.4-lzma/src/client/image_net.h 2007-11-21 11:19:23.000000000 -0500 @@ -26,6 +26,7 @@ #include <zlib.h> // gzip compression #include <bzlib.h> // bzip2 compression +#include <lzmadec.h> // lzma compression #include <pthread.h> // ================================================ diff -rud partimage-0.6.4/src/client/imagefile.cpp partimage-0.6.4-lzma/src/client/imagefile.cpp --- partimage-0.6.4/src/client/imagefile.cpp 2007-11-21 12:37:33.000000000 -0500 +++ partimage-0.6.4-lzma/src/client/imagefile.cpp 2007-11-21 11:19:23.000000000 -0500 @@ -43,6 +43,7 @@ #include <zlib.h> // gzip compression #include <bzlib.h> // bzip2 compression +#include <lzmadec.h> // lzma compression CParam g_param; @@ -129,6 +130,7 @@ m_fImageFile = NULL; m_gzImageFile = NULL; m_bzImageFile = NULL; + m_lzmaImageFile = NULL; RETURN; } @@ -390,6 +392,8 @@ nRes = gzread(m_gzImageFile, cBuf, dwLength); else if (m_options.dwCompression == COMPRESS_BZIP2) nRes = BZ2_bzread(m_bzImageFile, cBuf, dwLength); + else if (m_options.dwCompression == COMPRESS_LZMA) + nRes = lzmadec_read(m_lzmaImageFile, (uint8_t *)cBuf, dwLength); else THROW(ERR_COMP); @@ -568,6 +572,8 @@ } else if (m_options.dwCompression == COMPRESS_BZIP2) // Bzip2 compression BZ2_bzclose(m_bzImageFile); + else if (m_options.dwCompression == COMPRESS_LZMA) // Lzma compression + lzmadec_close(m_lzmaImageFile); if (nRes) THROW(ERR_ERRNO, errno); @@ -599,6 +605,8 @@ nRes = gzclose(m_gzImageFile); else if (m_options.dwCompression == COMPRESS_BZIP2) // Bzip2 compression BZ2_bzclose(m_bzImageFile); + else if (m_options.dwCompression == COMPRESS_LZMA) // Lzma compression + lzmadec_close(m_lzmaImageFile); if (nRes) THROW(ERR_ERRNO, errno); @@ -1100,6 +1108,14 @@ else showDebug(1, "bzip2 open\n"); } + else if (m_options.dwCompression == COMPRESS_LZMA) // Lzma compression + { + m_lzmaImageFile = lzmadec_dopen(m_nFdImage); + if (m_lzmaImageFile == NULL) + THROW( errno); + else + showDebug(1, "lzma open\n"); + } else THROW(ERR_COMP); diff -rud partimage-0.6.4/src/client/imagefile.h partimage-0.6.4-lzma/src/client/imagefile.h --- partimage-0.6.4/src/client/imagefile.h 2004-02-03 19:57:36.000000000 -0500 +++ partimage-0.6.4-lzma/src/client/imagefile.h 2007-11-21 11:19:23.000000000 -0500 @@ -43,6 +43,7 @@ FILE *m_fImageFile; gzFile *m_gzImageFile; BZFILE *m_bzImageFile; + lzmadec_FILE *m_lzmaImageFile; int m_nFdImage; diff -rud partimage-0.6.4/src/client/partimage.h partimage-0.6.4-lzma/src/client/partimage.h --- partimage-0.6.4/src/client/partimage.h 2007-11-21 12:37:33.000000000 -0500 +++ partimage-0.6.4-lzma/src/client/partimage.h 2007-11-21 11:19:23.000000000 -0500 @@ -139,6 +139,7 @@ #define COMPRESS_GZIP 1 #define COMPRESS_BZIP2 2 #define COMPRESS_LZO 3 +#define COMPRESS_LZMA 4 // ENCRYPTION #define ENCRYPT_NONE 0 diff -rud partimage-0.6.4/src/shared/image_disk.cpp partimage-0.6.4-lzma/src/shared/image_disk.cpp --- partimage-0.6.4/src/shared/image_disk.cpp 2007-11-21 12:37:33.000000000 -0500 +++ partimage-0.6.4-lzma/src/shared/image_disk.cpp 2007-11-21 13:43:45.000000000 -0500 @@ -328,16 +328,30 @@ checkBzip2: bzImageFile = BZ2_bzopen(szFilename, "rb"); if (bzImageFile == NULL) - goto checkNone; + goto checkLzma; dwRes = BZ2_bzread(bzImageFile, &headVolume, sizeof(CVolumeHeader)); BZ2_bzclose(bzImageFile); if (dwRes != sizeof(CVolumeHeader)) - goto checkNone; + goto checkLzma; if (strncmp(headVolume.szMagicString, szLabel, strlen(szLabel)) == 0) RETURN_int(COMPRESS_BZIP2); showDebug(3, "TRACE_003\n"); + // ------ 1.1 Check for lzma compression +checkLzma: + { // Make sure it's lzma, otherwise the decoder crashes + uint8_t b[4]; + FILE *f = fopen(szFilename, "rb"); + fread(b, 4, 1, f); + fclose(f); + if (b[0] != 0x5d || b[1] != 0x00 || b[2] != 0x00) + goto checkNone; + RETURN_int(COMPRESS_LZMA); + } + + showDebug(3, "TRACE_003\n"); + // ------ 2. Check for no compression checkNone: fImageFile = fopen(szFilename, "rb"); diff -rud partimage-0.6.4/src/shared/image_disk.h partimage-0.6.4-lzma/src/shared/image_disk.h --- partimage-0.6.4/src/shared/image_disk.h 2007-11-21 12:37:33.000000000 -0500 +++ partimage-0.6.4-lzma/src/shared/image_disk.h 2007-11-21 11:19:23.000000000 -0500 @@ -25,6 +25,7 @@ #include <zlib.h> // gzip compression #include <bzlib.h> // bzip2 compression +#include <lzmadec.h> // lzma compression #include <string.h> // ================================================