Second Extended Filesystem (ext2) and other improvements (#33)
[lunaix-os.git] / lunaix-os / kernel / process / task_attr.c
1 #include <lunaix/fs/taskfs.h>
2 #include <lunaix/process.h>
3
4 void
5 __read_parent(struct twimap* map)
6 {
7     struct proc_info* proc = twimap_data(map, struct proc_info*);
8     twimap_printf(map, "%d", proc->parent->pid);
9 }
10
11 void
12 __read_ctimestamp(struct twimap* map)
13 {
14     struct proc_info* proc = twimap_data(map, struct proc_info*);
15     twimap_printf(map, "%d", proc->created);
16 }
17
18 void
19 __read_pgid(struct twimap* map)
20 {
21     struct proc_info* proc = twimap_data(map, struct proc_info*);
22     twimap_printf(map, "%d", proc->pgid);
23 }
24
25 void
26 __read_children(struct twimap* map)
27 {
28     struct llist_header* proc_list = twimap_index(map, struct llist_header*);
29     struct proc_info* proc =
30       container_of(proc_list, struct proc_info, siblings);
31     if (!proc)
32         return;
33     twimap_printf(map, "%d ", proc->pid);
34 }
35
36 int
37 __next_children(struct twimap* map)
38 {
39     struct llist_header* proc = twimap_index(map, struct llist_header*);
40     struct proc_info* current = twimap_data(map, struct proc_info*);
41     if (!proc)
42         return 0;
43     map->index = proc->next;
44     if (map->index == &current->children) {
45         return 0;
46     }
47     return 1;
48 }
49
50 void
51 __reset_children(struct twimap* map)
52 {
53     struct proc_info* proc = twimap_data(map, struct proc_info*);
54     if (llist_empty(&proc->children)) {
55         map->index = 0;
56         return;
57     }
58     map->index = proc->children.next;
59 }
60
61 void
62 export_task_attr()
63 {
64     struct twimap* map;
65     
66     // FIXME goes to thread specific location
67     // map = twimap_create(NULL);
68     // map->read = __read_pending_sig;
69     // taskfs_export_attr("sig_pending", map);
70
71     // map = twimap_create(NULL);
72     // map->read = __read_masked_sig;
73     // taskfs_export_attr("sig_masked", map);
74
75     map = twimap_create(NULL);
76     map->read = __read_parent;
77     taskfs_export_attr("parent", map);
78
79     map = twimap_create(NULL);
80     map->read = __read_ctimestamp;
81     taskfs_export_attr("created", map);
82
83     map = twimap_create(NULL);
84     map->read = __read_pgid;
85     taskfs_export_attr("pgid", map);
86
87     map = twimap_create(NULL);
88     map->read = __read_children;
89     map->go_next = __next_children;
90     map->reset = __reset_children;
91     taskfs_export_attr("children", map);
92 }