|
@@ -66,6 +66,28 @@ void init_buffer ( struct buffer *buffer ) {
|
66
|
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
|
91
|
static inline int next_free_block ( struct buffer_free_block *block,
|
70
|
92
|
struct buffer *buffer ) {
|
71
|
93
|
/* Move to next block */
|
|
@@ -89,6 +111,17 @@ static inline int next_free_block ( struct buffer_free_block *block,
|
89
|
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
|
125
|
static inline void store_free_block ( struct buffer_free_block *block ) {
|
93
|
126
|
copy_to_phys ( block->start, block,
|
94
|
127
|
( block->tail ?
|
|
@@ -124,7 +157,7 @@ static inline void store_free_block ( struct buffer_free_block *block ) {
|
124
|
157
|
* @b NOTE: It is the caller's responsibility to ensure that the
|
125
|
158
|
* boundaries between data blocks are more than @c sizeof(struct @c
|
126
|
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
|
162
|
* In practice this is not a problem. Callers of fill_buffer() will
|
130
|
163
|
* be download protocols such as TFTP, and very few protocols have a
|
|
@@ -175,6 +208,8 @@ int fill_buffer ( struct buffer *buffer, const void *data,
|
175
|
208
|
/* Write back 'before' block, if any */
|
176
|
209
|
if ( before.start ) {
|
177
|
210
|
before.tail = 0;
|
|
211
|
+ ASSERT ( ( before.end - before.start ) >=
|
|
212
|
+ sizeof ( struct buffer_free_block ) );
|
178
|
213
|
store_free_block ( &before );
|
179
|
214
|
} else {
|
180
|
215
|
buffer->fill = before.next - buffer->start;
|
|
@@ -182,6 +217,9 @@ int fill_buffer ( struct buffer *buffer, const void *data,
|
182
|
217
|
|
183
|
218
|
/* Write back 'after' block, if any */
|
184
|
219
|
if ( after.start < buffer->end ) {
|
|
220
|
+ ASSERT ( after.tail ||
|
|
221
|
+ ( ( after.end - after.start ) >=
|
|
222
|
+ sizeof ( struct buffer_free_block ) ) );
|
185
|
223
|
store_free_block ( &after );
|
186
|
224
|
}
|
187
|
225
|
|