Changeset 19f24fd in mainline for uspace/lib/libc/generic


Ignore:
Timestamp:
2010-02-05T22:25:52Z (16 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
dafa2d04
Parents:
83349b03 (diff), d42976c (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/libc/generic
Files:
4 edited

Legend:

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

    r83349b03 r19f24fd  
    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/libc/generic/async.c

    r83349b03 r19f24fd  
    12871287}
    12881288
     1289/** Wrapper for forwarding any read request
     1290 *
     1291 *
     1292 */
     1293int async_data_read_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1,
     1294    ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipc_call_t *dataptr)
     1295{
     1296        ipc_callid_t callid;
     1297        if (!async_data_read_receive(&callid, NULL)) {
     1298                ipc_answer_0(callid, EINVAL);
     1299                return EINVAL;
     1300        }
     1301       
     1302        aid_t msg = async_send_fast(phoneid, method, arg1, arg2, arg3, arg4,
     1303            dataptr);
     1304        if (msg == 0) {
     1305                ipc_answer_0(callid, EINVAL);
     1306                return EINVAL;
     1307        }
     1308       
     1309        int retval = ipc_forward_fast(callid, phoneid, 0, 0, 0,
     1310            IPC_FF_ROUTE_FROM_ME);
     1311        if (retval != EOK) {
     1312                ipc_answer_0(callid, retval);
     1313                return retval;
     1314        }
     1315       
     1316        ipcarg_t rc;
     1317        async_wait_for(msg, &rc);
     1318       
     1319        return (int) rc;
     1320}
     1321
    12891322/** Wrapper for making IPC_M_DATA_WRITE calls using the async framework.
    12901323 *
    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.
     1324 * @param phoneid Phone that will be used to contact the receiving side.
     1325 * @param src     Address of the beginning of the source buffer.
     1326 * @param size    Size of the source buffer.
     1327 *
     1328 * @return Zero on success or a negative error code from errno.h.
     1329 *
    12961330 */
    12971331int async_data_write_start(int phoneid, const void *src, size_t size)
     
    13081342 * So far, this wrapper is to be used from within a connection fibril.
    13091343 *
    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.
     1344 * @param callid Storage where the hash of the IPC_M_DATA_WRITE call will
     1345 *               be stored.
     1346 * @param size   Storage where the suggested size will be stored. May be
     1347 *               NULL
     1348 *
     1349 * @return Non-zero on success, zero on failure.
     1350 *
    13161351 */
    13171352int async_data_write_receive(ipc_callid_t *callid, size_t *size)
     
    13201355       
    13211356        assert(callid);
    1322 
     1357       
    13231358        *callid = async_get_call(&data);
    13241359        if (IPC_GET_METHOD(data) != IPC_M_DATA_WRITE)
    13251360                return 0;
     1361       
    13261362        if (size)
    13271363                *size = (size_t) IPC_GET_ARG2(data);
     1364       
    13281365        return 1;
    13291366}
     
    13341371 * so that the user doesn't have to remember the meaning of each IPC argument.
    13351372 *
    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.
     1373 * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
     1374 * @param dst    Final destination address for the IPC_M_DATA_WRITE call.
     1375 * @param size   Final size for the IPC_M_DATA_WRITE call.
     1376 *
     1377 * @return Zero on success or a value from @ref errno.h on failure.
     1378 *
    13411379 */
    13421380int async_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
     
    13451383}
    13461384
    1347 /** Wrapper for receiving blobs via the async_data_write_*
     1385/** Wrapper for receiving binary data or strings
    13481386 *
    13491387 * This wrapper only makes it more comfortable to use async_data_write_*
    1350  * functions to receive blobs.
    1351  *
    1352  * @param blob     Pointer to data pointer (which should be later disposed
    1353  *                 by free()). If the operation fails, the pointer is not
    1354  *                 touched.
    1355  * @param max_size Maximum size (in bytes) of the blob to receive. 0 means
    1356  *                 no limit.
    1357  * @param received If not NULL, the size of the received data is stored here.
     1388 * functions to receive binary data or strings.
     1389 *
     1390 * @param data       Pointer to data pointer (which should be later disposed
     1391 *                   by free()). If the operation fails, the pointer is not
     1392 *                   touched.
     1393 * @param nullterm   If true then the received data is always zero terminated.
     1394 *                   This also causes to allocate one extra byte beyond the
     1395 *                   raw transmitted data.
     1396 * @param min_size   Minimum size (in bytes) of the data to receive.
     1397 * @param max_size   Maximum size (in bytes) of the data to receive. 0 means
     1398 *                   no limit.
     1399 * @param granulariy If non-zero then the size of the received data has to
     1400 *                   be divisible by this value.
     1401 * @param received   If not NULL, the size of the received data is stored here.
    13581402 *
    13591403 * @return Zero on success or a value from @ref errno.h on failure.
    13601404 *
    13611405 */
    1362 int async_data_blob_receive(char **blob, const size_t max_size, size_t *received)
     1406int async_data_write_accept(void **data, const bool nullterm,
     1407    const size_t min_size, const size_t max_size, const size_t granularity,
     1408    size_t *received)
    13631409{
    13641410        ipc_callid_t callid;
     
    13691415        }
    13701416       
     1417        if (size < min_size) {
     1418                ipc_answer_0(callid, EINVAL);
     1419                return EINVAL;
     1420        }
     1421       
    13711422        if ((max_size > 0) && (size > max_size)) {
    13721423                ipc_answer_0(callid, EINVAL);
     
    13741425        }
    13751426       
    1376         char *data = (char *) malloc(size);
    1377         if (data == NULL) {
     1427        if ((granularity > 0) && ((size % granularity) != 0)) {
     1428                ipc_answer_0(callid, EINVAL);
     1429                return EINVAL;
     1430        }
     1431       
     1432        void *_data;
     1433       
     1434        if (nullterm)
     1435                _data = malloc(size + 1);
     1436        else
     1437                _data = malloc(size);
     1438       
     1439        if (_data == NULL) {
    13781440                ipc_answer_0(callid, ENOMEM);
    13791441                return ENOMEM;
    13801442        }
    13811443       
    1382         int rc = async_data_write_finalize(callid, data, size);
     1444        int rc = async_data_write_finalize(callid, _data, size);
    13831445        if (rc != EOK) {
    1384                 free(data);
     1446                free(_data);
    13851447                return rc;
    13861448        }
    13871449       
    1388         *blob = data;
     1450        if (nullterm)
     1451                ((char *) _data)[size] = 0;
     1452       
     1453        *data = _data;
    13891454        if (received != NULL)
    13901455                *received = size;
     
    13931458}
    13941459
    1395 /** Wrapper for receiving strings via the async_data_write_*
    1396  *
    1397  * This wrapper only makes it more comfortable to use async_data_write_*
    1398  * functions to receive strings.
    1399  *
    1400  * @param str      Pointer to string pointer (which should be later disposed
    1401  *                 by free()). If the operation fails, the pointer is not
    1402  *                 touched.
    1403  * @param max_size Maximum size (in bytes) of the string to receive. 0 means
    1404  *                 no limit.
    1405  *
    1406  * @return Zero on success or a value from @ref errno.h on failure.
    1407  *
    1408  */
    1409 int async_data_string_receive(char **str, const size_t max_size)
     1460/** Wrapper for voiding any data that is about to be received
     1461 *
     1462 * This wrapper can be used to void any pending data
     1463 *
     1464 * @param retval Error value from @ref errno.h to be returned to the caller.
     1465 *
     1466 */
     1467void async_data_write_void(const int retval)
    14101468{
    14111469        ipc_callid_t callid;
    1412         size_t size;
    1413         if (!async_data_write_receive(&callid, &size)) {
     1470        async_data_write_receive(&callid, NULL);
     1471        ipc_answer_0(callid, retval);
     1472}
     1473
     1474/** Wrapper for forwarding any data that is about to be received
     1475 *
     1476 *
     1477 */
     1478int async_data_write_forward_fast(int phoneid, ipcarg_t method, ipcarg_t arg1,
     1479    ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipc_call_t *dataptr)
     1480{
     1481        ipc_callid_t callid;
     1482        if (!async_data_write_receive(&callid, NULL)) {
    14141483                ipc_answer_0(callid, EINVAL);
    14151484                return EINVAL;
    14161485        }
    14171486       
    1418         if ((max_size > 0) && (size > max_size)) {
     1487        aid_t msg = async_send_fast(phoneid, method, arg1, arg2, arg3, arg4,
     1488            dataptr);
     1489        if (msg == 0) {
    14191490                ipc_answer_0(callid, EINVAL);
    14201491                return EINVAL;
    14211492        }
    14221493       
    1423         char *data = (char *) malloc(size + 1);
    1424         if (data == NULL) {
    1425                 ipc_answer_0(callid, ENOMEM);
    1426                 return ENOMEM;
    1427         }
    1428        
    1429         int rc = async_data_write_finalize(callid, data, size);
    1430         if (rc != EOK) {
    1431                 free(data);
    1432                 return rc;
    1433         }
    1434        
    1435         data[size] = 0;
    1436         *str = data;
    1437         return EOK;
     1494        int retval = ipc_forward_fast(callid, phoneid, 0, 0, 0,
     1495            IPC_FF_ROUTE_FROM_ME);
     1496        if (retval != EOK) {
     1497                ipc_answer_0(callid, retval);
     1498                return retval;
     1499        }
     1500       
     1501        ipcarg_t rc;
     1502        async_wait_for(msg, &rc);
     1503       
     1504        return (int) rc;
    14381505}
    14391506
  • uspace/lib/libc/generic/clipboard.c

    r83349b03 r19f24fd  
    8484                clip_connect();
    8585               
    86                 aid_t req = async_send_1(clip_phone, CLIPBOARD_PUT_DATA, CLIPBOARD_TAG_BLOB, NULL);
     86                aid_t req = async_send_1(clip_phone, CLIPBOARD_PUT_DATA, CLIPBOARD_TAG_DATA, NULL);
    8787                ipcarg_t rc = async_data_write_start(clip_phone, (void *) str, size);
    8888                if (rc != EOK) {
     
    139139                        *str = sbuf;
    140140                        return EOK;
    141                 case CLIPBOARD_TAG_BLOB:
     141                case CLIPBOARD_TAG_DATA:
    142142                        sbuf = malloc(size + 1);
    143143                        if (sbuf == NULL)
  • uspace/lib/libc/generic/vfs/vfs.c

    r83349b03 r19f24fd  
    120120    const char *opts, unsigned int flags)
    121121{
    122         int res;
     122        int null_id = -1;
     123        char null[DEVMAP_NAME_MAXLEN];
     124       
     125        if (str_cmp(fqdn, "") == 0) {
     126                /* No device specified, create a fresh
     127                   null/%d device instead */
     128                null_id = devmap_null_create();
     129               
     130                if (null_id == -1)
     131                        return ENOMEM;
     132               
     133                snprintf(null, DEVMAP_NAME_MAXLEN, "null/%d", null_id);
     134                fqdn = null;
     135        }
     136       
     137        dev_handle_t dev_handle;
     138        int res = devmap_device_get_handle(fqdn, &dev_handle, flags);
     139        if (res != EOK) {
     140                if (null_id != -1)
     141                        devmap_null_destroy(null_id);
     142               
     143                return res;
     144        }
     145       
     146        size_t mpa_size;
     147        char *mpa = absolutize(mp, &mpa_size);
     148        if (!mpa) {
     149                if (null_id != -1)
     150                        devmap_null_destroy(null_id);
     151               
     152                return ENOMEM;
     153        }
     154       
     155        futex_down(&vfs_phone_futex);
     156        async_serialize_start();
     157        vfs_connect();
     158       
     159        ipcarg_t rc_orig;
     160        aid_t req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL);
     161        ipcarg_t rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);
     162        if (rc != EOK) {
     163                async_wait_for(req, &rc_orig);
     164                async_serialize_end();
     165                futex_up(&vfs_phone_futex);
     166                free(mpa);
     167               
     168                if (null_id != -1)
     169                        devmap_null_destroy(null_id);
     170               
     171                if (rc_orig == EOK)
     172                        return (int) rc;
     173                else
     174                        return (int) rc_orig;
     175        }
     176       
     177        rc = async_data_write_start(vfs_phone, (void *) opts, str_size(opts));
     178        if (rc != EOK) {
     179                async_wait_for(req, &rc_orig);
     180                async_serialize_end();
     181                futex_up(&vfs_phone_futex);
     182                free(mpa);
     183               
     184                if (null_id != -1)
     185                        devmap_null_destroy(null_id);
     186               
     187                if (rc_orig == EOK)
     188                        return (int) rc;
     189                else
     190                        return (int) rc_orig;
     191        }
     192       
     193        rc = async_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name));
     194        if (rc != EOK) {
     195                async_wait_for(req, &rc_orig);
     196                async_serialize_end();
     197                futex_up(&vfs_phone_futex);
     198                free(mpa);
     199               
     200                if (null_id != -1)
     201                        devmap_null_destroy(null_id);
     202               
     203                if (rc_orig == EOK)
     204                        return (int) rc;
     205                else
     206                        return (int) rc_orig;
     207        }
     208       
     209        /* Ask VFS whether it likes fs_name. */
     210        rc = async_req_0_0(vfs_phone, IPC_M_PING);
     211        if (rc != EOK) {
     212                async_wait_for(req, &rc_orig);
     213                async_serialize_end();
     214                futex_up(&vfs_phone_futex);
     215                free(mpa);
     216               
     217                if (null_id != -1)
     218                        devmap_null_destroy(null_id);
     219               
     220                if (rc_orig == EOK)
     221                        return (int) rc;
     222                else
     223                        return (int) rc_orig;
     224        }
     225       
     226        async_wait_for(req, &rc);
     227        async_serialize_end();
     228        futex_up(&vfs_phone_futex);
     229        free(mpa);
     230       
     231        if ((rc != EOK) && (null_id != -1))
     232                devmap_null_destroy(null_id);
     233       
     234        return (int) rc;
     235}
     236
     237int unmount(const char *mp)
     238{
    123239        ipcarg_t rc;
    124240        ipcarg_t rc_orig;
    125241        aid_t req;
    126         dev_handle_t dev_handle;
    127        
    128         res = devmap_device_get_handle(fqdn, &dev_handle, flags);
    129         if (res != EOK)
    130                 return res;
    131        
    132242        size_t mpa_size;
    133         char *mpa = absolutize(mp, &mpa_size);
     243        char *mpa;
     244       
     245        mpa = absolutize(mp, &mpa_size);
    134246        if (!mpa)
    135247                return ENOMEM;
     
    139251        vfs_connect();
    140252       
    141         req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL);
     253        req = async_send_0(vfs_phone, VFS_IN_UNMOUNT, NULL);
    142254        rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size);
    143255        if (rc != EOK) {
     
    152264        }
    153265       
    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        
     266
    191267        async_wait_for(req, &rc);
    192268        async_serialize_end();
Note: See TracChangeset for help on using the changeset viewer.