Changeset 2595dab in mainline for uspace/lib/libc/generic/vfs/vfs.c


Ignore:
Timestamp:
2009-06-03T19:26:28Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d00ae4c
Parents:
ca3ba3a
Message:

I/O subsystem overhaul:

  • add more POSIX-like file and stream functions (with real functionality of stdin, stdout, stderr)
  • cleanup console access methods (now generic to any console-like device)
  • remove unsafe stream functions
  • add special open_node(), fd_node(), fd_phone() (file) and fopen_node(), fnode(), fphone() (stream) functions for HelenOS-specific I/O operations
File:
1 edited

Legend:

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

    rca3ba3a r2595dab  
    5050#include <string.h>
    5151#include <devmap.h>
    52 #include "../../../srv/vfs/vfs.h"
    53 
    54 int vfs_phone = -1;
    55 futex_t vfs_phone_futex = FUTEX_INITIALIZER;
    56 
    57 futex_t cwd_futex = FUTEX_INITIALIZER;
     52#include <ipc/vfs.h>
     53#include <ipc/devmap.h>
     54
     55static int vfs_phone = -1;
     56static futex_t vfs_phone_futex = FUTEX_INITIALIZER;
     57static futex_t cwd_futex = FUTEX_INITIALIZER;
     58
    5859DIR *cwd_dir = NULL;
    5960char *cwd_path = NULL;
     
    211212        futex_up(&vfs_phone_futex);
    212213        free(pa);
    213 
     214       
    214215        if (rc != EOK)
    215216            return (int) rc;
     217       
    216218        return (int) IPC_GET_ARG1(answer);
    217219}
     
    220222{
    221223        return _open(path, L_FILE, oflag);
     224}
     225
     226int open_node(fs_node_t *node, int oflag)
     227{
     228        futex_down(&vfs_phone_futex);
     229        async_serialize_start();
     230        vfs_connect();
     231       
     232        ipc_call_t answer;
     233        aid_t req = async_send_4(vfs_phone, VFS_OPEN_NODE, node->fs_handle,
     234            node->dev_handle, node->index, oflag, &answer);
     235       
     236        ipcarg_t rc;
     237        async_wait_for(req, &rc);
     238        async_serialize_end();
     239        futex_up(&vfs_phone_futex);
     240       
     241        if (rc != EOK)
     242            return (int) rc;
     243       
     244        return (int) IPC_GET_ARG1(answer);
    222245}
    223246
     
    290313        else
    291314                return -1;
     315}
     316
     317int fd_phone(int fildes)
     318{
     319        futex_down(&vfs_phone_futex);
     320        async_serialize_start();
     321        vfs_connect();
     322       
     323        ipcarg_t device;
     324        ipcarg_t rc = async_req_1_1(vfs_phone, VFS_DEVICE, fildes, &device);
     325       
     326        async_serialize_end();
     327        futex_up(&vfs_phone_futex);
     328       
     329        if (rc != EOK)
     330                return -1;
     331       
     332        return devmap_device_connect((dev_handle_t) device, 0);
     333}
     334
     335void fd_node(int fildes, fs_node_t *node)
     336{
     337        futex_down(&vfs_phone_futex);
     338        async_serialize_start();
     339        vfs_connect();
     340       
     341        ipcarg_t fs_handle;
     342        ipcarg_t dev_handle;
     343        ipcarg_t index;
     344        ipcarg_t rc = async_req_1_3(vfs_phone, VFS_NODE, fildes, &fs_handle,
     345            &dev_handle, &index);
     346       
     347        async_serialize_end();
     348        futex_up(&vfs_phone_futex);
     349       
     350        if (rc == EOK) {
     351                node->fs_handle = (fs_handle_t) fs_handle;
     352                node->dev_handle = (dev_handle_t) dev_handle;
     353                node->index = (fs_index_t) index;
     354        } else {
     355                node->fs_handle = 0;
     356                node->dev_handle = 0;
     357                node->index = 0;
     358        }
     359}
     360
     361int fsync(int fildes)
     362{
     363        futex_down(&vfs_phone_futex);
     364        async_serialize_start();
     365        vfs_connect();
     366       
     367        ipcarg_t rc = async_req_1_0(vfs_phone, VFS_SYNC, fildes);
     368       
     369        async_serialize_end();
     370        futex_up(&vfs_phone_futex);
     371       
     372        return (int) rc;
    292373}
    293374
     
    387468        futex_up(&vfs_phone_futex);
    388469        free(pa);
    389         return rc; 
     470        return rc;
    390471}
    391472
     
    417498        futex_up(&vfs_phone_futex);
    418499        free(pa);
    419         return rc; 
     500        return rc;
    420501}
    421502
Note: See TracChangeset for help on using the changeset viewer.