Changeset 371bd7d in mainline for uspace/lib/c/generic


Ignore:
Timestamp:
2010-03-27T09:22:17Z (16 years ago)
Author:
Jiri Svoboda <jiri@…>
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.
Message:

Merge mainline changes.

Location:
uspace/lib/c/generic
Files:
3 added
40 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/adt/hash_table.c

    rcd82bb1 r371bd7d  
    4343#include <assert.h>
    4444#include <stdio.h>
    45 #include <string.h>
     45#include <str.h>
    4646
    4747/** Create chained hash table.
     
    193193}
    194194
     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 */
     201void
     202hash_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
    195215/** @}
    196216 */
  • uspace/lib/c/generic/async.c

    rcd82bb1 r371bd7d  
    11011101}
    11021102
     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 */
     1114int
     1115async_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 */
     1141int
     1142async_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
    11031157/** Wrapper for making IPC_M_SHARE_IN calls using the async framework.
    11041158 *
     
    12871341}
    12881342
     1343/** Wrapper for forwarding any read request
     1344 *
     1345 *
     1346 */
     1347int 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
    12891377/** Wrapper for making IPC_M_DATA_WRITE calls using the async framework.
    12901378 *
    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 *
    12961385 */
    12971386int async_data_write_start(int phoneid, const void *src, size_t size)
     
    13081397 * So far, this wrapper is to be used from within a connection fibril.
    13091398 *
    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 *
    13161406 */
    13171407int async_data_write_receive(ipc_callid_t *callid, size_t *size)
     
    13201410       
    13211411        assert(callid);
    1322 
     1412       
    13231413        *callid = async_get_call(&data);
    13241414        if (IPC_GET_METHOD(data) != IPC_M_DATA_WRITE)
    13251415                return 0;
     1416       
    13261417        if (size)
    13271418                *size = (size_t) IPC_GET_ARG2(data);
     1419       
    13281420        return 1;
    13291421}
     
    13341426 * so that the user doesn't have to remember the meaning of each IPC argument.
    13351427 *
    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 *
    13411434 */
    13421435int async_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
     
    13451438}
    13461439
     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 */
     1461int 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 */
     1522void 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 */
     1533int 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
    13471563/** @}
    13481564 */
  • uspace/lib/c/generic/devmap.c

    rcd82bb1 r371bd7d  
    2828 */
    2929
    30 #include <string.h>
     30#include <str.h>
    3131#include <ipc/ipc.h>
    3232#include <ipc/services.h>
     
    3535#include <async.h>
    3636#include <errno.h>
     37#include <malloc.h>
     38#include <bool.h>
    3739
    3840static int devmap_phone_driver = -1;
     
    105107        aid_t req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer);
    106108       
    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));
    109110        if (retval != EOK) {
    110111                async_wait_for(req, NULL);
     
    126127/** Register new device.
    127128 *
    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.
    130132 *
    131133 */
    132 int devmap_device_register(const char *name, dev_handle_t *handle)
     134int devmap_device_register(const char *fqdn, dev_handle_t *handle)
    133135{
    134136        int phone = devmap_get_phone(DEVMAP_DRIVER, IPC_FLAG_BLOCKING);
     
    143145            &answer);
    144146       
    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));
    147148        if (retval != EOK) {
    148149                async_wait_for(req, NULL);
     
    167168}
    168169
    169 int devmap_device_get_handle(const char *name, dev_handle_t *handle, unsigned int flags)
     170int devmap_device_get_handle(const char *fqdn, dev_handle_t *handle, unsigned int flags)
    170171{
    171172        int phone = devmap_get_phone(DEVMAP_CLIENT, flags);
     
    180181            &answer);
    181182       
    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));
    184184        if (retval != EOK) {
    185185                async_wait_for(req, NULL);
     
    202202       
    203203        return retval;
     204}
     205
     206int 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
     242devmap_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;
    204255}
    205256
     
    227278       
    228279        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);
    230281        if (retval != EOK)
    231282                return -1;
     
    241292                return;
    242293       
    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
     297static size_t devmap_count_namespaces_internal(int phone)
     298{
    253299        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);
    255301        if (retval != EOK)
    256302                return 0;
     
    259305}
    260306
    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        
     307static 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);
    285311        if (retval != EOK)
    286312                return 0;
    287313       
    288         return IPC_GET_ARG1(answer);
    289 }
     314        return count;
     315}
     316
     317size_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
     327size_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
     337size_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
     389size_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  
    4141#include <unistd.h>
    4242#include <stdio.h>
     43#include <arch/barrier.h>
    4344#include <libarch/faddr.h>
    4445#include <futex.h>
     
    133134int fibril_switch(fibril_switch_type_t stype)
    134135{
    135         fibril_t *srcf, *dstf;
    136136        int retval = 0;
    137137       
    138138        futex_down(&fibril_futex);
    139 
     139       
    140140        if (stype == FIBRIL_PREEMPT && list_empty(&ready_list))
    141141                goto ret_0;
    142 
     142       
    143143        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)))
    145145                        goto ret_0;
     146               
    146147                /*
    147148                 * Do not preempt if there is not enough threads to run the
    148149                 * ready fibrils which are not serialized.
    149150                 */
    150                 if (list_empty(&serialized_list) &&
    151                     threads_in_manager <= serialized_threads) {
     151                if ((list_empty(&serialized_list)) &&
     152                    (threads_in_manager <= serialized_threads)) {
    152153                        goto ret_0;
    153154                }
    154155        }
     156       
    155157        /* 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)) {
    157159                while (list_empty(&manager_list)) {
    158160                        futex_up(&fibril_futex);
     
    162164        }
    163165       
    164         srcf = __tcb_get()->fibril_data;
     166        fibril_t *srcf = __tcb_get()->fibril_data;
    165167        if (stype != FIBRIL_FROM_DEAD) {
     168               
    166169                /* Save current state */
    167170                if (!context_save(&srcf->ctx)) {
    168171                        if (serialization_count)
    169172                                srcf->flags &= ~FIBRIL_SERIALIZED;
     173                       
    170174                        if (srcf->clean_after_me) {
    171175                                /*
     
    173177                                 * restored context here.
    174178                                 */
    175                                 void *stack = srcf->clean_after_me->stack; 
     179                                void *stack = srcf->clean_after_me->stack;
    176180                                if (stack) {
    177181                                        /*
     
    188192                                srcf->clean_after_me = NULL;
    189193                        }
     194                       
    190195                        return 1;       /* futex_up already done here */
    191196                }
    192 
     197               
    193198                /* Save myself to the correct run list */
    194199                if (stype == FIBRIL_PREEMPT)
     
    197202                        list_append(&srcf->link, &manager_list);
    198203                        threads_in_manager--;
    199                 } else {       
     204                } else {
    200205                        /*
    201206                         * If stype == FIBRIL_TO_MANAGER, don't put ourselves to
     
    207212       
    208213        /* 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)) {
    210216                dstf = list_get_instance(manager_list.next, fibril_t, link);
    211217                if (serialization_count && stype == FIBRIL_TO_MANAGER) {
     
    214220                }
    215221                threads_in_manager++;
    216 
     222               
    217223                if (stype == FIBRIL_FROM_DEAD)
    218224                        dstf->clean_after_me = srcf;
     
    228234        }
    229235        list_remove(&dstf->link);
    230 
     236       
    231237        futex_up(&fibril_futex);
    232238        context_restore(&dstf->ctx);
    233239        /* not reached */
    234 
     240       
    235241ret_0:
    236242        futex_up(&fibril_futex);
  • uspace/lib/c/generic/fibril_synch.c

    rcd82bb1 r371bd7d  
    3333 */
    3434
    35 #include <fibril_sync.h>
     35#include <fibril_synch.h>
    3636#include <fibril.h>
    3737#include <async.h>
  • uspace/lib/c/generic/getopt.c

    rcd82bb1 r371bd7d  
    3838#include <getopt.h>
    3939#include <stdlib.h>
    40 #include <string.h>
     40#include <str.h>
    4141
    4242/* HelenOS Port : We're incorporating only the modern getopt_long with wrappers
  • uspace/lib/c/generic/io/asprintf.c

    rcd82bb1 r371bd7d  
    3737#include <stdio.h>
    3838#include <stdlib.h>
    39 #include <string.h>
     39#include <str.h>
    4040#include <io/printf_core.h>
    4141
  • uspace/lib/c/generic/io/io.c

    rcd82bb1 r371bd7d  
    3737#include <fcntl.h>
    3838#include <assert.h>
    39 #include <string.h>
     39#include <str.h>
    4040#include <errno.h>
    4141#include <bool.h>
     
    4646#include <adt/list.h>
    4747
     48static void _ffillbuf(FILE *stream);
    4849static void _fflushbuf(FILE *stream);
    4950
     
    5758        .buf = NULL,
    5859        .buf_size = 0,
    59         .buf_head = NULL
     60        .buf_head = NULL,
     61        .buf_tail = NULL,
     62        .buf_state = _bs_empty
    6063};
    6164
     
    6972        .buf = NULL,
    7073        .buf_size = BUFSIZ,
    71         .buf_head = NULL
     74        .buf_head = NULL,
     75        .buf_tail = NULL,
     76        .buf_state = _bs_empty
    7277};
    7378
     
    8186        .buf = NULL,
    8287        .buf_size = 0,
    83         .buf_head = NULL
     88        .buf_head = NULL,
     89        .buf_tail = NULL,
     90        .buf_state = _bs_empty
    8491};
    8592
     
    179186        stream->buf_size = size;
    180187        stream->buf_head = stream->buf;
     188        stream->buf_tail = stream->buf;
     189        stream->buf_state = _bs_empty;
    181190}
    182191
     
    210219       
    211220        stream->buf_head = stream->buf;
     221        stream->buf_tail = stream->buf;
    212222        return 0;
    213223}
     
    243253        stream->klog = false;
    244254        stream->phone = -1;
     255        stream->need_sync = false;
    245256        _setvbuf(stream);
    246257       
     
    264275        stream->klog = false;
    265276        stream->phone = -1;
     277        stream->need_sync = false;
    266278        _setvbuf(stream);
    267279       
     
    295307        stream->klog = false;
    296308        stream->phone = -1;
     309        stream->need_sync = false;
    297310        _setvbuf(stream);
    298311       
     
    331344}
    332345
    333 /** Read from a stream.
     346/** Read from a stream (unbuffered).
    334347 *
    335348 * @param buf    Destination buffer.
     
    337350 * @param nmemb  Number of records to read.
    338351 * @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 */
     353static 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;
    348362       
    349363        while ((left > 0) && (!stream->error) && (!stream->eof)) {
     
    363377}
    364378
     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 */
    365386static size_t _fwrite(const void *buf, size_t size, size_t nmemb, FILE *stream)
    366387{
    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
    370397        while ((left > 0) && (!stream->error)) {
    371398                ssize_t wr;
     
    383410                }
    384411        }
     412
     413        if (done > 0)
     414                stream->need_sync = true;
    385415       
    386416        return (done / size);
    387417}
    388418
    389 /** Drain stream buffer, do not sync stream. */
     419/** Read some data in stream buffer. */
     420static 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. */
    390442static void _fflushbuf(FILE *stream)
    391443{
    392444        size_t bytes_used;
    393        
     445
    394446        if ((!stream->buf) || (stream->btype == _IONBF) || (stream->error))
    395447                return;
    396        
    397         bytes_used = stream->buf_head - stream->buf;
     448
     449        bytes_used = stream->buf_head - stream->buf_tail;
    398450        if (bytes_used == 0)
    399451                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
    402461        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 */
     474size_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
    404533
    405534/** Write to a stream.
     
    421550        uint8_t b;
    422551        bool need_flush;
    423        
     552
     553        if (size == 0 || nmemb == 0)
     554                return 0;
     555
    424556        /* If not buffered stream, write out directly. */
    425557        if (stream->btype == _IONBF) {
     
    428560                return now;
    429561        }
    430        
     562
     563        /* Make sure buffer contains no prefetched data. */
     564        if (stream->buf_state == _bs_read)
     565                _fflushbuf(stream);
     566
     567
    431568        /* Perform lazy allocation of stream buffer. */
    432569        if (stream->buf == NULL) {
     
    468605        }
    469606       
     607        if (total_written > 0)
     608                stream->buf_state = _bs_write;
     609
    470610        if (need_flush)
    471611                fflush(stream);
     
    522662}
    523663
     664char *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
    524691int getchar(void)
    525692{
     
    527694}
    528695
    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. */
     696int 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. */
    534705                return -1;
    535706        }
    536        
     707
    537708        stream->eof = false;
    538        
    539709        return 0;
     710}
     711
     712off64_t ftell(FILE *stream)
     713{
     714        return lseek(stream->fd, 0, SEEK_CUR);
    540715}
    541716
     
    554729        }
    555730       
    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;
    557737                return fsync(stream->fd);
     738        }
    558739       
    559740        return ENOENT;
     
    568749{
    569750        return stream->error;
     751}
     752
     753void clearerr(FILE *stream)
     754{
     755        stream->eof = false;
     756        stream->error = false;
    570757}
    571758
  • uspace/lib/c/generic/io/klog.c

    rcd82bb1 r371bd7d  
    3535
    3636#include <libc.h>
    37 #include <string.h>
     37#include <str.h>
    3838#include <sys/types.h>
    3939#include <unistd.h>
  • uspace/lib/c/generic/io/printf_core.c

    rcd82bb1 r371bd7d  
    4141#include <io/printf_core.h>
    4242#include <ctype.h>
    43 #include <string.h>
     43#include <str.h>
    4444
    4545/** show prefixes 0x or 0 */
  • uspace/lib/c/generic/io/vprintf.c

    rcd82bb1 r371bd7d  
    3939#include <futex.h>
    4040#include <async.h>
    41 #include <string.h>
     41#include <str.h>
    4242
    4343static atomic_t printf_futex = FUTEX_INITIALIZER;
  • uspace/lib/c/generic/io/vsnprintf.c

    rcd82bb1 r371bd7d  
    3535#include <stdarg.h>
    3636#include <stdio.h>
    37 #include <string.h>
     37#include <str.h>
    3838#include <io/printf_core.h>
    3939#include <errno.h>
  • uspace/lib/c/generic/ipc.c

    rcd82bb1 r371bd7d  
    728728    int *flags)
    729729{
    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,
    733732            (ipcarg_t) size, arg, NULL, &tmp_flags);
     733       
    734734        if (flags)
    735735                *flags = tmp_flags;
     736       
    736737        return res;
    737738}
  • uspace/lib/c/generic/loader.c

    rcd82bb1 r371bd7d  
    3838#include <libc.h>
    3939#include <task.h>
    40 #include <string.h>
     40#include <str.h>
    4141#include <stdlib.h>
    4242#include <async.h>
     
    183183 *
    184184 */
    185 int loader_set_args(loader_t *ldr, char *const argv[])
     185int loader_set_args(loader_t *ldr, const char *const argv[])
    186186{
    187187        /*
     
    189189         * compute size of the buffer needed.
    190190         */
    191         char *const *ap = argv;
     191        const char *const *ap = argv;
    192192        size_t buffer_size = 0;
    193193        while (*ap != NULL) {
  • uspace/lib/c/generic/malloc.c

    rcd82bb1 r371bd7d  
    164164{
    165165        if (size == 0)
     166                return false;
     167
     168        if ((heap_start + size < heap_start) || (heap_end + size < heap_end))
    166169                return false;
    167170       
  • uspace/lib/c/generic/mman.c

    rcd82bb1 r371bd7d  
    3939
    4040void *mmap(void *start, size_t length, int prot, int flags, int fd,
    41     off_t offset)
     41    aoff64_t offset)
    4242{
    4343        if (!start)
  • uspace/lib/c/generic/str.c

    rcd82bb1 r371bd7d  
    3434 */
    3535
    36 #include <string.h>
     36#include <str.h>
    3737#include <stdlib.h>
    3838#include <assert.h>
     
    4343#include <align.h>
    4444#include <mem.h>
    45 #include <string.h>
     45#include <str.h>
    4646
    4747/** Byte mask consisting of lowest @n bits (out of 8) */
     
    896896}
    897897
     898char *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
     909char *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
    898925
    899926/** Convert initial part of string to unsigned long according to given base.
     
    920947}
    921948
    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 
    933949char *strtok(char *s, const char *delim)
    934950{
  • uspace/lib/c/generic/sysinfo.c

    rcd82bb1 r371bd7d  
    3535#include <libc.h>
    3636#include <sysinfo.h>
    37 #include <string.h>
     37#include <str.h>
    3838
    39 sysarg_t sysinfo_value(char *name)
     39sysarg_t sysinfo_value(const char *name)
    4040{
    41         return __SYSCALL2(SYS_SYSINFO_VALUE, (sysarg_t ) name,
     41        return __SYSCALL2(SYS_SYSINFO_VALUE, (sysarg_t) name,
    4242            (sysarg_t) str_size(name));
    4343}
  • uspace/lib/c/generic/task.c

    rcd82bb1 r371bd7d  
    3939#include <errno.h>
    4040#include <loader/loader.h>
    41 #include <string.h>
     41#include <str.h>
    4242#include <ipc/ns.h>
    4343#include <macros.h>
     
    7676 *
    7777 */
    78 task_id_t task_spawn(const char *path, char *const args[])
     78task_id_t task_spawn(const char *path, const char *const args[])
    7979{
    8080        /* Connect to a program loader. */
  • uspace/lib/c/generic/thread.c

    rcd82bb1 r371bd7d  
    3939#include <kernel/proc/uarg.h>
    4040#include <fibril.h>
    41 #include <string.h>
     41#include <str.h>
    4242#include <async.h>
    4343
     
    8686 * @return Zero on success or a code from @ref errno.h on failure.
    8787 */
    88 int thread_create(void (* function)(void *), void *arg, char *name,
     88int thread_create(void (* function)(void *), void *arg, const char *name,
    8989    thread_id_t *tid)
    9090{
  • uspace/lib/c/generic/time.c

    rcd82bb1 r371bd7d  
    3131 */
    3232/** @file
    33  */ 
     33 */
    3434
    3535#include <sys/time.h>
     
    4040#include <unistd.h>
    4141#include <atomic.h>
    42 #include <futex.h>
    4342#include <sysinfo.h>
    4443#include <ipc/services.h>
     44#include <libc.h>
    4545
    4646#include <sysinfo.h>
     
    189189
    190190/** 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);
     191int usleep(useconds_t usec)
     192{
     193        (void) __SYSCALL1(SYS_THREAD_USLEEP, usec);
    197194        return 0;
    198195}
    199196
    200197/** 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        
     198unsigned int sleep(unsigned int sec)
     199{
    207200        /* Sleep in 1000 second steps to support
    208201           full argument range */
    209         while (seconds > 0) {
    210                 unsigned int period = (seconds > 1000) ? 1000 : seconds;
     202        while (sec > 0) {
     203                unsigned int period = (sec > 1000) ? 1000 : sec;
    211204       
    212                 futex_down_timeout(&futex, period * 1000000, 0);
    213                 seconds -= period;
     205                usleep(period * 1000000);
     206                sec -= period;
    214207        }
    215208        return 0;
  • uspace/lib/c/generic/tls.c

    rcd82bb1 r371bd7d  
    4040#include <tls.h>
    4141#include <malloc.h>
    42 #include <string.h>
     42#include <str.h>
    4343#include <align.h>
    4444
  • uspace/lib/c/generic/udebug.c

    rcd82bb1 r371bd7d  
    6969}
    7070
     71int 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
     86int 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
    71101int udebug_mem_read(int phoneid, void *buffer, uintptr_t addr, size_t n)
    72102{
     
    78108{
    79109        return async_req_3_0(phoneid, IPC_M_DEBUG_ALL, UDEBUG_M_ARGS_READ,
     110            tid, (sysarg_t)buffer);
     111}
     112
     113int 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,
    80116            tid, (sysarg_t)buffer);
    81117}
  • uspace/lib/c/generic/vfs/vfs.c

    rcd82bb1 r371bd7d  
    3535#include <vfs/vfs.h>
    3636#include <vfs/canonify.h>
     37#include <macros.h>
    3738#include <stdlib.h>
    3839#include <unistd.h>
     
    4849#include <futex.h>
    4950#include <errno.h>
    50 #include <string.h>
     51#include <str.h>
    5152#include <devmap.h>
    5253#include <ipc/vfs.h>
     
    117118}
    118119
    119 int mount(const char *fs_name, const char *mp, const char *dev,
     120int mount(const char *fs_name, const char *mp, const char *fqdn,
    120121    const char *opts, unsigned int flags)
    121122{
    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
     238int unmount(const char *mp)
     239{
    123240        ipcarg_t rc;
    124241        ipcarg_t rc_orig;
    125242        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        
    132243        size_t mpa_size;
    133         char *mpa = absolutize(mp, &mpa_size);
     244        char *mpa;
     245       
     246        mpa = absolutize(mp, &mpa_size);
    134247        if (!mpa)
    135248                return ENOMEM;
     
    139252        vfs_connect();
    140253       
    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);
    142255        rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);
    143256        if (rc != EOK) {
     
    152265        }
    153266       
    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
    191268        async_wait_for(req, &rc);
    192269        async_serialize_end();
     
    358435}
    359436
    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             &newoffs);
    371 
    372         async_serialize_end();
    373         futex_up(&vfs_phone_futex);
    374 
     437off64_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       
    375452        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
     458int 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       
    392471        return (int) rc;
    393472}
     
    403482       
    404483        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));
    406485        if (rc != EOK) {
    407486                ipcarg_t rc_orig;
     
    477556        if (!abs) {
    478557                free(dirp);
    479                 return ENOMEM;
     558                return NULL;
    480559        }
    481560       
     
    703782        rc = fstat(fildes, &stat);
    704783
    705         if (!stat.devfs_stat.device)
     784        if (!stat.device)
    706785                return -1;
    707786       
    708         return devmap_device_connect(stat.devfs_stat.device, 0);
     787        return devmap_device_connect(stat.device, 0);
    709788}
    710789
Note: See TracChangeset for help on using the changeset viewer.