Changeset f65d9cc in mainline for uspace/app
- Timestamp:
- 2013-09-21T05:28:00Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 026271d5
- Parents:
- 772a172 (diff), b9f7848b (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. - Location:
- uspace/app
- Files:
-
- 2 edited
-
df/df.c (modified) (9 diffs)
-
inet/inet.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/df/df.c
r772a172 rf65d9cc 50 50 #define HEADER_TABLE_HR "Filesystem Size Used Available Used%% Mounted on" 51 51 52 #define PERCENTAGE(x, tot) ( (unsigned long long) (100L * (x) / (tot)))52 #define PERCENTAGE(x, tot) (tot ? (100ULL * (x) / (tot)) : 0) 53 53 #define FSBK_TO_BK(x, fsbk, bk) \ 54 54 (((fsbk) != 0 && (fsbk) < (bk)) ? \ … … 59 59 static unsigned int human_readable; 60 60 61 static int size_to_human_readable(char buf[], uint64_t bytes);61 static void size_to_human_readable(char *buf, uint64_t bytes); 62 62 static void print_header(void); 63 63 static void print_statfs(struct statfs *, char *, char *); … … 90 90 91 91 case ':': 92 fprintf(stderr, "Option -%c requires an operand\n", optopt); 92 fprintf(stderr, "Option -%c requires an operand\n", 93 optopt); 93 94 errflg++; 94 95 break; … … 100 101 101 102 default: 102 fprintf(stderr, "Unknown error while parsing command line options."); 103 fprintf(stderr, 104 "Unknown error while parsing command line options"); 103 105 errflg++; 104 106 break; … … 107 109 108 110 if (optind > argc) { 109 fprintf(stderr, "Too many input parameter \n");111 fprintf(stderr, "Too many input parameters\n"); 110 112 errflg++; 111 113 } … … 118 120 LIST_INITIALIZE(mtab_list); 119 121 get_mtab_list(&mtab_list); 122 120 123 print_header(); 121 124 list_foreach(mtab_list, link, mtab_ent_t, mtab_ent) { … … 123 126 print_statfs(&st, mtab_ent->fs_name, mtab_ent->mp); 124 127 } 128 125 129 putchar('\n'); 126 130 return 0; 127 131 } 128 132 129 static int size_to_human_readable(char buf[], uint64_t bytes)133 static void size_to_human_readable(char *buf, uint64_t bytes) 130 134 { 131 135 const char *units = "BkMGTPEZY"; 132 136 int i = 0; 133 int limit; 134 135 limit = str_length(units); 137 136 138 while (bytes >= 1024) { 137 if (i >= limit)138 return -1;139 139 bytes /= 1024; 140 140 i++; 141 141 } 142 snprintf(buf, 6, "%4llu%c", (unsigned long long)bytes, units[i]); 143 144 return 0; 142 143 snprintf(buf, 6, "%4llu%c", (unsigned long long) bytes, units[i]); 145 144 } 146 145 … … 151 150 else 152 151 printf(HEADER_TABLE, unit_size); 152 153 153 putchar('\n'); 154 154 } … … 156 156 static void print_statfs(struct statfs *st, char *name, char *mountpoint) 157 157 { 158 uint64_t const used_blocks = st->f_blocks - st->f_bfree; 159 unsigned const perc_used = PERCENTAGE(used_blocks, st->f_blocks); 160 158 161 printf("%10s", name); 159 162 160 163 if (human_readable) { 161 164 char tmp[1024]; 165 166 /* Print size */ 162 167 size_to_human_readable(tmp, st->f_blocks * st->f_bsize); 163 printf(" %14s", tmp); /* Size */ 164 size_to_human_readable(tmp, (st->f_blocks - st->f_bfree) * st->f_bsize); 165 printf(" %14s", tmp); /* Used */ 168 printf(" %14s", tmp); 169 170 /* Number of used blocks */ 171 size_to_human_readable(tmp, used_blocks * st->f_bsize); 172 printf(" %14s", tmp); 173 174 /* Number of available blocks */ 166 175 size_to_human_readable(tmp, st->f_bfree * st->f_bsize); 167 printf(" %14s", tmp); /* Available */ 168 printf(" %4llu%% %s\n", 169 (st->f_blocks)?PERCENTAGE(st->f_blocks - st->f_bfree, st->f_blocks):0L, /* Used% */ 170 mountpoint /* Mounted on */ 171 ); 172 } 173 else 174 printf(" %15llu %14llu %14llu %4llu%% %s\n", 175 FSBK_TO_BK(st->f_blocks, st->f_bsize, unit_size), /* Blocks */ 176 FSBK_TO_BK(st->f_blocks - st->f_bfree, st->f_bsize, unit_size), /* Used */ 177 FSBK_TO_BK(st->f_bfree, st->f_bsize, unit_size), /* Available */ 178 (st->f_blocks)?PERCENTAGE(st->f_blocks - st->f_bfree, st->f_blocks):0L, /* Used% */ 179 mountpoint /* Mounted on */ 180 ); 176 printf(" %14s", tmp); 177 178 /* Percentage of used blocks */ 179 printf(" %4u%%", perc_used); 180 181 /* Mount point */ 182 printf(" %s\n", mountpoint); 183 } else { 184 /* Blocks / Used blocks / Available blocks / Used% / Mounted on */ 185 printf(" %15llu %14llu %14llu %4u%% %s\n", 186 FSBK_TO_BK(st->f_blocks, st->f_bsize, unit_size), 187 FSBK_TO_BK(used_blocks, st->f_bsize, unit_size), 188 FSBK_TO_BK(st->f_bfree, st->f_bsize, unit_size), 189 perc_used, 190 mountpoint); 191 } 181 192 182 193 } -
uspace/app/inet/inet.c
r772a172 rf65d9cc 312 312 } 313 313 314 static int link_list(void) 315 { 316 sysarg_t *link_list; 317 inet_link_info_t linfo; 318 319 size_t count; 320 size_t i; 321 int rc; 322 323 rc = inetcfg_get_link_list(&link_list, &count); 324 if (rc != EOK) { 325 printf(NAME ": Failed getting link list.\n"); 326 return rc; 327 } 328 329 printf("IP links:\n"); 330 if (count > 0) 331 printf(" [Link-layer Address] [Link-Name] [Def-MTU]\n"); 332 333 for (i = 0; i < count; i++) { 334 rc = inetcfg_link_get(link_list[i], &linfo); 335 if (rc != EOK) { 336 printf("Failed getting properties of link %zu.\n", 337 (size_t)link_list[i]); 338 continue; 339 } 340 341 printf(" %02x:%02x:%02x:%02x:%02x:%02x %s %zu\n", 342 linfo.mac_addr[0], linfo.mac_addr[1], 343 linfo.mac_addr[2], linfo.mac_addr[3], 344 linfo.mac_addr[4], linfo.mac_addr[5], 345 linfo.name, linfo.def_mtu); 346 347 free(linfo.name); 348 349 linfo.name = NULL; 350 } 351 352 if (count == 0) 353 printf(" None\n"); 354 355 free(link_list); 356 357 return EOK; 358 } 359 314 360 static int sroute_list(void) 315 361 { … … 404 450 if (rc != EOK) 405 451 return 1; 452 rc = link_list(); 453 if (rc != EOK) 454 return 1; 406 455 return 0; 407 456 }
Note:
See TracChangeset
for help on using the changeset viewer.
