feat: asynchronized SATA IO
[lunaix-os.git] / lunaix-os / kernel / ds / buffer.c
1 #include <lunaix/buffer.h>
2 #include <lunaix/mm/valloc.h>
3
4 struct vecbuf*
5 vbuf_alloc(struct vecbuf* vec, void* buf, size_t size)
6 {
7     struct vecbuf* vbuf = valloc(sizeof(struct vecbuf));
8
9     *vbuf =
10       (struct vecbuf){ .buf = { .buffer = buf, .size = size }, .acc_sz = 0 };
11
12     if (vec) {
13         vbuf->acc_sz = vbuf_size(vec) + size;
14         llist_append(&vec->components, &vbuf->components);
15     } else {
16         llist_init_head(&vec->components);
17     }
18
19     return vbuf;
20 }
21
22 void
23 vbuf_free(struct vecbuf* vbuf)
24 {
25     struct vecbuf *pos, *n;
26     llist_for_each(pos, n, &vbuf->components, components)
27     {
28         vfree(pos);
29     }
30     vfree(pos);
31 }