taskfs fix up, minor refactoring
[lunaix-os.git] / lunaix-os / includes / lunaix / fs / twimap.h
1 #ifndef __LUNAIX_TWIMAP_H
2 #define __LUNAIX_TWIMAP_H
3
4 #include <lunaix/types.h>
5
6 #define twimap_index(twimap, type) ((type)__ptr((twimap)->index))
7 #define twimap_data(twimap, type) ((type)__ptr((twimap)->data))
8
9 extern struct v_file_ops twimap_file_ops;
10
11 struct twimap;
12 struct twimap_ops
13 {
14     void (*read)(struct twimap* mapping);
15     int (*go_next)(struct twimap* mapping);
16     void (*reset)(struct twimap* mapping);
17 };
18
19 struct twimap
20 {
21     void* index;
22     void* buffer;
23     void* data;
24     size_t size_acc;
25
26     union {
27         struct {
28             void (*read)(struct twimap* mapping);
29             int (*go_next)(struct twimap* mapping);
30             void (*reset)(struct twimap* mapping);
31         };
32         struct twimap_ops ops;
33     };
34 };
35
36 void
37 __twimap_default_reset(struct twimap* map);
38
39 int
40 __twimap_default_gonext(struct twimap* map);
41
42 int
43 twimap_read(struct twimap* map, void* buffer, size_t len, size_t fpos);
44
45 void
46 twimap_printf(struct twimap* mapping, const char* fmt, ...);
47
48 int
49 twimap_memcpy(struct twimap* mapping, const void* src, const size_t len);
50
51 int
52 twimap_memappend(struct twimap* mapping, const void* src, const size_t len);
53
54 struct twimap*
55 twimap_create(void* data);
56
57 #endif /* __LUNAIX_TWIMAP_H */