Second Extended Filesystem (ext2) and other improvements (#33)
[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, n_cakes, pg/cake, slices/cake, n_slices\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\n",
30                   pos->pile_name,
31                   pos->cakes_count,
32                   pos->pg_per_cake,
33                   pos->pieces_per_cake,
34                   pos->alloced_pieces);
35 }
36
37 void
38 __cake_rd_psize(struct twimap* map)
39 {
40     struct cake_pile* pile = twimap_data(map, struct cake_pile*);
41     twimap_printf(map, "%u", pile->piece_size);
42 }
43
44 void
45 __cake_rd_ccount(struct twimap* map)
46 {
47     struct cake_pile* pile = twimap_data(map, struct cake_pile*);
48     twimap_printf(map, "%u", pile->cakes_count);
49 }
50
51 void
52 __cake_rd_alloced(struct twimap* map)
53 {
54     struct cake_pile* pile = twimap_data(map, struct cake_pile*);
55     twimap_printf(map, "%u", pile->alloced_pieces);
56 }
57
58 void
59 __cake_rd_ppc(struct twimap* map)
60 {
61     struct cake_pile* pile = twimap_data(map, struct cake_pile*);
62     twimap_printf(map, "%u", pile->pieces_per_cake);
63 }
64
65 void
66 __cake_rd_ppg(struct twimap* map)
67 {
68     struct cake_pile* pile = twimap_data(map, struct cake_pile*);
69     twimap_printf(map, "%u", pile->pg_per_cake);
70 }
71
72 void
73 cake_export_pile(struct twifs_node* root, struct cake_pile* pile)
74 {
75     struct twifs_node* pile_rt = twifs_dir_node(root, pile->pile_name);
76
77     struct twimap* map = twifs_mapping(pile_rt, pile, "piece_size");
78     map->read = __cake_rd_psize;
79
80     map = twifs_mapping(pile_rt, pile, "cake_count");
81     map->read = __cake_rd_ccount;
82
83     map = twifs_mapping(pile_rt, pile, "grabbed");
84     map->read = __cake_rd_alloced;
85
86     map = twifs_mapping(pile_rt, pile, "pieces_per_cake");
87     map->read = __cake_rd_ppc;
88
89     map = twifs_mapping(pile_rt, pile, "page_per_cake");
90     map->read = __cake_rd_ppg;
91 }
92
93 void
94 cake_export()
95 {
96     struct twifs_node* cake_root = twifs_dir_node(NULL, "cake");
97
98     struct twimap* map = twifs_mapping(cake_root, NULL, "pinkiepie");
99     map->reset = __cake_stat_reset;
100     map->go_next = __cake_stat_gonext;
101     map->read = __cake_rd_stat;
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 }
109 EXPORT_TWIFS_PLUGIN(cake_alloc, cake_export);