Changeset 8565a42 in mainline for kernel/generic/src/sysinfo/sysinfo.c
- Timestamp:
- 2018-03-02T20:34:50Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a1a81f69, d5e5fd1
- Parents:
- 3061bc1 (diff), 34e1206 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:34:50)
- git-committer:
- GitHub <noreply@…> (2018-03-02 20:34:50)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/sysinfo/sysinfo.c
r3061bc1 r8565a42 64 64 { 65 65 sysinfo_item_t *item = (sysinfo_item_t *) obj; 66 66 67 67 item->name = NULL; 68 68 item->val_type = SYSINFO_VAL_UNDEFINED; … … 70 70 item->subtree.table = NULL; 71 71 item->next = NULL; 72 72 73 73 return EOK; 74 74 } … … 84 84 { 85 85 sysinfo_item_t *item = (sysinfo_item_t *) obj; 86 86 87 87 if (item->name != NULL) 88 88 free(item->name); 89 89 90 90 return 0; 91 91 } … … 101 101 sizeof(sysinfo_item_t), 0, sysinfo_item_constructor, 102 102 sysinfo_item_destructor, SLAB_CACHE_MAGDEFERRED); 103 103 104 104 mutex_initialize(&sysinfo_lock, MUTEX_ACTIVE); 105 105 } … … 127 127 { 128 128 assert(subtree != NULL); 129 129 130 130 sysinfo_item_t *cur = subtree; 131 131 132 132 /* Walk all siblings */ 133 133 while (cur != NULL) { 134 134 size_t i = 0; 135 135 136 136 /* Compare name with path */ 137 137 while ((cur->name[i] != 0) && (name[i] == cur->name[i])) 138 138 i++; 139 139 140 140 /* Check for perfect name and path match */ 141 141 if ((name[i] == 0) && (cur->name[i] == 0)) 142 142 return cur; 143 143 144 144 /* Partial match up to the delimiter */ 145 145 if ((name[i] == '.') && (cur->name[i] == 0)) { … … 155 155 **ret = cur->subtree.generator.fn(name + i + 1, 156 156 dry_run, cur->subtree.generator.data); 157 157 158 158 return NULL; 159 159 default: … … 161 161 if (ret != NULL) 162 162 *ret = NULL; 163 163 164 164 return NULL; 165 165 } 166 166 } 167 167 168 168 cur = cur->next; 169 169 } 170 170 171 171 /* Not found, no data generated */ 172 172 if (ret != NULL) 173 173 *ret = NULL; 174 174 175 175 return NULL; 176 176 } … … 193 193 { 194 194 assert(psubtree != NULL); 195 195 196 196 if (*psubtree == NULL) { 197 197 /* No parent */ 198 198 199 199 size_t i = 0; 200 200 201 201 /* Find the first delimiter in name */ 202 202 while ((name[i] != 0) && (name[i] != '.')) 203 203 i++; 204 204 205 205 *psubtree = 206 206 (sysinfo_item_t *) slab_alloc(sysinfo_item_cache, 0); 207 207 assert(*psubtree); 208 208 209 209 /* Fill in item name up to the delimiter */ 210 210 (*psubtree)->name = str_ndup(name, i); 211 211 assert((*psubtree)->name); 212 212 213 213 /* Create subtree items */ 214 214 if (name[i] == '.') { … … 217 217 &((*psubtree)->subtree.table)); 218 218 } 219 219 220 220 /* No subtree needs to be created */ 221 221 return *psubtree; 222 222 } 223 223 224 224 sysinfo_item_t *cur = *psubtree; 225 225 226 226 /* Walk all siblings */ 227 227 while (cur != NULL) { 228 228 size_t i = 0; 229 229 230 230 /* Compare name with path */ 231 231 while ((cur->name[i] != 0) && (name[i] == cur->name[i])) 232 232 i++; 233 233 234 234 /* Check for perfect name and path match 235 235 * -> item is already present. … … 237 237 if ((name[i] == 0) && (cur->name[i] == 0)) 238 238 return cur; 239 239 240 240 /* Partial match up to the delimiter */ 241 241 if ((name[i] == '.') && (cur->name[i] == 0)) { … … 257 257 } 258 258 } 259 259 260 260 /* No match and no more siblings to check 261 261 * -> create a new sibling item. … … 266 266 while ((name[i] != 0) && (name[i] != '.')) 267 267 i++; 268 268 269 269 sysinfo_item_t *item = 270 270 (sysinfo_item_t *) slab_alloc(sysinfo_item_cache, 0); 271 271 assert(item); 272 272 273 273 cur->next = item; 274 274 275 275 /* Fill in item name up to the delimiter */ 276 276 item->name = str_ndup(name, i); 277 277 assert(item->name); 278 278 279 279 /* Create subtree items */ 280 280 if (name[i] == '.') { … … 283 283 &(item->subtree.table)); 284 284 } 285 285 286 286 /* No subtree needs to be created */ 287 287 return item; 288 288 } 289 289 290 290 cur = cur->next; 291 291 } 292 292 293 293 /* Unreachable */ 294 294 assert(false); … … 309 309 /* Protect sysinfo tree consistency */ 310 310 mutex_lock(&sysinfo_lock); 311 311 312 312 if (root == NULL) 313 313 root = &global_root; 314 314 315 315 sysinfo_item_t *item = sysinfo_create_path(name, root); 316 316 if (item != NULL) { … … 318 318 item->val.val = val; 319 319 } 320 320 321 321 mutex_unlock(&sysinfo_lock); 322 322 } … … 340 340 /* Protect sysinfo tree consistency */ 341 341 mutex_lock(&sysinfo_lock); 342 342 343 343 if (root == NULL) 344 344 root = &global_root; 345 345 346 346 sysinfo_item_t *item = sysinfo_create_path(name, root); 347 347 if (item != NULL) { … … 350 350 item->val.data.size = size; 351 351 } 352 352 353 353 mutex_unlock(&sysinfo_lock); 354 354 } … … 368 368 /* Protect sysinfo tree consistency */ 369 369 mutex_lock(&sysinfo_lock); 370 370 371 371 if (root == NULL) 372 372 root = &global_root; 373 373 374 374 sysinfo_item_t *item = sysinfo_create_path(name, root); 375 375 if (item != NULL) { … … 378 378 item->val.gen_val.data = data; 379 379 } 380 380 381 381 mutex_unlock(&sysinfo_lock); 382 382 } … … 401 401 /* Protect sysinfo tree consistency */ 402 402 mutex_lock(&sysinfo_lock); 403 403 404 404 if (root == NULL) 405 405 root = &global_root; 406 406 407 407 sysinfo_item_t *item = sysinfo_create_path(name, root); 408 408 if (item != NULL) { … … 411 411 item->val.gen_data.data = data; 412 412 } 413 413 414 414 mutex_unlock(&sysinfo_lock); 415 415 } … … 426 426 /* Protect sysinfo tree consistency */ 427 427 mutex_lock(&sysinfo_lock); 428 428 429 429 if (root == NULL) 430 430 root = &global_root; 431 431 432 432 sysinfo_item_t *item = sysinfo_create_path(name, root); 433 433 if (item != NULL) 434 434 item->val_type = SYSINFO_VAL_UNDEFINED; 435 435 436 436 mutex_unlock(&sysinfo_lock); 437 437 } … … 451 451 /* Protect sysinfo tree consistency */ 452 452 mutex_lock(&sysinfo_lock); 453 453 454 454 if (root == NULL) 455 455 root = &global_root; 456 456 457 457 sysinfo_item_t *item = sysinfo_create_path(name, root); 458 458 459 459 /* Change the type of the subtree only if it is not already 460 460 a fixed subtree */ … … 464 464 item->subtree.generator.data = data; 465 465 } 466 466 467 467 mutex_unlock(&sysinfo_lock); 468 468 } … … 492 492 for (sysinfo_item_t *cur = root; cur; cur = cur->next) { 493 493 size_t length; 494 494 495 495 if (spaces == 0) { 496 496 printf("%s", cur->name); … … 501 501 length = str_length(cur->name) + 1; 502 502 } 503 503 504 504 sysarg_t val; 505 505 size_t size; 506 506 507 507 /* Display node value and type */ 508 508 switch (cur->val_type) { … … 531 531 printf("+ %s [unknown]\n", cur->name); 532 532 } 533 533 534 534 /* Recursivelly nest into the subtree */ 535 535 switch (cur->subtree_type) { … … 562 562 while we are dumping it */ 563 563 mutex_lock(&sysinfo_lock); 564 564 565 565 if (root == NULL) 566 566 sysinfo_dump_internal(global_root, 0); 567 567 else 568 568 sysinfo_dump_internal(root, 0); 569 569 570 570 mutex_unlock(&sysinfo_lock); 571 571 } … … 590 590 if (root == NULL) 591 591 root = &global_root; 592 592 593 593 /* Try to find the item or generate data */ 594 594 sysinfo_return_t ret; … … 596 596 sysinfo_item_t *item = sysinfo_find_item(name, *root, &ret_ptr, 597 597 dry_run); 598 598 599 599 if (item != NULL) { 600 600 /* Item found in the fixed sysinfo tree */ 601 601 602 602 ret.tag = item->val_type; 603 603 switch (item->val_type) { … … 625 625 } 626 626 } 627 627 628 628 return ret; 629 629 } … … 645 645 sysinfo_return_t ret; 646 646 ret.tag = SYSINFO_VAL_UNDEFINED; 647 647 648 648 if (size > SYSINFO_MAX_PATH) 649 649 return ret; 650 650 651 651 char *path = (char *) malloc(size + 1, 0); 652 652 assert(path); 653 653 654 654 if ((copy_from_uspace(path, ptr, size + 1) == 0) && 655 655 (path[size] == 0)) { … … 662 662 mutex_unlock(&sysinfo_lock); 663 663 } 664 664 665 665 free(path); 666 666 return ret; … … 686 686 if (root == NULL) 687 687 root = &global_root; 688 688 689 689 sysinfo_item_t *subtree = NULL; 690 690 691 691 if (name[0] != 0) { 692 692 /* Try to find the item */ … … 698 698 } else 699 699 subtree = *root; 700 700 701 701 sysinfo_return_t ret; 702 702 ret.tag = SYSINFO_VAL_UNDEFINED; 703 703 704 704 if (subtree != NULL) { 705 705 /* … … 709 709 for (sysinfo_item_t *cur = subtree; cur; cur = cur->next) 710 710 size += str_size(cur->name) + 1; 711 711 712 712 if (dry_run) { 713 713 ret.tag = SYSINFO_VAL_DATA; … … 719 719 if (names == NULL) 720 720 return ret; 721 721 722 722 size_t pos = 0; 723 723 for (sysinfo_item_t *cur = subtree; cur; cur = cur->next) { … … 725 725 pos += str_size(cur->name) + 1; 726 726 } 727 727 728 728 /* Correct return value */ 729 729 ret.tag = SYSINFO_VAL_DATA; … … 732 732 } 733 733 } 734 734 735 735 return ret; 736 736 } … … 754 754 ret.data.data = NULL; 755 755 ret.data.size = 0; 756 756 757 757 if (size > SYSINFO_MAX_PATH) 758 758 return ret; 759 759 760 760 char *path = (char *) malloc(size + 1, 0); 761 761 assert(path); 762 762 763 763 if ((copy_from_uspace(path, ptr, size + 1) == 0) && 764 764 (path[size] == 0)) { … … 771 771 mutex_unlock(&sysinfo_lock); 772 772 } 773 773 774 774 free(path); 775 775 return ret; … … 794 794 { 795 795 errno_t rc; 796 796 797 797 /* 798 798 * Get the keys. … … 803 803 sysinfo_return_t ret = 804 804 sysinfo_get_keys_uspace(path_ptr, path_size, true); 805 805 806 806 /* Check return data tag */ 807 807 if (ret.tag == SYSINFO_VAL_DATA) … … 810 810 else 811 811 rc = EINVAL; 812 812 813 813 return (sys_errno_t) rc; 814 814 } … … 842 842 { 843 843 errno_t rc; 844 844 845 845 /* Get the keys */ 846 846 sysinfo_return_t ret = sysinfo_get_keys_uspace(path_ptr, path_size, 847 847 false); 848 848 849 849 /* Check return data tag */ 850 850 if (ret.tag == SYSINFO_VAL_DATA) { … … 853 853 if (rc == EOK) 854 854 rc = copy_to_uspace(size_ptr, &size, sizeof(size)); 855 855 856 856 free(ret.data.data); 857 857 } else 858 858 rc = EINVAL; 859 859 860 860 return (sys_errno_t) rc; 861 861 } … … 882 882 */ 883 883 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true); 884 884 885 885 /* 886 886 * Map generated value types to constant types (user space does … … 891 891 else if (ret.tag == SYSINFO_VAL_FUNCTION_DATA) 892 892 ret.tag = SYSINFO_VAL_DATA; 893 893 894 894 return (sysarg_t) ret.tag; 895 895 } … … 913 913 { 914 914 errno_t rc; 915 915 916 916 /* 917 917 * Get the item. … … 921 921 */ 922 922 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true); 923 923 924 924 /* Only constant or generated numerical value is returned */ 925 925 if ((ret.tag == SYSINFO_VAL_VAL) || (ret.tag == SYSINFO_VAL_FUNCTION_VAL)) … … 927 927 else 928 928 rc = EINVAL; 929 929 930 930 return (sys_errno_t) rc; 931 931 } … … 949 949 { 950 950 errno_t rc; 951 951 952 952 /* 953 953 * Get the item. … … 957 957 */ 958 958 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true); 959 959 960 960 /* Only the size of constant or generated binary data is considered */ 961 961 if ((ret.tag == SYSINFO_VAL_DATA) || (ret.tag == SYSINFO_VAL_FUNCTION_DATA)) … … 964 964 else 965 965 rc = EINVAL; 966 966 967 967 return (sys_errno_t) rc; 968 968 } … … 999 999 { 1000 1000 errno_t rc; 1001 1001 1002 1002 /* Get the item */ 1003 1003 sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, 1004 1004 false); 1005 1005 1006 1006 /* Only constant or generated binary data is considered */ 1007 1007 if ((ret.tag == SYSINFO_VAL_DATA) || … … 1013 1013 } else 1014 1014 rc = EINVAL; 1015 1015 1016 1016 /* N.B.: The generated binary data should be freed */ 1017 1017 if ((ret.tag == SYSINFO_VAL_FUNCTION_DATA) && (ret.data.data != NULL)) 1018 1018 free(ret.data.data); 1019 1019 1020 1020 return (sys_errno_t) rc; 1021 1021 }
Note:
See TracChangeset
for help on using the changeset viewer.