Changeset 749122b in mainline
- Timestamp:
- 2006-05-14T14:40:59Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b1b723e
- Parents:
- e9a9469
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/src/sysinfo/sysinfo.c
re9a9469 r749122b 32 32 #include <syscall/copy.h> 33 33 34 sysinfo_item_t *_root=NULL; 35 36 37 static sysinfo_item_t* sysinfo_find_item(const char *name,sysinfo_item_t *subtree) 38 { 39 if(subtree==NULL) return NULL; 40 while(subtree!=NULL) 41 { 42 int i; 43 char *a,*b; 44 a=(char *)name; 45 b=subtree->name; 46 while((a[i]==b[i])&&(b[i])) i++; 47 if((!a[i]) && (!b[i])) return subtree; /*Last name in path matches*/ 48 if((a[i]=='.') && (!b[i])) /*Middle name in path matches*/ 49 { 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*/ 52 return NULL; /*No subinfo*/ 34 sysinfo_item_t *_root = NULL; 35 36 37 static sysinfo_item_t *sysinfo_find_item(const char *name, sysinfo_item_t *subtree) 38 { 39 if (subtree == NULL) 40 return NULL; 41 42 while (subtree != NULL) { 43 int i = 0; 44 char *a = (char *) name; 45 char *b = subtree->name; 46 47 while ((a[i] == b[i]) && (b[i])) 48 i++; 49 50 if ((!a[i]) && (!b[i])) /* Last name in path matches */ 51 return subtree; 52 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); 56 57 //if (subtree->subinfo_type == SYSINFO_SUBINFO_FUNCTION) /* Subinfo managed by subsystem */ 58 // return NULL; 59 60 return NULL; /* No subinfo */ 53 61 } 54 /* No matches try next */55 subtree =subtree->next;56 i =0;62 /* No matches try next */ 63 subtree = subtree->next; 64 i = 0; 57 65 } 58 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 71 sysinfo_item_t *subtree; 64 72 subtree = *psubtree; 65 73 66 if(subtree==NULL) 67 { 68 sysinfo_item_t *item; 69 int i=0,j; 70 71 item = malloc(sizeof(sysinfo_item_t),0); 74 if (subtree == NULL) { 75 sysinfo_item_t *item = malloc(sizeof(sysinfo_item_t), 0); 76 int i = 0, j; 77 72 78 ASSERT(item); 73 79 *psubtree = item; 74 item -> next = NULL; 75 item -> val_type = SYSINFO_VAL_UNDEFINED; 76 item -> subinfo.table = NULL; 77 78 while(name[i]&&(name[i]!='.')) i++; 79 80 item -> name = malloc(i,0); 81 ASSERT(item -> name); 82 83 for(j=0;j<i;j++) item->name[j]=name[j]; 84 item->name[j]=0; 85 86 if(name[i]/*=='.'*/) 87 { 88 item -> subinfo_type = SYSINFO_SUBINFO_TABLE; 89 return sysinfo_create_path(name+i+1,&(item->subinfo.table)); 80 item->next = NULL; 81 item->val_type = SYSINFO_VAL_UNDEFINED; 82 item->subinfo.table = NULL; 83 84 while (name[i] && (name[i] != '.')) 85 i++; 86 87 item->name = malloc(i, 0); 88 ASSERT(item->name); 89 90 for (j = 0; j < i; j++) 91 item->name[j] = name[j]; 92 item->name[j] = 0; 93 94 if (name[i]) { /* =='.' */ 95 item->subinfo_type = SYSINFO_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 99 return item; 93 100 } 94 101 95 while(subtree!=NULL) 96 { 97 int i=0,j; 98 char *a,*b; 99 a=(char *)name; 100 b=subtree->name; 101 while((a[i]==b[i])&&(b[i])) i++; 102 if((!a[i]) && (!b[i])) return subtree; /*Last name in path matches*/ 103 if((a[i]=='.') && (!b[i])) /*Middle name in path matches*/ 104 { 105 if(subtree->subinfo_type==SYSINFO_SUBINFO_TABLE) return sysinfo_create_path(a+i+1,&(subtree->subinfo.table)); 106 if(subtree->subinfo_type==SYSINFO_SUBINFO_NONE) 107 { 108 subtree->subinfo_type=SYSINFO_SUBINFO_TABLE; 109 return sysinfo_create_path(a+i+1,&(subtree->subinfo.table)); 110 } 111 //if(subtree->subinfo_type==SYSINFO_SUBINFO_FUNCTION) return NULL; /* Subinfo managed by subsystem*/ 102 while (subtree != NULL) { 103 int i = 0, j; 104 char *a = (char *) name; 105 char *b = subtree->name; 106 107 while ((a[i] == b[i]) && (b[i])) 108 i++; 109 110 if ((!a[i]) && (!b[i])) /* Last name in path matches */ 111 return subtree; 112 113 if ((a[i] == '.') && (!b[i])) { /* Middle name in path matches */ 114 if (subtree->subinfo_type == SYSINFO_SUBINFO_TABLE) 115 return sysinfo_create_path(a + i + 1, &(subtree->subinfo.table)); 116 117 if (subtree->subinfo_type == SYSINFO_SUBINFO_NONE) { 118 subtree->subinfo_type = SYSINFO_SUBINFO_TABLE; 119 return sysinfo_create_path(a + i + 1,&(subtree->subinfo.table)); 120 } 121 122 //if (subtree->subinfo_type == SYSINFO_SUBINFO_FUNCTION) /* Subinfo managed by subsystem */ 123 // return NULL; 124 112 125 return NULL; 113 126 } 114 127 /* No matches try next or create new*/ 115 if(subtree->next==NULL) 116 { 117 sysinfo_item_t *item; 118 119 item = malloc(sizeof(sysinfo_item_t),0); 128 if (subtree->next == NULL) { 129 sysinfo_item_t *item = malloc(sizeof(sysinfo_item_t), 0); 130 120 131 ASSERT(item); 121 subtree -> next = item; 122 item -> next = NULL; 123 item -> val_type = SYSINFO_VAL_UNDEFINED; 124 item -> subinfo.table = NULL; 125 126 i=0; 127 while(name[i]&&(name[i]!='.')) i++; 128 129 item -> name = malloc(i,0); 130 ASSERT(item -> name); 131 for(j=0;j<i;j++) item->name[j]=name[j]; 132 item->name[j]=0; 133 134 if(name[i]/*=='.'*/) 135 { 136 item -> subinfo_type = SYSINFO_SUBINFO_TABLE; 137 return sysinfo_create_path(name+i+1,&(item->subinfo.table)); 132 subtree->next = item; 133 item->next = NULL; 134 item->val_type = SYSINFO_VAL_UNDEFINED; 135 item->subinfo.table = NULL; 136 137 i = 0; 138 while (name[i] && (name[i] != '.')) 139 i++; 140 141 item->name = malloc(i, 0); 142 ASSERT(item->name); 143 144 for (j = 0; j < i; j++) 145 item->name[j] = name[j]; 146 147 item->name[j] = 0; 148 149 if(name[i]) { /* =='.' */ 150 item->subinfo_type = SYSINFO_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 154 return item; 141 142 } 143 else 144 { 145 subtree=subtree->next; 146 i=0; 155 } else { 156 subtree = subtree->next; 157 i = 0; 147 158 } 148 159 } … … 151 162 } 152 163 153 void sysinfo_set_item_val(const char *name,sysinfo_item_t **root,__native val) 154 { 155 if(root==NULL) root=&_root; 156 sysinfo_item_t *item; 157 item = sysinfo_create_path(name,root); /* If already created create only returns pointer 158 If ! , create it */ 159 if(item!=NULL) /* If in subsystem, unable to create or return so unable to set */ 160 { 164 void sysinfo_set_item_val(const char *name, sysinfo_item_t **root, __native val) 165 { 166 if (root == NULL) 167 root = &_root; 168 169 /* If already created create only returns pointer 170 If not, create it */ 171 sysinfo_item_t *item = sysinfo_create_path(name, root); 172 173 if (item != NULL) { /* If in subsystem, unable to create or return so unable to set */ 161 174 item->val.val=val; 162 item -> val_type = SYSINFO_VAL_VAL; 163 } 164 } 165 166 void sysinfo_set_item_function(const char *name,sysinfo_item_t **root,sysinfo_val_fn_t fn) 167 { 168 if(root==NULL) root=&_root; 169 sysinfo_item_t *item; 170 item = sysinfo_create_path(name,root); /* If already created create only returns pointer 171 If ! , create it */ 172 if(item!=NULL) /* If in subsystem, unable to create or return so unable to set */ 173 { 175 item->val_type = SYSINFO_VAL_VAL; 176 } 177 } 178 179 void sysinfo_set_item_function(const char *name, sysinfo_item_t **root, sysinfo_val_fn_t fn) 180 { 181 if (root == NULL) 182 root = &_root; 183 184 /* If already created create only returns pointer 185 If not, create it */ 186 sysinfo_item_t *item = sysinfo_create_path(name, root); 187 188 if (item != NULL) { /* If in subsystem, unable to create or return so unable to set */ 174 189 item->val.fn=fn; 175 item -> val_type = SYSINFO_VAL_FUNCTION; 176 } 177 } 178 179 180 void sysinfo_set_item_undefined(const char *name,sysinfo_item_t **root) 181 { 182 if(root==NULL) root=&_root; 183 sysinfo_item_t *item; 184 item = sysinfo_find_item(name,*root); 185 if(item!=NULL) item -> val_type = SYSINFO_VAL_UNDEFINED; 186 } 187 188 189 void sysinfo_dump(sysinfo_item_t **proot,int depth) 190 item->val_type = SYSINFO_VAL_FUNCTION; 191 } 192 } 193 194 195 void sysinfo_set_item_undefined(const char *name, sysinfo_item_t **root) 196 { 197 if (root == NULL) 198 root = &_root; 199 200 /* If already created create only returns pointer 201 If not, create it */ 202 sysinfo_item_t *item = sysinfo_create_path(name, root); 203 204 if (item != NULL) 205 item->val_type = SYSINFO_VAL_UNDEFINED; 206 } 207 208 209 void sysinfo_dump(sysinfo_item_t **proot, int depth) 190 210 { 191 211 sysinfo_item_t *root; 192 if(proot==NULL) proot=&_root; 212 if (proot == NULL) 213 proot = &_root; 214 193 215 root = *proot; 194 216 195 while(root!=NULL) 196 { 197 217 while (root != NULL) { 198 218 int i; 199 __native val=0; 200 char *vtype=NULL; 201 202 203 for(i=0;i<depth;i++) printf(" "); 204 205 switch (root->val_type) 206 { 207 case (SYSINFO_VAL_UNDEFINED): 208 val=0; 209 vtype="UND"; 210 break; 211 case (SYSINFO_VAL_VAL): 212 val=root->val.val; 213 vtype="VAL"; 214 break; 215 case (SYSINFO_VAL_FUNCTION): 216 val=((sysinfo_val_fn_t)(root->val.fn))(root); 217 vtype="FUN"; 218 break; 219 } 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 223 224 if(root -> subinfo_type == SYSINFO_SUBINFO_TABLE) 225 sysinfo_dump(&(root->subinfo.table),depth+1); 226 root=root->next; 227 } 228 } 229 230 sysinfo_rettype_t sysinfo_get_val(const char *name,sysinfo_item_t **root) 231 { 232 /*TODO: 233 Implement Subsystem subinfo (by function implemented subinfo) 234 */ 235 236 sysinfo_rettype_t ret={0,false}; 237 238 if(root==NULL) root=&_root; 239 sysinfo_item_t *item; 240 item = sysinfo_find_item(name,*root); 241 if(item!=NULL) 242 { 243 if (item -> val_type == SYSINFO_VAL_UNDEFINED) 219 __native val = 0; 220 char *vtype = NULL; 221 222 223 for (i = 0; i < depth; i++) 224 printf(" "); 225 226 switch (root->val_type) { 227 case SYSINFO_VAL_UNDEFINED: 228 val = 0; 229 vtype = "UND"; 230 break; 231 case SYSINFO_VAL_VAL: 232 val = root->val.val; 233 vtype = "VAL"; 234 break; 235 case SYSINFO_VAL_FUNCTION: 236 val = ((sysinfo_val_fn_t) (root->val.fn)) (root); 237 vtype = "FUN"; 238 break; 239 } 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")); 242 243 if (root->subinfo_type == SYSINFO_SUBINFO_TABLE) 244 sysinfo_dump(&(root -> subinfo.table), depth + 1); 245 246 root = root->next; 247 } 248 } 249 250 sysinfo_rettype_t sysinfo_get_val(const char *name, sysinfo_item_t **root) 251 { 252 // TODO: Implement Subsystem subinfo (by function implemented subinfo) 253 254 sysinfo_rettype_t ret = {0, false}; 255 256 if (root == NULL) 257 root = &_root; 258 259 sysinfo_item_t *item = sysinfo_find_item(name, *root); 260 261 if (item != NULL) { 262 if (item->val_type == SYSINFO_VAL_UNDEFINED) 244 263 return ret; 245 else ret.valid=true; 246 if (item -> val_type == SYSINFO_VAL_VAL) 247 ret.val=item -> val.val; 248 else ret.val=((sysinfo_val_fn_t)(item->val.fn))(item); 264 else 265 ret.valid = true; 266 267 if (item->val_type == SYSINFO_VAL_VAL) 268 ret.val = item->val.val; 269 else 270 ret.val = ((sysinfo_val_fn_t) (item->val.fn)) (item); 249 271 } 250 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 277 char *str; 256 sysinfo_rettype_t ret={0,0}; 257 str=malloc(len+1,0); 278 sysinfo_rettype_t ret = {0, 0}; 279 str = malloc(len + 1, 0); 280 258 281 ASSERT(str); 259 if(!((copy_from_uspace(str,(void *)ptr,len+1))||(str[len]))) 260 ret=sysinfo_get_val(str,NULL); 282 if (!((copy_from_uspace(str, (void *) ptr, len + 1)) || (str[len]))) 283 ret = sysinfo_get_val(str, NULL); 284 261 285 free(str); 262 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 291 char *str; 268 sysinfo_rettype_t ret={0,0}; 269 str=malloc(len+1,0); 292 sysinfo_rettype_t ret = {0, 0}; 293 str = malloc(len + 1, 0); 294 270 295 ASSERT(str); 271 if(!((copy_from_uspace(str,(void *)ptr,len+1))||(str[len]))) 272 ret=sysinfo_get_val(str,NULL); 296 if (!((copy_from_uspace(str, (void *) ptr, len + 1)) || (str[len]))) 297 ret = sysinfo_get_val(str, NULL); 298 273 299 free(str); 274 300 return ret.val; 275 301 } 276 277
Note:
See TracChangeset
for help on using the changeset viewer.