xdelta3.h

来自「Linux下一个可以比较二进制文件的工具xdelta3.0u的源码。」· C头文件 代码 · 共 1,311 行 · 第 1/3 页

H
1,311
字号
			* address (initially 0). */  MATCH_BACKWARD  = 1, /* currently expanding a match backward in the			  source/target. */  MATCH_FORWARD   = 2, /* currently expanding a match forward in the			  source/target. */  MATCH_SEARCHING = 3, /* currently searching for a match. */} xd3_match_state;/* The xd3_encode_input state machine steps through these states in * the following order.  The matcher is reentrant and returns * XD3_INPUT whenever it requires more data.  After receiving * XD3_INPUT, if the application reads EOF it should call * xd3_stream_close(). */typedef enum {  ENC_INIT      = 0, /* xd3_encode_input has never been called. */  ENC_INPUT     = 1, /* waiting for xd3_avail_input () to be called. */  ENC_SEARCH    = 2, /* currently searching for matches. */  ENC_INSTR     = 3, /* currently formatting output. */  ENC_FLUSH     = 4, /* currently emitting output. */  ENC_POSTOUT   = 5, /* after an output section. */  ENC_POSTWIN   = 6, /* after all output sections. */  ENC_ABORTED   = 7, /* abort. */} xd3_encode_state;/* The xd3_decode_input state machine steps through these states in * the following order.  The matcher is reentrant and returns * XD3_INPUT whenever it requires more data.  After receiving * XD3_INPUT, if the application reads EOF it should call * xd3_stream_close(). * * 0-8:   the VCDIFF header * 9-18:  the VCDIFF window header * 19-21: the three primary sections: data, inst, addr * 22:    producing output: returns XD3_OUTPUT, possibly XD3_GETSRCBLK, * 23:    return XD3_WINFINISH, set state=9 to decode more input */typedef enum {  DEC_VCHEAD   = 0, /* VCDIFF header */  DEC_HDRIND   = 1, /* header indicator */  DEC_SECONDID = 2, /* secondary compressor ID */  DEC_TABLEN   = 3, /* code table length */  DEC_NEAR     = 4, /* code table near */  DEC_SAME     = 5, /* code table same */  DEC_TABDAT   = 6, /* code table data */  DEC_APPLEN   = 7, /* application data length */  DEC_APPDAT   = 8, /* application data */  DEC_WININD   = 9, /* window indicator */  DEC_CPYLEN   = 10, /* copy window length */  DEC_CPYOFF   = 11, /* copy window offset */  DEC_ENCLEN   = 12, /* length of delta encoding */  DEC_TGTLEN   = 13, /* length of target window */  DEC_DELIND   = 14, /* delta indicator */  DEC_DATALEN  = 15, /* length of ADD+RUN data */  DEC_INSTLEN  = 16, /* length of instruction data */  DEC_ADDRLEN  = 17, /* length of address data */  DEC_CKSUM    = 18, /* window checksum */  DEC_DATA     = 19, /* data section */  DEC_INST     = 20, /* instruction section */  DEC_ADDR     = 21, /* address section */  DEC_EMIT     = 22, /* producing data */  DEC_FINISH   = 23, /* window finished */  DEC_ABORTED  = 24, /* xd3_abort_stream */} xd3_decode_state;/************************************************************ internal types ************************************************************//* instruction lists used in the IOPT buffer */struct _xd3_rlist{  xd3_rlist  *next;  xd3_rlist  *prev;};/* the raw encoding of an instruction used in the IOPT buffer */struct _xd3_rinst{  uint8_t     type;  uint8_t     xtra;  uint8_t     code1;  uint8_t     code2;  usize_t      pos;  usize_t      size;  xoff_t      addr;  xd3_rlist   link;};/* the code-table form of an single- or double-instruction */struct _xd3_dinst{  uint8_t     type1;  uint8_t     size1;  uint8_t     type2;  uint8_t     size2;};/* the decoded form of a single (half) instruction. */struct _xd3_hinst{  uint8_t     type;  uint32_t    size;  /* TODO: why decode breaks if this is usize_t? */  uint32_t    addr;  /* TODO: why decode breaks if this is usize_t? */};/* the form of a whole-file instruction */struct _xd3_winst{  uint8_t type;  /* RUN, ADD, COPY */  uint8_t mode;  /* 0, VCD_SOURCE, VCD_TARGET */  usize_t size;  xoff_t  addr;  xoff_t  position;  /* absolute position of this inst */};/* used by the encoder to buffer output in sections.  list of blocks. */struct _xd3_output{  uint8_t    *base;  usize_t     next;  usize_t     avail;  xd3_output *next_page;};/* used by the decoder to buffer input in sections. */struct _xd3_desect{  const uint8_t *buf;  const uint8_t *buf_max;  uint32_t       size;  /* TODO: why decode breaks if this is usize_t? */  usize_t        pos;  /* used in xdelta3-decode.h */  uint8_t       *copied1;  usize_t        alloc1;  /* used in xdelta3-second.h */  uint8_t       *copied2;  usize_t        alloc2;};/* the VCDIFF address cache, see the RFC */struct _xd3_addr_cache{  usize_t  s_near;  usize_t  s_same;  usize_t  next_slot;  /* the circular index for near */  usize_t *near_array; /* array of size s_near        */  usize_t *same_array; /* array of size s_same*256    */};/* the IOPT buffer list is just a list of buffers, which may be allocated * during encode when using an unlimited buffer. */struct _xd3_iopt_buflist{  xd3_rinst *buffer;  xd3_iopt_buflist *next;};/* This is the record of a pre-compiled configuration, a subset of   xd3_config. */struct _xd3_smatcher{  const char        *name;  int             (*string_match) (xd3_stream  *stream);  usize_t            large_look;  usize_t            large_step;  usize_t            small_look;  usize_t            small_chain;  usize_t            small_lchain;  usize_t            max_lazy;  usize_t            long_enough;};/* hash table size & power-of-two hash function. */struct _xd3_hash_cfg{  usize_t           size;  usize_t           shift;  usize_t           mask;};/* the sprev list */struct _xd3_slist{  usize_t     last_pos;};/* window info (for whole state) */struct _xd3_wininfo {  xoff_t offset;  usize_t length;  uint32_t adler32;};/* whole state for, e.g., merge */struct _xd3_whole_state {  usize_t addslen;  uint8_t *adds;  usize_t  adds_alloc;  usize_t instlen;  xd3_winst *inst;  usize_t  inst_alloc;  usize_t wininfolen;  xd3_wininfo *wininfo;  usize_t wininfo_alloc;  xoff_t length;};/******************************************************************** public types *******************************************************************//* Settings for the secondary compressor. */struct _xd3_sec_cfg{  int                data_type;     /* Which section. (set automatically) */  int                ngroups;       /* Number of DJW Huffman groups. */  int                sector_size;   /* Sector size. */  int                inefficient;   /* If true, ignore efficiency check [avoid XD3_NOSECOND]. */};/* This is the user-visible stream configuration. */struct _xd3_config{  usize_t             winsize;       /* The encoder window size. */  usize_t             sprevsz;       /* How far back small string					matching goes */  usize_t             iopt_size;     /* entries in the					instruction-optimizing					buffer */  usize_t             srcwin_maxsz;  /* srcwin_size grows by a factor					of 2 when no matches are					found */  xd3_getblk_func   *getblk;        /* The three callbacks. */  xd3_alloc_func    *alloc;  xd3_free_func     *freef;  void              *opaque;        /* Not used. */  int                flags;         /* stream->flags are initialized				     * from xd3_config & never				     * modified by the library.  Use				     * xd3_set_flags to modify flags				     * settings mid-stream. */  xd3_sec_cfg       sec_data;       /* Secondary compressor config: data */  xd3_sec_cfg       sec_inst;       /* Secondary compressor config: inst */  xd3_sec_cfg       sec_addr;       /* Secondary compressor config: addr */  xd3_smatch_cfg     smatch_cfg;    /* See enum: use fields below  for				       soft config */  xd3_smatcher       smatcher_soft;};/* The primary source file object. You create one of these objects and * initialize the first four fields.  This library maintains the next * 5 fields.  The configured getblk implementation is responsible for * setting the final 3 fields when called (and/or when XD3_GETSRCBLK * is returned). */struct _xd3_source{  /* you set */  xoff_t              size;          /* size of this source */  usize_t             blksize;       /* block size */  const char         *name;          /* its name, for debug/print					purposes */  void               *ioh;           /* opaque handle */  /* getblk sets */  xoff_t              curblkno;      /* current block number: client					sets after getblk request */  usize_t             onblk;         /* number of bytes on current					block: client sets, xd3					verifies */  const uint8_t      *curblk;        /* current block array: client					sets after getblk request */  /* xd3 sets */  usize_t             srclen;        /* length of this source window */  xoff_t              srcbase;       /* offset of this source window					in the source itself */  xoff_t              blocks;        /* the total number of blocks in					this source */  usize_t             onlastblk;     /* cached size info, avoid __udivdi3 */  int                 shiftby;       /* for power-of-two blocksizes */  int                 maskby;        /* for power-of-two blocksizes */    xoff_t              cpyoff_blocks; /* offset of dec_cpyoff in blocks */  usize_t             cpyoff_blkoff; /* offset of copy window in					blocks, remainder */  xoff_t              getblkno;      /* request block number: xd3 sets					current getblk request */};/* The primary xd3_stream object, used for encoding and decoding.  You * may access only two fields: avail_out, next_out.  Use the methods * above to operate on xd3_stream. */struct _xd3_stream{  /* input state */  const uint8_t    *next_in;          /* next input byte */  usize_t           avail_in;         /* number of bytes available at					 next_in */  xoff_t            total_in;         /* how many bytes in */  /* output state */  uint8_t          *next_out;         /* next output byte */  usize_t           avail_out;        /* number of bytes available at					 next_out */  usize_t           space_out;        /* total out space */  xoff_t            current_window;   /* number of windows encoded/decoded */  xoff_t            total_out;        /* how many bytes out */  /* to indicate an error, xd3 sets */  const char       *msg;              /* last error message, NULL if					 no error */  /* source configuration */  xd3_source       *src;              /* source array */  /* encoder memory configuration */  usize_t           winsize;          /* suggested window size */  usize_t           sprevsz;          /* small string, previous window					 size (power of 2) */  usize_t           sprevmask;        /* small string, previous window					 size mask */  usize_t           iopt_size;  usize_t           iopt_unlimited;  usize_t           srcwin_maxsz;  /* general configuration */  xd3_getblk_func  *getblk;           /* set nxtblk, nxtblkno to scanblkno */  xd3_alloc_func   *alloc;            /* malloc function */  xd3_free_func    *free;             /* free function */  void*             opaque;           /* private data object passed to					 alloc, free, and getblk */  int               flags;            /* various options */    /* secondary compressor configuration */  xd3_sec_cfg       sec_data;         /* Secondary compressor config: data */  xd3_sec_cfg       sec_inst;         /* Secondary compressor config: inst */  xd3_sec_cfg       sec_addr;         /* Secondary compressor config: addr */  xd3_smatcher      smatcher;  usize_t           *large_table;      /* table of large checksums */  xd3_hash_cfg       large_hash;       /* large hash config */  usize_t           *small_table;      /* table of small checksums */  xd3_slist         *small_prev;       /* table of previous offsets,					  circular linked list */  int                small_reset;      /* true if small table should					  be reset */  xd3_hash_cfg       small_hash;       /* small hash config */  xd3_addr_cache     acache;           /* the vcdiff address cache */  xd3_encode_state   enc_state;        /* state of the encoder */  usize_t            taroff;           /* base offset of the target input */  usize_t            input_position;   /* current input position */  usize_t            min_match;        /* current minimum match					  length, avoids redundent					  matches */  usize_t            unencoded_offset; /* current input, first				       * unencoded offset. this value				       * is <= the first instruction's				       * position in the iopt buffer,				       * if there is at least one				       * match in the buffer. */  // SRCWIN  // these variables plus srcwin_maxsz above (set by config)  int                srcwin_decided;    /* boolean: true if the					   srclen,srcbase have been					   decided. */  xoff_t             srcwin_cksum_pos;  /* Source checksum position */  // MATCH  xd3_match_state    match_state;      /* encoder match state */  xoff_t             match_srcpos;     /* current match source					  position relative to					  srcbase */  xoff_t             match_last_srcpos;  /* previously attempted					  * srcpos, to avoid loops. */  xoff_t             match_minaddr;    /* smallest matching address to				       * set window params (reset each				       * window xd3_encode_reset) */  xoff_t             match_maxaddr;    /* largest matching address to				       * set window params (reset each				       * window xd3_encode_reset) */  usize_t            match_back;       /* match extends back so far */  usize_t            match_maxback;    /* match extends back maximum */  usize_t            match_fwd;        /* match extends forward so far */  usize_t            match_maxfwd;     /* match extends forward maximum */  xoff_t             maxsrcaddr;      /* address of the last source					 match (across windows) */  uint8_t          *buf_in;           /* for saving buffered input */  usize_t            buf_avail;        /* amount of saved input */  const uint8_t    *buf_leftover;     /* leftover content of next_in					 (i.e., user's buffer) */  usize_t            buf_leftavail;    /* amount of leftover content */  xd3_output       *enc_current;      /* current output buffer */  xd3_output       *enc_free;         /* free output buffers */  xd3_output       *enc_heads[4];     /* array of encoded outputs:					 head of chain */  xd3_output       *enc_tails[4];     /* array of encoded outputs:					 tail of chain */  uint32_t          recode_adler32;   /* set the adler32 checksum				       * during "recode". */  xd3_rlist         iopt_used;        /* instruction optimizing buffer */  xd3_rlist         iopt_free;  xd3_rinst        *iout;             /* next single instruction */  xd3_iopt_buflist *iopt_alloc;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?