Changeset 826f3afa in rtems


Ignore:
Timestamp:
Oct 11, 2016, 10:15:23 PM (3 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
master
Children:
f5eff00
Parents:
be57318
git-author:
Chris Johns <chrisj@…> (10/11/16 22:15:23)
git-committer:
Chris Johns <chrisj@…> (10/13/16 02:11:40)
Message:

libmisc/xz: Add xz decompression.

Add support to untar XZ compressed files.

Files:
12 added
8 edited

Legend:

Unmodified
Added
Removed
  • cpukit/Makefile.am

    rbe57318 r826f3afa  
    4848include_utf8procdir = $(includedir)/utf8proc
    4949include_utf8proc_HEADERS = libmisc/utf8proc/utf8proc.h
     50
     51include_xzdir = $(includedir)
     52include_xz_HEADERS = libmisc/xz/xz.h
    5053
    5154include_sysdir = $(includedir)/sys
  • cpukit/libmisc/Makefile.am

    rbe57318 r826f3afa  
    156156## libuntar
    157157noinst_LIBRARIES += libuntar.a
    158 libuntar_a_SOURCES = untar/untar.c untar/untar_tgz.c untar/untar.h
     158libuntar_a_SOURCES = untar/untar.c untar/untar_txz.c untar/untar_tgz.c \
     159        untar/untar.h
    159160
    160161EXTRA_DIST += untar/README
     
    193194        uuid/uuid_time.c uuid/uuidd.h uuid/uuidP.h
    194195
     196## xz-embedded
     197noinst_LIBRARIES += libxz.a
     198libxz_a_SOURCES = xz/xz/h xz/xz_crc32.c xz/xz_crc64.c \
     199        xz/xz_dec_lzma2.c xz/xz_dec_stream.c
     200
     201EXTRA_DIST += xz/README xz/COPING
     202
    195203## ---
    196204include $(srcdir)/preinstall.am
  • cpukit/libmisc/untar/untar.h

    rbe57318 r826f3afa  
    2222#include <tar.h>
    2323#include <zlib.h>
     24#include <xz.h>
    2425
    2526#include <rtems/print.h>
     
    118119} Untar_GzChunkContext;
    119120
     121typedef struct {
     122  /**
     123   * @brief Instance of Chunk Context needed for tar decompression.
     124   */
     125  Untar_ChunkContext base;
     126
     127  /**
     128   * @brief Xz context.
     129   */
     130  struct xz_dec* strm;
     131
     132  /**
     133   * @brief Xz buffer.
     134   */
     135  struct xz_buf buf;
     136
     137  /**
     138   * @brief Buffer that contains the inflated data.
     139   */
     140  void *inflateBuffer;
     141
     142  /**
     143   * @brief Size of buffer that contains the inflated data.
     144   */
     145  size_t inflateBufferSize;
     146
     147} Untar_XzChunkContext;
     148
    120149/**
    121150 * @brief Initializes the Untar_ChunkContext files out of a part of a block of
     
    171200int Untar_FromGzChunk_Print(
    172201  Untar_GzChunkContext *ctx,
     202  void *chunk,
     203  size_t chunk_size,
     204  const rtems_printer* printer
     205);
     206
     207/**
     208 * @brief Initializes the Untar_ChunkXzContext.
     209 *
     210 * @param Untar_ChunkXzContext *context [in] Pointer to a context structure.
     211 * @param enum xz_mode mode [in] Dictionary mode.
     212 * @param uint32_t dict_max [in] Maximum size of dictionary.
     213 * @param void *inflateBuffer [in] Pointer to a context structure.
     214 * @param size_t inflateBufferSize [in] Size of inflateBuffer.
     215 */
     216int Untar_XzChunkContext_Init(
     217  Untar_XzChunkContext *ctx,
     218  enum xz_mode mode,
     219  uint32_t dict_max,
     220  void *inflateBuffer,
     221  size_t inflateBufferSize
     222);
     223
     224/*
     225 * @brief Untars a XZ compressed POSIX TAR file.
     226 *
     227 * This is a subroutine used to rip links, directories, and
     228 * files out of a tar.gz/tgz file.
     229 *
     230 * @param Untar_ChunkContext *context [in] Pointer to a context structure.
     231 * @param ssize buflen [in] Size of valid bytes in input buffer.
     232 * @param z_stream *strm [in] Pointer to the current zlib context.
     233 */
     234int Untar_FromXzChunk_Print(
     235  Untar_XzChunkContext *ctx,
    173236  void *chunk,
    174237  size_t chunk_size,
  • cpukit/preinstall.am

    rbe57318 r826f3afa  
    4646        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/utf8proc/utf8proc.h
    4747PREINSTALL_FILES += $(PROJECT_INCLUDE)/utf8proc/utf8proc.h
     48
     49$(PROJECT_INCLUDE)/$(dirstamp):
     50        @$(MKDIR_P) $(PROJECT_INCLUDE)
     51        @: > $(PROJECT_INCLUDE)/$(dirstamp)
     52PREINSTALL_DIRS += $(PROJECT_INCLUDE)/$(dirstamp)
     53
     54$(PROJECT_INCLUDE)/xz.h: libmisc/xz/xz.h $(PROJECT_INCLUDE)/$(dirstamp)
     55        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/xz.h
     56PREINSTALL_FILES += $(PROJECT_INCLUDE)/xz.h
    4857
    4958$(PROJECT_INCLUDE)/sys/$(dirstamp):
  • cpukit/wrapup/Makefile.am

    rbe57318 r826f3afa  
    6666
    6767TMP_LIBS += ../libmisc/libuuid.a
     68TMP_LIBS += ../libmisc/libxz.a
    6869TMP_LIBS += ../libi2c/libi2c.a
    6970
  • testsuites/libtests/configure.ac

    rbe57318 r826f3afa  
    3333AC_PATH_PROG([PAX],[pax],no)
    3434AC_PATH_PROG([GZIP],[gzip],no)
     35AC_PATH_PROG([XZ],[xz],no)
    3536
    3637AS_IF([test "x$PAX" = "xno"],[
     
    4142
    4243AM_CONDITIONAL(TARTESTS,test "$as_ln_s" = "ln -s" && test -n "$PAX" && test -n "$GZIP")
     44AM_CONDITIONAL(TARTEST_XZ,test -n "$XZ")
    4345
    4446AM_CONDITIONAL(HAS_CXX,test "$rtems_cv_HAS_CPLUSPLUS" = "yes")
  • testsuites/libtests/tar01/Makefile.am

    rbe57318 r826f3afa  
    1717BUILT_SOURCES += initial_filesystem_tar_gz.h
    1818
     19if TARTEST_XZ
     20tar01_SOURCES += initial_filesystem_tar_xz.c
     21tar01_SOURCES += initial_filesystem_tar_xz.h
     22
     23BUILT_SOURCES += initial_filesystem_tar_xz.c
     24BUILT_SOURCES += initial_filesystem_tar_xz.h
     25endif TARTEST_XZ
     26
    1927dist_rtems_tests_DATA = tar01.scn
    2028dist_rtems_tests_DATA += tar01.doc
     
    2937AM_CPPFLAGS += -I$(top_srcdir)/../support/include
    3038AM_CPPFLAGS += -I$(top_srcdir)/../psxtests/include
     39
     40if TARTEST_XZ
     41AM_CFLAGS += -DHAVE_XZ=1
     42endif TARTEST_XZ
    3143
    3244LINK_OBJS = $(tar01_OBJECTS) $(tar01_LDADD)
     
    4759initial_filesystem_tar_gz.c: initial_filesystem.tar.gz
    4860        $(BIN2C) -C initial_filesystem.tar.gz initial_filesystem_tar_gz
    49 CLEANFILES += initial_filesystem_tar_gz.h
     61CLEANFILES += initial_filesystem_tar_gz.c
    5062
    5163initial_filesystem_tar_gz.h: initial_filesystem.tar.gz
    5264        $(BIN2C) -H initial_filesystem.tar.gz initial_filesystem_tar_gz
    5365CLEANFILES += initial_filesystem_tar_gz.h
     66
     67initial_filesystem_tar_xz.c: initial_filesystem.tar.xz
     68        $(BIN2C) -C initial_filesystem.tar.xz initial_filesystem_tar_xz
     69CLEANFILES += initial_filesystem_tar_xz.c
     70
     71initial_filesystem_tar_xz.h: initial_filesystem.tar.xz
     72        $(BIN2C) -H initial_filesystem.tar.xz initial_filesystem_tar_xz
     73CLEANFILES += initial_filesystem_tar_xz.h
    5474
    5575initial_filesystem.tar:
     
    7090CLEANFILES += initial_filesystem.tar.gz
    7191
     92initial_filesystem.tar.xz: initial_filesystem.tar
     93        $(XZ) --lzma2=dict=8192 < initial_filesystem.tar > initial_filesystem.tar.xz
     94CLEANFILES += initial_filesystem.tar.xz
     95
    7296endif TARTESTS
    7397
  • testsuites/libtests/tar01/init.c

    rbe57318 r826f3afa  
    2626#include "initial_filesystem_tar.h"
    2727#include "initial_filesystem_tar_gz.h"
     28#if HAVE_XZ
     29#include "initial_filesystem_tar_xz.h"
     30#endif
    2831
    2932const char rtems_test_name[] = "TAR 1";
     
    3538void test_untar_chunks_from_memory(void);
    3639void test_untar_unzip_tgz(void);
     40void test_untar_unzip_txz(void);
    3741
    3842#define TARFILE_START initial_filesystem_tar
     
    4044#define TARFILE_GZ_START initial_filesystem_tar_gz
    4145#define TARFILE_GZ_SIZE  initial_filesystem_tar_gz_size
     46#if HAVE_XZ
     47#define TARFILE_XZ_START initial_filesystem_tar_xz
     48#define TARFILE_XZ_SIZE  initial_filesystem_tar_xz_size
     49#endif
    4250
    4351void test_cat(
     
    92100  int                rv;
    93101  ssize_t            n;
     102
     103  puts( "" );
    94104
    95105  puts( "Copy tar image to test.tar" );
     
    142152  size_t buflen = TARFILE_SIZE;
    143153
     154  puts( "" );
     155
    144156  rtems_print_printer_printf(&printer);
    145157
     
    186198  char inflate_buffer;
    187199
     200  puts( "" );
     201
     202  rtems_test_assert( buflen != 0 );
     203
    188204  rtems_print_printer_printf(&printer);
    189205
     
    219235}
    220236
     237void test_untar_unzip_txz(void)
     238{
     239#if HAVE_XZ
     240  int status;
     241  rtems_printer     printer;
     242  int rv;
     243  Untar_XzChunkContext ctx;
     244  size_t i = 0;
     245  char *buffer = (char *)TARFILE_XZ_START;
     246  size_t buflen = TARFILE_XZ_SIZE;
     247  char inflate_buffer;
     248
     249  puts( "" );
     250
     251  rtems_test_assert( buflen != 0 );
     252
     253  rtems_print_printer_printf(&printer);
     254
     255  /* make a directory to untar it into */
     256  rv = mkdir( "/dest4", 0777 );
     257  rtems_test_assert( rv == 0 );
     258
     259  rv = chdir( "/dest4" );
     260  rtems_test_assert( rv == 0 );
     261
     262  printf( "Untaring chunks from txz - " );
     263
     264  /*
     265   * Use 8K dict, this is set on the command line of xz when compressing.
     266   */
     267  status = Untar_XzChunkContext_Init(&ctx, XZ_DYNALLOC,
     268                                     8 * 1024, &inflate_buffer, 1);
     269  rtems_test_assert(status == UNTAR_SUCCESSFUL);
     270  for(i = 0; i < buflen; i++) {
     271    status = Untar_FromXzChunk_Print(&ctx, &buffer[i], 1, &printer);
     272    rtems_test_assert(status == UNTAR_SUCCESSFUL);
     273  }
     274  printf( "successful\n" );
     275
     276  /******************/
     277  printf( "========= /dest4/home/test_file =========\n" );
     278  test_cat( "/dest4/home/test_file", 0, 0 );
     279
     280  /******************/
     281  printf( "========= /dest4/home/test_script =========\n" );
     282  test_cat( "/dest4/home/test_script", 0, 0 );
     283  test_untar_check_mode("/dest4/home/test_script", 0755);
     284
     285  /******************/
     286  printf( "========= /dest4/symlink =========\n" );
     287  test_cat( "/dest4/symlink", 0, 0 );
     288#endif
     289}
     290
    221291rtems_task Init(
    222292  rtems_task_argument ignored
     
    226296
    227297  test_untar_from_memory();
    228   puts( "" );
    229298  test_untar_from_file();
    230   puts( "" );
    231299  test_untar_chunks_from_memory();
    232   puts( "" );
    233300  test_untar_unzip_tgz();
     301  test_untar_unzip_txz();
    234302
    235303  TEST_END();
Note: See TracChangeset for help on using the changeset viewer.