0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Macros | Typedefs | Functions | Variables
bmzip.c File Reference
#include "Common/compat-c.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <stdint.h>
#include <stdarg.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include "bmz-internal.h"
Include dependency graph for bmzip.c:

Go to the source code of this file.

Macros

#define BMZ_MAGIC   "BMZ"
 
#define BMZIP_VER   0x0110
 
#define BMZ_HEADER_SZ   (3 + 2 + 1 + 6 + 4)
 
#define BMZ_A_PACK   0
 
#define BMZ_A_UNPACK   1
 
#define BMZ_A_LIST   2
 
#define BMZ_O_BM_ONLY   1
 
#define BMZ_O_STREAM   2 /* TODO */
 
#define LOG(_lvl_, _fmt_,...)
 
#define WARN(_fmt_,...)
 
#define DIE(_fmt_,...)
 
#define BMZ_ALIGN(_mem_, _n_)   (Byte *)(_mem_) + _n_ - (((size_t)(_mem_))%(_n_))
 
#define BMZ_READ_INT16(_p_, _n_)
 
#define BMZ_READ_INT32(_p_, _n_)
 
#define BMZ_READ_INT48(_p_, _n_)
 
#define BMZ_WRITE_INT16(_p_, _n_)
 
#define BMZ_WRITE_INT32(_p_, _n_)
 
#define BMZ_WRITE_INT48(_p_, _n_)
 

Typedefs

typedef unsigned char Byte
 
typedef long long unsigned Llu
 
typedef long unsigned Lu
 

Functions

static void read_bmz_header (int fd, Byte *buf)
 
static void parse_bmz_header (const Byte *buf, uint16_t *version_p, uint64_t *orig_size_p, uint32_t *checksum_p, uint32_t *options)
 
static void write_bmz_header (int fd, size_t in_len, uint32_t checksum, Byte options)
 
static void do_list (int fd)
 
static void do_pack (const void *in, size_t in_len, size_t buf_len, size_t offset, size_t fp_len, Byte options)
 
static void do_unpack (const void *in, size_t in_len, size_t buf_len)
 
static void do_block (const void *in, size_t len, size_t buf_len, size_t offset, size_t fp_len, int action, int options)
 
static char * read_from_fp (FILE *fp, size_t *len_p, size_t *size_p)
 
static char * read_from_fd (int fd, size_t *len_p, size_t *size_p)
 
static void input_from_stdin (size_t offset, size_t fp_len, int action, int options)
 
static void input_from_file (const char *fname, size_t offset, size_t fp_len, int action, int options)
 
static int bm_hash (const char *name)
 
static void HT_NORETURN show_usage ()
 
int main (int ac, char *av[])
 

Variables

static int s_no_mmap = 0
 Copyright (C) 2007-2015 Hypertable, Inc. More...
 
static int s_verbosity = 0
 
static int s_bm_dump = 0
 
static int s_bm_hash = 0
 

Macro Definition Documentation

#define BMZ_A_LIST   2

Definition at line 53 of file bmzip.c.

#define BMZ_A_PACK   0

Definition at line 51 of file bmzip.c.

#define BMZ_A_UNPACK   1

Definition at line 52 of file bmzip.c.

#define BMZ_ALIGN (   _mem_,
  _n_ 
)    (Byte *)(_mem_) + _n_ - (((size_t)(_mem_))%(_n_))

Definition at line 83 of file bmzip.c.

#define BMZ_HEADER_SZ   (3 + 2 + 1 + 6 + 4)

Definition at line 49 of file bmzip.c.

#define BMZ_MAGIC   "BMZ"

Definition at line 44 of file bmzip.c.

#define BMZ_O_BM_ONLY   1

Definition at line 55 of file bmzip.c.

#define BMZ_O_STREAM   2 /* TODO */

Definition at line 56 of file bmzip.c.

#define BMZ_READ_INT16 (   _p_,
  _n_ 
)
Value:
_n_ = (*_p_++ << 8); \
_n_ |= (*_p_++)

Definition at line 85 of file bmzip.c.

#define BMZ_READ_INT32 (   _p_,
  _n_ 
)
Value:
_n_ = (*_p_++ << 24); \
_n_ |= (*_p_++ << 16); \
_n_ |= (*_p_++ << 8); \
_n_ |= (*_p_++)

Definition at line 89 of file bmzip.c.

#define BMZ_READ_INT48 (   _p_,
  _n_ 
)
Value:
_n_ = ((uint64_t)*_p_++ << 40); \
_n_ |= ((uint64_t)*_p_++ << 32); \
_n_ |= (*_p_++ << 24); \
_n_ |= (*_p_++ << 16); \
_n_ |= (*_p_++ << 8); \
_n_ |= (*_p_++)

Definition at line 95 of file bmzip.c.

#define BMZ_WRITE_INT16 (   _p_,
  _n_ 
)
Value:
*_p_++ = (Byte)(_n_ >> 8); \
*_p_++ = (Byte)(_n_)
unsigned char Byte
Definition: bmzip.c:58

Definition at line 103 of file bmzip.c.

#define BMZ_WRITE_INT32 (   _p_,
  _n_ 
)
Value:
*_p_++ = (Byte)(_n_ >> 24); \
*_p_++ = (Byte)(_n_ >> 16); \
*_p_++ = (Byte)(_n_ >> 8); \
*_p_++ = (Byte)(_n_)
unsigned char Byte
Definition: bmzip.c:58

Definition at line 107 of file bmzip.c.

#define BMZ_WRITE_INT48 (   _p_,
  _n_ 
)
Value:
*_p_++ = (Byte)(_n_ >> 40); \
*_p_++ = (Byte)(_n_ >> 32); \
*_p_++ = (Byte)(_n_ >> 24); \
*_p_++ = (Byte)(_n_ >> 16); \
*_p_++ = (Byte)(_n_ >> 8); \
*_p_++ = (Byte)(_n_)
unsigned char Byte
Definition: bmzip.c:58

Definition at line 113 of file bmzip.c.

#define BMZIP_VER   0x0110

Definition at line 45 of file bmzip.c.

#define DIE (   _fmt_,
  ... 
)
Value:
do { \
LOG(0, "fatal: " _fmt_, ##__VA_ARGS__); \
exit(1); \
} while (0)
#define LOG(_lvl_, _fmt_,...)
Definition: bmzip.c:68

Definition at line 78 of file bmzip.c.

#define LOG (   _lvl_,
  _fmt_,
  ... 
)
Value:
if (s_verbosity >= _lvl_) do { \
fprintf(stderr, "bmzip: %s: " _fmt_, __FUNCTION__, ##__VA_ARGS__); \
if (errno) fprintf(stderr, ": %s", strerror(errno)); \
putc('\n', stderr); \
} while (0)
static int s_verbosity
Definition: bmzip.c:64

Definition at line 68 of file bmzip.c.

#define WARN (   _fmt_,
  ... 
)
Value:
do { \
LOG(0, "warning: " _fmt_, ##__VA_ARGS__); \
} while (0)
#define LOG(_lvl_, _fmt_,...)
Definition: bmzip.c:68

Definition at line 74 of file bmzip.c.

Typedef Documentation

typedef unsigned char Byte

Definition at line 58 of file bmzip.c.

typedef long long unsigned Llu

Definition at line 61 of file bmzip.c.

typedef long unsigned Lu

Definition at line 62 of file bmzip.c.

Function Documentation

static int bm_hash ( const char *  name)
static

Definition at line 400 of file bmzip.c.

static void do_block ( const void *  in,
size_t  len,
size_t  buf_len,
size_t  offset,
size_t  fp_len,
int  action,
int  options 
)
static

Definition at line 290 of file bmzip.c.

static void do_list ( int  fd)
static

Definition at line 164 of file bmzip.c.

static void do_pack ( const void *  in,
size_t  in_len,
size_t  buf_len,
size_t  offset,
size_t  fp_len,
Byte  options 
)
static

Definition at line 182 of file bmzip.c.

static void do_unpack ( const void *  in,
size_t  in_len,
size_t  buf_len 
)
static

Definition at line 243 of file bmzip.c.

static void input_from_file ( const char *  fname,
size_t  offset,
size_t  fp_len,
int  action,
int  options 
)
static

Definition at line 382 of file bmzip.c.

static void input_from_stdin ( size_t  offset,
size_t  fp_len,
int  action,
int  options 
)
static

Definition at line 369 of file bmzip.c.

int main ( int  ac,
char *  av[] 
)

Definition at line 431 of file bmzip.c.

static void parse_bmz_header ( const Byte buf,
uint16_t *  version_p,
uint64_t *  orig_size_p,
uint32_t *  checksum_p,
uint32_t *  options 
)
static

Definition at line 128 of file bmzip.c.

static void read_bmz_header ( int  fd,
Byte buf 
)
static

Definition at line 122 of file bmzip.c.

static char* read_from_fd ( int  fd,
size_t *  len_p,
size_t *  size_p 
)
static

Definition at line 328 of file bmzip.c.

static char* read_from_fp ( FILE *  fp,
size_t *  len_p,
size_t *  size_p 
)
static

Definition at line 305 of file bmzip.c.

static void HT_NORETURN show_usage ( )
static

Definition at line 413 of file bmzip.c.

static void write_bmz_header ( int  fd,
size_t  in_len,
uint32_t  checksum,
Byte  options 
)
static

Definition at line 148 of file bmzip.c.

Variable Documentation

int s_bm_dump = 0
static

Definition at line 65 of file bmzip.c.

int s_bm_hash = 0
static

Definition at line 66 of file bmzip.c.

int s_no_mmap = 0
static

Copyright (C) 2007-2015 Hypertable, Inc.

This file is part of Hypertable.

Hypertable is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 3 of the License, or any later version.

Hypertable is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Hypertable. If not, see http://www.gnu.org/licenses/A demo app for bmz compression

Definition at line 35 of file bmzip.c.

int s_verbosity = 0
static

Definition at line 64 of file bmzip.c.