fix dependency check logic cause config always disabled
[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 static int
7 __twimap_gonext_pinkiepie(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 static void
18 __twimap_reset_pinkiepie(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 static void
25 __twimap_read_pinkiepie(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 static void
39 __twimap_read_piece_size(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 static void
46 __twimap_read_cake_count(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 static void
53 __twimap_read_grabbed(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 static void
60 __twimap_read_pieces_per_cake(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 static void
67 __twimap_read_page_per_cake(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;
77     
78     pile_rt = twifs_dir_node(root, pile->pile_name);
79
80     twimap_export_value(pile_rt, piece_size,        FSACL_ugR, pile);
81     twimap_export_value(pile_rt, cake_count,        FSACL_ugR, pile);
82     twimap_export_value(pile_rt, grabbed,           FSACL_ugR, pile);
83     twimap_export_value(pile_rt, pieces_per_cake,   FSACL_ugR, pile);
84     twimap_export_value(pile_rt, page_per_cake,     FSACL_ugR, pile);
85 }
86
87 void
88 cake_export()
89 {
90     struct cake_pile *pos, *n;
91     struct twifs_node* cake_root;
92     
93     cake_root = twifs_dir_node(NULL, "cake");
94
95     twimap_export_list(cake_root, pinkiepie, FSACL_ugR, NULL);
96
97     llist_for_each(pos, n, &piles, piles) {
98         cake_export_pile(cake_root, pos);
99     }
100 }
101 EXPORT_TWIFS_PLUGIN(cake_alloc, cake_export);