Rev 1325 | Rev 1702 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1325 | Rev 1326 | ||
---|---|---|---|
Line 29... | Line 29... | ||
29 | #include <sysinfo/sysinfo.h> |
29 | #include <sysinfo/sysinfo.h> |
30 | #include <mm/slab.h> |
30 | #include <mm/slab.h> |
31 | #include <print.h> |
31 | #include <print.h> |
32 | #include <syscall/copy.h> |
32 | #include <syscall/copy.h> |
33 | 33 | ||
34 | sysinfo_item_t *_root=NULL; |
34 | sysinfo_item_t *_root = NULL; |
35 | 35 | ||
36 | 36 | ||
37 | static sysinfo_item_t* sysinfo_find_item(const char *name,sysinfo_item_t *subtree) |
37 | static sysinfo_item_t *sysinfo_find_item(const char *name, sysinfo_item_t *subtree) |
38 | { |
38 | { |
39 | if(subtree==NULL) return NULL; |
39 | if (subtree == NULL) |
40 | while(subtree!=NULL) |
40 | return NULL; |
41 | { |
41 | |
42 | int i; |
42 | while (subtree != NULL) { |
43 | char *a,*b; |
43 | int i = 0; |
44 | a=(char *)name; |
44 | char *a = (char *) name; |
45 | b=subtree->name; |
45 | char *b = subtree->name; |
- | 46 | ||
46 | while((a[i]==b[i])&&(b[i])) i++; |
47 | while ((a[i] == b[i]) && (b[i])) |
- | 48 | i++; |
|
- | 49 | ||
47 | if((!a[i]) && (!b[i])) return subtree; /*Last name in path matches*/ |
50 | if ((!a[i]) && (!b[i])) /* Last name in path matches */ |
- | 51 | return subtree; |
|
- | 52 | ||
48 | if((a[i]=='.') && (!b[i])) /*Middle name in path matches*/ |
53 | if ((a[i] == '.') && (!b[i])) { /* Middle name in path matches */ |
- | 54 | if (subtree->subinfo_type == SYSINFO_SUBINFO_TABLE) |
|
- | 55 | return sysinfo_find_item(a + i + 1, subtree->subinfo.table); |
|
49 | { |
56 | |
50 | if(subtree->subinfo_type==SYSINFO_SUBINFO_TABLE) return sysinfo_find_item(a+i+1,subtree->subinfo.table); |
- | |
51 | //if(subtree->subinfo_type==SYSINFO_SUBINFO_FUNCTION) return NULL; /* Subinfo managed by subsystem*/ |
57 | //if (subtree->subinfo_type == SYSINFO_SUBINFO_FUNCTION) /* Subinfo managed by subsystem */ |
- | 58 | // return NULL; |
|
- | 59 | ||
52 | return NULL; /*No subinfo*/ |
60 | return NULL; /* No subinfo */ |
53 | } |
61 | } |
54 | /* No matches try next*/ |
62 | /* No matches try next */ |
55 | subtree=subtree->next; |
63 | subtree = subtree->next; |
56 | i=0; |
64 | i = 0; |
57 | } |
65 | } |
58 | return NULL; |
66 | return NULL; |
59 | } |
67 | } |
60 | 68 | ||
61 | static sysinfo_item_t* sysinfo_create_path(const char *name,sysinfo_item_t **psubtree) |
69 | static sysinfo_item_t *sysinfo_create_path(const char *name, sysinfo_item_t **psubtree) |
62 | { |
70 | { |
63 | sysinfo_item_t *subtree; |
71 | sysinfo_item_t *subtree; |
64 | subtree = *psubtree; |
72 | subtree = *psubtree; |
65 | 73 | ||
66 | if(subtree==NULL) |
74 | if (subtree == NULL) { |
67 | { |
- | |
68 | sysinfo_item_t *item; |
75 | sysinfo_item_t *item = malloc(sizeof(sysinfo_item_t), 0); |
69 | int i=0,j; |
76 | int i = 0, j; |
70 | 77 | ||
71 | item = malloc(sizeof(sysinfo_item_t),0); |
- | |
72 | ASSERT(item); |
78 | ASSERT(item); |
73 | *psubtree = item; |
79 | *psubtree = item; |
74 | item -> next = NULL; |
80 | item->next = NULL; |
75 | item -> val_type = SYSINFO_VAL_UNDEFINED; |
81 | item->val_type = SYSINFO_VAL_UNDEFINED; |
76 | item -> subinfo.table = NULL; |
82 | item->subinfo.table = NULL; |
77 | 83 | ||
78 | while(name[i]&&(name[i]!='.')) i++; |
84 | while (name[i] && (name[i] != '.')) |
- | 85 | i++; |
|
79 | 86 | ||
80 | item -> name = malloc(i,0); |
87 | item->name = malloc(i, 0); |
81 | ASSERT(item -> name); |
88 | ASSERT(item->name); |
82 | 89 | ||
- | 90 | for (j = 0; j < i; j++) |
|
83 | for(j=0;j<i;j++) item->name[j]=name[j]; |
91 | item->name[j] = name[j]; |
84 | item->name[j]=0; |
92 | item->name[j] = 0; |
85 | 93 | ||
86 | if(name[i]/*=='.'*/) |
94 | if (name[i]) { /* =='.' */ |
87 | { |
- | |
88 | item -> subinfo_type = SYSINFO_SUBINFO_TABLE; |
95 | item->subinfo_type = SYSINFO_SUBINFO_TABLE; |
89 | return sysinfo_create_path(name+i+1,&(item->subinfo.table)); |
96 | return sysinfo_create_path(name + i + 1, &(item->subinfo.table)); |
90 | } |
97 | } |
91 | item -> subinfo_type = SYSINFO_SUBINFO_NONE; |
98 | item->subinfo_type = SYSINFO_SUBINFO_NONE; |
92 | return item; |
99 | return item; |
93 | } |
100 | } |
94 | 101 | ||
95 | while(subtree!=NULL) |
102 | while (subtree != NULL) { |
96 | { |
- | |
97 | int i=0,j; |
103 | int i = 0, j; |
98 | char *a,*b; |
- | |
99 | a=(char *)name; |
104 | char *a = (char *) name; |
100 | b=subtree->name; |
105 | char *b = subtree->name; |
- | 106 | ||
101 | while((a[i]==b[i])&&(b[i])) i++; |
107 | while ((a[i] == b[i]) && (b[i])) |
- | 108 | i++; |
|
- | 109 | ||
102 | if((!a[i]) && (!b[i])) return subtree; /*Last name in path matches*/ |
110 | if ((!a[i]) && (!b[i])) /* Last name in path matches */ |
103 | if((a[i]=='.') && (!b[i])) /*Middle name in path matches*/ |
111 | return subtree; |
104 | { |
112 | |
105 | if(subtree->subinfo_type==SYSINFO_SUBINFO_TABLE) return sysinfo_create_path(a+i+1,&(subtree->subinfo.table)); |
113 | if ((a[i] == '.') && (!b[i])) { /* Middle name in path matches */ |
106 | if(subtree->subinfo_type==SYSINFO_SUBINFO_NONE) |
114 | if (subtree->subinfo_type == SYSINFO_SUBINFO_TABLE) |
- | 115 | return sysinfo_create_path(a + i + 1, &(subtree->subinfo.table)); |
|
107 | { |
116 | |
- | 117 | if (subtree->subinfo_type == SYSINFO_SUBINFO_NONE) { |
|
108 | subtree->subinfo_type=SYSINFO_SUBINFO_TABLE; |
118 | subtree->subinfo_type = SYSINFO_SUBINFO_TABLE; |
109 | return sysinfo_create_path(a+i+1,&(subtree->subinfo.table)); |
119 | return sysinfo_create_path(a + i + 1,&(subtree->subinfo.table)); |
110 | } |
120 | } |
- | 121 | ||
111 | //if(subtree->subinfo_type==SYSINFO_SUBINFO_FUNCTION) return NULL; /* Subinfo managed by subsystem*/ |
122 | //if (subtree->subinfo_type == SYSINFO_SUBINFO_FUNCTION) /* Subinfo managed by subsystem */ |
- | 123 | // return NULL; |
|
- | 124 | ||
112 | return NULL; |
125 | return NULL; |
113 | } |
126 | } |
114 | /* No matches try next or create new*/ |
127 | /* No matches try next or create new*/ |
115 | if(subtree->next==NULL) |
128 | if (subtree->next == NULL) { |
116 | { |
- | |
117 | sysinfo_item_t *item; |
129 | sysinfo_item_t *item = malloc(sizeof(sysinfo_item_t), 0); |
118 | 130 | ||
119 | item = malloc(sizeof(sysinfo_item_t),0); |
- | |
120 | ASSERT(item); |
131 | ASSERT(item); |
121 | subtree -> next = item; |
132 | subtree->next = item; |
122 | item -> next = NULL; |
133 | item->next = NULL; |
123 | item -> val_type = SYSINFO_VAL_UNDEFINED; |
134 | item->val_type = SYSINFO_VAL_UNDEFINED; |
124 | item -> subinfo.table = NULL; |
135 | item->subinfo.table = NULL; |
125 | 136 | ||
126 | i=0; |
137 | i = 0; |
127 | while(name[i]&&(name[i]!='.')) i++; |
138 | while (name[i] && (name[i] != '.')) |
- | 139 | i++; |
|
128 | 140 | ||
129 | item -> name = malloc(i,0); |
141 | item->name = malloc(i, 0); |
130 | ASSERT(item -> name); |
142 | ASSERT(item->name); |
- | 143 | ||
- | 144 | for (j = 0; j < i; j++) |
|
131 | for(j=0;j<i;j++) item->name[j]=name[j]; |
145 | item->name[j] = name[j]; |
- | 146 | ||
132 | item->name[j]=0; |
147 | item->name[j] = 0; |
133 | 148 | ||
134 | if(name[i]/*=='.'*/) |
149 | if(name[i]) { /* =='.' */ |
135 | { |
- | |
136 | item -> subinfo_type = SYSINFO_SUBINFO_TABLE; |
150 | item->subinfo_type = SYSINFO_SUBINFO_TABLE; |
137 | return sysinfo_create_path(name+i+1,&(item->subinfo.table)); |
151 | return sysinfo_create_path(name + i + 1, &(item->subinfo.table)); |
138 | } |
152 | } |
139 | item -> subinfo_type = SYSINFO_SUBINFO_NONE; |
153 | item->subinfo_type = SYSINFO_SUBINFO_NONE; |
140 | return item; |
154 | return item; |
141 | - | ||
142 | } |
- | |
143 | else |
155 | } else { |
144 | { |
- | |
145 | subtree=subtree->next; |
156 | subtree = subtree->next; |
146 | i=0; |
157 | i = 0; |
147 | } |
158 | } |
148 | } |
159 | } |
149 | panic("Not reached\n"); |
160 | panic("Not reached\n"); |
150 | return NULL; |
161 | return NULL; |
151 | } |
162 | } |
152 | 163 | ||
153 | void sysinfo_set_item_val(const char *name,sysinfo_item_t **root,__native val) |
164 | void sysinfo_set_item_val(const char *name, sysinfo_item_t **root, __native val) |
154 | { |
165 | { |
155 | if(root==NULL) root=&_root; |
166 | if (root == NULL) |
156 | sysinfo_item_t *item; |
167 | root = &_root; |
- | 168 | ||
157 | item = sysinfo_create_path(name,root); /* If already created create only returns pointer |
169 | /* If already created create only returns pointer |
158 | If ! , create it */ |
170 | If not, create it */ |
159 | if(item!=NULL) /* If in subsystem, unable to create or return so unable to set */ |
171 | sysinfo_item_t *item = sysinfo_create_path(name, root); |
160 | { |
172 | |
- | 173 | if (item != NULL) { /* If in subsystem, unable to create or return so unable to set */ |
|
161 | item->val.val=val; |
174 | item->val.val=val; |
162 | item -> val_type = SYSINFO_VAL_VAL; |
175 | item->val_type = SYSINFO_VAL_VAL; |
163 | } |
176 | } |
164 | } |
177 | } |
165 | 178 | ||
166 | void sysinfo_set_item_function(const char *name,sysinfo_item_t **root,sysinfo_val_fn_t fn) |
179 | void sysinfo_set_item_function(const char *name, sysinfo_item_t **root, sysinfo_val_fn_t fn) |
167 | { |
180 | { |
168 | if(root==NULL) root=&_root; |
181 | if (root == NULL) |
169 | sysinfo_item_t *item; |
182 | root = &_root; |
- | 183 | ||
170 | item = sysinfo_create_path(name,root); /* If already created create only returns pointer |
184 | /* If already created create only returns pointer |
171 | If ! , create it */ |
185 | If not, create it */ |
172 | if(item!=NULL) /* If in subsystem, unable to create or return so unable to set */ |
186 | sysinfo_item_t *item = sysinfo_create_path(name, root); |
173 | { |
187 | |
- | 188 | if (item != NULL) { /* If in subsystem, unable to create or return so unable to set */ |
|
174 | item->val.fn=fn; |
189 | item->val.fn=fn; |
175 | item -> val_type = SYSINFO_VAL_FUNCTION; |
190 | item->val_type = SYSINFO_VAL_FUNCTION; |
176 | } |
191 | } |
177 | } |
192 | } |
178 | 193 | ||
179 | 194 | ||
180 | void sysinfo_set_item_undefined(const char *name,sysinfo_item_t **root) |
195 | void sysinfo_set_item_undefined(const char *name, sysinfo_item_t **root) |
181 | { |
196 | { |
- | 197 | if (root == NULL) |
|
182 | if(root==NULL) root=&_root; |
198 | root = &_root; |
- | 199 | ||
- | 200 | /* If already created create only returns pointer |
|
183 | sysinfo_item_t *item; |
201 | If not, create it */ |
184 | item = sysinfo_find_item(name,*root); |
202 | sysinfo_item_t *item = sysinfo_create_path(name, root); |
- | 203 | ||
- | 204 | if (item != NULL) |
|
185 | if(item!=NULL) item -> val_type = SYSINFO_VAL_UNDEFINED; |
205 | item->val_type = SYSINFO_VAL_UNDEFINED; |
186 | } |
206 | } |
187 | 207 | ||
188 | 208 | ||
189 | void sysinfo_dump(sysinfo_item_t **proot,int depth) |
209 | void sysinfo_dump(sysinfo_item_t **proot, int depth) |
190 | { |
210 | { |
191 | sysinfo_item_t *root; |
211 | sysinfo_item_t *root; |
- | 212 | if (proot == NULL) |
|
192 | if(proot==NULL) proot=&_root; |
213 | proot = &_root; |
- | 214 | ||
193 | root = *proot; |
215 | root = *proot; |
194 | 216 | ||
195 | while(root!=NULL) |
217 | while (root != NULL) { |
196 | { |
- | |
197 | - | ||
198 | int i; |
218 | int i; |
199 | __native val=0; |
219 | __native val = 0; |
200 | char *vtype=NULL; |
220 | char *vtype = NULL; |
201 | 221 | ||
202 | 222 | ||
203 | for(i=0;i<depth;i++) printf(" "); |
223 | for (i = 0; i < depth; i++) |
- | 224 | printf(" "); |
|
204 | 225 | ||
205 | switch (root->val_type) |
226 | switch (root->val_type) { |
206 | { |
- | |
207 | case (SYSINFO_VAL_UNDEFINED): |
227 | case SYSINFO_VAL_UNDEFINED: |
208 | val=0; |
228 | val = 0; |
209 | vtype="UND"; |
229 | vtype = "UND"; |
210 | break; |
230 | break; |
211 | case (SYSINFO_VAL_VAL): |
231 | case SYSINFO_VAL_VAL: |
212 | val=root->val.val; |
232 | val = root->val.val; |
213 | vtype="VAL"; |
233 | vtype = "VAL"; |
214 | break; |
234 | break; |
215 | case (SYSINFO_VAL_FUNCTION): |
235 | case SYSINFO_VAL_FUNCTION: |
216 | val=((sysinfo_val_fn_t)(root->val.fn))(root); |
236 | val = ((sysinfo_val_fn_t) (root->val.fn)) (root); |
217 | vtype="FUN"; |
237 | vtype = "FUN"; |
218 | break; |
238 | break; |
219 | } |
239 | } |
220 | printf("%s %s val:%d(%X) sub:%s\n",root->name,vtype,val,val, |
- | |
221 | (root->subinfo_type==SYSINFO_SUBINFO_NONE)?"NON":((root->subinfo_type==SYSINFO_SUBINFO_TABLE)?"TAB":"FUN")); |
- | |
222 | 240 | ||
- | 241 | printf("%s %s val:%d(%X) sub:%s\n", root->name, vtype, val, val, (root->subinfo_type == SYSINFO_SUBINFO_NONE) ? "NON" : ((root->subinfo_type == SYSINFO_SUBINFO_TABLE) ? "TAB" : "FUN")); |
|
223 | 242 | ||
224 | if(root -> subinfo_type == SYSINFO_SUBINFO_TABLE) |
243 | if (root->subinfo_type == SYSINFO_SUBINFO_TABLE) |
225 | sysinfo_dump(&(root->subinfo.table),depth+1); |
244 | sysinfo_dump(&(root -> subinfo.table), depth + 1); |
- | 245 | ||
226 | root=root->next; |
246 | root = root->next; |
227 | } |
247 | } |
228 | } |
248 | } |
229 | 249 | ||
230 | sysinfo_rettype_t sysinfo_get_val(const char *name,sysinfo_item_t **root) |
250 | sysinfo_rettype_t sysinfo_get_val(const char *name, sysinfo_item_t **root) |
231 | { |
251 | { |
232 | /*TODO: |
- | |
233 | Implement Subsystem subinfo (by function implemented subinfo) |
252 | // TODO: Implement Subsystem subinfo (by function implemented subinfo) |
234 | */ |
- | |
235 | 253 | ||
236 | sysinfo_rettype_t ret={0,false}; |
254 | sysinfo_rettype_t ret = {0, false}; |
237 | 255 | ||
238 | if(root==NULL) root=&_root; |
256 | if (root == NULL) |
239 | sysinfo_item_t *item; |
257 | root = &_root; |
- | 258 | ||
240 | item = sysinfo_find_item(name,*root); |
259 | sysinfo_item_t *item = sysinfo_find_item(name, *root); |
- | 260 | ||
241 | if(item!=NULL) |
261 | if (item != NULL) { |
242 | { |
- | |
243 | if (item -> val_type == SYSINFO_VAL_UNDEFINED) |
262 | if (item->val_type == SYSINFO_VAL_UNDEFINED) |
244 | return ret; |
263 | return ret; |
- | 264 | else |
|
245 | else ret.valid=true; |
265 | ret.valid = true; |
- | 266 | ||
246 | if (item -> val_type == SYSINFO_VAL_VAL) |
267 | if (item->val_type == SYSINFO_VAL_VAL) |
247 | ret.val=item -> val.val; |
268 | ret.val = item->val.val; |
- | 269 | else |
|
248 | else ret.val=((sysinfo_val_fn_t)(item->val.fn))(item); |
270 | ret.val = ((sysinfo_val_fn_t) (item->val.fn)) (item); |
249 | } |
271 | } |
250 | return ret; |
272 | return ret; |
251 | } |
273 | } |
252 | 274 | ||
253 | __native sys_sysinfo_valid(__native ptr,__native len) |
275 | __native sys_sysinfo_valid(__native ptr, __native len) |
254 | { |
276 | { |
255 | char *str; |
277 | char *str; |
256 | sysinfo_rettype_t ret={0,0}; |
278 | sysinfo_rettype_t ret = {0, 0}; |
257 | str=malloc(len+1,0); |
279 | str = malloc(len + 1, 0); |
- | 280 | ||
258 | ASSERT(str); |
281 | ASSERT(str); |
259 | if(!((copy_from_uspace(str,(void *)ptr,len+1))||(str[len]))) |
282 | if (!((copy_from_uspace(str, (void *) ptr, len + 1)) || (str[len]))) |
260 | ret=sysinfo_get_val(str,NULL); |
283 | ret = sysinfo_get_val(str, NULL); |
- | 284 | ||
261 | free(str); |
285 | free(str); |
262 | return ret.valid; |
286 | return ret.valid; |
263 | } |
287 | } |
264 | 288 | ||
265 | __native sys_sysinfo_value(__native ptr,__native len) |
289 | __native sys_sysinfo_value(__native ptr, __native len) |
266 | { |
290 | { |
267 | char *str; |
291 | char *str; |
268 | sysinfo_rettype_t ret={0,0}; |
292 | sysinfo_rettype_t ret = {0, 0}; |
269 | str=malloc(len+1,0); |
293 | str = malloc(len + 1, 0); |
- | 294 | ||
270 | ASSERT(str); |
295 | ASSERT(str); |
271 | if(!((copy_from_uspace(str,(void *)ptr,len+1))||(str[len]))) |
296 | if (!((copy_from_uspace(str, (void *) ptr, len + 1)) || (str[len]))) |
272 | ret=sysinfo_get_val(str,NULL); |
297 | ret = sysinfo_get_val(str, NULL); |
- | 298 | ||
273 | free(str); |
299 | free(str); |
274 | return ret.val; |
300 | return ret.val; |
275 | } |
301 | } |
276 | - | ||
277 | - |