-Changed most of the header guard strings to be a little more verbose
[newos.git] / include / kernel / cbuf.h
blobefa862b92bee7e18119ed8b9044b4d14cdbb65aa
1 /*
2 ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
5 #ifndef _KERNEL_CBUF_H
6 #define _KERNEL_CBUF_H
8 #include <kernel/kernel.h>
10 #define CBUF_LEN 2048
12 #define CBUF_FLAG_CHAIN_HEAD 1
13 #define CBUF_FLAG_CHAIN_TAIL 2
15 typedef struct cbuf {
16 struct cbuf *next;
17 size_t len;
18 size_t total_len;
19 void *data;
20 int flags;
21 char dat[CBUF_LEN - sizeof(struct cbuf *) - 2*sizeof(int) - sizeof(void *) - sizeof(int)];
22 } cbuf;
24 int cbuf_init(void);
25 cbuf *cbuf_get_chain(size_t len);
26 cbuf *cbuf_get_chain_noblock(size_t len);
27 void cbuf_free_chain_noblock(cbuf *buf);
28 void cbuf_free_chain(cbuf *buf);
30 size_t cbuf_get_len(cbuf *buf);
31 void *cbuf_get_ptr(cbuf *buf, size_t offset);
32 int cbuf_is_contig_region(cbuf *buf, size_t start, size_t end);
34 int cbuf_memcpy_to_chain(cbuf *chain, size_t offset, const void *_src, size_t len);
35 int cbuf_memcpy_from_chain(void *dest, cbuf *chain, size_t offset, size_t len);
37 int cbuf_user_memcpy_to_chain(cbuf *chain, size_t offset, const void *_src, size_t len);
38 int cbuf_user_memcpy_from_chain(void *dest, cbuf *chain, size_t offset, size_t len);
40 uint16 cbuf_ones_cksum16(cbuf *chain, size_t offset, size_t len);
42 cbuf *cbuf_merge_chains(cbuf *chain1, cbuf *chain2);
43 cbuf *cbuf_duplicate_chain(cbuf *chain, size_t offset, size_t len);
45 int cbuf_truncate_head(cbuf *chain, size_t trunc_bytes);
46 int cbuf_truncate_tail(cbuf *chain, size_t trunc_bytes);
48 void cbuf_test(void);
50 #endif