X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/bb7ce16533fb6c1384775dea6e1150e74c229daf..a4ec38a4c7ef61b04b92d34637c846a8e2e95f7f:/lunaix-os/kernel/mm/cake_export.c diff --git a/lunaix-os/kernel/mm/cake_export.c b/lunaix-os/kernel/mm/cake_export.c new file mode 100644 index 0000000..276e823 --- /dev/null +++ b/lunaix-os/kernel/mm/cake_export.c @@ -0,0 +1,108 @@ +#include +#include + +extern struct llist_header piles; + +int +__cake_stat_gonext(struct twimap* map) +{ + struct cake_pile* pile = twimap_index(map, struct cake_pile*); + if (pile->piles.next == &piles) { + return 0; + } + map->index = list_entry(pile->piles.next, struct cake_pile, piles); + return 1; +} + +void +__cake_stat_reset(struct twimap* map) +{ + map->index = container_of(piles.next, struct cake_pile, piles); +} + +void +__cake_rd_stat(struct twimap* map) +{ + struct cake_pile* pos = twimap_index(map, struct cake_pile*); + twimap_printf(map, + "%s %d %d %d %d\n", + pos->pile_name, + pos->cakes_count, + pos->pg_per_cake, + pos->pieces_per_cake, + pos->alloced_pieces); +} + +void +__cake_rd_psize(struct twimap* map) +{ + struct cake_pile* pile = twimap_data(map, struct cake_pile*); + twimap_printf(map, "%u", pile->piece_size); +} + +void +__cake_rd_ccount(struct twimap* map) +{ + struct cake_pile* pile = twimap_data(map, struct cake_pile*); + twimap_printf(map, "%u", pile->cakes_count); +} + +void +__cake_rd_alloced(struct twimap* map) +{ + struct cake_pile* pile = twimap_data(map, struct cake_pile*); + twimap_printf(map, "%u", pile->alloced_pieces); +} + +void +__cake_rd_ppc(struct twimap* map) +{ + struct cake_pile* pile = twimap_data(map, struct cake_pile*); + twimap_printf(map, "%u", pile->pieces_per_cake); +} + +void +__cake_rd_ppg(struct twimap* map) +{ + struct cake_pile* pile = twimap_data(map, struct cake_pile*); + twimap_printf(map, "%u", pile->pg_per_cake); +} + +void +cake_export_pile(struct twifs_node* root, struct cake_pile* pile) +{ + struct twifs_node* pile_rt = twifs_dir_node(root, pile->pile_name); + + struct twimap* map = twifs_mapping(pile_rt, pile, "piece_size"); + map->read = __cake_rd_psize; + + map = twifs_mapping(pile_rt, pile, "cake_count"); + map->read = __cake_rd_ccount; + + map = twifs_mapping(pile_rt, pile, "grabbed"); + map->read = __cake_rd_alloced; + + map = twifs_mapping(pile_rt, pile, "pieces_per_cake"); + map->read = __cake_rd_ppc; + + map = twifs_mapping(pile_rt, pile, "page_per_cake"); + map->read = __cake_rd_ppg; +} + +void +cake_export() +{ + struct twifs_node* cake_root = twifs_dir_node(NULL, "cake"); + + struct twimap* map = twifs_mapping(cake_root, NULL, "pinkiepie"); + map->reset = __cake_stat_reset; + map->go_next = __cake_stat_gonext; + map->read = __cake_rd_stat; + __cake_stat_reset(map); + + struct cake_pile *pos, *n; + llist_for_each(pos, n, &piles, piles) + { + cake_export_pile(cake_root, pos); + } +} \ No newline at end of file