Changeset 30413b31 in mainline for uspace/lib
- Timestamp:
- 2011-12-10T08:29:44Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d9f8dd13
- Parents:
- b8b1e631 (diff), 87955bfb (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/lib
- Files:
-
- 8 edited
-
c/generic/ddi.c (modified) (1 diff)
-
c/generic/fibril_synch.c (modified) (1 diff)
-
c/include/bitops.h (modified) (1 diff)
-
c/include/ddi.h (modified) (1 diff)
-
c/include/errno.h (modified) (1 diff)
-
c/include/fibril_synch.h (modified) (2 diffs)
-
minix/minix.h (modified) (7 diffs)
-
net/generic/generic.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/ddi.c
rb8b1e631 r30413b31 53 53 } 54 54 55 /** Map piece of physical memory to task.55 /** Map a piece of physical memory to task. 56 56 * 57 57 * Caller of this function must have the CAP_MEM_MANAGER capability. 58 58 * 59 * @param pf Physical address of the starting frame.60 * @param vp Virtual address of the starting page.61 * @param pages Number of pages to map.62 * @param flags Flags for the new address space area.59 * @param pf Physical address of the starting frame. 60 * @param vp Virtual address of the starting page. 61 * @param pages Number of pages to map. 62 * @param flags Flags for the new address space area. 63 63 * 64 * @return 0 on success, EPERM if the caller lacks the 65 * CAP_MEM_MANAGER capability, ENOENT if there is no task 66 * with specified ID and ENOMEM if there was some problem 67 * in creating address space area. 64 * @return EOK on success 65 * @return EPERM if the caller lacks the CAP_MEM_MANAGER capability 66 * @return ENOENT if there is no task with specified ID 67 * @return ENOMEM if there was some problem in creating 68 * the address space area. 69 * 68 70 */ 69 int physmem_map(void *pf, void *vp, unsigned long pages,int flags)71 int physmem_map(void *pf, void *vp, size_t pages, unsigned int flags) 70 72 { 71 return __SYSCALL4(SYS_PHYSMEM_MAP, (sysarg_t) pf, (sysarg_t) vp, pages,72 flags);73 return __SYSCALL4(SYS_PHYSMEM_MAP, (sysarg_t) pf, (sysarg_t) vp, 74 pages, flags); 73 75 } 74 76 -
uspace/lib/c/generic/fibril_synch.c
rb8b1e631 r30413b31 447 447 } 448 448 449 /** Timer fibril. 450 * 451 * @param arg Timer 452 */ 453 static int fibril_timer_func(void *arg) 454 { 455 fibril_timer_t *timer = (fibril_timer_t *) arg; 456 int rc; 457 458 fibril_mutex_lock(&timer->lock); 459 460 while (true) { 461 while (timer->state != fts_active && 462 timer->state != fts_cleanup) { 463 464 if (timer->state == fts_cleanup) 465 break; 466 467 fibril_condvar_wait(&timer->cv, &timer->lock); 468 } 469 470 if (timer->state == fts_cleanup) 471 break; 472 473 rc = fibril_condvar_wait_timeout(&timer->cv, &timer->lock, 474 timer->delay); 475 if (rc == ETIMEOUT) { 476 timer->state = fts_fired; 477 fibril_mutex_unlock(&timer->lock); 478 timer->fun(timer->arg); 479 fibril_mutex_lock(&timer->lock); 480 } 481 } 482 483 fibril_mutex_unlock(&timer->lock); 484 return 0; 485 } 486 487 /** Create new timer. 488 * 489 * @return New timer on success, @c NULL if out of memory. 490 */ 491 fibril_timer_t *fibril_timer_create(void) 492 { 493 fid_t fid; 494 fibril_timer_t *timer; 495 496 timer = calloc(1, sizeof(fibril_timer_t)); 497 if (timer == NULL) 498 return NULL; 499 500 fid = fibril_create(fibril_timer_func, (void *) timer); 501 if (fid == 0) { 502 free(timer); 503 return NULL; 504 } 505 506 fibril_mutex_initialize(&timer->lock); 507 fibril_condvar_initialize(&timer->cv); 508 509 timer->fibril = fid; 510 timer->state = fts_not_set; 511 512 fibril_add_ready(fid); 513 514 return timer; 515 } 516 517 /** Destroy timer. 518 * 519 * @param timer Timer, must not be active or accessed by other threads. 520 */ 521 void fibril_timer_destroy(fibril_timer_t *timer) 522 { 523 fibril_mutex_lock(&timer->lock); 524 assert(timer->state != fts_active); 525 timer->state = fts_cleanup; 526 fibril_condvar_broadcast(&timer->cv); 527 fibril_mutex_unlock(&timer->lock); 528 } 529 530 /** Set timer. 531 * 532 * Set timer to execute a callback function after the specified 533 * interval. 534 * 535 * @param timer Timer 536 * @param delay Delay in microseconds 537 * @param fun Callback function 538 * @param arg Argument for @a fun 539 */ 540 void fibril_timer_set(fibril_timer_t *timer, suseconds_t delay, 541 fibril_timer_fun_t fun, void *arg) 542 { 543 fibril_mutex_lock(&timer->lock); 544 timer->state = fts_active; 545 timer->delay = delay; 546 timer->fun = fun; 547 timer->arg = arg; 548 fibril_condvar_broadcast(&timer->cv); 549 fibril_mutex_unlock(&timer->lock); 550 } 551 552 /** Clear timer. 553 * 554 * Clears (cancels) timer and returns last state of the timer. 555 * This can be one of: 556 * - fts_not_set If the timer has not been set or has been cleared 557 * - fts_active Timer was set but did not fire 558 * - fts_fired Timer fired 559 * 560 * @param timer Timer 561 * @return Last timer state 562 */ 563 fibril_timer_state_t fibril_timer_clear(fibril_timer_t *timer) 564 { 565 fibril_timer_state_t old_state; 566 567 fibril_mutex_lock(&timer->lock); 568 old_state = timer->state; 569 timer->state = fts_not_set; 570 571 timer->delay = 0; 572 timer->fun = NULL; 573 timer->arg = NULL; 574 fibril_condvar_broadcast(&timer->cv); 575 fibril_mutex_unlock(&timer->lock); 576 577 return old_state; 578 } 579 449 580 /** @} 450 581 */ -
uspace/lib/c/include/bitops.h
rb8b1e631 r30413b31 40 40 /** Mask with bit @a n set. */ 41 41 #define BIT_V(type, n) \ 42 ((type)1 << ( (n) - 1))42 ((type)1 << (n)) 43 43 44 44 /** Mask with rightmost @a n bits set. */ 45 45 #define BIT_RRANGE(type, n) \ 46 (BIT_V(type, (n) + 1) - 1)46 (BIT_V(type, (n)) - 1) 47 47 48 48 /** Mask with bits @a hi .. @a lo set. @a hi >= @a lo. */ -
uspace/lib/c/include/ddi.h
rb8b1e631 r30413b31 41 41 42 42 extern int device_assign_devno(void); 43 extern int physmem_map(void *, void *, unsigned long,int);43 extern int physmem_map(void *, void *, size_t, unsigned int); 44 44 extern int iospace_enable(task_id_t, void *, unsigned long); 45 45 extern int pio_enable(void *, size_t, void **); -
uspace/lib/c/include/errno.h
rb8b1e631 r30413b31 96 96 #define ENOTCONN (-10057) 97 97 98 #define ECONNREFUSED (-10058) 99 100 #define ECONNABORTED (-10059) 101 98 102 /** The requested operation was not performed. Try again later. */ 99 103 #define EAGAIN (-11002) -
uspace/lib/c/include/fibril_synch.h
rb8b1e631 r30413b31 107 107 fibril_condvar_t name = FIBRIL_CONDVAR_INITIALIZER(name) 108 108 109 typedef void (*fibril_timer_fun_t)(void *); 110 111 typedef enum { 112 /** Timer has not been set or has been cleared */ 113 fts_not_set, 114 /** Timer was set but did not fire yet */ 115 fts_active, 116 /** Timer has fired and has not been cleared since */ 117 fts_fired, 118 /** Timer is being destroyed */ 119 fts_cleanup 120 } fibril_timer_state_t; 121 122 /** Fibril timer. 123 * 124 * When a timer is set it executes a callback function (in a separate 125 * fibril) after a specified time interval. The timer can be cleared 126 * (canceled) before that. From the return value of fibril_timer_clear() 127 * one can tell whether the timer fired or not. 128 */ 129 typedef struct { 130 fibril_mutex_t lock; 131 fibril_condvar_t cv; 132 fid_t fibril; 133 fibril_timer_state_t state; 134 135 suseconds_t delay; 136 fibril_timer_fun_t fun; 137 void *arg; 138 } fibril_timer_t; 139 109 140 extern void fibril_mutex_initialize(fibril_mutex_t *); 110 141 extern void fibril_mutex_lock(fibril_mutex_t *); … … 129 160 extern void fibril_condvar_broadcast(fibril_condvar_t *); 130 161 162 extern fibril_timer_t *fibril_timer_create(void); 163 extern void fibril_timer_destroy(fibril_timer_t *); 164 extern void fibril_timer_set(fibril_timer_t *, suseconds_t, fibril_timer_fun_t, 165 void *); 166 extern fibril_timer_state_t fibril_timer_clear(fibril_timer_t *); 167 131 168 #endif 132 169 -
uspace/lib/minix/minix.h
rb8b1e631 r30413b31 39 39 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 40 40 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 41 #define S_IFDIR 0040000 /* Directory*/42 #define S_IFREG 0100000 /* Regular file*/41 #define S_IFDIR 0040000 /* Directory */ 42 #define S_IFREG 0100000 /* Regular file */ 43 43 #define S_IFMT 00170000 44 44 45 /* The following block sizes are valid only on V3 filesystem*/45 /* The following block sizes are valid only on V3 filesystem */ 46 46 #define MFS_MIN_BLOCKSIZE 1024 47 47 #define MFS_MAX_BLOCKSIZE 4096 … … 88 88 #define MFS_ERROR_FS 0x0002 89 89 90 /* MFS V1/V2 superblock data on disk*/90 /* MFS V1/V2 superblock data on disk */ 91 91 struct mfs_superblock { 92 /* Total number of inodes on the device*/92 /* Total number of inodes on the device */ 93 93 uint16_t s_ninodes; 94 /* Total number of zones on the device*/94 /* Total number of zones on the device */ 95 95 uint16_t s_nzones; 96 /* Number of inode bitmap blocks*/96 /* Number of inode bitmap blocks */ 97 97 uint16_t s_ibmap_blocks; 98 /* Number of zone bitmap blocks*/98 /* Number of zone bitmap blocks */ 99 99 uint16_t s_zbmap_blocks; 100 /* First data zone on device*/100 /* First data zone on device */ 101 101 uint16_t s_first_data_zone; 102 /* Base 2 logarithm of the zone to block ratio*/102 /* Base 2 logarithm of the zone to block ratio */ 103 103 uint16_t s_log2_zone_size; 104 /* Maximum file size expressed in bytes*/104 /* Maximum file size expressed in bytes */ 105 105 uint32_t s_max_file_size; 106 106 /* … … 109 109 */ 110 110 uint16_t s_magic; 111 /* Flag used to detect FS errors*/111 /* Flag used to detect FS errors*/ 112 112 uint16_t s_state; 113 /* Total number of zones on the device (V2 only)*/113 /* Total number of zones on the device (V2 only) */ 114 114 uint32_t s_nzones2; 115 115 } __attribute__ ((packed)); 116 116 117 117 118 /* MFS V3 superblock data on disk*/118 /* MFS V3 superblock data on disk */ 119 119 struct mfs3_superblock { 120 /* Total number of inodes on the device*/120 /* Total number of inodes on the device */ 121 121 uint32_t s_ninodes; 122 122 uint16_t s_pad0; 123 /* Number of inode bitmap blocks*/123 /* Number of inode bitmap blocks */ 124 124 int16_t s_ibmap_blocks; 125 /* Number of zone bitmap blocks*/125 /* Number of zone bitmap blocks */ 126 126 int16_t s_zbmap_blocks; 127 /* First data zone on device*/127 /* First data zone on device */ 128 128 uint16_t s_first_data_zone; 129 /* Base 2 logarithm of the zone to block ratio*/129 /* Base 2 logarithm of the zone to block ratio */ 130 130 int16_t s_log2_zone_size; 131 131 int16_t s_pad1; 132 /* Maximum file size expressed in bytes*/132 /* Maximum file size expressed in bytes */ 133 133 uint32_t s_max_file_size; 134 /* Total number of zones on the device*/134 /* Total number of zones on the device */ 135 135 uint32_t s_nzones; 136 136 /* … … 140 140 int16_t s_magic; 141 141 int16_t s_pad2; 142 /* Filesystem block size expressed in bytes*/142 /* Filesystem block size expressed in bytes */ 143 143 uint16_t s_block_size; 144 /* Filesystem disk format version*/144 /* Filesystem disk format version */ 145 145 int8_t s_disk_version; 146 146 } __attribute__ ((packed)); 147 147 148 /* MinixFS V1 inode structure as it is on disk*/148 /* MinixFS V1 inode structure as it is on disk */ 149 149 struct mfs_inode { 150 150 uint16_t i_mode; … … 154 154 uint8_t i_gid; 155 155 uint8_t i_nlinks; 156 /* Block numbers for direct zones*/156 /* Block numbers for direct zones */ 157 157 uint16_t i_dzone[V1_NR_DIRECT_ZONES]; 158 /* Block numbers for indirect zones*/158 /* Block numbers for indirect zones */ 159 159 uint16_t i_izone[V1_NR_INDIRECT_ZONES]; 160 160 } __attribute__ ((packed)); 161 161 162 /* MinixFS V2 inode structure as it is on disk (also valid for V3).*/162 /* MinixFS V2 inode structure as it is on disk (also valid for V3). */ 163 163 struct mfs2_inode { 164 164 uint16_t i_mode; … … 170 170 int32_t i_mtime; 171 171 int32_t i_ctime; 172 /* Block numbers for direct zones*/172 /* Block numbers for direct zones */ 173 173 uint32_t i_dzone[V2_NR_DIRECT_ZONES]; 174 /* Block numbers for indirect zones*/174 /* Block numbers for indirect zones */ 175 175 uint32_t i_izone[V2_NR_INDIRECT_ZONES]; 176 176 } __attribute__ ((packed)); 177 177 178 /* MinixFS V1/V2 directory entry on-disk structure*/178 /* MinixFS V1/V2 directory entry on-disk structure */ 179 179 struct mfs_dentry { 180 180 uint16_t d_inum; … … 182 182 }; 183 183 184 /* MinixFS V3 directory entry on-disk structure*/184 /* MinixFS V3 directory entry on-disk structure */ 185 185 struct mfs3_dentry { 186 186 uint32_t d_inum; -
uspace/lib/net/generic/generic.c
rb8b1e631 r30413b31 104 104 nic_device_id_t device_id, uint8_t *address, size_t max_len) 105 105 { 106 if (!address) 107 return EBADMEM; 106 aid_t aid; 107 ipc_call_t result; 108 109 assert(address != NULL); 108 110 109 111 /* Request the address */ 110 112 async_exch_t *exch = async_exchange_begin(sess); 111 aid_t aid = async_send_1(exch, message, (sysarg_t) device_id, 112 NULL); 113 aid = async_send_1(exch, message, (sysarg_t) device_id, &result); 114 115 sysarg_t ipcrc; 113 116 int rc = async_data_read_start(exch, address, max_len); 114 117 async_exchange_end(exch); 115 118 116 sysarg_t result; 117 async_wait_for(aid, &result); 118 119 if (rc != EOK) 119 if (rc != EOK) { 120 async_wait_for(aid, &ipcrc); 120 121 return rc; 121 122 return (int) result; 122 } 123 124 async_wait_for(aid, &ipcrc); 125 if (ipcrc == EOK) { 126 return IPC_GET_ARG1(result); 127 } else { 128 return (int) ipcrc; 129 } 123 130 } 124 131
Note:
See TracChangeset
for help on using the changeset viewer.
