Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2665 → Rev 2666

/trunk/uspace/srv/fs/tmpfs/tmpfs.h
62,6 → 62,7
 
extern void tmpfs_lookup(ipc_callid_t, ipc_call_t *);
extern void tmpfs_read(ipc_callid_t, ipc_call_t *);
extern void tmpfs_write(ipc_callid_t, ipc_call_t *);
 
#endif
 
/trunk/uspace/srv/fs/tmpfs/tmpfs_ops.c
315,6 → 315,57
ipc_answer_1(rid, EOK, bytes);
}
 
void tmpfs_write(ipc_callid_t rid, ipc_call_t *request)
{
int dev_handle = IPC_GET_ARG1(*request);
unsigned long index = IPC_GET_ARG2(*request);
off_t pos = IPC_GET_ARG3(*request);
 
/*
* Lookup the respective dentry.
*/
link_t *hlp;
hlp = hash_table_find(&dentries, &index);
if (!hlp) {
ipc_answer_0(rid, ENOENT);
return;
}
tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,
dh_link);
 
/*
* Receive the write request.
*/
ipc_callid_t callid;
size_t size;
if (!ipc_data_write_receive(&callid, NULL, &size)) {
ipc_answer_0(callid, EINVAL);
ipc_answer_0(rid, EINVAL);
return;
}
 
/*
* At this point, we are deliberately extremely straightforward and
* simply realloc the contents of the file on every write. In the end,
* the situation might not be as bad as it may look: our heap allocator
* can save us and just grow the block whenever possible.
*/
void *newdata = realloc(dentry->data, size);
if (!newdata) {
ipc_answer_0(callid, ENOMEM);
ipc_answer_1(rid, EOK, 0);
return;
}
dentry->size = size;
dentry->data = newdata;
(void) ipc_data_write_deliver(callid, dentry->data + pos, size);
 
/*
* Answer the VFS_WRITE call.
*/
ipc_answer_1(rid, EOK, size);
}
 
/**
* @}
*/
/trunk/uspace/srv/vfs/vfs_read.c
File deleted
/trunk/uspace/srv/vfs/vfs.c
96,10 → 96,12
case VFS_READ:
vfs_read(callid, &call);
break;
case VFS_WRITE:
vfs_write(callid, &call);
break;
case VFS_UNMOUNT:
case VFS_CREATE:
case VFS_CLOSE:
case VFS_WRITE:
case VFS_SEEK:
case VFS_UNLINK:
case VFS_RENAME:
/trunk/uspace/srv/vfs/vfs.h
199,6 → 199,7
extern void vfs_mount(ipc_callid_t, ipc_call_t *);
extern void vfs_open(ipc_callid_t, ipc_call_t *);
extern void vfs_read(ipc_callid_t, ipc_call_t *);
extern void vfs_write(ipc_callid_t, ipc_call_t *);
 
#endif
 
/trunk/uspace/srv/vfs/Makefile
48,7 → 48,7
vfs_lookup.c \
vfs_mount.c \
vfs_open.c \
vfs_read.c \
vfs_rdwr.c \
vfs_unlink.c
 
OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
/trunk/uspace/srv/vfs/vfs_rdwr.c
0,0 → 1,135
/*
* Copyright (c) 2007 Jakub Jermar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup fs
* @{
*/
 
/**
* @file vfs_rdwr.c
* @brief
*/
 
#include "vfs.h"
#include <ipc/ipc.h>
#include <async.h>
#include <errno.h>
 
static void vfs_rdwr(ipc_callid_t rid, ipc_call_t *request, bool read)
{
 
/*
* The following code strongly depends on the fact that the files data
* structure can be only accessed by a single fibril and all file
* operations are serialized (i.e. the reads and writes cannot
* interleave and a file cannot be closed while it is being read).
*
* Additional synchronization needs to be added once the table of
* open files supports parallel access!
*/
 
int fd = IPC_GET_ARG1(*request);
 
/*
* Lookup the file structure corresponding to the file descriptor.
*/
vfs_file_t *file = vfs_file_get(fd);
if (!file) {
ipc_answer_0(rid, ENOENT);
return;
}
 
/*
* Now we need to receive a call with client's
* IPC_M_DATA_READ/IPC_M_DATA_WRITE request.
*/
ipc_callid_t callid;
int res;
if (read)
res = ipc_data_read_receive(&callid, NULL);
else
res = ipc_data_write_receive(&callid, NULL, NULL);
if (!res) {
ipc_answer_0(callid, EINVAL);
ipc_answer_0(rid, EINVAL);
return;
}
 
int fs_phone = vfs_grab_phone(file->node->fs_handle);
/*
* Make a VFS_READ/VFS_WRITE request at the destination FS server.
*/
aid_t msg;
ipc_call_t answer;
msg = async_send_3(fs_phone, IPC_GET_METHOD(*request),
file->node->dev_handle, file->node->index, file->pos, &answer);
/*
* Forward the IPC_M_DATA_READ/IPC_M_DATA_WRITE request to the
* destination FS server. The call will be routed as if sent by
* ourselves. Note that call arguments are immutable in this case so we
* don't have to bother.
*/
ipc_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
 
vfs_release_phone(fs_phone);
 
/*
* Wait for reply from the FS server.
*/
ipcarg_t rc;
async_wait_for(msg, &rc);
size_t bytes = IPC_GET_ARG1(answer);
 
/*
* Update the position pointer.
*/
file->pos += bytes;
 
/*
* FS server's reply is the final result of the whole operation we
* return to the client.
*/
ipc_answer_1(rid, rc, bytes);
}
 
 
void vfs_read(ipc_callid_t rid, ipc_call_t *request)
{
vfs_rdwr(rid, request, true);
}
 
void vfs_write(ipc_callid_t rid, ipc_call_t *request)
{
vfs_rdwr(rid, request, false);
}
 
/**
* @}
*/