276e823c20be1b092ae731bb9c93c94937b4e78a
[lunaix-os.git] / lunaix-os / kernel / mm / cake_export.c
1 #include <lunaix/fs/twifs.h>
2 #include <lunaix/mm/cake.h>
3
4 extern struct llist_header piles;
5
6 int
7 __cake_stat_gonext(struct twimap* map)
8 {
9     struct cake_pile* pile = twimap_index(map, struct cake_pile*);
10     if (pile->piles.next == &piles) {
11         return 0;
12     }
13     map->index = list_entry(pile->piles.next, struct cake_pile, piles);
14     return 1;
15 }
16
17 void
18 __cake_stat_reset(struct twimap* map)
19 {
20     map->index = container_of(piles.next, struct cake_pile, piles);
21 }
22
23 void
24 __cake_rd_stat(struct twimap* map)
25 {
26     struct cake_pile* pos = twimap_index(map, struct cake_pile*);
27     twimap_printf(map,
28                   "%s %d %d %d %d\n",
29                   pos->pile_name,
30                   pos->cakes_count,
31                   pos->pg_per_cake,
32                   pos->pieces_per_cake,
33                   pos->alloced_pieces);
34 }
35
36 void
37 __cake_rd_psize(struct twimap* map)
38 {
39     struct cake_pile* pile = twimap_data(map, struct cake_pile*);
40     twimap_printf(map, "%u", pile->piece_size);
41 }
42
43 void
44 __cake_rd_ccount(struct twimap* map)
45 {
46     struct cake_pile* pile = twimap_data(map, struct cake_pile*);
47     twimap_printf(map, "%u", pile->cakes_count);
48 }
49
50 void
51 __cake_rd_alloced(struct twimap* map)
52 {
53     struct cake_pile* pile = twimap_data(map, struct cake_pile*);
54     twimap_printf(map, "%u", pile->alloced_pieces);
55 }
56
57 void
58 __cake_rd_ppc(struct twimap* map)
59 {
60     struct cake_pile* pile = twimap_data(map, struct cake_pile*);
61     twimap_printf(map, "%u", pile->pieces_per_cake);
62 }
63
64 void
65 __cake_rd_ppg(struct twimap* map)
66 {
67     struct cake_pile* pile = twimap_data(map, struct cake_pile*);
68     twimap_printf(map, "%u", pile->pg_per_cake);
69 }
70
71 void
72 cake_export_pile(struct twifs_node* root, struct cake_pile* pile)
73 {
74     struct twifs_node* pile_rt = twifs_dir_node(root, pile->pile_name);
75
76     struct twimap* map = twifs_mapping(pile_rt, pile, "piece_size");
77     map->read = __cake_rd_psize;
78
79     map = twifs_mapping(pile_rt, pile, "cake_count");
80     map->read = __cake_rd_ccount;
81
82     map = twifs_mapping(pile_rt, pile, "grabbed");
83     map->read = __cake_rd_alloced;
84
85     map = twifs_mapping(pile_rt, pile, "pieces_per_cake");
86     map->read = __cake_rd_ppc;
87
88     map = twifs_mapping(pile_rt, pile, "page_per_cake");
89     map->read = __cake_rd_ppg;
90 }
91
92 void
93 cake_export()
94 {
95     struct twifs_node* cake_root = twifs_dir_node(NULL, "cake");
96
97     struct twimap* map = twifs_mapping(cake_root, NULL, "pinkiepie");
98     map->reset = __cake_stat_reset;
99     map->go_next = __cake_stat_gonext;
100     map->read = __cake_rd_stat;
101     __cake_stat_reset(map);
102
103     struct cake_pile *pos, *n;
104     llist_for_each(pos, n, &piles, piles)
105     {
106         cake_export_pile(cake_root, pos);
107     }
108 }