nckernel  0.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rootfs.c
Go to the documentation of this file.
1 #include <slibc.h>
2 #include <sys/types.h>
3 #include <stdio.h>
4 #include <stddef.h>
5 #include <stdlib.h>
6 #include <fcntl.h>
7 #include <stdint.h>
8 #include <unistd.h>
9 #include <string.h>
10 #include <stdarg.h>
11 #include <errno.h>
12 #include <ctype.h>
13 #include <libgen.h>
14 #include <stropts.h>
15 
16 #include <object.h>
17 #include <list.h>
18 #include <vfs.h>
19 #include <vfs0.h>
20 
21 #include <rootfs.h>
22 
23 struct rootfs {
24  struct ninfo *root;
25 };
26 
27 static struct ninfo *get_ninfo(struct sinfo *this, unsigned long id)
28 {
29  if (id == ROOT_NINFO) {
30  struct rootfs *rootfs;
31 
32  rootfs = this->priv;
33  if (!rootfs) {
34  return NULL;
35  }
36 
37  return rootfs->root;
38  }
39 
40  return NULL;
41 }
42 
43 static void refresh_children(struct sinfo *sinfo, struct ninfo *root)
44 {
46 }
47 
48 static int fill_ninfo(struct sinfo *this,
49  struct ninfo *parent, struct ninfo *ninfo, void *info)
50 {
51  if (!ninfo) {
52  return -EINVAL;
53  }
54 
55  ninfo->size = 0;
59  return 0;
60 }
61 
62 static int del_ninfo(struct sinfo *this, struct ninfo *node)
63 {
64  return 0;
65 }
66 
67 static struct sinfo s_si = {
68  .head = LIST_HEAD_INIT(s_si.head),
69  .refcnt = 0,
70 
71  .get_ninfo = get_ninfo,
72  .fill_ninfo = fill_ninfo,
73  .del_ninfo = del_ninfo,
74  .refresh_children = refresh_children,
75 };
76 
77 static void init_folder_schema(struct sinfo *si)
78 {
79  struct rootfs *priv;
80  struct ninfo *parent;
81  struct ninfo *ninfo;
82 
83  priv = si->priv;
84  parent = priv->root;
85 
86  ninfo = vfs_new_ninfo(parent->si, parent, "dev", NULL);
87  if (!ninfo) {
88  printf("Failed to create a \"dev\" folder\n");
89  }
90 }
91 
92 struct sinfo *load_rootfs(void)
93 {
94  struct rootfs *rootfs;
95 
96  rootfs = malloc(sizeof(*rootfs));
97  if (!rootfs) {
98  return NULL;
99  }
100 
101  rootfs->root = vfs_new_ninfo(&s_si, NULL, NULL, NULL);
102  if (!rootfs->root) {
103  free(rootfs);
104  return NULL;
105  }
106 
107  rootfs->root->type = NINFO_TYPE_FOLDER;
108  rootfs->root->priv = NULL;
109  rootfs->root->id = 0;
110  s_si.priv = rootfs;
111 
112  init_folder_schema(&s_si);
113  return &s_si;
114 }
115 
116 /* End of a file */