1f1abbce7SDavid van Moolenbroek /* ProcFS - main.c - main functions of the process file system */
2433d6423SLionel Sambuc
3433d6423SLionel Sambuc #include "inc.h"
4433d6423SLionel Sambuc
5433d6423SLionel Sambuc static void init_hook(void);
6433d6423SLionel Sambuc
7433d6423SLionel Sambuc /* The hook functions that will be called by VTreeFS. */
8433d6423SLionel Sambuc static struct fs_hooks hooks = {
95eefd0feSDavid van Moolenbroek .init_hook = init_hook,
105eefd0feSDavid van Moolenbroek .lookup_hook = lookup_hook,
115eefd0feSDavid van Moolenbroek .getdents_hook = getdents_hook,
125eefd0feSDavid van Moolenbroek .read_hook = read_hook,
135eefd0feSDavid van Moolenbroek .rdlink_hook = rdlink_hook,
14433d6423SLionel Sambuc };
15433d6423SLionel Sambuc
16f1abbce7SDavid van Moolenbroek /*
17f1abbce7SDavid van Moolenbroek * Construct a tree of static files from a null-terminated array of file
18f1abbce7SDavid van Moolenbroek * structures, recursively creating directories which have their associated
19f1abbce7SDavid van Moolenbroek * data point to child file structures.
20433d6423SLionel Sambuc */
21f1abbce7SDavid van Moolenbroek static void
construct_tree(struct inode * dir,struct file * files)22f1abbce7SDavid van Moolenbroek construct_tree(struct inode * dir, struct file * files)
23f1abbce7SDavid van Moolenbroek {
24433d6423SLionel Sambuc struct file *file;
25433d6423SLionel Sambuc struct inode *node;
26433d6423SLionel Sambuc struct inode_stat stat;
27433d6423SLionel Sambuc
28433d6423SLionel Sambuc stat.uid = SUPER_USER;
29433d6423SLionel Sambuc stat.gid = SUPER_USER;
30433d6423SLionel Sambuc stat.size = 0;
31433d6423SLionel Sambuc stat.dev = NO_DEV;
32433d6423SLionel Sambuc
33433d6423SLionel Sambuc for (file = files; file->name != NULL; file++) {
34433d6423SLionel Sambuc stat.mode = file->mode;
35433d6423SLionel Sambuc
36433d6423SLionel Sambuc node = add_inode(dir, file->name, NO_INDEX, &stat, (index_t)0,
37433d6423SLionel Sambuc (cbdata_t)file->data);
38433d6423SLionel Sambuc
39433d6423SLionel Sambuc assert(node != NULL);
40433d6423SLionel Sambuc
41433d6423SLionel Sambuc if (S_ISDIR(file->mode))
42433d6423SLionel Sambuc construct_tree(node, (struct file *)file->data);
43433d6423SLionel Sambuc }
44433d6423SLionel Sambuc }
45433d6423SLionel Sambuc
46f1abbce7SDavid van Moolenbroek /*
47f1abbce7SDavid van Moolenbroek * Initialization hook. Generate the static part of the tree.
48433d6423SLionel Sambuc */
49f1abbce7SDavid van Moolenbroek static void
init_hook(void)50f1abbce7SDavid van Moolenbroek init_hook(void)
51f1abbce7SDavid van Moolenbroek {
5231b6611aSDavid van Moolenbroek static int first_time = TRUE;
53433d6423SLionel Sambuc struct inode *root;
54*3f82ac6aSCristiano Giuffrida int r;
55433d6423SLionel Sambuc
56433d6423SLionel Sambuc if (first_time) {
57*3f82ac6aSCristiano Giuffrida /*
58*3f82ac6aSCristiano Giuffrida * Initialize some state. If we are incompatible with the kernel,
59*3f82ac6aSCristiano Giuffrida * exit immediately.
60*3f82ac6aSCristiano Giuffrida */
61*3f82ac6aSCristiano Giuffrida if ((r = init_tree()) != OK)
62*3f82ac6aSCristiano Giuffrida panic("init_tree failed!");
63*3f82ac6aSCristiano Giuffrida
64433d6423SLionel Sambuc root = get_root_inode();
65433d6423SLionel Sambuc
66433d6423SLionel Sambuc construct_tree(root, root_files);
67433d6423SLionel Sambuc
6831b6611aSDavid van Moolenbroek service_init();
6931b6611aSDavid van Moolenbroek
7031b6611aSDavid van Moolenbroek first_time = FALSE;
71433d6423SLionel Sambuc }
72433d6423SLionel Sambuc }
73433d6423SLionel Sambuc
74f1abbce7SDavid van Moolenbroek /*
75f1abbce7SDavid van Moolenbroek * ProcFS entry point.
76f1abbce7SDavid van Moolenbroek */
main(void)77433d6423SLionel Sambuc int main(void)
78433d6423SLionel Sambuc {
7950b7f13fSCristiano Giuffrida static struct inode_stat stat;
80433d6423SLionel Sambuc
81433d6423SLionel Sambuc /* Properties of the root directory. */
82433d6423SLionel Sambuc stat.mode = DIR_ALL_MODE;
83433d6423SLionel Sambuc stat.uid = SUPER_USER;
84433d6423SLionel Sambuc stat.gid = SUPER_USER;
85433d6423SLionel Sambuc stat.size = 0;
86433d6423SLionel Sambuc stat.dev = NO_DEV;
87433d6423SLionel Sambuc
8852be5c0aSDavid van Moolenbroek /* Run VTreeFS. */
8952be5c0aSDavid van Moolenbroek run_vtreefs(&hooks, NR_INODES, 0, &stat, NR_PROCS + NR_TASKS,
9052be5c0aSDavid van Moolenbroek BUF_SIZE);
91433d6423SLionel Sambuc
92433d6423SLionel Sambuc return 0;
93433d6423SLionel Sambuc }
94