Changeset 19b28b0 in mainline


Ignore:
Timestamp:
2009-03-02T17:31:05Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8026731
Parents:
97c9da8
Message:

add IPC_FLAG_BLOCKING for generic IPC blocking operations
add ipc_connect_me_to_blocking() for blocking connections
mount() has new flags argument
get_cons_phone() → get_console_phone()
add common console_wait()
simplify vfs_connect() using blocking connection
add blocking support for device_get_handle()
swap VFS_MOUNT arguments, and blocking mount support

Location:
uspace/lib/libc
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/console.c

    r97c9da8 r19b28b0  
    4040void console_clear(void)
    4141{
    42         int cons_phone = get_cons_phone();
     42        int cons_phone = get_console_phone();
    4343        async_msg_0(cons_phone, CONSOLE_CLEAR);
    4444}
     
    4646void console_goto(int row, int col)
    4747{
    48         int cons_phone = get_cons_phone();
     48        int cons_phone = get_console_phone();
    4949        async_msg_2(cons_phone, CONSOLE_GOTO, row, col);
    5050}
     
    5252void console_flush(void)
    5353{
    54         int cons_phone = get_cons_phone();
     54        int cons_phone = get_console_phone();
    5555        async_msg_0(cons_phone, CONSOLE_FLUSH);
    5656}
     
    5858int console_get_size(int *rows, int *cols)
    5959{
    60         int cons_phone = get_cons_phone();
     60        int cons_phone = get_console_phone();
    6161        ipcarg_t r, c;
    6262        int rc;
     
    7272void console_set_style(int style)
    7373{
    74         int cons_phone = get_cons_phone();
     74        int cons_phone = get_console_phone();
    7575        async_msg_1(cons_phone, CONSOLE_SET_STYLE, style);
    7676}
     
    7878void console_set_color(int fg_color, int bg_color, int flags)
    7979{
    80         int cons_phone = get_cons_phone();
     80        int cons_phone = get_console_phone();
    8181        async_msg_3(cons_phone, CONSOLE_SET_COLOR, fg_color, bg_color, flags);
    8282}
     
    8484void console_set_rgb_color(int fg_color, int bg_color)
    8585{
    86         int cons_phone = get_cons_phone();
     86        int cons_phone = get_console_phone();
    8787        async_msg_2(cons_phone, CONSOLE_SET_RGB_COLOR, fg_color, bg_color);
    8888}
     
    9090void console_cursor_visibility(int show)
    9191{
    92         int cons_phone = get_cons_phone();
     92        int cons_phone = get_console_phone();
    9393        async_msg_1(cons_phone, CONSOLE_CURSOR_VISIBILITY, show != 0);
    9494}
  • uspace/lib/libc/generic/io/stream.c

    r97c9da8 r19b28b0  
    116116}
    117117
    118 int get_cons_phone(void)
     118int get_console_phone(void)
    119119{
    120         open_console();
     120        if (console_phone < 0)
     121                console_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_CONSOLE, 0, 0);
     122       
    121123        return console_phone;
     124}
     125
     126void console_wait(void)
     127{
     128        while (console_phone < 0)
     129                get_console_phone();
    122130}
    123131
  • uspace/lib/libc/generic/ipc.c

    r97c9da8 r19b28b0  
    599599        int res;
    600600
    601         res = ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3, 
     601        res = ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
    602602            NULL, NULL, NULL, NULL, &newphid);
     603        if (res)
     604                return res;
     605        return newphid;
     606}
     607
     608/** Ask through phone for a new connection to some service.
     609 *
     610 * If the connection is not available at the moment, the
     611 * call will block.
     612 *
     613 * @param phoneid       Phone handle used for contacting the other side.
     614 * @param arg1          User defined argument.
     615 * @param arg2          User defined argument.
     616 * @param arg3          User defined argument.
     617 *
     618 * @return              New phone handle on success or a negative error code.
     619 */
     620int ipc_connect_me_to_blocking(int phoneid, int arg1, int arg2, int arg3)
     621{
     622        ipcarg_t newphid;
     623        int res;
     624
     625        res = ipc_call_sync_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
     626            IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid);
    603627        if (res)
    604628                return res;
  • uspace/lib/libc/generic/kbd.c

    r97c9da8 r19b28b0  
    4242int kbd_get_event(kbd_event_t *ev)
    4343{
    44         int console_phone = get_cons_phone();
     44        int console_phone = get_console_phone();
    4545        ipcarg_t r0, r1, r2, r3;
    4646        int rc;
  • uspace/lib/libc/generic/vfs/vfs.c

    r97c9da8 r19b28b0  
    3232/** @file
    3333 */
    34  
     34
    3535#include <vfs/vfs.h>
    3636#include <vfs/canonify.h>
     
    5858DIR *cwd_dir = NULL;
    5959char *cwd_path = NULL;
    60 size_t cwd_len = 0; 
     60size_t cwd_len = 0;
    6161
    6262char *absolutize(const char *path, size_t *retlen)
     
    110110}
    111111
    112 static int vfs_connect(void)
    113 {
    114         if (vfs_phone < 0)
    115                 vfs_phone = ipc_connect_me_to(PHONE_NS, SERVICE_VFS, 0, 0);
    116         return vfs_phone;
    117 }
    118 
    119 static int device_get_handle(const char *name, dev_handle_t *handle)
    120 {
    121         int phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT,
    122             0);
     112static void vfs_connect(void)
     113{
     114        while (vfs_phone < 0)
     115                vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0);
     116}
     117
     118static int device_get_handle(const char *name, dev_handle_t *handle,
     119    const unsigned int flags)
     120{
     121        int phone;
     122       
     123        if (flags & IPC_FLAG_BLOCKING)
     124                phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT, 0);
     125        else
     126                phone = ipc_connect_me_to(PHONE_NS, SERVICE_DEVMAP, DEVMAP_CLIENT, 0);
     127       
    123128        if (phone < 0)
    124129                return phone;
    125130       
    126131        ipc_call_t answer;
    127         aid_t req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, 0, 0,
     132        aid_t req = async_send_2(phone, DEVMAP_DEVICE_GET_HANDLE, flags, 0,
    128133            &answer);
    129134       
    130135        ipcarg_t retval = ipc_data_write_start(phone, name, strlen(name) + 1);
    131 
     136       
    132137        if (retval != EOK) {
    133138                async_wait_for(req, NULL);
     
    135140                return retval;
    136141        }
    137 
     142       
    138143        async_wait_for(req, &retval);
    139 
     144       
    140145        if (handle != NULL)
    141146                *handle = -1;
     
    150155}
    151156
    152 int mount(const char *fs_name, const char *mp, const char *dev)
     157int mount(const char *fs_name, const char *mp, const char *dev,
     158        const unsigned int flags)
    153159{
    154160        int res;
     
    157163        dev_handle_t dev_handle;
    158164       
    159         res = device_get_handle(dev, &dev_handle);
     165        res = device_get_handle(dev, &dev_handle, flags);
    160166        if (res != EOK)
    161167                return res;
     
    165171        if (!mpa)
    166172                return ENOMEM;
    167 
    168         futex_down(&vfs_phone_futex);
    169         async_serialize_start();
    170         if (vfs_phone < 0) {
    171                 res = vfs_connect();
    172                 if (res < 0) {
    173                         async_serialize_end();
    174                         futex_up(&vfs_phone_futex);
    175                         free(mpa);
    176                         return res;
    177                 }
    178         }
    179         req = async_send_1(vfs_phone, VFS_MOUNT, dev_handle, NULL);
    180         rc = ipc_data_write_start(vfs_phone, (void *)fs_name, strlen(fs_name));
     173       
     174        futex_down(&vfs_phone_futex);
     175        async_serialize_start();
     176        vfs_connect();
     177       
     178        req = async_send_2(vfs_phone, VFS_MOUNT, dev_handle, flags, NULL);
     179        rc = ipc_data_write_start(vfs_phone, (void *) mpa, mpa_len);
    181180        if (rc != EOK) {
    182181                async_wait_for(req, NULL);
     
    186185                return (int) rc;
    187186        }
    188         /* Ask VFS whether it likes fs_name. */
    189         rc = async_req_0_0(vfs_phone, IPC_M_PING);
     187       
     188        rc = ipc_data_write_start(vfs_phone, (void *) fs_name, strlen(fs_name));
    190189        if (rc != EOK) {
    191190                async_wait_for(req, NULL);
     
    195194                return (int) rc;
    196195        }
    197         rc = ipc_data_write_start(vfs_phone, (void *)mpa, mpa_len);
    198         if (rc != EOK) {
    199                 async_wait_for(req, NULL);
    200                 async_serialize_end();
    201                 futex_up(&vfs_phone_futex);
    202                 free(mpa);
    203                 return (int) rc;
    204         }
     196       
    205197        async_wait_for(req, &rc);
    206198        async_serialize_end();
    207199        futex_up(&vfs_phone_futex);
    208200        free(mpa);
     201       
    209202        return (int) rc;
    210203}
     
    212205static int _open(const char *path, int lflag, int oflag, ...)
    213206{
    214         int res;
    215207        ipcarg_t rc;
    216208        ipc_call_t answer;
     
    224216        futex_down(&vfs_phone_futex);
    225217        async_serialize_start();
    226         if (vfs_phone < 0) {
    227                 res = vfs_connect();
    228                 if (res < 0) {
    229                         async_serialize_end();
    230                         futex_up(&vfs_phone_futex);
    231                         free(pa);
    232                         return res;
    233                 }
    234         }
     218        vfs_connect();
     219       
    235220        req = async_send_3(vfs_phone, VFS_OPEN, lflag, oflag, 0, &answer);
    236221        rc = ipc_data_write_start(vfs_phone, pa, pa_len);
     
    259244int close(int fildes)
    260245{
    261         int res;
    262         ipcarg_t rc;
    263 
    264         futex_down(&vfs_phone_futex);
    265         async_serialize_start();
    266         if (vfs_phone < 0) {
    267                 res = vfs_connect();
    268                 if (res < 0) {
    269                         async_serialize_end();
    270                         futex_up(&vfs_phone_futex);
    271                         return res;
    272                 }
    273         }
    274                
     246        ipcarg_t rc;
     247       
     248        futex_down(&vfs_phone_futex);
     249        async_serialize_start();
     250        vfs_connect();
     251       
    275252        rc = async_req_1_0(vfs_phone, VFS_CLOSE, fildes);
    276 
     253       
    277254        async_serialize_end();
    278255        futex_up(&vfs_phone_futex);
     
    283260ssize_t read(int fildes, void *buf, size_t nbyte)
    284261{
    285         int res;
    286262        ipcarg_t rc;
    287263        ipc_call_t answer;
     
    290266        futex_down(&vfs_phone_futex);
    291267        async_serialize_start();
    292         if (vfs_phone < 0) {
    293                 res = vfs_connect();
    294                 if (res < 0) {
    295                         async_serialize_end();
    296                         futex_up(&vfs_phone_futex);
    297                         return res;
    298                 }
    299         }
     268        vfs_connect();
     269       
    300270        req = async_send_1(vfs_phone, VFS_READ, fildes, &answer);
    301271        rc = ipc_data_read_start(vfs_phone, (void *)buf, nbyte);
     
    317287ssize_t write(int fildes, const void *buf, size_t nbyte)
    318288{
    319         int res;
    320289        ipcarg_t rc;
    321290        ipc_call_t answer;
     
    324293        futex_down(&vfs_phone_futex);
    325294        async_serialize_start();
    326         if (vfs_phone < 0) {
    327                 res = vfs_connect();
    328                 if (res < 0) {
    329                         async_serialize_end();
    330                         futex_up(&vfs_phone_futex);
    331                         return res;
    332                 }
    333         }
     295        vfs_connect();
     296       
    334297        req = async_send_1(vfs_phone, VFS_WRITE, fildes, &answer);
    335298        rc = ipc_data_write_start(vfs_phone, (void *)buf, nbyte);
     
    351314off_t lseek(int fildes, off_t offset, int whence)
    352315{
    353         int res;
    354         ipcarg_t rc;
    355 
    356         futex_down(&vfs_phone_futex);
    357         async_serialize_start();
    358         if (vfs_phone < 0) {
    359                 res = vfs_connect();
    360                 if (res < 0) {
    361                         async_serialize_end();
    362                         futex_up(&vfs_phone_futex);
    363                         return res;
    364                 }
    365         }
    366                
     316        ipcarg_t rc;
     317
     318        futex_down(&vfs_phone_futex);
     319        async_serialize_start();
     320        vfs_connect();
     321       
    367322        ipcarg_t newoffs;
    368323        rc = async_req_3_1(vfs_phone, VFS_SEEK, fildes, offset, whence,
     
    380335int ftruncate(int fildes, off_t length)
    381336{
    382         int res;
    383         ipcarg_t rc;
    384        
    385         futex_down(&vfs_phone_futex);
    386         async_serialize_start();
    387         if (vfs_phone < 0) {
    388                 res = vfs_connect();
    389                 if (res < 0) {
    390                         async_serialize_end();
    391                         futex_up(&vfs_phone_futex);
    392                         return res;
    393                 }
    394         }
     337        ipcarg_t rc;
     338       
     339        futex_down(&vfs_phone_futex);
     340        async_serialize_start();
     341        vfs_connect();
     342       
    395343        rc = async_req_2_0(vfs_phone, VFS_TRUNCATE, fildes, length);
    396344        async_serialize_end();
     
    434382int mkdir(const char *path, mode_t mode)
    435383{
    436         int res;
    437384        ipcarg_t rc;
    438385        aid_t req;
     
    442389        if (!pa)
    443390                return ENOMEM;
    444 
    445         futex_down(&vfs_phone_futex);
    446         async_serialize_start();
    447         if (vfs_phone < 0) {
    448                 res = vfs_connect();
    449                 if (res < 0) {
    450                         async_serialize_end();
    451                         futex_up(&vfs_phone_futex);
    452                         free(pa);
    453                         return res;
    454                 }
    455         }
     391       
     392        futex_down(&vfs_phone_futex);
     393        async_serialize_start();
     394        vfs_connect();
     395       
    456396        req = async_send_1(vfs_phone, VFS_MKDIR, mode, NULL);
    457397        rc = ipc_data_write_start(vfs_phone, pa, pa_len);
     
    472412static int _unlink(const char *path, int lflag)
    473413{
    474         int res;
    475414        ipcarg_t rc;
    476415        aid_t req;
     
    483422        futex_down(&vfs_phone_futex);
    484423        async_serialize_start();
    485         if (vfs_phone < 0) {
    486                 res = vfs_connect();
    487                 if (res < 0) {
    488                         async_serialize_end();
    489                         futex_up(&vfs_phone_futex);
    490                         free(pa);
    491                         return res;
    492                 }
    493         }
     424        vfs_connect();
     425       
    494426        req = async_send_0(vfs_phone, VFS_UNLINK, NULL);
    495427        rc = ipc_data_write_start(vfs_phone, pa, pa_len);
     
    520452int rename(const char *old, const char *new)
    521453{
    522         int res;
    523454        ipcarg_t rc;
    524455        aid_t req;
     
    538469        futex_down(&vfs_phone_futex);
    539470        async_serialize_start();
    540         if (vfs_phone < 0) {
    541                 res = vfs_connect();
    542                 if (res < 0) {
    543                         async_serialize_end();
    544                         futex_up(&vfs_phone_futex);
    545                         free(olda);
    546                         free(newa);
    547                         return res;
    548                 }
    549         }
     471        vfs_connect();
     472       
    550473        req = async_send_0(vfs_phone, VFS_RENAME, NULL);
    551474        rc = ipc_data_write_start(vfs_phone, olda, olda_len);
  • uspace/lib/libc/include/async.h

    r97c9da8 r19b28b0  
    7777    async_send_slow((phoneid), (method), (arg1), (arg2), (arg3), (arg4), \
    7878        (arg5), (dataptr))
    79  
     79
    8080extern aid_t async_send_fast(int phoneid, ipcarg_t method, ipcarg_t arg1,
    8181    ipcarg_t arg2, ipcarg_t arg3, ipcarg_t arg4, ipc_call_t *dataptr);
     
    8787    suseconds_t timeout);
    8888
    89 fid_t async_new_connection(ipcarg_t in_phone_hash,ipc_callid_t callid,
    90     ipc_call_t *call, void (*cthread)(ipc_callid_t,ipc_call_t *));
     89fid_t async_new_connection(ipcarg_t in_phone_hash, ipc_callid_t callid,
     90    ipc_call_t *call, void (*cthread)(ipc_callid_t, ipc_call_t *));
    9191void async_usleep(suseconds_t timeout);
    9292void async_create_manager(void);
  • uspace/lib/libc/include/io/stream.h

    r97c9da8 r19b28b0  
    4848extern ssize_t write_stderr(const void *, size_t);
    4949
    50 extern int get_cons_phone(void);
     50extern int get_console_phone(void);
     51extern void console_wait(void);
    5152
    5253#endif
  • uspace/lib/libc/include/ipc/ipc.h

    r97c9da8 r19b28b0  
    247247    ipcarg_t, ipcarg_t, void *, ipc_async_callback_t, int);
    248248
     249#define IPC_FLAG_BLOCKING  0x01
     250
    249251extern int ipc_connect_to_me(int, int, int, int, ipcarg_t *);
    250252extern int ipc_connect_me_to(int, int, int, int);
     253extern int ipc_connect_me_to_blocking(int, int, int, int);
    251254extern int ipc_hangup(int);
    252255extern int ipc_register_irq(int, int, int, irq_code_t *);
  • uspace/lib/libc/include/ipc/services.h

    r97c9da8 r19b28b0  
    3131 */
    3232/**
    33  * @file        services.h
    34  * @brief       List of all known services and their codes.
     33 * @file  services.h
     34 * @brief List of all known services and their codes.
    3535 */
    3636
  • uspace/lib/libc/include/vfs/vfs.h

    r97c9da8 r19b28b0  
    4040extern char *absolutize(const char *, size_t *);
    4141
    42 extern int mount(const char *, const char *, const char *);
     42extern int mount(const char *, const char *, const char *,
     43    const unsigned int flags);
    4344
    4445#endif
Note: See TracChangeset for help on using the changeset viewer.