Example #1
0
/*
 * read_one_buf
 *
 * Read one buffer from the tape
 */
static int
read_one_buf(ndmpd_module_params_t *mod_params, tlm_buffers_t *bufs,
    tlm_buffer_t *buf)
{
	int rv;

	if ((rv = MOD_READ(mod_params, buf->tb_buffer_data,
	    bufs->tbs_data_transfer_size)) == 0) {
		buf->tb_eof = buf->tb_eot = FALSE;
		buf->tb_errno = 0;
		buf->tb_buffer_size = bufs->tbs_data_transfer_size;
		buf->tb_buffer_spot = 0;
		buf->tb_full = TRUE;
		(void) tlm_buffer_advance_in_idx(bufs);
	}

	return (rv);
}
Example #2
0
/*ARGSUSED*/
char *
tlm_get_write_buffer(long want, long *actual_size,
                     tlm_buffers_t *buffers, int zero)
{
    int	buf = buffers->tbs_buffer_in;
    tlm_buffer_t *buffer = &buffers->tbs_buffer[buf];
    int	align_size = RECORDSIZE - 1;
    char	*rec;

    /*
     * make sure the allocation is in chunks of 512 bytes
     */
    want += align_size;
    want &= ~align_size;

    *actual_size = buffer->tb_buffer_size - buffer->tb_buffer_spot;
    if (*actual_size <= 0) {
        /*
         * no room, send this one
         * and wait for a free one
         */
        if (!buffer->tb_full) {
            /*
             * we are now ready to send a full buffer
             * instead of trying to get a new buffer
             *
             * do not send if we failed to get a buffer
             * on the previous call
             */
            buffer->tb_full = TRUE;

            /*
             * tell the writer that a buffer is available
             */
            tlm_buffer_release_in_buf(buffers);

            buffer = tlm_buffer_advance_in_idx(buffers);
        }

        buffer = tlm_buffer_in_buf(buffers, NULL);

        if (buffer->tb_full) {
            /*
             * wait for the writer to free up a buffer
             */
            tlm_buffer_out_buf_timed_wait(buffers, 500);
        }

        buffer = tlm_buffer_in_buf(buffers, NULL);
        if (buffer->tb_full) {
            /*
             * the next buffer is still full
             * of data from previous activity
             *
             * nothing has changed.
             */
            return (0);
        }

        buffer->tb_buffer_spot = 0;
        *actual_size = buffer->tb_buffer_size - buffer->tb_buffer_spot;
    }

    *actual_size = min(want, *actual_size);
    rec = &buffer->tb_buffer_data[buffer->tb_buffer_spot];
    buffer->tb_buffer_spot += *actual_size;
    buffers->tbs_offset += *actual_size;
    if (zero) {
        (void) memset(rec, 0, *actual_size);
    }
    return (rec);
}