feat: asynchronized SATA IO
[lunaix-os.git] / lunaix-os / kernel / ds / buffer.c
diff --git a/lunaix-os/kernel/ds/buffer.c b/lunaix-os/kernel/ds/buffer.c
new file mode 100644 (file)
index 0000000..0efea6f
--- /dev/null
@@ -0,0 +1,31 @@
+#include <lunaix/buffer.h>
+#include <lunaix/mm/valloc.h>
+
+struct vecbuf*
+vbuf_alloc(struct vecbuf* vec, void* buf, size_t size)
+{
+    struct vecbuf* vbuf = valloc(sizeof(struct vecbuf));
+
+    *vbuf =
+      (struct vecbuf){ .buf = { .buffer = buf, .size = size }, .acc_sz = 0 };
+
+    if (vec) {
+        vbuf->acc_sz = vbuf_size(vec) + size;
+        llist_append(&vec->components, &vbuf->components);
+    } else {
+        llist_init_head(&vec->components);
+    }
+
+    return vbuf;
+}
+
+void
+vbuf_free(struct vecbuf* vbuf)
+{
+    struct vecbuf *pos, *n;
+    llist_for_each(pos, n, &vbuf->components, components)
+    {
+        vfree(pos);
+    }
+    vfree(pos);
+}
\ No newline at end of file