Exemple #1
0
int isal_deflate(struct isal_zstream *stream)
{
	struct isal_zstate *state = &stream->internal_state;
	int ret = COMP_OK;
	uint8_t *next_in;
	uint32_t avail_in, avail_in_start;
	uint32_t flush_type = stream->flush;
	uint32_t end_of_stream = stream->end_of_stream;
	int size = 0;
	uint8_t *copy_down_src = NULL;
	uint64_t copy_down_size = 0;
	int32_t processed = -(state->b_bytes_valid - state->b_bytes_processed);

	if (stream->flush >= 3)
		return INVALID_FLUSH;

	next_in = stream->next_in;
	avail_in = stream->avail_in;
	stream->total_in -= state->b_bytes_valid - state->b_bytes_processed;

	do {
		size = avail_in;
		if (size > sizeof(state->buffer) - state->b_bytes_valid) {
			size = sizeof(state->buffer) - state->b_bytes_valid;
			stream->flush = NO_FLUSH;
			stream->end_of_stream = 0;
		}
		memcpy(&state->buffer[state->b_bytes_valid], next_in, size);

		next_in += size;
		avail_in -= size;
		state->b_bytes_valid += size;

		stream->next_in = &state->buffer[state->b_bytes_processed];
		stream->avail_in = state->b_bytes_valid - state->b_bytes_processed;
		state->file_start = stream->next_in - stream->total_in;
		processed += stream->avail_in;

		if (stream->avail_in > IGZIP_HIST_SIZE
		    || stream->end_of_stream || stream->flush != NO_FLUSH) {
			avail_in_start = stream->avail_in;
			isal_deflate_int(stream);
			state->b_bytes_processed += avail_in_start - stream->avail_in;

			if (state->b_bytes_processed > IGZIP_HIST_SIZE) {
				copy_down_src =
				    &state->buffer[state->b_bytes_processed - IGZIP_HIST_SIZE];
				copy_down_size =
				    state->b_bytes_valid - state->b_bytes_processed +
				    IGZIP_HIST_SIZE;
				memmove(state->buffer, copy_down_src, copy_down_size);

				state->b_bytes_valid -= copy_down_src - state->buffer;
				state->b_bytes_processed -= copy_down_src - state->buffer;
			}

		}

		stream->flush = flush_type;
		stream->end_of_stream = end_of_stream;
		processed -= stream->avail_in;
	} while (processed < IGZIP_HIST_SIZE + ISAL_LOOK_AHEAD && avail_in > 0
		 && stream->avail_out > 0);

	if (processed >= IGZIP_HIST_SIZE + ISAL_LOOK_AHEAD) {
		stream->next_in = next_in - stream->avail_in;
		stream->avail_in = avail_in + stream->avail_in;

		state->file_start = stream->next_in - stream->total_in;

		if (stream->avail_in > 0 && stream->avail_out > 0)
			isal_deflate_int(stream);

		size = stream->avail_in;
		if (stream->avail_in > IGZIP_HIST_SIZE)
			size = 0;

		memmove(state->buffer, stream->next_in - IGZIP_HIST_SIZE,
			size + IGZIP_HIST_SIZE);
		state->b_bytes_processed = IGZIP_HIST_SIZE;
		state->b_bytes_valid = size + IGZIP_HIST_SIZE;

		stream->next_in += size;
		stream->avail_in -= size;
		stream->total_in += size;

	} else {
		stream->total_in += state->b_bytes_valid - state->b_bytes_processed;
		stream->next_in = next_in;
		stream->avail_in = avail_in;
		state->file_start = stream->next_in - stream->total_in;

	}

	return ret;
}
Exemple #2
0
int isal_deflate(struct isal_zstream *stream)
{
	struct isal_zstate *state = &stream->internal_state;
	uint32_t size;
	int ret = COMP_OK;

	if (stream->flush < 3) {

		state->last_flush = stream->flush;

		if (state->state >= TMP_OFFSET_SIZE) {
			size = state->tmp_out_end - state->tmp_out_start;
			if (size > stream->avail_out)
				size = stream->avail_out;
			memcpy(stream->next_out, state->tmp_out_buff + state->tmp_out_start,
			       size);
			stream->next_out += size;
			stream->avail_out -= size;
			stream->total_out += size;
			state->tmp_out_start += size;

			if (state->tmp_out_start == state->tmp_out_end)
				state->state -= TMP_OFFSET_SIZE;

			if (stream->avail_out == 0 || state->state == ZSTATE_END)
				return ret;
		}
		assert(state->tmp_out_start == state->tmp_out_end);

		isal_deflate_int(stream);

		if (stream->avail_out == 0)
			return ret;

		else if (stream->avail_out < 8) {
			uint8_t *next_out;
			uint32_t avail_out;
			uint32_t total_out;

			next_out = stream->next_out;
			avail_out = stream->avail_out;
			total_out = stream->total_out;

			stream->next_out = state->tmp_out_buff;
			stream->avail_out = sizeof(state->tmp_out_buff);
			stream->total_out = 0;

			isal_deflate_int(stream);

			state->tmp_out_start = 0;
			state->tmp_out_end = stream->total_out;

			stream->next_out = next_out;
			stream->avail_out = avail_out;
			stream->total_out = total_out;
			if (state->tmp_out_end) {
				size = state->tmp_out_end;
				if (size > stream->avail_out)
					size = stream->avail_out;
				memcpy(stream->next_out, state->tmp_out_buff, size);
				stream->next_out += size;
				stream->avail_out -= size;
				stream->total_out += size;
				state->tmp_out_start += size;
				if (state->tmp_out_start != state->tmp_out_end)
					state->state += TMP_OFFSET_SIZE;

			}
		}
	} else
		ret = INVALID_FLUSH;

	return ret;
}