Browse Source

Added documentation and ASSERT() statements.

tags/v0.9.3
Michael Brown 20 years ago
parent
commit
df9cbc23cc
1 changed files with 39 additions and 1 deletions
  1. 39
    1
      src/core/buffer.c

+ 39
- 1
src/core/buffer.c View File

66
 	DBG ( "BUFFER [%x,%x) initialised\n", buffer->start, buffer->end );
66
 	DBG ( "BUFFER [%x,%x) initialised\n", buffer->start, buffer->end );
67
 }
67
 }
68
 
68
 
69
+/**
70
+ * Move to the next block in the free list
71
+ *
72
+ * @v block		The current free block
73
+ * @v buffer		The buffer
74
+ * @ret True		Successfully moved to the next free block
75
+ * @ret False		There are no more free blocks
76
+ * @ret block		The next free block
77
+ * @err None		-
78
+ *
79
+ * Move to the next block in the free block list, filling in @c block
80
+ * with the descriptor for this next block.  If the next block is the
81
+ * tail block, @c block will be filled with the values calculated for
82
+ * the tail block, otherwise the descriptor will be read from the free
83
+ * block itself.
84
+ *
85
+ * If there are no more free blocks, next_free_block() returns False
86
+ * and leaves @c block with invalid contents.
87
+ *
88
+ * Set <tt> block->next = buffer->start + buffer->fill </tt> for the
89
+ * first call to next_free_block().
90
+ */
69
 static inline int next_free_block ( struct buffer_free_block *block,
91
 static inline int next_free_block ( struct buffer_free_block *block,
70
 				    struct buffer *buffer ) {
92
 				    struct buffer *buffer ) {
71
 	/* Move to next block */
93
 	/* Move to next block */
89
 	return 1;
111
 	return 1;
90
 }
112
 }
91
 
113
 
114
+/**
115
+ * Store a free block descriptor
116
+ *
117
+ * @v block		The free block descriptor to store
118
+ * @ret None		-
119
+ * @err None		-
120
+ *
121
+ * Writes a free block descriptor back to a free block.  If the block
122
+ * is a tail block, only the tail marker will be written, otherwise
123
+ * the whole block descriptor will be written.
124
+ */
92
 static inline void store_free_block ( struct buffer_free_block *block ) {
125
 static inline void store_free_block ( struct buffer_free_block *block ) {
93
 	copy_to_phys ( block->start, block,
126
 	copy_to_phys ( block->start, block,
94
 		       ( block->tail ?
127
 		       ( block->tail ?
124
  * @b NOTE: It is the caller's responsibility to ensure that the
157
  * @b NOTE: It is the caller's responsibility to ensure that the
125
  * boundaries between data blocks are more than @c sizeof(struct @c
158
  * boundaries between data blocks are more than @c sizeof(struct @c
126
  * buffer_free_block) apart.  If this condition is not satisfied, data
159
  * buffer_free_block) apart.  If this condition is not satisfied, data
127
- * corruption will occur.  (See split_free_block() for details.)
160
+ * corruption will occur.
128
  *
161
  *
129
  * In practice this is not a problem.  Callers of fill_buffer() will
162
  * In practice this is not a problem.  Callers of fill_buffer() will
130
  * be download protocols such as TFTP, and very few protocols have a
163
  * be download protocols such as TFTP, and very few protocols have a
175
 	/* Write back 'before' block, if any */
208
 	/* Write back 'before' block, if any */
176
 	if ( before.start ) {
209
 	if ( before.start ) {
177
 		before.tail = 0;
210
 		before.tail = 0;
211
+		ASSERT ( ( before.end - before.start ) >=
212
+			 sizeof ( struct buffer_free_block ) );
178
 		store_free_block ( &before );
213
 		store_free_block ( &before );
179
 	} else {
214
 	} else {
180
 		buffer->fill = before.next - buffer->start;
215
 		buffer->fill = before.next - buffer->start;
182
 
217
 
183
 	/* Write back 'after' block, if any */
218
 	/* Write back 'after' block, if any */
184
 	if ( after.start < buffer->end ) {
219
 	if ( after.start < buffer->end ) {
220
+		ASSERT ( after.tail ||
221
+			 ( ( after.end - after.start ) >=
222
+			   sizeof ( struct buffer_free_block ) ) );
185
 		store_free_block ( &after );
223
 		store_free_block ( &after );
186
 	}
224
 	}
187
 	
225
 	

Loading…
Cancel
Save