Changeset ee1b8ca in mainline


Ignore:
Timestamp:
2007-12-25T20:02:25Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c1bf5cb
Parents:
1356a04c
Message:

VFS and TMPFS support for VFS_WRITE.

Location:
uspace/srv
Files:
5 edited
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/tmpfs/tmpfs.h

    r1356a04c ree1b8ca  
    6363extern void tmpfs_lookup(ipc_callid_t, ipc_call_t *);
    6464extern void tmpfs_read(ipc_callid_t, ipc_call_t *);
     65extern void tmpfs_write(ipc_callid_t, ipc_call_t *);
    6566
    6667#endif
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    r1356a04c ree1b8ca  
    316316}
    317317
     318void tmpfs_write(ipc_callid_t rid, ipc_call_t *request)
     319{
     320        int dev_handle = IPC_GET_ARG1(*request);
     321        unsigned long index = IPC_GET_ARG2(*request);
     322        off_t pos = IPC_GET_ARG3(*request);
     323
     324        /*
     325         * Lookup the respective dentry.
     326         */
     327        link_t *hlp;
     328        hlp = hash_table_find(&dentries, &index);
     329        if (!hlp) {
     330                ipc_answer_0(rid, ENOENT);
     331                return;
     332        }
     333        tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
     334            dh_link);
     335
     336        /*
     337         * Receive the write request.
     338         */
     339        ipc_callid_t callid;
     340        size_t size;
     341        if (!ipc_data_write_receive(&callid, NULL, &size)) {
     342                ipc_answer_0(callid, EINVAL);   
     343                ipc_answer_0(rid, EINVAL);
     344                return;
     345        }
     346
     347        /*
     348         * At this point, we are deliberately extremely straightforward and
     349         * simply realloc the contents of the file on every write. In the end,
     350         * the situation might not be as bad as it may look: our heap allocator
     351         * can save us and just grow the block whenever possible.
     352         */
     353        void *newdata = realloc(dentry->data, size);
     354        if (!newdata) {
     355                ipc_answer_0(callid, ENOMEM);
     356                ipc_answer_1(rid, EOK, 0);
     357                return;
     358        }
     359        dentry->size = size;
     360        dentry->data = newdata;
     361        (void) ipc_data_write_deliver(callid, dentry->data + pos, size);
     362
     363        /*
     364         * Answer the VFS_WRITE call.
     365         */
     366        ipc_answer_1(rid, EOK, size);
     367}
     368
    318369/**
    319370 * @}
  • uspace/srv/vfs/Makefile

    r1356a04c ree1b8ca  
    4949        vfs_mount.c \
    5050        vfs_open.c \
    51         vfs_read.c \
     51        vfs_rdwr.c \
    5252        vfs_unlink.c
    5353
  • uspace/srv/vfs/vfs.c

    r1356a04c ree1b8ca  
    9797                        vfs_read(callid, &call);
    9898                        break;
     99                case VFS_WRITE:
     100                        vfs_write(callid, &call);
     101                        break;
    99102                case VFS_UNMOUNT:
    100103                case VFS_CREATE:
    101104                case VFS_CLOSE:
    102                 case VFS_WRITE:
    103105                case VFS_SEEK:
    104106                case VFS_UNLINK:
  • uspace/srv/vfs/vfs.h

    r1356a04c ree1b8ca  
    200200extern void vfs_open(ipc_callid_t, ipc_call_t *);
    201201extern void vfs_read(ipc_callid_t, ipc_call_t *);
     202extern void vfs_write(ipc_callid_t, ipc_call_t *);
    202203
    203204#endif
  • uspace/srv/vfs/vfs_rdwr.c

    r1356a04c ree1b8ca  
    3232
    3333/**
    34  * @file        vfs_read.c
     34 * @file        vfs_rdwr.c
    3535 * @brief
    3636 */
     
    4141#include <errno.h>
    4242
    43 void vfs_read(ipc_callid_t rid, ipc_call_t *request)
     43static void vfs_rdwr(ipc_callid_t rid, ipc_call_t *request, bool read)
    4444{
    4545
     
    6666
    6767        /*
    68          * Now we need to receive a call with client's IPC_M_DATA_READ request.
     68         * Now we need to receive a call with client's
     69         * IPC_M_DATA_READ/IPC_M_DATA_WRITE request.
    6970         */
    7071        ipc_callid_t callid;
    71         if (!ipc_data_read_receive(&callid, NULL)) {
     72        int res;
     73        if (read)
     74                res = ipc_data_read_receive(&callid, NULL);
     75        else
     76                res = ipc_data_write_receive(&callid, NULL, NULL);
     77        if (!res) {
    7278                ipc_answer_0(callid, EINVAL);
    7379                ipc_answer_0(rid, EINVAL);
     
    7884       
    7985        /*
    80          * Make a VFS_READ request at the destination FS server.
     86         * Make a VFS_READ/VFS_WRITE request at the destination FS server.
    8187         */
    8288        aid_t msg;
    8389        ipc_call_t answer;
    84         msg = async_send_3(fs_phone, VFS_READ, file->node->dev_handle,
    85             file->node->index, file->pos, &answer);
     90        msg = async_send_3(fs_phone, IPC_GET_METHOD(*request),
     91            file->node->dev_handle, file->node->index, file->pos, &answer);
    8692       
    8793        /*
    88          * Forward the IPC_M_DATA_READ request to the destination FS server.
    89          * The call will be routed as if sent by ourselves. Note that call
    90          * arguments are immutable in this case so we don't have to bother.
     94         * Forward the IPC_M_DATA_READ/IPC_M_DATA_WRITE request to the
     95         * destination FS server. The call will be routed as if sent by
     96         * ourselves. Note that call arguments are immutable in this case so we
     97         * don't have to bother.
    9198         */
    9299        ipc_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
     
    113120}
    114121
     122
     123void vfs_read(ipc_callid_t rid, ipc_call_t *request)
     124{
     125        vfs_rdwr(rid, request, true);
     126}
     127
     128void vfs_write(ipc_callid_t rid, ipc_call_t *request)
     129{
     130        vfs_rdwr(rid, request, false);
     131}
     132
    115133/**
    116134 * @}
Note: See TracChangeset for help on using the changeset viewer.