1 /* ProcFS - main.c - by Alen Stojanov and David van Moolenbroek */ 2 3 #include "inc.h" 4 #include "cpuinfo.h" 5 6 static void init_hook(void); 7 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 */ 17 }; 18 19 /*===========================================================================* 20 * construct_tree * 21 *===========================================================================*/ 22 static void construct_tree(struct inode *dir, struct file *files) 23 { 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. 27 */ 28 struct file *file; 29 struct inode *node; 30 struct inode_stat stat; 31 32 stat.uid = SUPER_USER; 33 stat.gid = SUPER_USER; 34 stat.size = 0; 35 stat.dev = NO_DEV; 36 37 for (file = files; file->name != NULL; file++) { 38 stat.mode = file->mode; 39 40 node = add_inode(dir, file->name, NO_INDEX, &stat, (index_t) 0, 41 (cbdata_t) file->data); 42 43 assert(node != NULL); 44 45 if (S_ISDIR(file->mode)) 46 construct_tree(node, (struct file *) file->data); 47 } 48 } 49 50 /*===========================================================================* 51 * init_hook * 52 *===========================================================================*/ 53 static void init_hook(void) 54 { 55 /* Initialization hook. Generate the static part of the tree. 56 */ 57 static int first_time = 1; 58 struct inode *root; 59 60 if (first_time) { 61 root = get_root_inode(); 62 63 construct_tree(root, root_files); 64 65 first_time = 0; 66 } 67 } 68 69 /*===========================================================================* 70 * main * 71 *===========================================================================*/ 72 int main(void) 73 { 74 /* ProcFS entry point. 75 */ 76 struct inode_stat stat; 77 int r; 78 79 /* Initialize some state. If we are incompatible with the kernel, exit 80 * immediately. 81 */ 82 if ((r = init_tree()) != OK) 83 return r; 84 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; 91 92 /* Start VTreeFS. This call does not return. */ 93 start_vtreefs(&hooks, NR_INODES, &stat, NR_PROCS + NR_TASKS); 94 95 return 0; 96 } 97