|
@@ -200,3 +200,33 @@ struct io_buffer * iob_concatenate ( struct list_head *list ) {
|
200
|
200
|
|
201
|
201
|
return concatenated;
|
202
|
202
|
}
|
|
203
|
+
|
|
204
|
+/**
|
|
205
|
+ * Split I/O buffer
|
|
206
|
+ *
|
|
207
|
+ * @v iobuf I/O buffer
|
|
208
|
+ * @v len Length to split into a new I/O buffer
|
|
209
|
+ * @ret split New I/O buffer, or NULL on allocation failure
|
|
210
|
+ *
|
|
211
|
+ * Split the first @c len bytes of the existing I/O buffer into a
|
|
212
|
+ * separate I/O buffer. The resulting buffers are likely to have no
|
|
213
|
+ * headroom or tailroom.
|
|
214
|
+ *
|
|
215
|
+ * If this call fails, then the original buffer will be unmodified.
|
|
216
|
+ */
|
|
217
|
+struct io_buffer * iob_split ( struct io_buffer *iobuf, size_t len ) {
|
|
218
|
+ struct io_buffer *split;
|
|
219
|
+
|
|
220
|
+ /* Sanity checks */
|
|
221
|
+ assert ( len <= iob_len ( iobuf ) );
|
|
222
|
+
|
|
223
|
+ /* Allocate new I/O buffer */
|
|
224
|
+ split = alloc_iob ( len );
|
|
225
|
+ if ( ! split )
|
|
226
|
+ return NULL;
|
|
227
|
+
|
|
228
|
+ /* Copy in data */
|
|
229
|
+ memcpy ( iob_put ( split, len ), iobuf->data, len );
|
|
230
|
+ iob_pull ( iobuf, len );
|
|
231
|
+ return split;
|
|
232
|
+}
|