Files
mars-nwe/include/nwnss/include/cdcomp.h

319 lines
10 KiB
C

/****************************************************************************
|
| (C) Copyright 1985, 1991, 1993, 1996-1999 Novell, Inc.
| All Rights Reserved.
|
| This program is free software; you can redistribute it and/or
| modify it under the terms of version 2 of the GNU General Public
| License as published by the Free Software Foundation.
|
| This program 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 this program; if not, contact Novell, Inc.
|
| To contact Novell about this file by physical or electronic mail,
| you may find current contact information at www.novell.com
|
|***************************************************************************
|
| Netware file compression algorithm ported to NSS
|
|---------------------------------------------------------------------------
|
| $Author: vandana $
| $Date: 2005-08-10 01:03:51 +0530 (Wed, 10 Aug 2005) $
|
| $RCSfile$
| $Revision: 1177 $
|
|---------------------------------------------------------------------------
| Module Description:
|
+-------------------------------------------------------------------------*/
#ifndef __CDCOMP_H__
#define __CDCOMP_H__
/***************************************************************************
*
*
*
***************************************************************************/
#define COMPRESS_ERROR_OUT_OF_RAM 10001
#define COMPRESS_ERROR_READ_ZERO_BYTES 10002
#define COMPRESS_ERROR_READ_BEYOND_EOF 10003
#define COMPRESS_ERROR_ABORTED 10004
#define COMPRESS_ERROR_UNCOMPRESSABLE 10005
#define COMPRESS_ERROR_CODE_COUNTS_MISMATCH 10006
#define COMPRESS_ERROR_TOTALS_MISMATCH 10007
#define COMPRESS_ERROR_TREE_TOO_BIG 10008
#define COMPRESS_ERROR_MATCH_SIZE_FAIL 10009
#define COMPRESS_ERROR_TEMP_FILE_ERROR 10010
#define COMPRESS_ERROR_NO_RESOURCES 10011
#define COMPRESS_ERROR_HOLE_COUNT_MISMATCH 10012
#define COMPRESS_ERROR_FILE_TOO_BIG 10013
#define COMPRESS_ERROR_WRITE_TREE_ERROR 10014
#define COMPRESS_ERROR_NO_MIN_PERCENT 10015
#define COMPRESS_ERROR_NO_MIN_BYTES 10016
#define COMPRESS_ERROR_INVALID_HOLE 10017
#define COMPRESS_ERROR_TRY_AGAIN 10018
#define COMPRESS_ERROR_COUNT 18
/**************************************************************************
*
* this is the number of bytes from our current location in the buffer to
* look back for duplicate strings, to obtain the maximum results thi
* be 8096
*
**************************************************************************/
#define COMPRESS_WINDOW_SIZE (8 * 1024)
#define COMPRESS_WINDOW_MASK COMPRESS_WINDOW_SIZE -1
/**************************************************************************
*
* this is the size of the hash table for a series of three bytes.
* the larger this table the better the hash into it. 16K is best
*
**************************************************************************/
#define COMPRESS_MATCH_HEAD_SIZE (16 * 1024)
#define COMPRESS_LINK_HEAD_MASK (COMPRESS_MATCH_HEAD_SIZE - 1)
#define GET_HASH GET_HASH_16K
/***************************************************************************
*
* Hash for ?K head list links
*
***************************************************************************/
#define GET_HASH_4K( b1, b2, b3 ) \
((((LONG)b1 + ((LONG)b2 << 2)) + ((LONG)b3 << 4)) & COMPRESS_LINK_HEAD_MASK)
#define GET_HASH_8K( b1, b2, b3 ) \
((((LONG)b1 | ((LONG)b2 << 3)) + ((LONG)b3 << 5)) & COMPRESS_LINK_HEAD_MASK)
#define GET_HASH_16K( b1, b2, b3 ) \
((((LONG)b1 | ((LONG)b2 << 4)) + ((LONG)b3 << 6)) & COMPRESS_LINK_HEAD_MASK)
#define GET_HASH_32K( b1, b2, b3 ) \
((((LONG)b1 | ((LONG)b2 << 5)) + ((LONG)b3 << 7)) & COMPRESS_LINK_HEAD_MASK)
#define GET_HASH_64K( b1, b2, b3 ) \
((((LONG)b1 | ((LONG)b2 << 6)) + ((LONG)b3 << 8)) & COMPRESS_LINK_HEAD_MASK)
/*************************************************************************
* this allows us to look back 8K and forward 8K at any index
*
*
*************************************************************************/
#define COMPRESS_READ_CACHE_BUFFER_RANGE 5
/**************************************************************************
*
* this is indexes into the window of the next series of matches for these
* three bytes. One might consider is a bucket to the head array
*
***************************************************************************/
#define COMPRESS_LINK_SIZE COMPRESS_WINDOW_SIZE
#define COMPRESS_LINK_MASK (COMPRESS_LINK_SIZE -1)
/***************************************************************************
*
* Compress Reschedule Size is the number of bytes before we relinquish
* control
*
***************************************************************************/
#define COMPRESS_RESCHEDULE_BYTE_MASK 0x3F /*(notted) every 128 bytes reschedule */
/***************************************************************************
*
* Compress Offset shift of offset bits encoded in the offset shannon tree
*
***************************************************************************/
#define COMPRESS_OFFSET_SHIFT 5
/***************************************************************************
*
* Number of characters in a row that are the same to start duplicate
* Encoding
*
***************************************************************************/
#define COMPRESS_MIN_DUPLICATE_COUNT 5
/***************************************************************************
*
* always 256
*
*
***************************************************************************/
#define COMPRESS_VALUE_RANGE 256
/***************************************************************************
*
* projected file size is calculated in bits first then changed to bytes
* since projected file size is a LONG. The projected compress size cannot
* exceed 4G bits (0x1FFFFFFF bytes).
* In case the projected compress size is larger than the original we half
* that to this.
*
***************************************************************************/
#define COMPRESS_MAX_FILE_SIZE 0x0FFFFFFF
/***************************************************************************
*
*
*
***************************************************************************/
typedef struct compressCheckHeader_s {
LONG LengthOffsetEncodes;
LONG LargeLengthOffsetEncodes;
LONG OffsetEncodes;
LONG DataEncodes;
LONG LengthTotal;
LONG OffsetTotal;
LONG NumberOfHoles;
} compressCheckHeader_t, *compressCheckHeader_tp;
/***************************************************************************
*
*
*
***************************************************************************/
typedef struct compressHoleNode_s {
struct compressHoleNode_s *next;
LONG offset;
LONG size;
} compressHoleNode_t, *compressHoleNode_tp;
/***************************************************************************
*
* shannon tree node type
*
***************************************************************************/
typedef struct compressNode_s {
struct compressNode_s *left;
struct compressNode_s *right;
LONG value;
LONG count;
LONG length;
LONG code; /* for 4G files code will never > 32 bits */
} compressNode_t, *compressNode_tp, * *compressNode_tpp;
/***************************************************************************
*
*
*
***************************************************************************/
typedef struct compressData_s {
LONG ReadCacheBase;
LONG ReadFileSize;
LONG ReadBytesValidInCache[ COMPRESS_READ_CACHE_BUFFER_RANGE ];
LONG ReadCacheHoleFlags [ COMPRESS_READ_CACHE_BUFFER_RANGE ];
BYTE *ReadCachePointers [ COMPRESS_READ_CACHE_BUFFER_RANGE ];
IoHandle_t WriteHandle;
LONG WriteBlockNumber;
BYTE *WriteCurrentPointer;
BYTE *WriteBufferBegin;
BYTE *WriteBufferEnd ;
LONG WriteBufferHandle;
LONG WriteBitBuffer;
LONG WriteBitIndex;
LONG WriteNoFlushFlag;
LONG UnprocessedDataSize;
LONG DataProcessedIndex;
LONG DataReadIndex;
LONG ProjectedCompressSize;
LONG WindowSize;
LONG DataTable [ COMPRESS_VALUE_RANGE ]; /* 1K */
LONG LengthTable[ COMPRESS_VALUE_RANGE ];
LONG OffsetTable[ COMPRESS_VALUE_RANGE ];
compressNode_tp DataPointer [ COMPRESS_VALUE_RANGE ]; /* 1K */
compressNode_tp OffsetPointer[ COMPRESS_VALUE_RANGE ];
compressNode_tp LengthPointer[ COMPRESS_VALUE_RANGE ];
compressNode_tp DataTree;
compressNode_tp OffsetTree;
compressNode_tp LengthTree;
BYTE BitString[ COMPRESS_VALUE_RANGE ];
compressHoleNode_tp HoleHead, HoleTail;
LONG HoleTotalByteCount;
LONG FileVolume;
LONG AbortCompression;
#if TESTING_COMPRESSION
BYTE FileName[16];
#endif
LONG *Heads; /* 16K x 4 */
LONG *Links; /* 8K x 4 */
CompressStatus_t *compressStatus;
} compressData_t, *compressData_tp, **compressData_tpp;
LONG CCDCompressFile(
IoHandle_t InHandle,
IoHandle_t OutHandle,
IoHandle_t TempHandle,
QUAD InFileSize,
LONG Volume,
ADDR *CompressionHandle,
BYTE *FileName,
CompressStatus_t *compressStatus);
/***************************************************************************/
#if zNETWARE
extern BYTE StopCompressionTable[];
#define zStopCompression(_volume) StopCompressionTable[_volume]
#else
#define zStopCompression(_volume) FALSE
#endif
/***************************************************************************/
#endif
/****************************************************************************/
/****************************************************************************/