rework parsing of interupt-map in interrupt node.
[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, struct cake_pile, piles);
21     twimap_printf(map, "name cakes pages size slices actives\n");
22 }
23
24 void
25 __cake_rd_stat(struct twimap* map)
26 {
27     struct cake_pile* pos = twimap_index(map, struct cake_pile*);
28     twimap_printf(map,
29                   "%s %d %d %d %d %d\n",
30                   pos->pile_name,
31                   pos->cakes_count,
32                   pos->pg_per_cake,
33                   pos->piece_size,
34                   pos->pieces_per_cake,
35                   pos->alloced_pieces);
36 }
37
38 void
39 __cake_rd_psize(struct twimap* map)
40 {
41     struct cake_pile* pile = twimap_data(map, struct cake_pile*);
42     twimap_printf(map, "%u", pile->piece_size);
43 }
44
45 void
46 __cake_rd_ccount(struct twimap* map)
47 {
48     struct cake_pile* pile = twimap_data(map, struct cake_pile*);
49     twimap_printf(map, "%u", pile->cakes_count);
50 }
51
52 void
53 __cake_rd_alloced(struct twimap* map)
54 {
55     struct cake_pile* pile = twimap_data(map, struct cake_pile*);
56     twimap_printf(map, "%u", pile->alloced_pieces);
57 }
58
59 void
60 __cake_rd_ppc(struct twimap* map)
61 {
62     struct cake_pile* pile = twimap_data(map, struct cake_pile*);
63     twimap_printf(map, "%u", pile->pieces_per_cake);
64 }
65
66 void
67 __cake_rd_ppg(struct twimap* map)
68 {
69     struct cake_pile* pile = twimap_data(map, struct cake_pile*);
70     twimap_printf(map, "%u", pile->pg_per_cake);
71 }
72
73 void
74 cake_export_pile(struct twifs_node* root, struct cake_pile* pile)
75 {
76     struct twifs_node* pile_rt = twifs_dir_node(root, pile->pile_name);
77
78     struct twimap* map = twifs_mapping(pile_rt, pile, "piece_size");
79     map->read = __cake_rd_psize;
80
81     map = twifs_mapping(pile_rt, pile, "cake_count");
82     map->read = __cake_rd_ccount;
83
84     map = twifs_mapping(pile_rt, pile, "grabbed");
85     map->read = __cake_rd_alloced;
86
87     map = twifs_mapping(pile_rt, pile, "pieces_per_cake");
88     map->read = __cake_rd_ppc;
89
90     map = twifs_mapping(pile_rt, pile, "page_per_cake");
91     map->read = __cake_rd_ppg;
92 }
93
94 void
95 cake_export()
96 {
97     struct twifs_node* cake_root = twifs_dir_node(NULL, "cake");
98
99     struct twimap* map = twifs_mapping(cake_root, NULL, "pinkiepie");
100     map->reset = __cake_stat_reset;
101     map->go_next = __cake_stat_gonext;
102     map->read = __cake_rd_stat;
103
104     struct cake_pile *pos, *n;
105     llist_for_each(pos, n, &piles, piles)
106     {
107         cake_export_pile(cake_root, pos);
108     }
109 }
110 EXPORT_TWIFS_PLUGIN(cake_alloc, cake_export);