Changeset f65d9cc in mainline
- Timestamp:
- 2013-09-21T05:28:00Z (11 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
- Files:
-
- 2 added
- 15 edited
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 } -
uspace/lib/block/block.c
r772a172 rf65d9cc 37 37 */ 38 38 39 #include "../../srv/vfs/vfs.h"40 39 #include <ipc/loc.h> 41 40 #include <ipc/services.h> -
uspace/lib/block/block.h
r772a172 rf65d9cc 29 29 */ 30 30 31 /** @addtogroup libblock 31 /** @addtogroup libblock 32 32 * @{ 33 */ 33 */ 34 34 /** 35 35 * @file … … 41 41 #include <stdint.h> 42 42 #include <async.h> 43 #include "../../srv/vfs/vfs.h"44 43 #include <fibril_synch.h> 45 44 #include <adt/hash_table.h> 46 45 #include <adt/list.h> 46 #include <loc.h> 47 47 48 48 /* … … 50 50 */ 51 51 52 /** 52 /** 53 53 * This macro is a symbolic value for situations where no special flags are 54 54 * needed. -
uspace/lib/c/generic/inetcfg.c
r772a172 rf65d9cc 279 279 aid_t req = async_send_1(exch, INETCFG_LINK_GET, link_id, &answer); 280 280 aid_t dreq = async_data_read(exch, name_buf, LOC_NAME_MAXLEN, &dreply); 281 int rc = async_data_read_start(exch, &linfo->mac_addr, sizeof(addr48_t)); 281 282 async_wait_for(dreq, &dretval); 282 283 283 284 async_exchange_end(exch); 284 285 285 if (dretval != EOK ) {286 if (dretval != EOK || rc != EOK) { 286 287 async_forget(req); 287 288 return dretval; -
uspace/lib/c/generic/vfs/vfs.c
r772a172 rf65d9cc 893 893 } 894 894 895 int statfs(const char *path, struct statfs *statfs) 896 { 897 sysarg_t rc; 898 sysarg_t rc_orig; 895 int statfs(const char *path, struct statfs *st) 896 { 897 sysarg_t rc, rc_orig; 899 898 aid_t req; 900 899 size_t pa_size; 901 900 902 901 char *pa = absolutize(path, &pa_size); 903 902 if (!pa) 904 903 return ENOMEM; 905 async_exch_t *exch = vfs_exchange_begin(); 906 904 905 async_exch_t *exch = vfs_exchange_begin(); 906 907 907 req = async_send_0(exch, VFS_IN_STATFS, NULL); 908 908 rc = async_data_write_start(exch, pa, pa_size); 909 if (rc != EOK) { 910 vfs_exchange_end(exch); 911 free(pa); 912 async_wait_for(req, &rc_orig); 913 if (rc_orig == EOK) 914 return (int) rc; 915 else 916 return (int) rc_orig; 917 } 918 rc = async_data_read_start(exch, (void *) statfs, sizeof(struct statfs)); 919 if (rc != EOK) { 920 vfs_exchange_end(exch); 921 free(pa); 922 async_wait_for(req, &rc_orig); 923 if (rc_orig == EOK) 924 return (int) rc; 925 else 926 return (int) rc_orig; 927 } 909 if (rc != EOK) 910 goto exit; 911 912 rc = async_data_read_start(exch, (void *) st, sizeof(*st)); 913 914 exit: 928 915 vfs_exchange_end(exch); 929 916 free(pa); 930 async_wait_for(req, &rc );931 return rc;917 async_wait_for(req, &rc_orig); 918 return (int) (rc_orig != EOK ? rc_orig : rc); 932 919 } 933 920 -
uspace/lib/c/include/inet/inet.h
r772a172 rf65d9cc 39 39 #include <ipc/loc.h> 40 40 #include <sys/types.h> 41 42 #define INET_TTL_MAX 255 43 44 typedef struct { 45 /** Local IP link service ID (optional) */ 46 service_id_t iplink; 47 inet_addr_t src; 48 inet_addr_t dest; 49 uint8_t tos; 50 void *data; 51 size_t size; 52 } inet_dgram_t; 53 54 typedef struct { 55 int (*recv)(inet_dgram_t *); 56 } inet_ev_ops_t; 57 58 typedef enum { 59 INET_DF = 1 60 } inet_df_t; 41 #include <types/inet.h> 61 42 62 43 extern int inet_init(uint8_t, inet_ev_ops_t *); -
uspace/lib/c/include/inet/inetcfg.h
r772a172 rf65d9cc 38 38 #include <inet/inet.h> 39 39 #include <sys/types.h> 40 41 /** Address object info */ 42 typedef struct { 43 /** Network address */ 44 inet_naddr_t naddr; 45 /** Link service ID */ 46 sysarg_t ilink; 47 /** Address object name */ 48 char *name; 49 } inet_addr_info_t; 50 51 /** IP link info */ 52 typedef struct { 53 /** Link service name */ 54 char *name; 55 /** Default MTU */ 56 size_t def_mtu; 57 } inet_link_info_t; 58 59 /** Static route info */ 60 typedef struct { 61 /** Destination network address */ 62 inet_naddr_t dest; 63 /** Router address */ 64 inet_addr_t router; 65 /** Static route name */ 66 char *name; 67 } inet_sroute_info_t; 40 #include <types/inetcfg.h> 68 41 69 42 extern int inetcfg_init(void); -
uspace/lib/ext4/libext4_filesystem.c
r772a172 rf65d9cc 39 39 #include <errno.h> 40 40 #include <malloc.h> 41 #include <ipc/vfs.h> 41 42 #include "libext4.h" 42 43 -
uspace/lib/fs/libfs.c
r772a172 rf65d9cc 806 806 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 807 807 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 808 808 809 809 fs_node_t *fn; 810 810 int rc = ops->node_get(&fn, service_id, index); 811 811 on_error(rc, answer_and_return(rid, rc)); 812 812 813 813 ipc_callid_t callid; 814 814 size_t size; … … 820 820 return; 821 821 } 822 822 823 823 struct stat stat; 824 824 memset(&stat, 0, sizeof(struct stat)); 825 825 826 826 stat.fs_handle = fs_handle; 827 827 stat.service_id = service_id; … … 832 832 stat.size = ops->size_get(fn); 833 833 stat.service = ops->service_get(fn); 834 834 835 835 ops->node_put(fn); 836 836 … … 845 845 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 846 846 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 847 847 848 848 fs_node_t *fn; 849 849 int rc = ops->node_get(&fn, service_id, index); 850 850 on_error(rc, answer_and_return(rid, rc)); 851 851 852 852 ipc_callid_t callid; 853 853 size_t size; 854 854 if ((!async_data_read_receive(&callid, &size)) || 855 855 (size != sizeof(struct statfs))) { 856 ops->node_put(fn);857 async_answer_0(callid, EINVAL);858 async_answer_0(rid, EINVAL); 859 return;860 }861 862 struct statfs statfs;863 memset(&statfs, 0, sizeof(struct statfs));864 865 if (NULL != ops->size_block) {866 rc = ops->size_block(service_id, &statfs.f_bsize);867 if (rc != EOK) goto error; 868 }869 870 if (NULL != ops->total_block_count) {871 rc = ops->total_block_count(service_id, &statfs.f_blocks);872 if (rc != EOK) goto error;873 } 874 875 if (NULL != ops->free_block_count) {876 rc = ops->free_block_count(service_id, &statfs.f_bfree);877 if (rc != EOK)goto error;856 goto error; 857 } 858 859 struct statfs st; 860 memset(&st, 0, sizeof(struct statfs)); 861 862 if (ops->size_block != NULL) { 863 rc = ops->size_block(service_id, &st.f_bsize); 864 if (rc != EOK) 865 goto error; 866 } 867 868 if (ops->total_block_count != NULL) { 869 rc = ops->total_block_count(service_id, &st.f_blocks); 870 if (rc != EOK) 871 goto error; 872 } 873 874 if (ops->free_block_count != NULL) { 875 rc = ops->free_block_count(service_id, &st.f_bfree); 876 if (rc != EOK) 877 goto error; 878 878 } 879 879 880 880 ops->node_put(fn); 881 async_data_read_finalize(callid, &st atfs, sizeof(struct statfs));881 async_data_read_finalize(callid, &st, sizeof(struct statfs)); 882 882 async_answer_0(rid, EOK); 883 883 return; -
uspace/srv/net/dhcp/dhcp.c
r772a172 rf65d9cc 53 53 54 54 static int transport_fd = -1; 55 static addr48_t mac_addr;55 static inet_link_info_t link_info; 56 56 static uint8_t msgbuf[MAX_MSG_SIZE]; 57 57 … … 132 132 hdr->flags = flag_broadcast; 133 133 134 addr48( mac_addr, hdr->chaddr);134 addr48(link_info.mac_addr, hdr->chaddr); 135 135 hdr->opt_magic = host2uint32_t_be(dhcp_opt_magic); 136 136 … … 178 178 hdr->flags = flag_broadcast; 179 179 hdr->ciaddr = host2uint32_t_be(offer->oaddr.addr); 180 addr48( mac_addr, hdr->chaddr);180 addr48(link_info.mac_addr, hdr->chaddr); 181 181 hdr->opt_magic = host2uint32_t_be(dhcp_opt_magic); 182 182 … … 387 387 rc = dnsr_set_srvaddr(&offer->dns_server); 388 388 if (rc != EOK) { 389 printf("%s: Failedsetting nameserver address (%d))\n",389 printf("%s: Error setting nameserver address (%d))\n", 390 390 NAME, rc); 391 391 return rc; … … 413 413 rc = inetcfg_init(); 414 414 if (rc != EOK) { 415 printf(" Failedcontacting inet configuration service.\n");415 printf("Error contacting inet configuration service.\n"); 416 416 return 1; 417 417 } … … 419 419 rc = loc_service_get_id(argv[1], &iplink, 0); 420 420 if (rc != EOK) { 421 printf("Failed resolving service '%s'.\n", argv[1]); 422 return 1; 423 } 424 425 /* XXX Determine MAC address automatically */ 426 mac_addr[0] = 0xaa; 427 mac_addr[1] = 0xde; 428 mac_addr[2] = 0xad; 429 mac_addr[3] = 0xbe; 430 mac_addr[4] = 0xef; 431 mac_addr[5] = 0xfe; 421 printf("Error resolving service '%s'.\n", argv[1]); 422 return 1; 423 } 424 425 /* Get link hardware address */ 426 rc = inetcfg_link_get(iplink, &link_info); 427 if (rc != EOK) { 428 printf("Error getting properties for link '%s'.\n", argv[1]); 429 return 1; 430 } 432 431 433 432 laddr.sin_family = AF_INET; -
uspace/srv/net/inetsrv/inet_link.c
r772a172 rf65d9cc 493 493 } 494 494 495 /** Get IDs of all links. */ 496 int inet_link_get_id_list(sysarg_t **rid_list, size_t *rcount) 497 { 498 sysarg_t *id_list; 499 size_t count, i; 500 501 fibril_mutex_lock(&inet_discovery_lock); 502 count = list_count(&inet_link_list); 503 504 id_list = calloc(count, sizeof(sysarg_t)); 505 if (id_list == NULL) { 506 fibril_mutex_unlock(&inet_discovery_lock); 507 return ENOMEM; 508 } 509 510 i = 0; 511 list_foreach(inet_link_list, link_list, inet_link_t, ilink) { 512 id_list[i++] = ilink->svc_id; 513 log_msg(LOG_DEFAULT, LVL_NOTE, "add link to list"); 514 } 515 516 fibril_mutex_unlock(&inet_discovery_lock); 517 518 log_msg(LOG_DEFAULT, LVL_NOTE, "return %zu links", count); 519 *rid_list = id_list; 520 *rcount = count; 521 522 return EOK; 523 } 524 495 525 /** @} 496 526 */ -
uspace/srv/net/inetsrv/inet_link.h
r772a172 rf65d9cc 47 47 uint8_t, uint8_t, int); 48 48 extern inet_link_t *inet_link_get_by_id(sysarg_t); 49 extern int inet_link_get_id_list(sysarg_t **, size_t *); 49 50 50 51 #endif -
uspace/srv/net/inetsrv/inetcfg.c
r772a172 rf65d9cc 44 44 #include <str.h> 45 45 #include <sys/types.h> 46 #include <types/inetcfg.h> 46 47 47 48 #include "addrobj.h" … … 151 152 static int inetcfg_get_link_list(sysarg_t **addrs, size_t *count) 152 153 { 153 return ENOTSUP;154 return inet_link_get_id_list(addrs, count); 154 155 } 155 156 … … 170 171 linfo->name = str_dup(ilink->svc_name); 171 172 linfo->def_mtu = ilink->def_mtu; 173 if (ilink->mac_valid) { 174 addr48(ilink->mac, linfo->mac_addr); 175 } else { 176 memset(linfo->mac_addr, 0, sizeof(linfo->mac_addr)); 177 } 178 172 179 return EOK; 173 180 } … … 411 418 { 412 419 ipc_callid_t rcallid; 420 size_t count; 413 421 size_t max_size; 414 422 size_t act_size; … … 417 425 int rc; 418 426 419 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_get_ link_list_srv()");427 log_msg(LOG_DEFAULT, LVL_DEBUG, "inetcfg_get_addr_list_srv()"); 420 428 421 429 if (!async_data_read_receive(&rcallid, &max_size)) { … … 425 433 } 426 434 427 rc = inetcfg_get_link_list(&id_buf, & act_size);435 rc = inetcfg_get_link_list(&id_buf, &count); 428 436 if (rc != EOK) { 429 437 async_answer_0(rcallid, rc); … … 432 440 } 433 441 442 act_size = count * sizeof(sysarg_t); 434 443 size = min(act_size, max_size); 435 444 … … 476 485 static void inetcfg_link_get_srv(ipc_callid_t callid, ipc_call_t *call) 477 486 { 478 ipc_callid_t rcallid; 479 size_t max_size; 487 ipc_callid_t name_callid; 488 ipc_callid_t laddr_callid; 489 size_t name_max_size; 490 size_t laddr_max_size; 480 491 481 492 sysarg_t link_id; … … 488 499 linfo.name = NULL; 489 500 490 if (!async_data_read_receive(&rcallid, &max_size)) { 491 async_answer_0(rcallid, EREFUSED); 501 if (!async_data_read_receive(&name_callid, &name_max_size)) { 502 async_answer_0(name_callid, EREFUSED); 503 async_answer_0(callid, EREFUSED); 504 return; 505 } 506 507 if (!async_data_read_receive(&laddr_callid, &laddr_max_size)) { 508 async_answer_0(name_callid, EREFUSED); 492 509 async_answer_0(callid, EREFUSED); 493 510 return; … … 496 513 rc = inetcfg_link_get(link_id, &linfo); 497 514 if (rc != EOK) { 498 async_answer_0(rcallid, rc); 499 async_answer_0(callid, rc); 500 return; 501 } 502 503 sysarg_t retval = async_data_read_finalize(rcallid, linfo.name, 504 min(max_size, str_size(linfo.name))); 515 async_answer_0(laddr_callid, rc); 516 async_answer_0(name_callid, rc); 517 async_answer_0(callid, rc); 518 return; 519 } 520 521 sysarg_t retval = async_data_read_finalize(name_callid, linfo.name, 522 min(name_max_size, str_size(linfo.name))); 523 if (retval != EOK) { 524 free(linfo.name); 525 async_answer_0(laddr_callid, retval); 526 async_answer_0(callid, retval); 527 return; 528 } 529 530 retval = async_data_read_finalize(laddr_callid, &linfo.mac_addr, 531 min(laddr_max_size, sizeof(linfo.mac_addr))); 532 505 533 free(linfo.name); 506 534 -
uspace/srv/net/inetsrv/inetsrv.h
r772a172 rf65d9cc 44 44 #include <ipc/loc.h> 45 45 #include <sys/types.h> 46 #include <types/inet.h> 46 47 #include <async.h> 47 48 … … 73 74 } inetping6_client_t; 74 75 75 /** Address object info */76 typedef struct {77 /** Network address */78 inet_naddr_t naddr;79 /** Link service ID */80 sysarg_t ilink;81 /** Address object name */82 char *name;83 } inet_addr_info_t;84 85 /** IP link info */86 typedef struct {87 /** Link service name */88 char *name;89 /** Default MTU */90 size_t def_mtu;91 } inet_link_info_t;92 93 /** Static route info */94 typedef struct {95 /** Destination network address */96 inet_naddr_t dest;97 /** Router address */98 inet_addr_t router;99 /** Static route name */100 char *name;101 } inet_sroute_info_t;102 103 76 typedef struct { 104 77 /** Source address */ … … 125 98 size_t size; 126 99 } inet_packet_t; 127 128 typedef struct {129 service_id_t iplink;130 inet_addr_t src;131 inet_addr_t dest;132 uint8_t tos;133 void *data;134 size_t size;135 } inet_dgram_t;136 100 137 101 typedef struct {
Note:
See TracChangeset
for help on using the changeset viewer.