Changeset 371bd7d in mainline for uspace/lib/c/generic
- Timestamp:
- 2010-03-27T09:22:17Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 36a75a2
- Parents:
- cd82bb1 (diff), eaf22d4 (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/c/generic
- Files:
-
- 3 added
- 40 moved
-
adt/hash_table.c (moved) (moved from uspace/lib/libc/generic/adt/hash_table.c ) (2 diffs)
-
adt/list.c (moved) (moved from uspace/lib/libc/generic/adt/list.c )
-
as.c (moved) (moved from uspace/lib/libc/generic/as.c )
-
async.c (moved) (moved from uspace/lib/libc/generic/async.c ) (6 diffs)
-
cap.c (moved) (moved from uspace/lib/libc/generic/cap.c )
-
clipboard.c (added)
-
ddi.c (moved) (moved from uspace/lib/libc/generic/ddi.c )
-
devmap.c (moved) (moved from uspace/lib/libc/generic/devmap.c ) (11 diffs)
-
err.c (moved) (moved from uspace/lib/libc/generic/err.c )
-
errno.c (moved) (moved from uspace/lib/libc/generic/errno.c )
-
event.c (moved) (moved from uspace/lib/libc/generic/event.c )
-
fibril.c (moved) (moved from uspace/lib/libc/generic/fibril.c ) (9 diffs)
-
fibril_synch.c (moved) (moved from uspace/lib/libc/generic/fibril_sync.c ) (1 diff)
-
futex.c (added)
-
getopt.c (moved) (moved from uspace/lib/libc/generic/getopt.c ) (1 diff)
-
io/asprintf.c (moved) (moved from uspace/lib/libc/generic/io/asprintf.c ) (1 diff)
-
io/console.c (moved) (moved from uspace/lib/libc/generic/io/console.c )
-
io/io.c (moved) (moved from uspace/lib/libc/generic/io/io.c ) (21 diffs)
-
io/klog.c (moved) (moved from uspace/lib/libc/generic/io/klog.c ) (1 diff)
-
io/printf.c (moved) (moved from uspace/lib/libc/generic/io/printf.c )
-
io/printf_core.c (moved) (moved from uspace/lib/libc/generic/io/printf_core.c ) (1 diff)
-
io/snprintf.c (moved) (moved from uspace/lib/libc/generic/io/snprintf.c )
-
io/vprintf.c (moved) (moved from uspace/lib/libc/generic/io/vprintf.c ) (1 diff)
-
io/vsnprintf.c (moved) (moved from uspace/lib/libc/generic/io/vsnprintf.c ) (1 diff)
-
ipc.c (moved) (moved from uspace/lib/libc/generic/ipc.c ) (1 diff)
-
libc.c (moved) (moved from uspace/lib/libc/generic/libc.c )
-
loader.c (moved) (moved from uspace/lib/libc/generic/loader.c ) (3 diffs)
-
malloc.c (moved) (moved from uspace/lib/libc/generic/malloc.c ) (1 diff)
-
mem.c (moved) (moved from uspace/lib/libc/generic/mem.c )
-
mman.c (moved) (moved from uspace/lib/libc/generic/mman.c ) (1 diff)
-
pcb.c (moved) (moved from uspace/lib/libc/generic/pcb.c )
-
smc.c (moved) (moved from uspace/lib/libc/generic/smc.c )
-
stacktrace.c (added)
-
stdlib.c (moved) (moved from uspace/lib/libc/generic/stdlib.c )
-
str.c (moved) (moved from uspace/lib/libc/generic/string.c ) (4 diffs)
-
sysinfo.c (moved) (moved from uspace/lib/libc/generic/sysinfo.c ) (1 diff)
-
task.c (moved) (moved from uspace/lib/libc/generic/task.c ) (2 diffs)
-
thread.c (moved) (moved from uspace/lib/libc/generic/thread.c ) (2 diffs)
-
time.c (moved) (moved from uspace/lib/libc/generic/time.c ) (3 diffs)
-
tls.c (moved) (moved from uspace/lib/libc/generic/tls.c ) (1 diff)
-
udebug.c (moved) (moved from uspace/lib/libc/generic/udebug.c ) (2 diffs)
-
vfs/canonify.c (moved) (moved from uspace/lib/libc/generic/vfs/canonify.c )
-
vfs/vfs.c (moved) (moved from uspace/lib/libc/generic/vfs/vfs.c ) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/adt/hash_table.c
rcd82bb1 r371bd7d 43 43 #include <assert.h> 44 44 #include <stdio.h> 45 #include <str ing.h>45 #include <str.h> 46 46 47 47 /** Create chained hash table. … … 193 193 } 194 194 195 /** Apply fucntion to all items in hash table. 196 * 197 * @param h Hash table. 198 * @param f Function to be applied. 199 * @param arg Argument to be passed to the function. 200 */ 201 void 202 hash_table_apply(hash_table_t *h, void (*f)(link_t *, void *), void *arg) 203 { 204 hash_index_t bucket; 205 link_t *cur; 206 207 for (bucket = 0; bucket < h->entries; bucket++) { 208 for (cur = h->entry[bucket].next; cur != &h->entry[bucket]; 209 cur = cur->next) { 210 f(cur, arg); 211 } 212 } 213 } 214 195 215 /** @} 196 216 */ -
uspace/lib/c/generic/async.c
rcd82bb1 r371bd7d 1101 1101 } 1102 1102 1103 /** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework. 1104 * 1105 * Ask through phone for a new connection to some service. 1106 * 1107 * @param phoneid Phone handle used for contacting the other side. 1108 * @param arg1 User defined argument. 1109 * @param arg2 User defined argument. 1110 * @param arg3 User defined argument. 1111 * 1112 * @return New phone handle on success or a negative error code. 1113 */ 1114 int 1115 async_connect_me_to(int phoneid, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3) 1116 { 1117 int rc; 1118 ipcarg_t newphid; 1119 1120 rc = async_req_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, NULL, 1121 NULL, NULL, NULL, &newphid); 1122 1123 if (rc != EOK) 1124 return rc; 1125 1126 return newphid; 1127 } 1128 1129 /** Wrapper for making IPC_M_CONNECT_ME_TO calls using the async framework. 1130 * 1131 * Ask through phone for a new connection to some service and block until 1132 * success. 1133 * 1134 * @param phoneid Phone handle used for contacting the other side. 1135 * @param arg1 User defined argument. 1136 * @param arg2 User defined argument. 1137 * @param arg3 User defined argument. 1138 * 1139 * @return New phone handle on success or a negative error code. 1140 */ 1141 int 1142 async_connect_me_to_blocking(int phoneid, ipcarg_t arg1, ipcarg_t arg2, 1143 ipcarg_t arg3) 1144 { 1145 int rc; 1146 ipcarg_t newphid; 1147 1148 rc = async_req_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, 1149 IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid); 1150 1151 if (rc != EOK) 1152 return rc; 1153 1154 return newphid; 1155 } 1156 1103 1157 /** Wrapper for making IPC_M_SHARE_IN calls using the async framework. 1104 1158 * … … 1287 1341 } 1288 1342 1343 /** Wrapper for forwarding any read request 1344 * 1345 * 1346 */ 1347 int async_data_read_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1, 1348 ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipc_call_t *dataptr) 1349 { 1350 ipc_callid_t callid; 1351 if (!async_data_read_receive(&callid, NULL)) { 1352 ipc_answer_0(callid, EINVAL); 1353 return EINVAL; 1354 } 1355 1356 aid_t msg = async_send_fast(phoneid, method, arg1, arg2, arg3, arg4, 1357 dataptr); 1358 if (msg == 0) { 1359 ipc_answer_0(callid, EINVAL); 1360 return EINVAL; 1361 } 1362 1363 int retval = ipc_forward_fast(callid, phoneid, 0, 0, 0, 1364 IPC_FF_ROUTE_FROM_ME); 1365 if (retval != EOK) { 1366 async_wait_for(msg, NULL); 1367 ipc_answer_0(callid, retval); 1368 return retval; 1369 } 1370 1371 ipcarg_t rc; 1372 async_wait_for(msg, &rc); 1373 1374 return (int) rc; 1375 } 1376 1289 1377 /** Wrapper for making IPC_M_DATA_WRITE calls using the async framework. 1290 1378 * 1291 * @param phoneid Phone that will be used to contact the receiving side. 1292 * @param src Address of the beginning of the source buffer. 1293 * @param size Size of the source buffer. 1294 * 1295 * @return Zero on success or a negative error code from errno.h. 1379 * @param phoneid Phone that will be used to contact the receiving side. 1380 * @param src Address of the beginning of the source buffer. 1381 * @param size Size of the source buffer. 1382 * 1383 * @return Zero on success or a negative error code from errno.h. 1384 * 1296 1385 */ 1297 1386 int async_data_write_start(int phoneid, const void *src, size_t size) … … 1308 1397 * So far, this wrapper is to be used from within a connection fibril. 1309 1398 * 1310 * @param callid Storage where the hash of the IPC_M_DATA_WRITE call will 1311 * be stored. 1312 * @param size Storage where the suggested size will be stored. May be 1313 * NULL 1314 * 1315 * @return Non-zero on success, zero on failure. 1399 * @param callid Storage where the hash of the IPC_M_DATA_WRITE call will 1400 * be stored. 1401 * @param size Storage where the suggested size will be stored. May be 1402 * NULL 1403 * 1404 * @return Non-zero on success, zero on failure. 1405 * 1316 1406 */ 1317 1407 int async_data_write_receive(ipc_callid_t *callid, size_t *size) … … 1320 1410 1321 1411 assert(callid); 1322 1412 1323 1413 *callid = async_get_call(&data); 1324 1414 if (IPC_GET_METHOD(data) != IPC_M_DATA_WRITE) 1325 1415 return 0; 1416 1326 1417 if (size) 1327 1418 *size = (size_t) IPC_GET_ARG2(data); 1419 1328 1420 return 1; 1329 1421 } … … 1334 1426 * so that the user doesn't have to remember the meaning of each IPC argument. 1335 1427 * 1336 * @param callid Hash of the IPC_M_DATA_WRITE call to answer. 1337 * @param dst Final destination address for the IPC_M_DATA_WRITE call. 1338 * @param size Final size for the IPC_M_DATA_WRITE call. 1339 * 1340 * @return Zero on success or a value from @ref errno.h on failure. 1428 * @param callid Hash of the IPC_M_DATA_WRITE call to answer. 1429 * @param dst Final destination address for the IPC_M_DATA_WRITE call. 1430 * @param size Final size for the IPC_M_DATA_WRITE call. 1431 * 1432 * @return Zero on success or a value from @ref errno.h on failure. 1433 * 1341 1434 */ 1342 1435 int async_data_write_finalize(ipc_callid_t callid, void *dst, size_t size) … … 1345 1438 } 1346 1439 1440 /** Wrapper for receiving binary data or strings 1441 * 1442 * This wrapper only makes it more comfortable to use async_data_write_* 1443 * functions to receive binary data or strings. 1444 * 1445 * @param data Pointer to data pointer (which should be later disposed 1446 * by free()). If the operation fails, the pointer is not 1447 * touched. 1448 * @param nullterm If true then the received data is always zero terminated. 1449 * This also causes to allocate one extra byte beyond the 1450 * raw transmitted data. 1451 * @param min_size Minimum size (in bytes) of the data to receive. 1452 * @param max_size Maximum size (in bytes) of the data to receive. 0 means 1453 * no limit. 1454 * @param granulariy If non-zero then the size of the received data has to 1455 * be divisible by this value. 1456 * @param received If not NULL, the size of the received data is stored here. 1457 * 1458 * @return Zero on success or a value from @ref errno.h on failure. 1459 * 1460 */ 1461 int async_data_write_accept(void **data, const bool nullterm, 1462 const size_t min_size, const size_t max_size, const size_t granularity, 1463 size_t *received) 1464 { 1465 ipc_callid_t callid; 1466 size_t size; 1467 if (!async_data_write_receive(&callid, &size)) { 1468 ipc_answer_0(callid, EINVAL); 1469 return EINVAL; 1470 } 1471 1472 if (size < min_size) { 1473 ipc_answer_0(callid, EINVAL); 1474 return EINVAL; 1475 } 1476 1477 if ((max_size > 0) && (size > max_size)) { 1478 ipc_answer_0(callid, EINVAL); 1479 return EINVAL; 1480 } 1481 1482 if ((granularity > 0) && ((size % granularity) != 0)) { 1483 ipc_answer_0(callid, EINVAL); 1484 return EINVAL; 1485 } 1486 1487 void *_data; 1488 1489 if (nullterm) 1490 _data = malloc(size + 1); 1491 else 1492 _data = malloc(size); 1493 1494 if (_data == NULL) { 1495 ipc_answer_0(callid, ENOMEM); 1496 return ENOMEM; 1497 } 1498 1499 int rc = async_data_write_finalize(callid, _data, size); 1500 if (rc != EOK) { 1501 free(_data); 1502 return rc; 1503 } 1504 1505 if (nullterm) 1506 ((char *) _data)[size] = 0; 1507 1508 *data = _data; 1509 if (received != NULL) 1510 *received = size; 1511 1512 return EOK; 1513 } 1514 1515 /** Wrapper for voiding any data that is about to be received 1516 * 1517 * This wrapper can be used to void any pending data 1518 * 1519 * @param retval Error value from @ref errno.h to be returned to the caller. 1520 * 1521 */ 1522 void async_data_write_void(const int retval) 1523 { 1524 ipc_callid_t callid; 1525 async_data_write_receive(&callid, NULL); 1526 ipc_answer_0(callid, retval); 1527 } 1528 1529 /** Wrapper for forwarding any data that is about to be received 1530 * 1531 * 1532 */ 1533 int async_data_write_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1, 1534 ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipc_call_t *dataptr) 1535 { 1536 ipc_callid_t callid; 1537 if (!async_data_write_receive(&callid, NULL)) { 1538 ipc_answer_0(callid, EINVAL); 1539 return EINVAL; 1540 } 1541 1542 aid_t msg = async_send_fast(phoneid, method, arg1, arg2, arg3, arg4, 1543 dataptr); 1544 if (msg == 0) { 1545 ipc_answer_0(callid, EINVAL); 1546 return EINVAL; 1547 } 1548 1549 int retval = ipc_forward_fast(callid, phoneid, 0, 0, 0, 1550 IPC_FF_ROUTE_FROM_ME); 1551 if (retval != EOK) { 1552 async_wait_for(msg, NULL); 1553 ipc_answer_0(callid, retval); 1554 return retval; 1555 } 1556 1557 ipcarg_t rc; 1558 async_wait_for(msg, &rc); 1559 1560 return (int) rc; 1561 } 1562 1347 1563 /** @} 1348 1564 */ -
uspace/lib/c/generic/devmap.c
rcd82bb1 r371bd7d 28 28 */ 29 29 30 #include <str ing.h>30 #include <str.h> 31 31 #include <ipc/ipc.h> 32 32 #include <ipc/services.h> … … 35 35 #include <async.h> 36 36 #include <errno.h> 37 #include <malloc.h> 38 #include <bool.h> 37 39 38 40 static int devmap_phone_driver = -1; … … 105 107 aid_t req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer); 106 108 107 ipcarg_t retval = async_data_write_start(phone, name, str_size(name) + 1); 108 109 ipcarg_t retval = async_data_write_start(phone, name, str_size(name)); 109 110 if (retval != EOK) { 110 111 async_wait_for(req, NULL); … … 126 127 /** Register new device. 127 128 * 128 * @param name Device name. 129 * @param handle Output: Handle to the created instance of device. 129 * @param namespace Namespace name. 130 * @param fqdn Fully qualified device name. 131 * @param handle Output: Handle to the created instance of device. 130 132 * 131 133 */ 132 int devmap_device_register(const char * name, dev_handle_t *handle)134 int devmap_device_register(const char *fqdn, dev_handle_t *handle) 133 135 { 134 136 int phone = devmap_get_phone(DEVMAP_DRIVER, IPC_FLAG_BLOCKING); … … 143 145 &answer); 144 146 145 ipcarg_t retval = async_data_write_start(phone, name, str_size(name) + 1); 146 147 ipcarg_t retval = async_data_write_start(phone, fqdn, str_size(fqdn)); 147 148 if (retval != EOK) { 148 149 async_wait_for(req, NULL); … … 167 168 } 168 169 169 int devmap_device_get_handle(const char * name, dev_handle_t *handle, unsigned int flags)170 int devmap_device_get_handle(const char *fqdn, dev_handle_t *handle, unsigned int flags) 170 171 { 171 172 int phone = devmap_get_phone(DEVMAP_CLIENT, flags); … … 180 181 &answer); 181 182 182 ipcarg_t retval = async_data_write_start(phone, name, str_size(name) + 1); 183 183 ipcarg_t retval = async_data_write_start(phone, fqdn, str_size(fqdn)); 184 184 if (retval != EOK) { 185 185 async_wait_for(req, NULL); … … 202 202 203 203 return retval; 204 } 205 206 int devmap_namespace_get_handle(const char *name, dev_handle_t *handle, unsigned int flags) 207 { 208 int phone = devmap_get_phone(DEVMAP_CLIENT, flags); 209 210 if (phone < 0) 211 return phone; 212 213 async_serialize_start(); 214 215 ipc_call_t answer; 216 aid_t req = async_send_2(phone, DEVMAP_NAMESPACE_GET_HANDLE, flags, 0, 217 &answer); 218 219 ipcarg_t retval = async_data_write_start(phone, name, str_size(name)); 220 if (retval != EOK) { 221 async_wait_for(req, NULL); 222 async_serialize_end(); 223 return retval; 224 } 225 226 async_wait_for(req, &retval); 227 228 async_serialize_end(); 229 230 if (retval != EOK) { 231 if (handle != NULL) 232 *handle = (dev_handle_t) -1; 233 return retval; 234 } 235 236 if (handle != NULL) 237 *handle = (dev_handle_t) IPC_GET_ARG1(answer); 238 239 return retval; 240 } 241 242 devmap_handle_type_t devmap_handle_probe(dev_handle_t handle) 243 { 244 int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING); 245 246 if (phone < 0) 247 return phone; 248 249 ipcarg_t type; 250 int retval = async_req_1_1(phone, DEVMAP_HANDLE_PROBE, handle, &type); 251 if (retval != EOK) 252 return DEV_HANDLE_NONE; 253 254 return (devmap_handle_type_t) type; 204 255 } 205 256 … … 227 278 228 279 ipcarg_t null_id; 229 int retval = async_req_0_1(phone, DEVMAP_ DEVICE_NULL_CREATE, &null_id);280 int retval = async_req_0_1(phone, DEVMAP_NULL_CREATE, &null_id); 230 281 if (retval != EOK) 231 282 return -1; … … 241 292 return; 242 293 243 async_req_1_0(phone, DEVMAP_DEVICE_NULL_DESTROY, (ipcarg_t) null_id); 244 } 245 246 ipcarg_t devmap_device_get_count(void) 247 { 248 int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING); 249 250 if (phone < 0) 251 return 0; 252 294 async_req_1_0(phone, DEVMAP_NULL_DESTROY, (ipcarg_t) null_id); 295 } 296 297 static size_t devmap_count_namespaces_internal(int phone) 298 { 253 299 ipcarg_t count; 254 int retval = async_req_0_1(phone, DEVMAP_ DEVICE_GET_COUNT, &count);300 int retval = async_req_0_1(phone, DEVMAP_GET_NAMESPACE_COUNT, &count); 255 301 if (retval != EOK) 256 302 return 0; … … 259 305 } 260 306 261 ipcarg_t devmap_device_get_devices(ipcarg_t count, dev_desc_t *data) 262 { 263 int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING); 264 265 if (phone < 0) 266 return 0; 267 268 async_serialize_start(); 269 270 ipc_call_t answer; 271 aid_t req = async_send_0(phone, DEVMAP_DEVICE_GET_DEVICES, &answer); 272 273 ipcarg_t retval = async_data_read_start(phone, data, count * sizeof(dev_desc_t)); 274 275 if (retval != EOK) { 276 async_wait_for(req, NULL); 277 async_serialize_end(); 278 return 0; 279 } 280 281 async_wait_for(req, &retval); 282 283 async_serialize_end(); 284 307 static size_t devmap_count_devices_internal(int phone, dev_handle_t ns_handle) 308 { 309 ipcarg_t count; 310 int retval = async_req_1_1(phone, DEVMAP_GET_DEVICE_COUNT, ns_handle, &count); 285 311 if (retval != EOK) 286 312 return 0; 287 313 288 return IPC_GET_ARG1(answer); 289 } 314 return count; 315 } 316 317 size_t devmap_count_namespaces(void) 318 { 319 int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING); 320 321 if (phone < 0) 322 return 0; 323 324 return devmap_count_namespaces_internal(phone); 325 } 326 327 size_t devmap_count_devices(dev_handle_t ns_handle) 328 { 329 int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING); 330 331 if (phone < 0) 332 return 0; 333 334 return devmap_count_devices_internal(phone, ns_handle); 335 } 336 337 size_t devmap_get_namespaces(dev_desc_t **data) 338 { 339 int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING); 340 341 if (phone < 0) 342 return 0; 343 344 /* Loop until namespaces read succesful */ 345 while (true) { 346 size_t count = devmap_count_namespaces_internal(phone); 347 if (count == 0) 348 return 0; 349 350 dev_desc_t *devs = (dev_desc_t *) calloc(count, sizeof(dev_desc_t)); 351 if (devs == NULL) 352 return 0; 353 354 async_serialize_start(); 355 356 ipc_call_t answer; 357 aid_t req = async_send_0(phone, DEVMAP_GET_NAMESPACES, &answer); 358 359 int rc = async_data_read_start(phone, devs, count * sizeof(dev_desc_t)); 360 if (rc == EOVERFLOW) { 361 /* 362 * Number of namespaces has changed since 363 * the last call of DEVMAP_DEVICE_GET_NAMESPACE_COUNT 364 */ 365 async_serialize_end(); 366 free(devs); 367 continue; 368 } 369 370 if (rc != EOK) { 371 async_wait_for(req, NULL); 372 async_serialize_end(); 373 free(devs); 374 return 0; 375 } 376 377 ipcarg_t retval; 378 async_wait_for(req, &retval); 379 async_serialize_end(); 380 381 if (retval != EOK) 382 return 0; 383 384 *data = devs; 385 return count; 386 } 387 } 388 389 size_t devmap_get_devices(dev_handle_t ns_handle, dev_desc_t **data) 390 { 391 int phone = devmap_get_phone(DEVMAP_CLIENT, IPC_FLAG_BLOCKING); 392 393 if (phone < 0) 394 return 0; 395 396 /* Loop until namespaces read succesful */ 397 while (true) { 398 size_t count = devmap_count_devices_internal(phone, ns_handle); 399 if (count == 0) 400 return 0; 401 402 dev_desc_t *devs = (dev_desc_t *) calloc(count, sizeof(dev_desc_t)); 403 if (devs == NULL) 404 return 0; 405 406 async_serialize_start(); 407 408 ipc_call_t answer; 409 aid_t req = async_send_1(phone, DEVMAP_GET_DEVICES, ns_handle, &answer); 410 411 int rc = async_data_read_start(phone, devs, count * sizeof(dev_desc_t)); 412 if (rc == EOVERFLOW) { 413 /* 414 * Number of devices has changed since 415 * the last call of DEVMAP_DEVICE_GET_DEVICE_COUNT 416 */ 417 async_serialize_end(); 418 free(devs); 419 continue; 420 } 421 422 if (rc != EOK) { 423 async_wait_for(req, NULL); 424 async_serialize_end(); 425 free(devs); 426 return 0; 427 } 428 429 ipcarg_t retval; 430 async_wait_for(req, &retval); 431 async_serialize_end(); 432 433 if (retval != EOK) 434 return 0; 435 436 *data = devs; 437 return count; 438 } 439 } -
uspace/lib/c/generic/fibril.c
rcd82bb1 r371bd7d 41 41 #include <unistd.h> 42 42 #include <stdio.h> 43 #include <arch/barrier.h> 43 44 #include <libarch/faddr.h> 44 45 #include <futex.h> … … 133 134 int fibril_switch(fibril_switch_type_t stype) 134 135 { 135 fibril_t *srcf, *dstf;136 136 int retval = 0; 137 137 138 138 futex_down(&fibril_futex); 139 139 140 140 if (stype == FIBRIL_PREEMPT && list_empty(&ready_list)) 141 141 goto ret_0; 142 142 143 143 if (stype == FIBRIL_FROM_MANAGER) { 144 if ( list_empty(&ready_list) && list_empty(&serialized_list))144 if ((list_empty(&ready_list)) && (list_empty(&serialized_list))) 145 145 goto ret_0; 146 146 147 /* 147 148 * Do not preempt if there is not enough threads to run the 148 149 * ready fibrils which are not serialized. 149 150 */ 150 if ( list_empty(&serialized_list) &&151 threads_in_manager <= serialized_threads) {151 if ((list_empty(&serialized_list)) && 152 (threads_in_manager <= serialized_threads)) { 152 153 goto ret_0; 153 154 } 154 155 } 156 155 157 /* If we are going to manager and none exists, create it */ 156 if ( stype == FIBRIL_TO_MANAGER || stype == FIBRIL_FROM_DEAD) {158 if ((stype == FIBRIL_TO_MANAGER) || (stype == FIBRIL_FROM_DEAD)) { 157 159 while (list_empty(&manager_list)) { 158 160 futex_up(&fibril_futex); … … 162 164 } 163 165 164 srcf = __tcb_get()->fibril_data;166 fibril_t *srcf = __tcb_get()->fibril_data; 165 167 if (stype != FIBRIL_FROM_DEAD) { 168 166 169 /* Save current state */ 167 170 if (!context_save(&srcf->ctx)) { 168 171 if (serialization_count) 169 172 srcf->flags &= ~FIBRIL_SERIALIZED; 173 170 174 if (srcf->clean_after_me) { 171 175 /* … … 173 177 * restored context here. 174 178 */ 175 void *stack = srcf->clean_after_me->stack; 179 void *stack = srcf->clean_after_me->stack; 176 180 if (stack) { 177 181 /* … … 188 192 srcf->clean_after_me = NULL; 189 193 } 194 190 195 return 1; /* futex_up already done here */ 191 196 } 192 197 193 198 /* Save myself to the correct run list */ 194 199 if (stype == FIBRIL_PREEMPT) … … 197 202 list_append(&srcf->link, &manager_list); 198 203 threads_in_manager--; 199 } else { 204 } else { 200 205 /* 201 206 * If stype == FIBRIL_TO_MANAGER, don't put ourselves to … … 207 212 208 213 /* Choose a new fibril to run */ 209 if (stype == FIBRIL_TO_MANAGER || stype == FIBRIL_FROM_DEAD) { 214 fibril_t *dstf; 215 if ((stype == FIBRIL_TO_MANAGER) || (stype == FIBRIL_FROM_DEAD)) { 210 216 dstf = list_get_instance(manager_list.next, fibril_t, link); 211 217 if (serialization_count && stype == FIBRIL_TO_MANAGER) { … … 214 220 } 215 221 threads_in_manager++; 216 222 217 223 if (stype == FIBRIL_FROM_DEAD) 218 224 dstf->clean_after_me = srcf; … … 228 234 } 229 235 list_remove(&dstf->link); 230 236 231 237 futex_up(&fibril_futex); 232 238 context_restore(&dstf->ctx); 233 239 /* not reached */ 234 240 235 241 ret_0: 236 242 futex_up(&fibril_futex); -
uspace/lib/c/generic/fibril_synch.c
rcd82bb1 r371bd7d 33 33 */ 34 34 35 #include <fibril_sync .h>35 #include <fibril_synch.h> 36 36 #include <fibril.h> 37 37 #include <async.h> -
uspace/lib/c/generic/getopt.c
rcd82bb1 r371bd7d 38 38 #include <getopt.h> 39 39 #include <stdlib.h> 40 #include <str ing.h>40 #include <str.h> 41 41 42 42 /* HelenOS Port : We're incorporating only the modern getopt_long with wrappers -
uspace/lib/c/generic/io/asprintf.c
rcd82bb1 r371bd7d 37 37 #include <stdio.h> 38 38 #include <stdlib.h> 39 #include <str ing.h>39 #include <str.h> 40 40 #include <io/printf_core.h> 41 41 -
uspace/lib/c/generic/io/io.c
rcd82bb1 r371bd7d 37 37 #include <fcntl.h> 38 38 #include <assert.h> 39 #include <str ing.h>39 #include <str.h> 40 40 #include <errno.h> 41 41 #include <bool.h> … … 46 46 #include <adt/list.h> 47 47 48 static void _ffillbuf(FILE *stream); 48 49 static void _fflushbuf(FILE *stream); 49 50 … … 57 58 .buf = NULL, 58 59 .buf_size = 0, 59 .buf_head = NULL 60 .buf_head = NULL, 61 .buf_tail = NULL, 62 .buf_state = _bs_empty 60 63 }; 61 64 … … 69 72 .buf = NULL, 70 73 .buf_size = BUFSIZ, 71 .buf_head = NULL 74 .buf_head = NULL, 75 .buf_tail = NULL, 76 .buf_state = _bs_empty 72 77 }; 73 78 … … 81 86 .buf = NULL, 82 87 .buf_size = 0, 83 .buf_head = NULL 88 .buf_head = NULL, 89 .buf_tail = NULL, 90 .buf_state = _bs_empty 84 91 }; 85 92 … … 179 186 stream->buf_size = size; 180 187 stream->buf_head = stream->buf; 188 stream->buf_tail = stream->buf; 189 stream->buf_state = _bs_empty; 181 190 } 182 191 … … 210 219 211 220 stream->buf_head = stream->buf; 221 stream->buf_tail = stream->buf; 212 222 return 0; 213 223 } … … 243 253 stream->klog = false; 244 254 stream->phone = -1; 255 stream->need_sync = false; 245 256 _setvbuf(stream); 246 257 … … 264 275 stream->klog = false; 265 276 stream->phone = -1; 277 stream->need_sync = false; 266 278 _setvbuf(stream); 267 279 … … 295 307 stream->klog = false; 296 308 stream->phone = -1; 309 stream->need_sync = false; 297 310 _setvbuf(stream); 298 311 … … 331 344 } 332 345 333 /** Read from a stream .346 /** Read from a stream (unbuffered). 334 347 * 335 348 * @param buf Destination buffer. … … 337 350 * @param nmemb Number of records to read. 338 351 * @param stream Pointer to the stream. 339 * 340 */ 341 size_t fread(void *buf, size_t size, size_t nmemb, FILE *stream) 342 { 343 size_t left = size * nmemb; 344 size_t done = 0; 345 346 /* Make sure no data is pending write. */ 347 _fflushbuf(stream); 352 */ 353 static size_t _fread(void *buf, size_t size, size_t nmemb, FILE *stream) 354 { 355 size_t left, done; 356 357 if (size == 0 || nmemb == 0) 358 return 0; 359 360 left = size * nmemb; 361 done = 0; 348 362 349 363 while ((left > 0) && (!stream->error) && (!stream->eof)) { … … 363 377 } 364 378 379 /** Write to a stream (unbuffered). 380 * 381 * @param buf Source buffer. 382 * @param size Size of each record. 383 * @param nmemb Number of records to write. 384 * @param stream Pointer to the stream. 385 */ 365 386 static size_t _fwrite(const void *buf, size_t size, size_t nmemb, FILE *stream) 366 387 { 367 size_t left = size * nmemb; 368 size_t done = 0; 369 388 size_t left; 389 size_t done; 390 391 if (size == 0 || nmemb == 0) 392 return 0; 393 394 left = size * nmemb; 395 done = 0; 396 370 397 while ((left > 0) && (!stream->error)) { 371 398 ssize_t wr; … … 383 410 } 384 411 } 412 413 if (done > 0) 414 stream->need_sync = true; 385 415 386 416 return (done / size); 387 417 } 388 418 389 /** Drain stream buffer, do not sync stream. */ 419 /** Read some data in stream buffer. */ 420 static void _ffillbuf(FILE *stream) 421 { 422 ssize_t rc; 423 424 stream->buf_head = stream->buf_tail = stream->buf; 425 426 rc = read(stream->fd, stream->buf, stream->buf_size); 427 if (rc < 0) { 428 stream->error = true; 429 return; 430 } 431 432 if (rc == 0) { 433 stream->eof = true; 434 return; 435 } 436 437 stream->buf_head += rc; 438 stream->buf_state = _bs_read; 439 } 440 441 /** Write out stream buffer, do not sync stream. */ 390 442 static void _fflushbuf(FILE *stream) 391 443 { 392 444 size_t bytes_used; 393 445 394 446 if ((!stream->buf) || (stream->btype == _IONBF) || (stream->error)) 395 447 return; 396 397 bytes_used = stream->buf_head - stream->buf ;448 449 bytes_used = stream->buf_head - stream->buf_tail; 398 450 if (bytes_used == 0) 399 451 return; 400 401 (void) _fwrite(stream->buf, 1, bytes_used, stream); 452 453 /* If buffer has prefetched read data, we need to seek back. */ 454 if (stream->buf_state == _bs_read) 455 lseek(stream->fd, - (ssize_t) bytes_used, SEEK_CUR); 456 457 /* If buffer has unwritten data, we need to write them out. */ 458 if (stream->buf_state == _bs_write) 459 (void) _fwrite(stream->buf_tail, 1, bytes_used, stream); 460 402 461 stream->buf_head = stream->buf; 403 } 462 stream->buf_tail = stream->buf; 463 stream->buf_state = _bs_empty; 464 } 465 466 /** Read from a stream. 467 * 468 * @param dest Destination buffer. 469 * @param size Size of each record. 470 * @param nmemb Number of records to read. 471 * @param stream Pointer to the stream. 472 * 473 */ 474 size_t fread(void *dest, size_t size, size_t nmemb, FILE *stream) 475 { 476 uint8_t *dp; 477 size_t bytes_left; 478 size_t now; 479 size_t data_avail; 480 size_t total_read; 481 size_t i; 482 483 if (size == 0 || nmemb == 0) 484 return 0; 485 486 /* If not buffered stream, read in directly. */ 487 if (stream->btype == _IONBF) { 488 now = _fread(dest, size, nmemb, stream); 489 return now; 490 } 491 492 /* Make sure no data is pending write. */ 493 if (stream->buf_state == _bs_write) 494 _fflushbuf(stream); 495 496 /* Perform lazy allocation of stream buffer. */ 497 if (stream->buf == NULL) { 498 if (_fallocbuf(stream) != 0) 499 return 0; /* Errno set by _fallocbuf(). */ 500 } 501 502 bytes_left = size * nmemb; 503 total_read = 0; 504 dp = (uint8_t *) dest; 505 506 while ((!stream->error) && (!stream->eof) && (bytes_left > 0)) { 507 if (stream->buf_head == stream->buf_tail) 508 _ffillbuf(stream); 509 510 if (stream->error || stream->eof) 511 break; 512 513 data_avail = stream->buf_head - stream->buf_tail; 514 515 if (bytes_left > data_avail) 516 now = data_avail; 517 else 518 now = bytes_left; 519 520 for (i = 0; i < now; i++) { 521 dp[i] = stream->buf_tail[i]; 522 } 523 524 dp += now; 525 stream->buf_tail += now; 526 bytes_left -= now; 527 total_read += now; 528 } 529 530 return (total_read / size); 531 } 532 404 533 405 534 /** Write to a stream. … … 421 550 uint8_t b; 422 551 bool need_flush; 423 552 553 if (size == 0 || nmemb == 0) 554 return 0; 555 424 556 /* If not buffered stream, write out directly. */ 425 557 if (stream->btype == _IONBF) { … … 428 560 return now; 429 561 } 430 562 563 /* Make sure buffer contains no prefetched data. */ 564 if (stream->buf_state == _bs_read) 565 _fflushbuf(stream); 566 567 431 568 /* Perform lazy allocation of stream buffer. */ 432 569 if (stream->buf == NULL) { … … 468 605 } 469 606 607 if (total_written > 0) 608 stream->buf_state = _bs_write; 609 470 610 if (need_flush) 471 611 fflush(stream); … … 522 662 } 523 663 664 char *fgets(char *str, int size, FILE *stream) 665 { 666 int c; 667 int idx; 668 669 idx = 0; 670 while (idx < size - 1) { 671 c = fgetc(stream); 672 if (c == EOF) 673 break; 674 675 str[idx++] = c; 676 677 if (c == '\n') 678 break; 679 } 680 681 if (ferror(stream)) 682 return NULL; 683 684 if (idx == 0) 685 return NULL; 686 687 str[idx] = '\0'; 688 return str; 689 } 690 524 691 int getchar(void) 525 692 { … … 527 694 } 528 695 529 int fseek(FILE *stream, long offset, int origin) 530 { 531 off_t rc = lseek(stream->fd, offset, origin); 532 if (rc == (off_t) (-1)) { 533 /* errno has been set by lseek. */ 696 int fseek(FILE *stream, off64_t offset, int whence) 697 { 698 off64_t rc; 699 700 _fflushbuf(stream); 701 702 rc = lseek(stream->fd, offset, whence); 703 if (rc == (off64_t) (-1)) { 704 /* errno has been set by lseek64. */ 534 705 return -1; 535 706 } 536 707 537 708 stream->eof = false; 538 539 709 return 0; 710 } 711 712 off64_t ftell(FILE *stream) 713 { 714 return lseek(stream->fd, 0, SEEK_CUR); 540 715 } 541 716 … … 554 729 } 555 730 556 if (stream->fd >= 0) 731 if (stream->fd >= 0 && stream->need_sync) { 732 /** 733 * Better than syncing always, but probably still not the 734 * right thing to do. 735 */ 736 stream->need_sync = false; 557 737 return fsync(stream->fd); 738 } 558 739 559 740 return ENOENT; … … 568 749 { 569 750 return stream->error; 751 } 752 753 void clearerr(FILE *stream) 754 { 755 stream->eof = false; 756 stream->error = false; 570 757 } 571 758 -
uspace/lib/c/generic/io/klog.c
rcd82bb1 r371bd7d 35 35 36 36 #include <libc.h> 37 #include <str ing.h>37 #include <str.h> 38 38 #include <sys/types.h> 39 39 #include <unistd.h> -
uspace/lib/c/generic/io/printf_core.c
rcd82bb1 r371bd7d 41 41 #include <io/printf_core.h> 42 42 #include <ctype.h> 43 #include <str ing.h>43 #include <str.h> 44 44 45 45 /** show prefixes 0x or 0 */ -
uspace/lib/c/generic/io/vprintf.c
rcd82bb1 r371bd7d 39 39 #include <futex.h> 40 40 #include <async.h> 41 #include <str ing.h>41 #include <str.h> 42 42 43 43 static atomic_t printf_futex = FUTEX_INITIALIZER; -
uspace/lib/c/generic/io/vsnprintf.c
rcd82bb1 r371bd7d 35 35 #include <stdarg.h> 36 36 #include <stdio.h> 37 #include <str ing.h>37 #include <str.h> 38 38 #include <io/printf_core.h> 39 39 #include <errno.h> -
uspace/lib/c/generic/ipc.c
rcd82bb1 r371bd7d 728 728 int *flags) 729 729 { 730 int res; 731 sysarg_t tmp_flags; 732 res = ipc_call_sync_3_2(phoneid, IPC_M_SHARE_IN, (ipcarg_t) dst, 730 sysarg_t tmp_flags = 0; 731 int res = ipc_call_sync_3_2(phoneid, IPC_M_SHARE_IN, (ipcarg_t) dst, 733 732 (ipcarg_t) size, arg, NULL, &tmp_flags); 733 734 734 if (flags) 735 735 *flags = tmp_flags; 736 736 737 return res; 737 738 } -
uspace/lib/c/generic/loader.c
rcd82bb1 r371bd7d 38 38 #include <libc.h> 39 39 #include <task.h> 40 #include <str ing.h>40 #include <str.h> 41 41 #include <stdlib.h> 42 42 #include <async.h> … … 183 183 * 184 184 */ 185 int loader_set_args(loader_t *ldr, c har *const argv[])185 int loader_set_args(loader_t *ldr, const char *const argv[]) 186 186 { 187 187 /* … … 189 189 * compute size of the buffer needed. 190 190 */ 191 c har *const *ap = argv;191 const char *const *ap = argv; 192 192 size_t buffer_size = 0; 193 193 while (*ap != NULL) { -
uspace/lib/c/generic/malloc.c
rcd82bb1 r371bd7d 164 164 { 165 165 if (size == 0) 166 return false; 167 168 if ((heap_start + size < heap_start) || (heap_end + size < heap_end)) 166 169 return false; 167 170 -
uspace/lib/c/generic/mman.c
rcd82bb1 r371bd7d 39 39 40 40 void *mmap(void *start, size_t length, int prot, int flags, int fd, 41 off_t offset)41 aoff64_t offset) 42 42 { 43 43 if (!start) -
uspace/lib/c/generic/str.c
rcd82bb1 r371bd7d 34 34 */ 35 35 36 #include <str ing.h>36 #include <str.h> 37 37 #include <stdlib.h> 38 38 #include <assert.h> … … 43 43 #include <align.h> 44 44 #include <mem.h> 45 #include <str ing.h>45 #include <str.h> 46 46 47 47 /** Byte mask consisting of lowest @n bits (out of 8) */ … … 896 896 } 897 897 898 char *str_dup(const char *src) 899 { 900 size_t size = str_size(src); 901 void *dest = malloc(size + 1); 902 903 if (dest == NULL) 904 return (char *) NULL; 905 906 return (char *) memcpy(dest, src, size + 1); 907 } 908 909 char *str_ndup(const char *src, size_t max_size) 910 { 911 size_t size = str_size(src); 912 if (size > max_size) 913 size = max_size; 914 915 char *dest = (char *) malloc(size + 1); 916 917 if (dest == NULL) 918 return (char *) NULL; 919 920 memcpy(dest, src, size); 921 dest[size] = 0; 922 return dest; 923 } 924 898 925 899 926 /** Convert initial part of string to unsigned long according to given base. … … 920 947 } 921 948 922 char *str_dup(const char *src)923 {924 size_t size = str_size(src);925 void *dest = malloc(size + 1);926 927 if (dest == NULL)928 return (char *) NULL;929 930 return (char *) memcpy(dest, src, size + 1);931 }932 933 949 char *strtok(char *s, const char *delim) 934 950 { -
uspace/lib/c/generic/sysinfo.c
rcd82bb1 r371bd7d 35 35 #include <libc.h> 36 36 #include <sysinfo.h> 37 #include <str ing.h>37 #include <str.h> 38 38 39 sysarg_t sysinfo_value(c har *name)39 sysarg_t sysinfo_value(const char *name) 40 40 { 41 return __SYSCALL2(SYS_SYSINFO_VALUE, (sysarg_t ) name,41 return __SYSCALL2(SYS_SYSINFO_VALUE, (sysarg_t) name, 42 42 (sysarg_t) str_size(name)); 43 43 } -
uspace/lib/c/generic/task.c
rcd82bb1 r371bd7d 39 39 #include <errno.h> 40 40 #include <loader/loader.h> 41 #include <str ing.h>41 #include <str.h> 42 42 #include <ipc/ns.h> 43 43 #include <macros.h> … … 76 76 * 77 77 */ 78 task_id_t task_spawn(const char *path, c har *const args[])78 task_id_t task_spawn(const char *path, const char *const args[]) 79 79 { 80 80 /* Connect to a program loader. */ -
uspace/lib/c/generic/thread.c
rcd82bb1 r371bd7d 39 39 #include <kernel/proc/uarg.h> 40 40 #include <fibril.h> 41 #include <str ing.h>41 #include <str.h> 42 42 #include <async.h> 43 43 … … 86 86 * @return Zero on success or a code from @ref errno.h on failure. 87 87 */ 88 int thread_create(void (* function)(void *), void *arg, c har *name,88 int thread_create(void (* function)(void *), void *arg, const char *name, 89 89 thread_id_t *tid) 90 90 { -
uspace/lib/c/generic/time.c
rcd82bb1 r371bd7d 31 31 */ 32 32 /** @file 33 */ 33 */ 34 34 35 35 #include <sys/time.h> … … 40 40 #include <unistd.h> 41 41 #include <atomic.h> 42 #include <futex.h>43 42 #include <sysinfo.h> 44 43 #include <ipc/services.h> 44 #include <libc.h> 45 45 46 46 #include <sysinfo.h> … … 189 189 190 190 /** Wait unconditionally for specified number of microseconds */ 191 int usleep(unsigned long usec) 192 { 193 atomic_t futex = FUTEX_INITIALIZER; 194 195 futex_initialize(&futex, 0); 196 futex_down_timeout(&futex, usec, 0); 191 int usleep(useconds_t usec) 192 { 193 (void) __SYSCALL1(SYS_THREAD_USLEEP, usec); 197 194 return 0; 198 195 } 199 196 200 197 /** Wait unconditionally for specified number of seconds */ 201 unsigned int sleep(unsigned int seconds) 202 { 203 atomic_t futex = FUTEX_INITIALIZER; 204 205 futex_initialize(&futex, 0); 206 198 unsigned int sleep(unsigned int sec) 199 { 207 200 /* Sleep in 1000 second steps to support 208 201 full argument range */ 209 while (sec onds> 0) {210 unsigned int period = (sec onds > 1000) ? 1000 : seconds;202 while (sec > 0) { 203 unsigned int period = (sec > 1000) ? 1000 : sec; 211 204 212 futex_down_timeout(&futex, period * 1000000,0);213 sec onds-= period;205 usleep(period * 1000000); 206 sec -= period; 214 207 } 215 208 return 0; -
uspace/lib/c/generic/tls.c
rcd82bb1 r371bd7d 40 40 #include <tls.h> 41 41 #include <malloc.h> 42 #include <str ing.h>42 #include <str.h> 43 43 #include <align.h> 44 44 -
uspace/lib/c/generic/udebug.c
rcd82bb1 r371bd7d 69 69 } 70 70 71 int udebug_name_read(int phoneid, void *buffer, size_t n, 72 size_t *copied, size_t *needed) 73 { 74 ipcarg_t a_copied, a_needed; 75 int rc; 76 77 rc = async_req_3_3(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_NAME_READ, 78 (sysarg_t)buffer, n, NULL, &a_copied, &a_needed); 79 80 *copied = (size_t)a_copied; 81 *needed = (size_t)a_needed; 82 83 return rc; 84 } 85 86 int udebug_areas_read(int phoneid, void *buffer, size_t n, 87 size_t *copied, size_t *needed) 88 { 89 ipcarg_t a_copied, a_needed; 90 int rc; 91 92 rc = async_req_3_3(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_AREAS_READ, 93 (sysarg_t)buffer, n, NULL, &a_copied, &a_needed); 94 95 *copied = (size_t)a_copied; 96 *needed = (size_t)a_needed; 97 98 return rc; 99 } 100 71 101 int udebug_mem_read(int phoneid, void *buffer, uintptr_t addr, size_t n) 72 102 { … … 78 108 { 79 109 return async_req_3_0(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_ARGS_READ, 110 tid, (sysarg_t)buffer); 111 } 112 113 int udebug_regs_read(int phoneid, thash_t tid, void *buffer) 114 { 115 return async_req_3_0(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_REGS_READ, 80 116 tid, (sysarg_t)buffer); 81 117 } -
uspace/lib/c/generic/vfs/vfs.c
rcd82bb1 r371bd7d 35 35 #include <vfs/vfs.h> 36 36 #include <vfs/canonify.h> 37 #include <macros.h> 37 38 #include <stdlib.h> 38 39 #include <unistd.h> … … 48 49 #include <futex.h> 49 50 #include <errno.h> 50 #include <str ing.h>51 #include <str.h> 51 52 #include <devmap.h> 52 53 #include <ipc/vfs.h> … … 117 118 } 118 119 119 int mount(const char *fs_name, const char *mp, const char * dev,120 int mount(const char *fs_name, const char *mp, const char *fqdn, 120 121 const char *opts, unsigned int flags) 121 122 { 122 int res; 123 int null_id = -1; 124 char null[DEVMAP_NAME_MAXLEN]; 125 126 if (str_cmp(fqdn, "") == 0) { 127 /* No device specified, create a fresh 128 null/%d device instead */ 129 null_id = devmap_null_create(); 130 131 if (null_id == -1) 132 return ENOMEM; 133 134 snprintf(null, DEVMAP_NAME_MAXLEN, "null/%d", null_id); 135 fqdn = null; 136 } 137 138 dev_handle_t dev_handle; 139 int res = devmap_device_get_handle(fqdn, &dev_handle, flags); 140 if (res != EOK) { 141 if (null_id != -1) 142 devmap_null_destroy(null_id); 143 144 return res; 145 } 146 147 size_t mpa_size; 148 char *mpa = absolutize(mp, &mpa_size); 149 if (!mpa) { 150 if (null_id != -1) 151 devmap_null_destroy(null_id); 152 153 return ENOMEM; 154 } 155 156 futex_down(&vfs_phone_futex); 157 async_serialize_start(); 158 vfs_connect(); 159 160 ipcarg_t rc_orig; 161 aid_t req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL); 162 ipcarg_t rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size); 163 if (rc != EOK) { 164 async_wait_for(req, &rc_orig); 165 async_serialize_end(); 166 futex_up(&vfs_phone_futex); 167 free(mpa); 168 169 if (null_id != -1) 170 devmap_null_destroy(null_id); 171 172 if (rc_orig == EOK) 173 return (int) rc; 174 else 175 return (int) rc_orig; 176 } 177 178 rc = async_data_write_start(vfs_phone, (void *) opts, str_size(opts)); 179 if (rc != EOK) { 180 async_wait_for(req, &rc_orig); 181 async_serialize_end(); 182 futex_up(&vfs_phone_futex); 183 free(mpa); 184 185 if (null_id != -1) 186 devmap_null_destroy(null_id); 187 188 if (rc_orig == EOK) 189 return (int) rc; 190 else 191 return (int) rc_orig; 192 } 193 194 rc = async_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name)); 195 if (rc != EOK) { 196 async_wait_for(req, &rc_orig); 197 async_serialize_end(); 198 futex_up(&vfs_phone_futex); 199 free(mpa); 200 201 if (null_id != -1) 202 devmap_null_destroy(null_id); 203 204 if (rc_orig == EOK) 205 return (int) rc; 206 else 207 return (int) rc_orig; 208 } 209 210 /* Ask VFS whether it likes fs_name. */ 211 rc = async_req_0_0(vfs_phone, IPC_M_PING); 212 if (rc != EOK) { 213 async_wait_for(req, &rc_orig); 214 async_serialize_end(); 215 futex_up(&vfs_phone_futex); 216 free(mpa); 217 218 if (null_id != -1) 219 devmap_null_destroy(null_id); 220 221 if (rc_orig == EOK) 222 return (int) rc; 223 else 224 return (int) rc_orig; 225 } 226 227 async_wait_for(req, &rc); 228 async_serialize_end(); 229 futex_up(&vfs_phone_futex); 230 free(mpa); 231 232 if ((rc != EOK) && (null_id != -1)) 233 devmap_null_destroy(null_id); 234 235 return (int) rc; 236 } 237 238 int unmount(const char *mp) 239 { 123 240 ipcarg_t rc; 124 241 ipcarg_t rc_orig; 125 242 aid_t req; 126 dev_handle_t dev_handle;127 128 res = devmap_device_get_handle(dev, &dev_handle, flags);129 if (res != EOK)130 return res;131 132 243 size_t mpa_size; 133 char *mpa = absolutize(mp, &mpa_size); 244 char *mpa; 245 246 mpa = absolutize(mp, &mpa_size); 134 247 if (!mpa) 135 248 return ENOMEM; … … 139 252 vfs_connect(); 140 253 141 req = async_send_ 2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL);254 req = async_send_0(vfs_phone, VFS_IN_UNMOUNT, NULL); 142 255 rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size); 143 256 if (rc != EOK) { … … 152 265 } 153 266 154 rc = async_data_write_start(vfs_phone, (void *) opts, str_size(opts)); 155 if (rc != EOK) { 156 async_wait_for(req, &rc_orig); 157 async_serialize_end(); 158 futex_up(&vfs_phone_futex); 159 free(mpa); 160 if (rc_orig == EOK) 161 return (int) rc; 162 else 163 return (int) rc_orig; 164 } 165 166 rc = async_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name)); 167 if (rc != EOK) { 168 async_wait_for(req, &rc_orig); 169 async_serialize_end(); 170 futex_up(&vfs_phone_futex); 171 free(mpa); 172 if (rc_orig == EOK) 173 return (int) rc; 174 else 175 return (int) rc_orig; 176 } 177 178 /* Ask VFS whether it likes fs_name. */ 179 rc = async_req_0_0(vfs_phone, IPC_M_PING); 180 if (rc != EOK) { 181 async_wait_for(req, &rc_orig); 182 async_serialize_end(); 183 futex_up(&vfs_phone_futex); 184 free(mpa); 185 if (rc_orig == EOK) 186 return (int) rc; 187 else 188 return (int) rc_orig; 189 } 190 267 191 268 async_wait_for(req, &rc); 192 269 async_serialize_end(); … … 358 435 } 359 436 360 off _t lseek(int fildes, off_t offset, int whence)361 { 362 ipcarg_t rc;363 364 futex_down(&vfs_phone_futex);365 async_serialize_start();366 vfs_connect();367 368 ipcarg_t newoffs;369 rc = async_req_3_1(vfs_phone, VFS_IN_SEEK, fildes, offset, whence,370 &newoff s);371 372 async_serialize_end(); 373 futex_up(&vfs_phone_futex); 374 437 off64_t lseek(int fildes, off64_t offset, int whence) 438 { 439 futex_down(&vfs_phone_futex); 440 async_serialize_start(); 441 vfs_connect(); 442 443 ipcarg_t newoff_lo; 444 ipcarg_t newoff_hi; 445 ipcarg_t rc = async_req_4_2(vfs_phone, VFS_IN_SEEK, fildes, 446 LOWER32(offset), UPPER32(offset), whence, 447 &newoff_lo, &newoff_hi); 448 449 async_serialize_end(); 450 futex_up(&vfs_phone_futex); 451 375 452 if (rc != EOK) 376 return (off_t) -1; 377 378 return (off_t) newoffs; 379 } 380 381 int ftruncate(int fildes, off_t length) 382 { 383 ipcarg_t rc; 384 385 futex_down(&vfs_phone_futex); 386 async_serialize_start(); 387 vfs_connect(); 388 389 rc = async_req_2_0(vfs_phone, VFS_IN_TRUNCATE, fildes, length); 390 async_serialize_end(); 391 futex_up(&vfs_phone_futex); 453 return (off64_t) -1; 454 455 return (off64_t) MERGE_LOUP32(newoff_lo, newoff_hi); 456 } 457 458 int ftruncate(int fildes, aoff64_t length) 459 { 460 ipcarg_t rc; 461 462 futex_down(&vfs_phone_futex); 463 async_serialize_start(); 464 vfs_connect(); 465 466 rc = async_req_3_0(vfs_phone, VFS_IN_TRUNCATE, fildes, 467 LOWER32(length), UPPER32(length)); 468 async_serialize_end(); 469 futex_up(&vfs_phone_futex); 470 392 471 return (int) rc; 393 472 } … … 403 482 404 483 req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL); 405 rc = async_data_read_start(vfs_phone, (void *) stat, sizeof(struct stat));484 rc = async_data_read_start(vfs_phone, (void *) stat, sizeof(struct stat)); 406 485 if (rc != EOK) { 407 486 ipcarg_t rc_orig; … … 477 556 if (!abs) { 478 557 free(dirp); 479 return ENOMEM;558 return NULL; 480 559 } 481 560 … … 703 782 rc = fstat(fildes, &stat); 704 783 705 if (!stat.dev fs_stat.device)784 if (!stat.device) 706 785 return -1; 707 786 708 return devmap_device_connect(stat.dev fs_stat.device, 0);787 return devmap_device_connect(stat.device, 0); 709 788 } 710 789
Note:
See TracChangeset
for help on using the changeset viewer.
