/* Whenever you want to write a blob of data to the internal buffer you have to start by using this function first. It will write the number of bytes that will be written to the buffer. If necessary it will remove old records to make room for the new one. Needs to be called with bufferlock held.  */
static int dasd_eer_start_record(struct eerbuffer *eerb, int count)
/* Whenever you want to write a blob of data to the internal buffer you have to start by using this function first. It will write the number of bytes that will be written to the buffer. If necessary it will remove old records to make room for the new one. Needs to be called with bufferlock held.  */
static int dasd_eer_start_record(struct eerbuffer *eerb, int count)
{
	int tailcount;
	if (count + sizeof(count) > eerb->buffersize)
		return -ENOMEM;
	while (dasd_eer_get_free_bytes(eerb) < count + sizeof(count)) {
		if (eerb->residual > 0) {
			eerb->tail += eerb->residual;
			if (eerb->tail >= eerb->buffersize)
				eerb->tail -= eerb->buffersize;
			eerb->residual = -1;
		}
		dasd_eer_read_buffer(eerb, (char *) &tailcount,
				     sizeof(tailcount));
		eerb->tail += tailcount;
		if (eerb->tail >= eerb->buffersize)
			eerb->tail -= eerb->buffersize;
	}
	dasd_eer_write_buffer(eerb, (char*) &count, sizeof(count));
	return 0;
}