Changeset e503517a in mainline


Ignore:
Timestamp:
2016-09-02T14:09:40Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c1f7a315
Parents:
42d08592
Message:

Introduce vfs_rdwr_internal()

This function can be used by the VFS itself to do read/write I/O on
client's file descriptor.

Location:
uspace/srv/vfs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/vfs/vfs.h

    r42d08592 re503517a  
    224224extern void vfs_statfs(ipc_callid_t, ipc_call_t *);
    225225
     226typedef struct {
     227        void *buffer;
     228        size_t size;
     229} rdwr_io_chunk_t;
     230
     231extern int vfs_rdwr_internal(int, bool, rdwr_io_chunk_t *);
     232
    226233#endif
    227234
  • uspace/srv/vfs/vfs_ops.c

    r42d08592 re503517a  
    734734}
    735735
    736 typedef sysarg_t (* rdwr_ipc_cb_t)(async_exch_t *, vfs_file_t *, ipc_call_t *,
     736typedef int (* rdwr_ipc_cb_t)(async_exch_t *, vfs_file_t *, ipc_call_t *,
    737737    bool, void *);
    738738
    739 static sysarg_t rdwr_ipc_client(async_exch_t *exch, vfs_file_t *file,
     739static int rdwr_ipc_client(async_exch_t *exch, vfs_file_t *file,
    740740    ipc_call_t *answer, bool read, void *data)
    741741{
     742        size_t *bytes = (size_t *) data;
     743        int rc;
     744
    742745        /*
    743746         * Make a VFS_READ/VFS_WRITE request at the destination FS server
     
    749752
    750753        if (read) {
    751                 return async_data_read_forward_4_1(exch, VFS_OUT_READ,
     754                rc = async_data_read_forward_4_1(exch, VFS_OUT_READ,
    752755                    file->node->service_id, file->node->index,
    753756                    LOWER32(file->pos), UPPER32(file->pos), answer);
    754757        } else {
    755                 return async_data_write_forward_4_1(exch, VFS_OUT_WRITE,
     758                rc = async_data_write_forward_4_1(exch, VFS_OUT_WRITE,
    756759                    file->node->service_id, file->node->index,
    757760                    LOWER32(file->pos), UPPER32(file->pos), answer);
    758         }       
    759 }
    760        
    761 static void vfs_rdwr(ipc_callid_t rid, ipc_call_t *request, bool read,
    762     rdwr_ipc_cb_t ipc_cb, void *ipc_cb_data)
     761        }
     762
     763        *bytes = IPC_GET_ARG1(*answer);
     764        return rc;
     765}
     766
     767static int rdwr_ipc_internal(async_exch_t *exch, vfs_file_t *file,
     768    ipc_call_t *answer, bool read, void *data)
     769{
     770        rdwr_io_chunk_t *chunk = (rdwr_io_chunk_t *) data;
     771
     772        if (exch == NULL)
     773                return ENOENT;
     774       
     775        aid_t msg = async_send_fast(exch, read ? VFS_OUT_READ : VFS_OUT_WRITE,
     776            file->node->service_id, file->node->index, LOWER32(file->pos),
     777            UPPER32(file->pos), answer);
     778        if (msg == 0)
     779                return EINVAL;
     780
     781        int retval = async_data_read_start(exch, chunk->buffer, chunk->size);
     782        if (retval != EOK) {
     783                async_forget(msg);
     784                return retval;
     785        }
     786       
     787        sysarg_t rc;
     788        async_wait_for(msg, &rc);
     789       
     790        chunk->size = IPC_GET_ARG1(*answer);
     791
     792        return (int) rc;
     793}
     794
     795static int vfs_rdwr(int fd, bool read, rdwr_ipc_cb_t ipc_cb, void *ipc_cb_data)
    763796{
    764797        /*
     
    772805         */
    773806       
    774         int fd = IPC_GET_ARG1(*request);
    775        
    776807        /* Lookup the file structure corresponding to the file descriptor. */
    777808        vfs_file_t *file = vfs_file_get(fd);
    778         if (!file) {
    779                 async_answer_0(rid, ENOENT);
    780                 return;
    781         }
     809        if (!file)
     810                return ENOENT;
    782811       
    783812        /*
     
    819848         */
    820849        ipc_call_t answer;
    821         sysarg_t rc = ipc_cb(fs_exch, file, &answer, read, ipc_cb_data);
     850        int rc = ipc_cb(fs_exch, file, &answer, read, ipc_cb_data);
    822851       
    823852        vfs_exchange_release(fs_exch);
     
    846875        vfs_file_put(file);     
    847876
    848         /*
    849          * FS server's reply is the final result of the whole operation we
    850          * return to the client.
    851          */
     877        return rc;
     878}
     879       
     880static void vfs_rdwr_client(ipc_callid_t rid, ipc_call_t *request, bool read)
     881{
     882        size_t bytes = 0;       
     883        int rc = vfs_rdwr(IPC_GET_ARG1(*request), read, rdwr_ipc_client,
     884            &bytes);
    852885        async_answer_1(rid, rc, bytes);
    853886}
    854887
     888int vfs_rdwr_internal(int fd, bool read, rdwr_io_chunk_t *chunk)
     889{
     890        return vfs_rdwr(fd, read, rdwr_ipc_internal, chunk);
     891}
     892
    855893void vfs_read(ipc_callid_t rid, ipc_call_t *request)
    856894{
    857         vfs_rdwr(rid, request, true, rdwr_ipc_client, NULL);
     895        vfs_rdwr_client(rid, request, true);
    858896}
    859897
    860898void vfs_write(ipc_callid_t rid, ipc_call_t *request)
    861899{
    862         vfs_rdwr(rid, request, false, rdwr_ipc_client, NULL);
     900        vfs_rdwr_client(rid, request, false);
    863901}
    864902
Note: See TracChangeset for help on using the changeset viewer.