char tail = 1;
copy_to_phys ( start, &tail, sizeof ( tail ) );
}
+
+ DBG ( "BUFFER [%x,%x) initialised\n", buffer->start, buffer->end );
}
/*
if ( split >= desc->end )
return;
+ DBG ( "BUFFER splitting [%x,%x) into [%x,%x) and [%x,%x)\n",
+ block, desc->end, block, split, split, desc->end );
+
/* Create descriptor for new free block */
copy_to_phys ( split, &desc->tail, sizeof ( desc->tail ) );
if ( ! desc->tail )
/* If this is the first block, just update first_free */
if ( ! prev_block ) {
+ DBG ( "BUFFER marking [%x,%x) as used\n",
+ buffer->first_free, desc->end );
buffer->first_free = desc->next_free;
return;
}
/* Get descriptor for previous block (which cannot be a tail block) */
copy_from_phys ( &prev_desc, prev_block, sizeof ( prev_desc ) );
+ DBG ( "BUFFER marking [%x,%x) as used\n",
+ prev_desc.next_free, desc->end );
+
/* Modify descriptor for previous block and write it back */
prev_desc.next_free = desc->next_free;
copy_to_phys ( prev_block, &prev_desc, sizeof ( prev_desc ) );
/* Calculate start and end addresses of data */
data_start = buffer->start + offset;
data_end = data_start + len;
+ DBG ( "BUFFER [%x,%x) writing portion [%x,%x)\n",
+ buffer->start, buffer->end, data_start, data_end );
/* Iterate through the buffer's free blocks */
prev_block = 0;
/* Block is now either completely contained by or
* completely outside the data area
*/
- if ( ( block >= data_start ) && ( block <= data_end ) ) {
+ if ( ( block >= data_start ) && ( block < data_end ) ) {
/* Block is within the data area */
unfree_block ( buffer, &desc, prev_block );
copy_to_phys ( block, data + ( block - data_start ),
block = desc.next_free;
}
+ DBG ( "BUFFER [%x,%x) full up to %x\n",
+ buffer->start, buffer->end, buffer->first_free );
+
return ( buffer->first_free - buffer->start );
}