feat: disk read/write support for both ATA and ATAPI device
[lunaix-os.git] / lunaix-os / includes / lunaix / mm / cake.h
1 #ifndef __LUNAIX_CAKE_H
2 #define __LUNAIX_CAKE_H
3
4 #include <lunaix/ds/llist.h>
5
6 #define PILE_NAME_MAXLEN 20
7
8 #define PILE_CACHELINE 1
9
10 struct cake_pile
11 {
12     struct llist_header piles;
13     struct llist_header full;
14     struct llist_header partial;
15     struct llist_header free;
16     unsigned int offset;
17     unsigned int piece_size;
18     unsigned int cakes_count;
19     unsigned int alloced_pieces;
20     unsigned int pieces_per_cake;
21     unsigned int pg_per_cake;
22     char pile_name[PILE_NAME_MAXLEN];
23 };
24
25 typedef unsigned int piece_index_t;
26
27 #define EO_FREE_PIECE (-1)
28
29 struct cake_s
30 {
31     struct llist_header cakes;
32     void* first_piece;
33     unsigned int used_pieces;
34     unsigned int next_free;
35     piece_index_t free_list[0];
36 };
37
38 /**
39  * @brief 创建一个蛋糕堆
40  *
41  * @param name 堆名称
42  * @param piece_size 每个蛋糕切块儿的大小
43  * @param pg_per_cake 每个蛋糕所占据的页数
44  * @return struct cake_pile*
45  */
46 struct cake_pile*
47 cake_new_pile(char* name,
48               unsigned int piece_size,
49               unsigned int pg_per_cake,
50               int options);
51
52 /**
53  * @brief 拿一块儿蛋糕
54  *
55  * @param pile
56  * @return void*
57  */
58 void*
59 cake_grab(struct cake_pile* pile);
60
61 /**
62  * @brief 归还一块儿蛋糕
63  *
64  * @param pile
65  * @param area
66  */
67 int
68 cake_release(struct cake_pile* pile, void* area);
69
70 void
71 cake_init();
72
73 /**
74  * @brief 统计蛋糕数量 - 问问Pinkie :D
75  *
76  */
77 void
78 cake_stats();
79
80 #endif /* __LUNAIX_VALLOC_H */