coverity appeasement - redundant check
[minix.git] / servers / procfs / main.c
blob6a99bdc891df546f660c158f9784da8859ac547f
1 /* ProcFS - main.c - by Alen Stojanov and David van Moolenbroek */
3 #include "inc.h"
4 #include "cpuinfo.h"
6 static void init_hook(void);
8 /* The hook functions that will be called by VTreeFS. */
9 static struct fs_hooks hooks = {
10 init_hook,
11 NULL, /* cleanup_hook */
12 lookup_hook,
13 getdents_hook,
14 read_hook,
15 rdlink_hook,
16 NULL /* message_hook */
19 /*===========================================================================*
20 * construct_tree *
21 *===========================================================================*/
22 static void construct_tree(struct inode *dir, struct file *files)
24 /* Construct a tree of static files from a null-terminated array of
25 * file structures, recursively creating directories which have their
26 * associated data point to child file structures.
28 struct file *file;
29 struct inode *node;
30 struct inode_stat stat;
32 stat.uid = SUPER_USER;
33 stat.gid = SUPER_USER;
34 stat.size = 0;
35 stat.dev = NO_DEV;
37 for (file = files; file->name != NULL; file++) {
38 stat.mode = file->mode;
40 node = add_inode(dir, file->name, NO_INDEX, &stat, (index_t) 0,
41 (cbdata_t) file->data);
43 assert(node != NULL);
45 if (S_ISDIR(file->mode))
46 construct_tree(node, (struct file *) file->data);
50 /*===========================================================================*
51 * init_hook *
52 *===========================================================================*/
53 static void init_hook(void)
55 /* Initialization hook. Generate the static part of the tree.
57 static int first_time = 1;
58 struct inode *root;
60 if (first_time) {
61 root = get_root_inode();
63 construct_tree(root, root_files);
65 first_time = 0;
69 /*===========================================================================*
70 * main *
71 *===========================================================================*/
72 int main(void)
74 /* ProcFS entry point.
76 struct inode_stat stat;
77 int r;
79 /* Initialize some state. If we are incompatible with the kernel, exit
80 * immediately.
82 if ((r = init_tree()) != OK)
83 return r;
85 /* Properties of the root directory. */
86 stat.mode = DIR_ALL_MODE;
87 stat.uid = SUPER_USER;
88 stat.gid = SUPER_USER;
89 stat.size = 0;
90 stat.dev = NO_DEV;
92 /* Start VTreeFS. This call does not return. */
93 start_vtreefs(&hooks, NR_INODES, &stat, NR_PROCS + NR_TASKS);
95 return 0;