Changeset 76f382b in mainline
- Timestamp:
- 2012-03-02T14:50:42Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8b9a443
- Parents:
- 560d79f
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/sysinfo/sysinfo.c
r560d79f r76f382b 678 678 root = &global_root; 679 679 680 /* Try to find the item */ 681 sysinfo_item_t *item = sysinfo_find_item(name, *root, NULL, 682 dry_run); 680 sysinfo_item_t *subtree = NULL; 681 682 if (name[0] != 0) { 683 /* Try to find the item */ 684 sysinfo_item_t *item = 685 sysinfo_find_item(name, *root, NULL, dry_run); 686 if ((item != NULL) && 687 (item->subtree_type == SYSINFO_SUBTREE_TABLE)) 688 subtree = item->subtree.table; 689 } else 690 subtree = *root; 683 691 684 692 sysinfo_return_t ret; 685 693 686 if ( (item != NULL) && (item->subtree_type == SYSINFO_SUBTREE_TABLE)) {694 if (subtree != NULL) { 687 695 /* 688 * Subtree found in the fixed sysinfo tree.689 696 * Calculate the size of subkeys. 690 697 */ 691 698 size_t size = 0; 692 for (sysinfo_item_t *cur = item->subtree.table; cur; 693 cur = cur->next) 699 for (sysinfo_item_t *cur = subtree; cur; cur = cur->next) 694 700 size += str_size(cur->name) + 1; 695 701 696 702 if (dry_run) { 697 ret.tag = SYSINFO_VAL_ FUNCTION_DATA;703 ret.tag = SYSINFO_VAL_DATA; 698 704 ret.data.data = NULL; 699 705 ret.data.size = size; … … 705 711 706 712 size_t pos = 0; 707 for (sysinfo_item_t *cur = item->subtree.table; cur; 708 cur = cur->next) { 713 for (sysinfo_item_t *cur = subtree; cur; cur = cur->next) { 709 714 str_cpy(names + pos, size - pos, cur->name); 710 715 pos += str_size(cur->name) + 1; … … 712 717 713 718 /* Correct return value */ 714 ret.tag = SYSINFO_VAL_ FUNCTION_DATA;719 ret.tag = SYSINFO_VAL_DATA; 715 720 ret.data.data = (void *) names; 716 721 ret.data.size = size; -
uspace/app/sysinfo/sysinfo.c
r560d79f r76f382b 37 37 #include <stdio.h> 38 38 #include <sysinfo.h> 39 #include <malloc.h> 39 40 #include <sys/types.h> 40 41 41 static int print_item_val(char *ipath); 42 static int print_item_data(char *ipath); 42 static void dump_bytes_hex(char *data, size_t size) 43 { 44 for (size_t i = 0; i < size; i++) { 45 if (i > 0) 46 putchar(' '); 47 printf("0x%02x", (uint8_t) data[i]); 48 } 49 } 43 50 44 static void dump_bytes_hex(char *data, size_t size); 45 static void dump_bytes_text(char *data, size_t size); 51 static void dump_bytes_text(char *data, size_t size) 52 { 53 size_t offset = 0; 54 55 while (offset < size) { 56 wchar_t c = str_decode(data, &offset, size); 57 printf("%lc", (wint_t) c); 58 } 59 } 46 60 47 static void print_syntax(void); 61 static int print_item_val(char *ipath) 62 { 63 sysarg_t value; 64 int rc = sysinfo_get_value(ipath, &value); 65 if (rc != EOK) { 66 printf("Error reading item '%s'.\n", ipath); 67 return rc; 68 } 69 70 printf("%s -> %" PRIu64 " (0x%" PRIx64 ")\n", ipath, 71 (uint64_t) value, (uint64_t) value); 72 73 return EOK; 74 } 75 76 static int print_item_data(char *ipath) 77 { 78 size_t size; 79 void *data = sysinfo_get_data(ipath, &size); 80 if (data == NULL) { 81 printf("Error reading item '%s'.\n", ipath); 82 return -1; 83 } 84 85 printf("%s -> ", ipath); 86 dump_bytes_hex(data, size); 87 fputs(" ('", stdout); 88 dump_bytes_text(data, size); 89 fputs("')\n", stdout); 90 91 return EOK; 92 } 93 94 static void print_keys(const char *path) 95 { 96 size_t size; 97 char *keys = sysinfo_get_keys(path, &size); 98 if ((keys == NULL) || (size == 0)) 99 return; 100 101 size_t pos = 0; 102 while (pos < size) { 103 /* Process each key with sanity checks */ 104 size_t cur_size = str_nsize(keys + pos, size - pos); 105 size_t path_size = str_size(path) + cur_size + 2; 106 char *cur_path = (char *) malloc(path_size); 107 if (cur_path == NULL) 108 break; 109 110 if (path[0] != 0) 111 snprintf(cur_path, path_size, "%s.%s", path, keys + pos); 112 else 113 snprintf(cur_path, path_size, "%s", keys + pos); 114 115 printf("%s\n", cur_path); 116 print_keys(cur_path); 117 118 free(cur_path); 119 pos += cur_size + 1; 120 } 121 122 free(keys); 123 } 48 124 49 125 int main(int argc, char *argv[]) 50 126 { 51 int rc;52 char *ipath;53 sysinfo_item_val_type_t tag;54 55 127 if (argc != 2) { 56 print_syntax(); 57 return 1; 128 /* Print keys */ 129 print_keys(""); 130 return 0; 58 131 } 59 60 ipath = argv[1]; 61 62 tag = sysinfo_get_val_type(ipath); 63 132 133 char *ipath = argv[1]; 134 sysinfo_item_val_type_t tag = sysinfo_get_val_type(ipath); 135 64 136 /* Silence warning */ 65 rc = EOK;66 137 int rc = 0; 138 67 139 switch (tag) { 68 140 case SYSINFO_VAL_UNDEFINED: … … 82 154 break; 83 155 } 84 156 85 157 return rc; 86 }87 88 static int print_item_val(char *ipath)89 {90 sysarg_t value;91 int rc;92 93 rc = sysinfo_get_value(ipath, &value);94 if (rc != EOK) {95 printf("Error reading item '%s'.\n", ipath);96 return rc;97 }98 99 printf("%s -> %" PRIu64 " (0x%" PRIx64 ")\n", ipath,100 (uint64_t) value, (uint64_t) value);101 102 return EOK;103 }104 105 static int print_item_data(char *ipath)106 {107 void *data;108 size_t size;109 110 data = sysinfo_get_data(ipath, &size);111 if (data == NULL) {112 printf("Error reading item '%s'.\n", ipath);113 return -1;114 }115 116 printf("%s -> ", ipath);117 dump_bytes_hex(data, size);118 fputs(" ('", stdout);119 dump_bytes_text(data, size);120 fputs("')\n", stdout);121 122 return EOK;123 }124 125 static void dump_bytes_hex(char *data, size_t size)126 {127 size_t i;128 129 for (i = 0; i < size; ++i) {130 if (i > 0) putchar(' ');131 printf("0x%02x", (uint8_t) data[i]);132 }133 }134 135 static void dump_bytes_text(char *data, size_t size)136 {137 wchar_t c;138 size_t offset;139 140 offset = 0;141 142 while (offset < size) {143 c = str_decode(data, &offset, size);144 printf("%lc", (wint_t) c);145 }146 }147 148 149 static void print_syntax(void)150 {151 printf("Syntax: sysinfo <item_path>\n");152 158 } 153 159 -
uspace/lib/c/generic/sysinfo.c
r560d79f r76f382b 40 40 #include <bool.h> 41 41 42 /** Get sysinfo keys size 43 * 44 * @param path Sysinfo path. 45 * @param value Pointer to store the keys size. 46 * 47 * @return EOK if the keys were successfully read. 48 * 49 */ 50 static int sysinfo_get_keys_size(const char *path, size_t *size) 51 { 52 return (int) __SYSCALL3(SYS_SYSINFO_GET_KEYS_SIZE, (sysarg_t) path, 53 (sysarg_t) str_size(path), (sysarg_t) size); 54 } 55 56 /** Get sysinfo keys 57 * 58 * @param path Sysinfo path. 59 * @param value Pointer to store the keys size. 60 * 61 * @return Keys read from sysinfo or NULL if the 62 * sysinfo item has no subkeys. 63 * The returned non-NULL pointer should be 64 * freed by free(). 65 * 66 */ 67 char *sysinfo_get_keys(const char *path, size_t *size) 68 { 69 /* 70 * The size of the keys might change during time. 71 * Unfortunatelly we cannot allocate the buffer 72 * and transfer the keys as a single atomic operation. 73 */ 74 75 /* Get the keys size */ 76 int ret = sysinfo_get_keys_size(path, size); 77 if ((ret != EOK) || (size == 0)) { 78 /* 79 * Item with no subkeys. 80 */ 81 *size = 0; 82 return NULL; 83 } 84 85 char *data = malloc(*size); 86 if (data == NULL) { 87 *size = 0; 88 return NULL; 89 } 90 91 /* Get the data */ 92 size_t sz; 93 ret = __SYSCALL5(SYS_SYSINFO_GET_KEYS, (sysarg_t) path, 94 (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size, 95 (sysarg_t) &sz); 96 if (ret == EOK) { 97 *size = sz; 98 return data; 99 } 100 101 free(data); 102 *size = 0; 103 return NULL; 104 } 105 42 106 /** Get sysinfo item type 43 107 * -
uspace/lib/c/include/sysinfo.h
r560d79f r76f382b 40 40 #include <abi/sysinfo.h> 41 41 42 extern char *sysinfo_get_keys(const char *, size_t *); 42 43 extern sysinfo_item_val_type_t sysinfo_get_val_type(const char *); 43 44 extern int sysinfo_get_value(const char *, sysarg_t *);
Note:
See TracChangeset
for help on using the changeset viewer.