Index: uspace/srv/vfs/Makefile
===================================================================
--- uspace/srv/vfs/Makefile	(revision 5126f801cf167ce675ecc93b5079c64358dcbacb)
+++ uspace/srv/vfs/Makefile	(revision 0d35511b07352cce59e443fae082937725227cae)
@@ -39,4 +39,5 @@
 	vfs_lookup.c \
 	vfs_register.c \
+	vfs_ipc.c \
 	vfs_pager.c
 
Index: uspace/srv/vfs/vfs.c
===================================================================
--- uspace/srv/vfs/vfs.c	(revision 5126f801cf167ce675ecc93b5079c64358dcbacb)
+++ uspace/srv/vfs/vfs.c	(revision 0d35511b07352cce59e443fae082937725227cae)
@@ -74,92 +74,4 @@
 		}
 	}
-}
-
-static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
-{
-	bool cont = true;
-	
-	/*
-	 * The connection was opened via the IPC_CONNECT_ME_TO call.
-	 * This call needs to be answered.
-	 */
-	async_answer_0(iid, EOK);
-	
-	while (cont) {
-		ipc_call_t call;
-		ipc_callid_t callid = async_get_call(&call);
-		
-		if (!IPC_GET_IMETHOD(call))
-			break;
-		
-		switch (IPC_GET_IMETHOD(call)) {
-		case VFS_IN_REGISTER:
-			vfs_register(callid, &call);
-			cont = false;
-			break;
-		case VFS_IN_MOUNT:
-			vfs_mount_srv(callid, &call);
-			break;
-		case VFS_IN_UNMOUNT:
-			vfs_unmount_srv(callid, &call);
-			break;
-		case VFS_IN_WALK:
-			vfs_walk(callid, &call);
-			break;
-		case VFS_IN_OPEN2:
-			vfs_open2(callid, &call);
-			break;
-		case VFS_IN_CLOSE:
-			vfs_close(callid, &call);
-			break;
-		case VFS_IN_READ:
-			vfs_read(callid, &call);
-			break;
-		case VFS_IN_WRITE:
-			vfs_write(callid, &call);
-			break;
-		case VFS_IN_SEEK:
-			vfs_seek(callid, &call);
-			break;
-		case VFS_IN_TRUNCATE:
-			vfs_truncate(callid, &call);
-			break;
-		case VFS_IN_FSTAT:
-			vfs_fstat(callid, &call);
-			break;
-		case VFS_IN_UNLINK2:
-			vfs_unlink2(callid, &call);
-			break;
-		case VFS_IN_RENAME:
-			vfs_rename(callid, &call);
-			break;
-		case VFS_IN_SYNC:
-			vfs_sync(callid, &call);
-			break;
-		case VFS_IN_DUP:
-			vfs_dup(callid, &call);
-			break;
-		case VFS_IN_WAIT_HANDLE:
-			vfs_wait_handle(callid, &call);
-			break;
-		case VFS_IN_MTAB_GET:
-			vfs_get_mtab(callid, &call);
-			break;
-		case VFS_IN_STATFS:
-			vfs_statfs(callid, &call);
-			break;
-		case VFS_IN_CLONE:
-			vfs_op_clone(callid, &call);
-			break;
-		default:
-			async_answer_0(callid, ENOTSUP);
-			break;
-		}
-	}
-	
-	/*
-	 * Open files for this client will be cleaned up when its last
-	 * connection fibril terminates.
-	 */
 }
 
Index: uspace/srv/vfs/vfs.h
===================================================================
--- uspace/srv/vfs/vfs.h	(revision 5126f801cf167ce675ecc93b5079c64358dcbacb)
+++ uspace/srv/vfs/vfs.h	(revision 0d35511b07352cce59e443fae082937725227cae)
@@ -144,5 +144,5 @@
 
 	/** Current absolute position in the file. */
-	aoff64_t pos;
+	int64_t pos;
 } vfs_file_t;
 
@@ -175,5 +175,5 @@
 extern void vfs_exchange_release(async_exch_t *);
 
-extern fs_handle_t fs_name_to_handle(unsigned int instance, char *, bool);
+extern fs_handle_t fs_name_to_handle(unsigned int instance, const char *, bool);
 extern vfs_info_t *fs_handle_to_info(fs_handle_t);
 
@@ -209,19 +209,24 @@
 extern int vfs_open_node_remote(vfs_node_t *);
 
+extern int vfs_op_clone(int oldfd, bool desc);
+extern int vfs_op_close(int fd);
+extern int vfs_op_dup(int oldfd, int newfd);
+extern int vfs_op_fstat_forward(int fd);
+extern int vfs_op_mount(int mpfd, unsigned servid, unsigned flags, unsigned instance, const char *opts, const char *fsname, int *outfd);
+extern int vfs_op_mtab_get(void);
+extern int vfs_op_open2(int fd, int flags);
+extern int vfs_op_read(int fd, size_t *out_bytes);
+extern int vfs_op_rename(int basefd, char *old, char *new);
+extern int vfs_op_seek(int fd, int64_t offset, int whence, int64_t *out_offset);
+extern int vfs_op_statfs(int fd);
+extern int vfs_op_sync(int fd);
+extern int vfs_op_truncate(int fd, int64_t size);
+extern int vfs_op_unlink2(int parentfd, int expectfd, int wflag, char *path);
+extern int vfs_op_unmount(int mpfd);
+extern int vfs_op_wait_handle(bool high_fd);
+extern int vfs_op_walk(int parentfd, int flags, char *path, int *out_fd);
+extern int vfs_op_write(int fd, size_t *out_bytes);
+
 extern void vfs_register(ipc_callid_t, ipc_call_t *);
-extern void vfs_mount_srv(ipc_callid_t, ipc_call_t *);
-extern void vfs_unmount_srv(ipc_callid_t, ipc_call_t *);
-extern void vfs_sync(ipc_callid_t, ipc_call_t *);
-extern void vfs_dup(ipc_callid_t, ipc_call_t *);
-extern void vfs_close(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 *);
-extern void vfs_seek(ipc_callid_t, ipc_call_t *);
-extern void vfs_truncate(ipc_callid_t, ipc_call_t *);
-extern void vfs_fstat(ipc_callid_t, ipc_call_t *);
-extern void vfs_rename(ipc_callid_t, ipc_call_t *);
-extern void vfs_wait_handle(ipc_callid_t, ipc_call_t *);
-extern void vfs_get_mtab(ipc_callid_t, ipc_call_t *);
-extern void vfs_statfs(ipc_callid_t, ipc_call_t *);
 
 extern void vfs_page_in(ipc_callid_t, ipc_call_t *);
@@ -234,8 +239,5 @@
 extern int vfs_rdwr_internal(int, bool, rdwr_io_chunk_t *);
 
-extern void vfs_walk(ipc_callid_t, ipc_call_t *);
-extern void vfs_open2(ipc_callid_t, ipc_call_t *);
-extern void vfs_unlink2(ipc_callid_t, ipc_call_t *);
-extern void vfs_op_clone(ipc_callid_t, ipc_call_t *);
+extern void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg);
 
 #endif
Index: uspace/srv/vfs/vfs_ipc.c
===================================================================
--- uspace/srv/vfs/vfs_ipc.c	(revision 0d35511b07352cce59e443fae082937725227cae)
+++ uspace/srv/vfs/vfs_ipc.c	(revision 0d35511b07352cce59e443fae082937725227cae)
@@ -0,0 +1,361 @@
+/*
+ * Copyright (c) 2008 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.
+ */
+
+#include "vfs.h"
+
+#include <errno.h>
+#include <stdlib.h>
+#include <str.h>
+#include <vfs/canonify.h>
+
+static void vfs_in_clone(ipc_callid_t rid, ipc_call_t *request)
+{
+	int oldfd = IPC_GET_ARG1(*request);
+	bool desc = IPC_GET_ARG2(*request);
+	
+	int ret = vfs_op_clone(oldfd, desc);
+	async_answer_0(rid, ret);
+}
+
+static void vfs_in_close(ipc_callid_t rid, ipc_call_t *request)
+{
+	int fd = IPC_GET_ARG1(*request);
+	int rc = vfs_op_close(fd);
+	async_answer_0(rid, rc);
+}
+
+static void vfs_in_dup(ipc_callid_t rid, ipc_call_t *request)
+{
+	int oldfd = IPC_GET_ARG1(*request);
+	int newfd = IPC_GET_ARG2(*request);
+	int rc = vfs_op_dup(oldfd, newfd);
+	async_answer_1(rid, rc, newfd);
+}
+
+static void vfs_in_fstat(ipc_callid_t rid, ipc_call_t *request)
+{
+	int fd = IPC_GET_ARG1(*request);
+	int rc = vfs_op_fstat_forward(fd);
+	async_answer_0(rid, rc);
+}
+
+static void vfs_in_mount(ipc_callid_t rid, ipc_call_t *request)
+{
+	int mpfd = IPC_GET_ARG1(*request);
+	
+	/*
+	 * We expect the library to do the device-name to device-handle
+	 * translation for us, thus the device handle will arrive as ARG1
+	 * in the request.
+	 */
+	service_id_t service_id = (service_id_t) IPC_GET_ARG2(*request);
+	
+	unsigned int flags = (unsigned int) IPC_GET_ARG3(*request);
+	unsigned int instance = IPC_GET_ARG4(*request);
+	
+	char *opts = NULL;
+	char *fs_name = NULL;
+	
+	/* Now we expect to receive the mount options. */
+	int rc = async_data_write_accept((void **) &opts, true, 0,
+	    MAX_MNTOPTS_LEN, 0, NULL);
+	if (rc != EOK) {
+		async_answer_0(rid, rc);
+		return;
+	}
+	
+	/* Now, we expect the client to send us data with the name of the file 
+	 * system.
+	 */
+	rc = async_data_write_accept((void **) &fs_name, true, 0,
+	    FS_NAME_MAXLEN, 0, NULL);
+	if (rc != EOK) {
+		free(opts);
+		async_answer_0(rid, rc);
+		return;
+	}
+	
+	int outfd = 0;
+	rc = vfs_op_mount(mpfd, service_id, flags, instance, opts, fs_name,
+	     &outfd);
+	async_answer_1(rid, rc, outfd);
+	
+	free(opts);
+	free(fs_name);
+}
+
+static void vfs_in_mtab_get(ipc_callid_t rid, ipc_call_t *request)
+{
+	int rc = vfs_op_mtab_get();
+	async_answer_0(rid, rc);
+}
+
+static void vfs_in_open2(ipc_callid_t rid, ipc_call_t *request)
+{
+	int fd = IPC_GET_ARG1(*request);
+	int flags = IPC_GET_ARG2(*request);
+
+	int rc = vfs_op_open2(fd, flags);
+	async_answer_0(rid, rc);
+}
+
+static void vfs_in_read(ipc_callid_t rid, ipc_call_t *request)
+{
+	int fd = IPC_GET_ARG1(*request);
+
+	size_t bytes = 0;
+	int rc = vfs_op_read(fd, &bytes);
+	async_answer_1(rid, rc, bytes);
+}
+
+static void vfs_in_rename(ipc_callid_t rid, ipc_call_t *request)
+{
+	/* The common base directory. */
+	int basefd;
+	char *old = NULL;
+	char *new = NULL;
+	int rc;
+	
+	basefd = IPC_GET_ARG1(*request);
+	
+	/* Retrieve the old path. */
+	rc = async_data_write_accept((void **) &old, true, 0, 0, 0, NULL);
+	if (rc != EOK) {
+		goto out;
+	}
+	
+	/* Retrieve the new path. */
+	rc = async_data_write_accept((void **) &new, true, 0, 0, 0, NULL);
+	if (rc != EOK) {
+		goto out;
+	}
+	
+	size_t olen;
+	size_t nlen;
+	char *oldc = canonify(old, &olen);
+	char *newc = canonify(new, &nlen);
+	
+	if ((!oldc) || (!newc)) {
+		rc = EINVAL;
+		goto out;
+	}
+	
+	assert(oldc[olen] == '\0');
+	assert(newc[nlen] == '\0');
+	
+	rc = vfs_op_rename(basefd, oldc, newc);
+
+out:
+	async_answer_0(rid, rc);
+
+	if (old) {
+		free(old);
+	}
+	if (new) {
+		free(new);
+	}
+}
+
+static void vfs_in_seek(ipc_callid_t rid, ipc_call_t *request)
+{
+	int fd = (int) IPC_GET_ARG1(*request);
+	int64_t off = (int64_t) MERGE_LOUP32(IPC_GET_ARG2(*request), IPC_GET_ARG3(*request));
+	int whence = (int) IPC_GET_ARG4(*request);
+
+	int64_t new_offset = 0;
+	int rc = vfs_op_seek(fd, off, whence, &new_offset);
+	async_answer_2(rid, rc, LOWER32(new_offset), UPPER32(new_offset));
+}
+
+static void vfs_in_statfs(ipc_callid_t rid, ipc_call_t *request)
+{
+	int fd = (int) IPC_GET_ARG1(*request);
+	
+	int rc = vfs_op_statfs(fd);
+	async_answer_0(rid, rc);
+}
+
+static void vfs_in_sync(ipc_callid_t rid, ipc_call_t *request)
+{
+	int fd = IPC_GET_ARG1(*request);
+	int rc = vfs_op_sync(fd);
+	async_answer_0(rid, rc);
+}
+
+static void vfs_in_truncate(ipc_callid_t rid, ipc_call_t *request)
+{
+	int fd = IPC_GET_ARG1(*request);
+	int64_t size = MERGE_LOUP32(IPC_GET_ARG2(*request), IPC_GET_ARG3(*request));
+	int rc = vfs_op_truncate(fd, size);
+	async_answer_0(rid, rc);
+}
+
+static void vfs_in_unlink2(ipc_callid_t rid, ipc_call_t *request)
+{
+	int parentfd = IPC_GET_ARG1(*request);
+	int expectfd = IPC_GET_ARG2(*request);
+	int wflag = IPC_GET_ARG3(*request);
+	
+	char *path;
+	int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
+	if (rc == EOK) {
+		rc = vfs_op_unlink2(parentfd, expectfd, wflag, path);
+	}
+	
+	async_answer_0(rid, rc);
+}
+
+static void vfs_in_unmount(ipc_callid_t rid, ipc_call_t *request)
+{
+	int mpfd = IPC_GET_ARG1(*request);
+	int rc = vfs_op_unmount(mpfd);
+	async_answer_0(rid, rc);
+}
+
+static void vfs_in_wait_handle(ipc_callid_t rid, ipc_call_t *request)
+{
+	bool high_fd = IPC_GET_ARG1(*request);
+	int fd = vfs_op_wait_handle(high_fd);
+	async_answer_1(rid, EOK, fd);
+}
+
+static void vfs_in_walk(ipc_callid_t rid, ipc_call_t *request)
+{
+	/*
+	 * Parent is our relative root for file lookup.
+	 * For defined flags, see <ipc/vfs.h>.
+	 */
+	int parentfd = IPC_GET_ARG1(*request);
+	int flags = IPC_GET_ARG2(*request);
+	
+	int fd = 0;
+	char *path;
+	int rc = async_data_write_accept((void **)&path, true, 0, 0, 0, NULL);
+	if (rc == EOK) {
+		rc = vfs_op_walk(parentfd, flags, path, &fd);
+		free(path);
+	}
+	async_answer_1(rid, rc, fd);
+}
+
+static void vfs_in_write(ipc_callid_t rid, ipc_call_t *request)
+{
+	int fd = IPC_GET_ARG1(*request);
+
+	size_t bytes = 0;
+	int rc = vfs_op_write(fd, &bytes);
+	async_answer_1(rid, rc, bytes);
+}
+
+void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
+{
+	bool cont = true;
+	
+	/*
+	 * The connection was opened via the IPC_CONNECT_ME_TO call.
+	 * This call needs to be answered.
+	 */
+	async_answer_0(iid, EOK);
+	
+	while (cont) {
+		ipc_call_t call;
+		ipc_callid_t callid = async_get_call(&call);
+		
+		if (!IPC_GET_IMETHOD(call))
+			break;
+		
+		switch (IPC_GET_IMETHOD(call)) {
+		case VFS_IN_CLONE:
+			vfs_in_clone(callid, &call);
+			break;
+		case VFS_IN_CLOSE:
+			vfs_in_close(callid, &call);
+			break;
+		case VFS_IN_DUP:
+			vfs_in_dup(callid, &call);
+			break;
+		case VFS_IN_FSTAT:
+			vfs_in_fstat(callid, &call);
+			break;
+		case VFS_IN_MOUNT:
+			vfs_in_mount(callid, &call);
+			break;
+		case VFS_IN_MTAB_GET:
+			vfs_in_mtab_get(callid, &call);
+			break;
+		case VFS_IN_OPEN2:
+			vfs_in_open2(callid, &call);
+			break;
+		case VFS_IN_READ:
+			vfs_in_read(callid, &call);
+			break;
+		case VFS_IN_REGISTER:
+			vfs_register(callid, &call);
+			cont = false;
+			break;
+		case VFS_IN_RENAME:
+			vfs_in_rename(callid, &call);
+			break;
+		case VFS_IN_SEEK:
+			vfs_in_seek(callid, &call);
+			break;
+		case VFS_IN_STATFS:
+			vfs_in_statfs(callid, &call);
+			break;
+		case VFS_IN_SYNC:
+			vfs_in_sync(callid, &call);
+			break;
+		case VFS_IN_TRUNCATE:
+			vfs_in_truncate(callid, &call);
+			break;
+		case VFS_IN_UNLINK2:
+			vfs_in_unlink2(callid, &call);
+			break;
+		case VFS_IN_UNMOUNT:
+			vfs_in_unmount(callid, &call);
+			break;
+		case VFS_IN_WAIT_HANDLE:
+			vfs_in_wait_handle(callid, &call);
+			break;
+		case VFS_IN_WALK:
+			vfs_in_walk(callid, &call);
+			break;
+		case VFS_IN_WRITE:
+			vfs_in_write(callid, &call);
+			break;
+		default:
+			async_answer_0(callid, ENOTSUP);
+			break;
+		}
+	}
+	
+	/*
+	 * Open files for this client will be cleaned up when its last
+	 * connection fibril terminates.
+	 */
+}
Index: uspace/srv/vfs/vfs_ops.c
===================================================================
--- uspace/srv/vfs/vfs_ops.c	(revision 5126f801cf167ce675ecc93b5079c64358dcbacb)
+++ uspace/srv/vfs/vfs_ops.c	(revision 0d35511b07352cce59e443fae082937725227cae)
@@ -68,6 +68,119 @@
 FIBRIL_RWLOCK_INITIALIZE(namespace_rwlock);
 
-static int vfs_connect_internal(service_id_t service_id, unsigned flags, unsigned instance,
-    char *options, char *fsname, vfs_node_t **root)
+static size_t shared_path(char *a, char *b)
+{
+	size_t res = 0;
+	
+	while (a[res] == b[res] && a[res] != 0) {
+		res++;
+	}
+	
+	if (a[res] == b[res]) {
+		return res;
+	}
+	
+	res--;
+	while (a[res] != '/') {
+		res--;
+	}
+	return res;
+}
+
+/* This call destroys the file if and only if there are no hard links left. */
+static void out_destroy(vfs_triplet_t *file)
+{
+	async_exch_t *exch = vfs_exchange_grab(file->fs_handle);
+	async_msg_2(exch, VFS_OUT_DESTROY,
+		(sysarg_t) file->service_id, (sysarg_t) file->index);
+	vfs_exchange_release(exch);
+}
+
+int vfs_op_clone(int oldfd, bool desc)
+{
+	/* Lookup the file structure corresponding to fd. */
+	vfs_file_t *oldfile = vfs_file_get(oldfd);
+	if (oldfile == NULL) {
+		return EBADF;
+	}
+	assert(oldfile->node != NULL);
+	
+	vfs_file_t *newfile;
+	int newfd = vfs_fd_alloc(&newfile, desc);
+	if (newfd >= 0) {
+		newfile->node = oldfile->node;
+		newfile->permissions = oldfile->permissions;
+		vfs_node_addref(newfile->node);
+	
+		vfs_file_put(newfile);
+	}
+	vfs_file_put(oldfile);
+	
+	return newfd;
+}
+
+int vfs_op_close(int fd)
+{
+	return vfs_fd_free(fd);
+}
+
+int vfs_op_dup(int oldfd, int newfd)
+{
+	/* If the file descriptors are the same, do nothing. */
+	if (oldfd == newfd) {
+		return EOK;
+	}
+	
+	/* Lookup the file structure corresponding to oldfd. */
+	vfs_file_t *oldfile = vfs_file_get(oldfd);
+	if (!oldfile) {
+		return EBADF;
+	}
+	
+	/* Make sure newfd is closed. */
+	(void) vfs_fd_free(newfd);
+	
+	/* Assign the old file to newfd. */
+	int ret = vfs_fd_assign(oldfile, newfd);
+	vfs_file_put(oldfile);
+	
+	return ret;
+}
+
+int vfs_op_fstat_forward(int fd)
+{
+	vfs_file_t *file = vfs_file_get(fd);
+	if (!file) {
+		return EBADF;
+	}
+	assert(file->node);
+	
+	ipc_callid_t callid;
+	if (!async_data_read_receive(&callid, NULL)) {
+		vfs_file_put(file);
+		async_answer_0(callid, EINVAL);
+		return EINVAL;
+	}
+
+	async_exch_t *exch = vfs_exchange_grab(file->node->fs_handle);
+	assert(exch);
+	
+	aid_t msg;
+	msg = async_send_3(exch, VFS_OUT_STAT, file->node->service_id,
+	    file->node->index, true, NULL);
+	assert(msg);
+	async_forward_fast(callid, exch, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
+	
+	vfs_exchange_release(exch);
+	
+	sysarg_t rc;
+	async_wait_for(msg, &rc);
+	
+	vfs_file_put(file);
+	return rc;
+}
+
+static int vfs_connect_internal(service_id_t service_id, unsigned flags,
+    unsigned instance, const char *options, const char *fsname,
+    vfs_node_t **root)
 {
 	fs_handle_t fs_handle = 0;
@@ -92,5 +205,6 @@
 	ipc_call_t answer;
 	async_exch_t *exch = vfs_exchange_grab(fs_handle);
-	aid_t msg = async_send_1(exch, VFS_OUT_MOUNTED, (sysarg_t) service_id, &answer);
+	aid_t msg = async_send_1(exch, VFS_OUT_MOUNTED, (sysarg_t) service_id,
+	    &answer);
 	/* Send the mount options */
 	sysarg_t rc = async_data_write_start(exch, options, str_size(options));
@@ -111,5 +225,6 @@
 	res.triplet.service_id = service_id;
 	res.triplet.index = (fs_index_t) IPC_GET_ARG1(answer);
-	res.size = (int64_t) MERGE_LOUP32(IPC_GET_ARG2(answer), IPC_GET_ARG3(answer));
+	res.size = (int64_t) MERGE_LOUP32(IPC_GET_ARG2(answer),
+	    IPC_GET_ARG3(answer));
 	res.type = VFS_NODE_DIRECTORY;
 	
@@ -121,49 +236,12 @@
 }
 
-void vfs_mount_srv(ipc_callid_t rid, ipc_call_t *request)
-{
-	int mpfd = IPC_GET_ARG1(*request);
-	
-	/*
-	 * We expect the library to do the device-name to device-handle
-	 * translation for us, thus the device handle will arrive as ARG1
-	 * in the request.
-	 */
-	service_id_t service_id = (service_id_t) IPC_GET_ARG2(*request);
-	
-	/*
-	 * Mount flags are passed as ARG2.
-	 */
-	unsigned int flags = (unsigned int) IPC_GET_ARG3(*request);
-	
-	/*
-	 * Instance number is passed as ARG3.
-	 */
-	unsigned int instance = IPC_GET_ARG4(*request);
-	
-	char *opts = NULL;
-	char *fs_name = NULL;
+int vfs_op_mount(int mpfd, unsigned service_id, unsigned flags,
+    unsigned instance, const char *opts, const char *fs_name, int *outfd)
+{
+	int rc;
 	vfs_file_t *mp = NULL;
 	vfs_file_t *file = NULL;
 	int fd = -1;
 	mtab_ent_t *mtab_ent = NULL;
-
-	/* Now we expect to receive the mount options. */
-	int rc = async_data_write_accept((void **) &opts, true, 0, MAX_MNTOPTS_LEN,
-	    0, NULL);
-	if (rc != EOK) {
-		async_data_write_void(rc);
-		goto out;
-	}
-	
-	/*
-	 * Now, we expect the client to send us data with the name of the file
-	 * system.
-	 */
-	rc = async_data_write_accept((void **) &fs_name, true, 0,
-	    FS_NAME_MAXLEN, 0, NULL);
-	if (rc != EOK) {
-		goto out;
-	}
 	
 	if (!(flags & VFS_MOUNT_CONNECT_ONLY)) {
@@ -209,5 +287,6 @@
 	fibril_rwlock_write_lock(&namespace_rwlock);
 
-	rc = vfs_connect_internal(service_id, flags, instance, opts, fs_name, &root);
+	rc = vfs_connect_internal(service_id, flags, instance, opts, fs_name,
+	     &root);
 	if (rc == EOK && !(flags & VFS_MOUNT_CONNECT_ONLY)) {
 		vfs_node_addref(mp->node);
@@ -235,30 +314,18 @@
 	
 	/* Add the filesystem info to the list of mounted filesystems */
-	if (rc == EOK) {
-		str_cpy(mtab_ent->mp, MAX_PATH_LEN, "fixme");
-		str_cpy(mtab_ent->fs_name, FS_NAME_MAXLEN, fs_name);
-		str_cpy(mtab_ent->opts, MAX_MNTOPTS_LEN, opts);
-		mtab_ent->instance = instance;
-		mtab_ent->service_id = service_id;
-
-		link_initialize(&mtab_ent->link);
-
-		fibril_mutex_lock(&mtab_list_lock);
-		list_append(&mtab_ent->link, &mtab_list);
-		mtab_size++;
-		fibril_mutex_unlock(&mtab_list_lock);
-	}	
-	
-	rc = EOK;
+	str_cpy(mtab_ent->mp, MAX_PATH_LEN, "fixme");
+	str_cpy(mtab_ent->fs_name, FS_NAME_MAXLEN, fs_name);
+	str_cpy(mtab_ent->opts, MAX_MNTOPTS_LEN, opts);
+	mtab_ent->instance = instance;
+	mtab_ent->service_id = service_id;
+
+	link_initialize(&mtab_ent->link);
+
+	fibril_mutex_lock(&mtab_list_lock);
+	list_append(&mtab_ent->link, &mtab_list);
+	mtab_size++;
+	fibril_mutex_unlock(&mtab_list_lock);	
 
 out:
-	async_answer_1(rid, rc, rc == EOK ? fd : 0);
-
-	if (opts) {
-		free(opts);
-	}
-	if (fs_name) {
-		free(fs_name);
-	}
 	if (mp) {
 		vfs_file_put(mp);
@@ -269,209 +336,92 @@
 	if (rc != EOK && fd >= 0) {
 		vfs_fd_free(fd);
-	}
-}
-
-void vfs_unmount_srv(ipc_callid_t rid, ipc_call_t *request)
-{
-	int mpfd = IPC_GET_ARG1(*request);
-	
-	vfs_file_t *mp = vfs_file_get(mpfd);
-	if (mp == NULL) {
-		async_answer_0(rid, EBADF);
-		return;
-	}
-	
-	if (mp->node->mount == NULL) {
-		async_answer_0(rid, ENOENT);
-		vfs_file_put(mp);
-		return;
-	}
-	
-	fibril_rwlock_write_lock(&namespace_rwlock);
-	
-	/*
-	 * Count the total number of references for the mounted file system. We
-	 * are expecting at least one, which is held by the mount point.
-	 * If we find more, it means that
-	 * the file system cannot be gracefully unmounted at the moment because
-	 * someone is working with it.
-	 */
-	if (vfs_nodes_refcount_sum_get(mp->node->mount->fs_handle, mp->node->mount->service_id) != 1) {
-		async_answer_0(rid, EBUSY);
-		vfs_file_put(mp);
-		fibril_rwlock_write_unlock(&namespace_rwlock);
-		return;
-	}
-	
-	async_exch_t *exch = vfs_exchange_grab(mp->node->mount->fs_handle);
-	int rc = async_req_1_0(exch, VFS_OUT_UNMOUNTED, mp->node->mount->service_id);
-	vfs_exchange_release(exch);
-	
-	if (rc != EOK) {
-		async_answer_0(rid, rc);
-		vfs_file_put(mp);
-		fibril_rwlock_write_unlock(&namespace_rwlock);
-		return;
-	}
-	
-	vfs_node_forget(mp->node->mount);
-	vfs_node_put(mp->node);
-	mp->node->mount = NULL;
-	
-	fibril_rwlock_write_unlock(&namespace_rwlock);
-	
+		fd = 0;
+	}
+	
+	*outfd = fd;
+	return rc;
+}
+
+int vfs_op_mtab_get(void)
+{
+	ipc_callid_t callid;
+	ipc_call_t data;
+	sysarg_t rc = EOK;
+	size_t len;
+
 	fibril_mutex_lock(&mtab_list_lock);
-	int found = 0;
+
+	/* Send to the caller the number of mounted filesystems */
+	callid = async_get_call(&data);
+	if (IPC_GET_IMETHOD(data) != VFS_IN_PING) {
+		rc = ENOTSUP;
+		async_answer_0(callid, rc);
+		goto exit;
+	}
+	async_answer_1(callid, EOK, mtab_size);
 
 	list_foreach(mtab_list, link, mtab_ent_t, mtab_ent) {
-		// FIXME: mp name
-		if (str_cmp(mtab_ent->mp, "fixme") == 0) {
-			list_remove(&mtab_ent->link);
-			mtab_size--;
-			free(mtab_ent);
-			found = 1;
-			break;
-		}
-	}
-	assert(found);
+		rc = ENOTSUP;
+
+		if (!async_data_read_receive(&callid, &len)) {
+			async_answer_0(callid, rc);
+			goto exit;
+		}
+
+		(void) async_data_read_finalize(callid, mtab_ent->mp,
+		    str_size(mtab_ent->mp));
+
+		if (!async_data_read_receive(&callid, &len)) {
+			async_answer_0(callid, rc);
+			goto exit;
+		}
+
+		(void) async_data_read_finalize(callid, mtab_ent->opts,
+		    str_size(mtab_ent->opts));
+
+		if (!async_data_read_receive(&callid, &len)) {
+			async_answer_0(callid, rc);
+			goto exit;
+		}
+
+		(void) async_data_read_finalize(callid, mtab_ent->fs_name,
+		    str_size(mtab_ent->fs_name));
+
+		callid = async_get_call(&data);
+
+		if (IPC_GET_IMETHOD(data) != VFS_IN_PING) {
+			async_answer_0(callid, rc);
+			goto exit;
+		}
+
+		rc = EOK;
+		async_answer_2(callid, rc, mtab_ent->instance,
+		    mtab_ent->service_id);
+	}
+
+exit:
 	fibril_mutex_unlock(&mtab_list_lock);
-	
-	vfs_file_put(mp);
-	async_answer_0(rid, EOK);
-}
-
-static inline bool walk_flags_valid(int flags)
-{
-	if ((flags&~WALK_ALL_FLAGS) != 0) {
-		return false;
-	}
-	if ((flags&WALK_MAY_CREATE) && (flags&WALK_MUST_CREATE)) {
-		return false;
-	}
-	if ((flags&WALK_REGULAR) && (flags&WALK_DIRECTORY)) {
-		return false;
-	}
-	if ((flags&WALK_MAY_CREATE) || (flags&WALK_MUST_CREATE)) {
-		if (!(flags&WALK_DIRECTORY) && !(flags&WALK_REGULAR)) {
-			return false;
-		}
-	}
-	return true;
-}
-
-static inline int walk_lookup_flags(int flags)
-{
-	int lflags = 0;
-	if (flags&WALK_MAY_CREATE || flags&WALK_MUST_CREATE) {
-		lflags |= L_CREATE;
-	}
-	if (flags&WALK_MUST_CREATE) {
-		lflags |= L_EXCLUSIVE;
-	}
-	if (flags&WALK_REGULAR) {
-		lflags |= L_FILE;
-	}
-	if (flags&WALK_DIRECTORY) {
-		lflags |= L_DIRECTORY;
-	}
-	if (flags&WALK_MOUNT_POINT) {
-		lflags |= L_MP;
-	}
-	return lflags;
-}
-
-void vfs_walk(ipc_callid_t rid, ipc_call_t *request)
-{
-	/*
-	 * Parent is our relative root for file lookup.
-	 * For defined flags, see <ipc/vfs.h>.
-	 */
-	int parentfd = IPC_GET_ARG1(*request);
-	int flags = IPC_GET_ARG2(*request);
-	
-	if (!walk_flags_valid(flags)) {
-		async_answer_0(rid, EINVAL);
-		return;
-	}
-	
-	char *path;
-	int rc = async_data_write_accept((void **)&path, true, 0, 0, 0, NULL);
-	
-	/* Lookup the file structure corresponding to the file descriptor. */
-	vfs_file_t *parent = vfs_file_get(parentfd);
-	if (!parent) {
-		free(path);
-		async_answer_0(rid, EBADF);
-		return;
-	}
-	
-	fibril_rwlock_read_lock(&namespace_rwlock);
-	
-	vfs_lookup_res_t lr;
-	rc = vfs_lookup_internal(parent->node, path, walk_lookup_flags(flags), &lr);
-	free(path);
-
-	if (rc != EOK) {
-		fibril_rwlock_read_unlock(&namespace_rwlock);
-		if (parent) {
-			vfs_file_put(parent);
-		}
-		async_answer_0(rid, rc);
-		return;
-	}
-	
-	vfs_node_t *node = vfs_node_get(&lr);
-	
-	vfs_file_t *file;
-	int fd = vfs_fd_alloc(&file, false);
-	if (fd < 0) {
-		vfs_node_put(node);
-		if (parent) {
-			vfs_file_put(parent);
-		}
-		async_answer_0(rid, fd);
-		return;
-	}
-	assert(file != NULL);
-	
-	file->node = node;
-	if (parent) {
-		file->permissions = parent->permissions;
-	} else {
-		file->permissions = MODE_READ | MODE_WRITE | MODE_APPEND;
-	}
-	file->open_read = false;
-	file->open_write = false;
-	
-	vfs_file_put(file);
-	if (parent) {
-		vfs_file_put(parent);
-	}
-	
-	fibril_rwlock_read_unlock(&namespace_rwlock);
-
-	async_answer_1(rid, EOK, fd);
-}
-
-void vfs_open2(ipc_callid_t rid, ipc_call_t *request)
-{
-	int fd = IPC_GET_ARG1(*request);
-	int flags = IPC_GET_ARG2(*request);
-
+	return rc;
+}
+
+int vfs_op_open2(int fd, int flags)
+{
 	if (flags == 0) {
-		async_answer_0(rid, EINVAL);
-		return;
+		return EINVAL;
 	}
 
 	vfs_file_t *file = vfs_file_get(fd);
 	if (!file) {
-		async_answer_0(rid, EBADF);
-		return;
+		return EBADF;
 	}
 	
 	if ((flags & ~file->permissions) != 0) {
 		vfs_file_put(file);
-		async_answer_0(rid, EPERM);
-		return;
+		return EPERM;
+	}
+	
+	if (file->open_read || file->open_write) {
+		vfs_file_put(file);
+		return EBUSY;
 	}
 	
@@ -482,6 +432,5 @@
 	if (!file->open_read && !file->open_write) {
 		vfs_file_put(file);
-		async_answer_0(rid, EINVAL);
-		return;
+		return EINVAL;
 	}
 	
@@ -489,6 +438,5 @@
 		file->open_read = file->open_write = false;
 		vfs_file_put(file);
-		async_answer_0(rid, EINVAL);
-		return;
+		return EINVAL;
 	}
 	
@@ -497,50 +445,9 @@
 		file->open_read = file->open_write = false;
 		vfs_file_put(file);
-		async_answer_0(rid, rc);
-		return;
+		return rc;
 	}
 	
 	vfs_file_put(file);
-	async_answer_0(rid, EOK);
-}
-
-void vfs_sync(ipc_callid_t rid, ipc_call_t *request)
-{
-	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) {
-		async_answer_0(rid, ENOENT);
-		return;
-	}
-	
-	/*
-	 * Lock the open file structure so that no other thread can manipulate
-	 * the same open file at a time.
-	 */
-	async_exch_t *fs_exch = vfs_exchange_grab(file->node->fs_handle);
-	
-	/* Make a VFS_OUT_SYMC request at the destination FS server. */
-	aid_t msg;
-	ipc_call_t answer;
-	msg = async_send_2(fs_exch, VFS_OUT_SYNC, file->node->service_id,
-	    file->node->index, &answer);
-	
-	vfs_exchange_release(fs_exch);
-	
-	/* Wait for reply from the FS server. */
-	sysarg_t rc;
-	async_wait_for(msg, &rc);
-	
-	vfs_file_put(file);
-	async_answer_0(rid, rc);
-}
-
-void vfs_close(ipc_callid_t rid, ipc_call_t *request)
-{
-	int fd = IPC_GET_ARG1(*request);
-	int ret = vfs_fd_free(fd);
-	async_answer_0(rid, ret);
+	return EOK;
 }
 
@@ -629,5 +536,6 @@
 	assert(fs_info);
 	
-	bool rlock = read || ((fs_info->concurrent_read_write) && (fs_info->write_retains_size));
+	bool rlock = read ||
+	    (fs_info->concurrent_read_write && fs_info->write_retains_size);
 	
 	/*
@@ -650,7 +558,9 @@
 		if (!read) {
 			if (rlock) {
-				fibril_rwlock_read_unlock(&file->node->contents_rwlock);
+				fibril_rwlock_read_unlock(
+				    &file->node->contents_rwlock);
 			} else {
-				fibril_rwlock_write_unlock(&file->node->contents_rwlock);
+				fibril_rwlock_write_unlock(
+				    &file->node->contents_rwlock);
 			}
 			vfs_file_put(file);
@@ -700,12 +610,4 @@
 	return rc;
 }
-	
-static void vfs_rdwr_client(ipc_callid_t rid, ipc_call_t *request, bool read)
-{
-	size_t bytes = 0;	
-	int rc = vfs_rdwr(IPC_GET_ARG1(*request), read, rdwr_ipc_client,
-	    &bytes);
-	async_answer_1(rid, rc, bytes);
-}
 
 int vfs_rdwr_internal(int fd, bool read, rdwr_io_chunk_t *chunk)
@@ -714,288 +616,18 @@
 }
 
-void vfs_read(ipc_callid_t rid, ipc_call_t *request)
-{
-	vfs_rdwr_client(rid, request, true);
-}
-
-void vfs_write(ipc_callid_t rid, ipc_call_t *request)
-{
-	vfs_rdwr_client(rid, request, false);
-}
-
-void vfs_seek(ipc_callid_t rid, ipc_call_t *request)
-{
-	int fd = (int) IPC_GET_ARG1(*request);
-	off64_t off = (off64_t) MERGE_LOUP32(IPC_GET_ARG2(*request),
-	    IPC_GET_ARG3(*request));
-	int whence = (int) IPC_GET_ARG4(*request);
-	
-	/* Lookup the file structure corresponding to the file descriptor. */
-	vfs_file_t *file = vfs_file_get(fd);
-	if (!file) {
-		async_answer_0(rid, ENOENT);
-		return;
-	}
-	
-	off64_t newoff;
-	switch (whence) {
-	case SEEK_SET:
-		if (off >= 0) {
-			file->pos = (aoff64_t) off;
-			vfs_file_put(file);
-			async_answer_1(rid, EOK, off);
-			return;
-		}
-		break;
-	case SEEK_CUR:
-		if ((off >= 0) && (file->pos + off < file->pos)) {
-			vfs_file_put(file);
-			async_answer_0(rid, EOVERFLOW);
-			return;
-		}
-		
-		if ((off < 0) && (file->pos < (aoff64_t) -off)) {
-			vfs_file_put(file);
-			async_answer_0(rid, EOVERFLOW);
-			return;
-		}
-		
-		file->pos += off;
-		newoff = (file->pos > OFF64_MAX) ? OFF64_MAX : file->pos;
-		
-		vfs_file_put(file);
-		async_answer_2(rid, EOK, LOWER32(newoff),
-		    UPPER32(newoff));
-		return;
-	case SEEK_END:
-		fibril_rwlock_read_lock(&file->node->contents_rwlock);
-		aoff64_t size = vfs_node_get_size(file->node);
-		
-		if ((off >= 0) && (size + off < size)) {
-			fibril_rwlock_read_unlock(&file->node->contents_rwlock);
-			vfs_file_put(file);
-			async_answer_0(rid, EOVERFLOW);
-			return;
-		}
-		
-		if ((off < 0) && (size < (aoff64_t) -off)) {
-			fibril_rwlock_read_unlock(&file->node->contents_rwlock);
-			vfs_file_put(file);
-			async_answer_0(rid, EOVERFLOW);
-			return;
-		}
-		
-		file->pos = size + off;
-		newoff = (file->pos > OFF64_MAX) ?  OFF64_MAX : file->pos;
-		
-		fibril_rwlock_read_unlock(&file->node->contents_rwlock);
-		vfs_file_put(file);
-		async_answer_2(rid, EOK, LOWER32(newoff), UPPER32(newoff));
-		return;
-	}
-	
-	vfs_file_put(file);
-	async_answer_0(rid, EINVAL);
-}
-
-int vfs_truncate_internal(fs_handle_t fs_handle, service_id_t service_id,
-    fs_index_t index, aoff64_t size)
-{
-	async_exch_t *exch = vfs_exchange_grab(fs_handle);
-	sysarg_t rc = async_req_4_0(exch, VFS_OUT_TRUNCATE,
-	    (sysarg_t) service_id, (sysarg_t) index, LOWER32(size),
-	    UPPER32(size));
-	vfs_exchange_release(exch);
-	
-	return (int) rc;
-}
-
-void vfs_truncate(ipc_callid_t rid, ipc_call_t *request)
-{
-	int fd = IPC_GET_ARG1(*request);
-	aoff64_t size = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG2(*request),
-	    IPC_GET_ARG3(*request));
-	int rc;
-
-	vfs_file_t *file = vfs_file_get(fd);
-	if (!file) {
-		async_answer_0(rid, ENOENT);
-		return;
-	}
-
-	fibril_rwlock_write_lock(&file->node->contents_rwlock);
-	rc = vfs_truncate_internal(file->node->fs_handle,
-	    file->node->service_id, file->node->index, size);
-	if (rc == EOK)
-		file->node->size = size;
-	fibril_rwlock_write_unlock(&file->node->contents_rwlock);
-
-	vfs_file_put(file);
-	async_answer_0(rid, (sysarg_t)rc);
-}
-
-void vfs_fstat(ipc_callid_t rid, ipc_call_t *request)
-{
-	int fd = IPC_GET_ARG1(*request);
-	sysarg_t rc;
-
-	vfs_file_t *file = vfs_file_get(fd);
-	if (!file) {
-		async_answer_0(rid, ENOENT);
-		return;
-	}
-	assert(file->node);
-
-	ipc_callid_t callid;
-	if (!async_data_read_receive(&callid, NULL)) {
-		vfs_file_put(file);
-		async_answer_0(callid, EINVAL);
-		async_answer_0(rid, EINVAL);
-		return;
-	}
-
-	async_exch_t *exch = vfs_exchange_grab(file->node->fs_handle);
-	assert(exch);
-	
-	aid_t msg;
-	msg = async_send_3(exch, VFS_OUT_STAT, file->node->service_id,
-	    file->node->index, true, NULL);
-	assert(msg);
-	async_forward_fast(callid, exch, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
-	
-	vfs_exchange_release(exch);
-	
-	async_wait_for(msg, &rc);
-	
-	vfs_file_put(file);
-	async_answer_0(rid, rc);
-}
-
-static void out_destroy(vfs_triplet_t *file)
-{
-	async_exch_t *exch = vfs_exchange_grab(file->fs_handle);
-	async_msg_2(exch, VFS_OUT_DESTROY,
-		(sysarg_t) file->service_id, (sysarg_t) file->index);
-	vfs_exchange_release(exch);
-}
-
-void vfs_unlink2(ipc_callid_t rid, ipc_call_t *request)
-{
-	int rc;
-	char *path;
-	vfs_file_t *parent = NULL;
-	vfs_file_t *expect = NULL;
-	
-	int parentfd = IPC_GET_ARG1(*request);
-	int expectfd = IPC_GET_ARG2(*request);
-	int wflag = IPC_GET_ARG3(*request);
-	
-	rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
-	if (rc != EOK) {
-		async_answer_0(rid, rc);
-		return;
-	}
-	if (parentfd == expectfd) {
-		async_answer_0(rid, EINVAL);
-		return;
-	}
-	
-	fibril_rwlock_write_lock(&namespace_rwlock);
-	
-	int lflag = (wflag&WALK_DIRECTORY) ? L_DIRECTORY: 0;
-
-	/* Files are retrieved in order of file descriptors, to prevent deadlock. */
-	if (parentfd < expectfd) {
-		parent = vfs_file_get(parentfd);
-		if (!parent) {
-			rc = EBADF;
-			goto exit;
-		}
-	}
-	
-	if (expectfd >= 0) {
-		expect = vfs_file_get(expectfd);
-		if (!expect) {
-			rc = ENOENT;
-			goto exit;
-		}
-	}
-	
-	if (parentfd > expectfd) {
-		parent = vfs_file_get(parentfd);
-		if (!parent) {
-			rc = EBADF;
-			goto exit;
-		}
-	}
-	
-	assert(parent != NULL);
-	
-	if (expectfd >= 0) {
-		vfs_lookup_res_t lr;
-		rc = vfs_lookup_internal(parent->node, path, lflag, &lr);
-		if (rc != EOK) {
-			goto exit;
-		}
-		
-		vfs_node_t *found_node = vfs_node_peek(&lr);		
-		if (expect->node != found_node) {
-			rc = ENOENT;
-			goto exit;
-		}
-		
-		vfs_file_put(expect);
-		expect = NULL;
-	}
-	
-	vfs_lookup_res_t lr;
-	rc = vfs_lookup_internal(parent->node, path, lflag | L_UNLINK, &lr);
-	if (rc != EOK) {
-		goto exit;
-	}
-
-	/* If the node is not held by anyone, try to destroy it. */
-	if (vfs_node_peek(&lr) == NULL) {
-		out_destroy(&lr.triplet);
-	}
-
-exit:
-	if (path) {
-		free(path);
-	}
-	if (parent) {
-		vfs_file_put(parent);
-	}
-	if (expect) {
-		vfs_file_put(expect);
-	}
-	fibril_rwlock_write_unlock(&namespace_rwlock);
-	async_answer_0(rid, rc);
-}
-
-static size_t shared_path(char *a, char *b)
-{
-	size_t res = 0;
-	
-	while (a[res] == b[res] && a[res] != 0) {
-		res++;
-	}
-	
-	if (a[res] == b[res]) {
-		return res;
-	}
-	
-	res--;
-	while (a[res] != '/') {
-		res--;
-	}
-	return res;
-}
-
-static int vfs_rename_internal(vfs_node_t *base, char *old, char *new)
-{
-	assert(base != NULL);
-	assert(old != NULL);
-	assert(new != NULL);
+int vfs_op_read(int fd, size_t *out_bytes)
+{
+	return vfs_rdwr(fd, true, rdwr_ipc_client, out_bytes);
+}
+
+int vfs_op_rename(int basefd, char *old, char *new)
+{
+	vfs_file_t *base_file = vfs_file_get(basefd);
+	if (!base_file) {
+		return EBADF;
+	}
+	vfs_node_t *base = base_file->node;
+	vfs_node_addref(base);
+	vfs_file_put(base_file);
 	
 	vfs_lookup_res_t base_lr;
@@ -1026,14 +658,13 @@
 		}
 		
+		vfs_node_put(base);
 		base = vfs_node_get(&base_lr);
 		old[shared] = '/';
 		old += shared;
 		new += shared;
-	} else {
-		vfs_node_addref(base);
-	}
-	
-	
-	rc = vfs_lookup_internal(base, new, L_UNLINK | L_DISABLE_MOUNTS, &new_lr_orig);
+	}
+		
+	rc = vfs_lookup_internal(base, new, L_UNLINK | L_DISABLE_MOUNTS,
+	    &new_lr_orig);
 	if (rc == EOK) {
 		orig_unlinked = true;
@@ -1044,5 +675,6 @@
 	}
 	
-	rc = vfs_lookup_internal(base, old, L_UNLINK | L_DISABLE_MOUNTS, &old_lr);
+	rc = vfs_lookup_internal(base, old, L_UNLINK | L_DISABLE_MOUNTS,
+	    &old_lr);
 	if (rc != EOK) {
 		if (orig_unlinked) {
@@ -1075,172 +707,68 @@
 }
 
-void vfs_rename(ipc_callid_t rid, ipc_call_t *request)
-{
-	/* The common base directory. */
-	int basefd;
-	char *old = NULL;
-	char *new = NULL;
-	vfs_file_t *base = NULL;
-	int rc;
-	
-	basefd = IPC_GET_ARG1(*request);
-	
-	/* Retrieve the old path. */
-	rc = async_data_write_accept((void **) &old, true, 0, 0, 0, NULL);
-	if (rc != EOK) {
-		goto out;
-	}
-	
-	/* Retrieve the new path. */
-	rc = async_data_write_accept((void **) &new, true, 0, 0, 0, NULL);
-	if (rc != EOK) {
-		goto out;
-	}
-	
-	size_t olen;
-	size_t nlen;
-	char *oldc = canonify(old, &olen);
-	char *newc = canonify(new, &nlen);
-	
-	if ((!oldc) || (!newc)) {
-		rc = EINVAL;
-		goto out;
-	}
-	
-	assert(oldc[olen] == '\0');
-	assert(newc[nlen] == '\0');
-	
-	/* Lookup the file structure corresponding to the file descriptor. */
-	base = vfs_file_get(basefd);
-	if (!base) {
-		rc = EBADF;
-		goto out;
-	}
-	
-	rc = vfs_rename_internal(base->node, oldc, newc);
-
-out:
-	async_answer_0(rid, rc);
-
-	if (old) {
-		free(old);
-	}
-	if (new) {
-		free(new);
-	}
-	if (base) {
-		vfs_file_put(base);
-	}
-}
-
-void vfs_dup(ipc_callid_t rid, ipc_call_t *request)
-{
-	int oldfd = IPC_GET_ARG1(*request);
-	int newfd = IPC_GET_ARG2(*request);
-	
-	/* If the file descriptors are the same, do nothing. */
-	if (oldfd == newfd) {
-		async_answer_1(rid, EOK, newfd);
-		return;
-	}
-	
-	/* Lookup the file structure corresponding to oldfd. */
-	vfs_file_t *oldfile = vfs_file_get(oldfd);
-	if (!oldfile) {
-		async_answer_0(rid, EBADF);
-		return;
-	}
-	
-	/* Make sure newfd is closed. */
-	(void) vfs_fd_free(newfd);
-	
-	/* Assign the old file to newfd. */
-	int ret = vfs_fd_assign(oldfile, newfd);
-	vfs_file_put(oldfile);
-	
-	if (ret != EOK)
-		async_answer_0(rid, ret);
-	else
-		async_answer_1(rid, EOK, newfd);
-}
-
-void vfs_wait_handle(ipc_callid_t rid, ipc_call_t *request)
-{
-	bool high_fd = IPC_GET_ARG1(*request);
-	int fd = vfs_wait_handle_internal(high_fd);
-	async_answer_1(rid, EOK, fd);
-}
-
-void vfs_get_mtab(ipc_callid_t rid, ipc_call_t *request)
+int vfs_op_seek(int fd, int64_t offset, int whence, int64_t *out_offset)
+{
+	vfs_file_t *file = vfs_file_get(fd);
+	if (!file) {
+		return EBADF;
+	}
+	
+	switch (whence) {
+	case SEEK_SET:
+		if (offset < 0) {
+			vfs_file_put(file);
+			return EINVAL;
+		}
+		file->pos = offset;
+		*out_offset = offset;
+		vfs_file_put(file);
+		return EOK;
+	case SEEK_CUR:
+		if (offset > 0 && file->pos > (INT64_MAX - offset)) {
+			vfs_file_put(file);
+			return EOVERFLOW;
+		}
+		
+		if (offset < 0 && -file->pos > offset) {
+			vfs_file_put(file);
+			return EOVERFLOW;
+		}
+		
+		file->pos += offset;
+		*out_offset = file->pos;
+		vfs_file_put(file);
+		return EOK;
+	case SEEK_END:
+		fibril_rwlock_read_lock(&file->node->contents_rwlock);
+		int64_t size = vfs_node_get_size(file->node);
+		fibril_rwlock_read_unlock(&file->node->contents_rwlock);
+		
+		if (offset > 0 && size > (INT64_MAX - offset)) {
+			vfs_file_put(file);
+			return EOVERFLOW;
+		}
+		
+		if (offset < 0 && -size > offset) {
+			vfs_file_put(file);
+			return EOVERFLOW;
+		}
+		
+		file->pos = size + offset;
+		*out_offset = file->pos;
+		vfs_file_put(file);
+		return EOK;
+	}
+	
+	vfs_file_put(file);
+	return EINVAL;
+}
+
+int vfs_op_statfs(int fd)
 {
 	ipc_callid_t callid;
-	ipc_call_t data;
-	sysarg_t rc = EOK;
-	size_t len;
-
-	fibril_mutex_lock(&mtab_list_lock);
-
-	/* Send to the caller the number of mounted filesystems */
-	callid = async_get_call(&data);
-	if (IPC_GET_IMETHOD(data) != VFS_IN_PING) {
-		rc = ENOTSUP;
-		async_answer_0(callid, rc);
-		goto exit;
-	}
-	async_answer_1(callid, EOK, mtab_size);
-
-	list_foreach(mtab_list, link, mtab_ent_t, mtab_ent) {
-		rc = ENOTSUP;
-
-		if (!async_data_read_receive(&callid, &len)) {
-			async_answer_0(callid, rc);
-			goto exit;
-		}
-
-		(void) async_data_read_finalize(callid, mtab_ent->mp,
-		    str_size(mtab_ent->mp));
-
-		if (!async_data_read_receive(&callid, &len)) {
-			async_answer_0(callid, rc);
-			goto exit;
-		}
-
-		(void) async_data_read_finalize(callid, mtab_ent->opts,
-		    str_size(mtab_ent->opts));
-
-		if (!async_data_read_receive(&callid, &len)) {
-			async_answer_0(callid, rc);
-			goto exit;
-		}
-
-		(void) async_data_read_finalize(callid, mtab_ent->fs_name,
-		    str_size(mtab_ent->fs_name));
-
-		callid = async_get_call(&data);
-
-		if (IPC_GET_IMETHOD(data) != VFS_IN_PING) {
-			async_answer_0(callid, rc);
-			goto exit;
-		}
-
-		rc = EOK;
-		async_answer_2(callid, rc, mtab_ent->instance,
-		    mtab_ent->service_id);
-	}
-
-exit:
-	fibril_mutex_unlock(&mtab_list_lock);
-	async_answer_0(rid, rc);
-}
-
-void vfs_statfs(ipc_callid_t rid, ipc_call_t *request)
-{
-	int fd = IPC_GET_ARG1(*request);
-	
-	ipc_callid_t callid;
+	
 	if (!async_data_read_receive(&callid, NULL)) {
 		async_answer_0(callid, EINVAL);
-		async_answer_0(rid, EINVAL);
-		return;
+	       	return EINVAL;
 	}
 
@@ -1248,5 +776,5 @@
 	if (!file) {
 		async_answer_0(callid, EBADF);
-		async_answer_0(rid, EBADF);
+		return EBADF;
 	}
 
@@ -1254,49 +782,322 @@
 
 	async_exch_t *exch = vfs_exchange_grab(node->fs_handle);
-	
+							        
 	aid_t msg;
 	msg = async_send_3(exch, VFS_OUT_STATFS, node->service_id,
-	    node->index, false, NULL);
+	node->index, false, NULL);
 	async_forward_fast(callid, exch, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);
-	
+
 	vfs_exchange_release(exch);
-	
+
 	sysarg_t rv;
 	async_wait_for(msg, &rv);
 
 	vfs_file_put(file);
-
-	async_answer_0(rid, rv);
-}
-
-void vfs_op_clone(ipc_callid_t rid, ipc_call_t *request)
-{
-	int oldfd = IPC_GET_ARG1(*request);
-	bool desc = IPC_GET_ARG2(*request);
-	
-	/* Lookup the file structure corresponding to fd. */
-	vfs_file_t *oldfile = vfs_file_get(oldfd);
-	if (oldfile == NULL) {
-		async_answer_0(rid, EBADF);
-		return;
-	}
-	
-	vfs_file_t *newfile;
-	int newfd = vfs_fd_alloc(&newfile, desc);
-	async_answer_0(rid, newfd);
-	
-	if (newfd < 0) {
-		vfs_file_put(oldfile);
-		return;
-	}
-	
-	assert(oldfile->node != NULL);
-	
-	newfile->node = oldfile->node;
-	newfile->permissions = oldfile->permissions;
-	vfs_node_addref(newfile->node);
-
-	vfs_file_put(oldfile);
-	vfs_file_put(newfile);
+	return rv;
+}
+
+int vfs_op_sync(int fd)
+{
+	vfs_file_t *file = vfs_file_get(fd);
+	if (!file) {
+		return EBADF;
+	}
+	
+	async_exch_t *fs_exch = vfs_exchange_grab(file->node->fs_handle);
+	
+	aid_t msg;
+	ipc_call_t answer;
+	msg = async_send_2(fs_exch, VFS_OUT_SYNC, file->node->service_id,
+		file->node->index, &answer);
+	
+	vfs_exchange_release(fs_exch);
+	
+	sysarg_t rc;
+	async_wait_for(msg, &rc);
+	
+	vfs_file_put(file);
+	return rc;
+	
+}
+
+static int vfs_truncate_internal(fs_handle_t fs_handle, service_id_t service_id,
+    fs_index_t index, aoff64_t size)
+{
+	async_exch_t *exch = vfs_exchange_grab(fs_handle);
+	sysarg_t rc = async_req_4_0(exch, VFS_OUT_TRUNCATE,
+	    (sysarg_t) service_id, (sysarg_t) index, LOWER32(size),
+	    UPPER32(size));
+	vfs_exchange_release(exch);
+	
+	return (int) rc;
+}
+
+int vfs_op_truncate(int fd, int64_t size)
+{
+	vfs_file_t *file = vfs_file_get(fd);
+	if (!file) {
+		return EBADF;
+	}
+
+	fibril_rwlock_write_lock(&file->node->contents_rwlock);
+	
+	int rc = vfs_truncate_internal(file->node->fs_handle,
+		file->node->service_id, file->node->index, size);
+	if (rc == EOK) {
+		file->node->size = size;
+	}
+	
+	fibril_rwlock_write_unlock(&file->node->contents_rwlock);
+	vfs_file_put(file);
+	return rc;
+}
+
+int vfs_op_unlink2(int parentfd, int expectfd, int wflag, char *path)
+{
+	int rc = EOK;
+	vfs_file_t *parent = NULL;
+	vfs_file_t *expect = NULL;
+	
+	if (parentfd == expectfd) {
+		return EINVAL;
+	}
+	
+	fibril_rwlock_write_lock(&namespace_rwlock);
+	
+	int lflag = (wflag&WALK_DIRECTORY) ? L_DIRECTORY: 0;
+
+	/* 
+	 * Files are retrieved in order of file descriptors, to prevent
+	 * deadlock.
+	 */
+	if (parentfd < expectfd) {
+		parent = vfs_file_get(parentfd);
+		if (!parent) {
+			rc = EBADF;
+			goto exit;
+		}
+	}
+	
+	if (expectfd >= 0) {
+		expect = vfs_file_get(expectfd);
+		if (!expect) {
+			rc = EBADF;
+			goto exit;
+		}
+	}
+	
+	if (parentfd > expectfd) {
+		parent = vfs_file_get(parentfd);
+		if (!parent) {
+			rc = EBADF;
+			goto exit;
+		}
+	}
+	
+	assert(parent != NULL);
+	
+	if (expectfd >= 0) {
+		vfs_lookup_res_t lr;
+		rc = vfs_lookup_internal(parent->node, path, lflag, &lr);
+		if (rc != EOK) {
+			goto exit;
+		}
+		
+		vfs_node_t *found_node = vfs_node_peek(&lr);		
+		if (expect->node != found_node) {
+			rc = ENOENT;
+			goto exit;
+		}
+		
+		vfs_file_put(expect);
+		expect = NULL;
+	}
+	
+	vfs_lookup_res_t lr;
+	rc = vfs_lookup_internal(parent->node, path, lflag | L_UNLINK, &lr);
+	if (rc != EOK) {
+		goto exit;
+	}
+
+	/* If the node is not held by anyone, try to destroy it. */
+	if (vfs_node_peek(&lr) == NULL) {
+		out_destroy(&lr.triplet);
+	}
+
+exit:
+	if (path) {
+		free(path);
+	}
+	if (parent) {
+		vfs_file_put(parent);
+	}
+	if (expect) {
+		vfs_file_put(expect);
+	}
+	fibril_rwlock_write_unlock(&namespace_rwlock);
+	return rc;
+}
+
+int vfs_op_unmount(int mpfd)
+{
+	vfs_file_t *mp = vfs_file_get(mpfd);
+	if (mp == NULL) {
+		return EBADF;
+	}
+	
+	if (mp->node->mount == NULL) {
+		vfs_file_put(mp);
+		return ENOENT;
+	}
+	
+	fibril_rwlock_write_lock(&namespace_rwlock);
+	
+	/*
+	 * Count the total number of references for the mounted file system. We
+	 * are expecting at least one, which is held by the mount point.
+	 * If we find more, it means that
+	 * the file system cannot be gracefully unmounted at the moment because
+	 * someone is working with it.
+	 */
+	if (vfs_nodes_refcount_sum_get(mp->node->mount->fs_handle,
+	    mp->node->mount->service_id) != 1) {
+		vfs_file_put(mp);
+		fibril_rwlock_write_unlock(&namespace_rwlock);
+		return EBUSY;
+	}
+	
+	async_exch_t *exch = vfs_exchange_grab(mp->node->mount->fs_handle);
+	int rc = async_req_1_0(exch, VFS_OUT_UNMOUNTED,
+	    mp->node->mount->service_id);
+	vfs_exchange_release(exch);
+	
+	if (rc != EOK) {
+		vfs_file_put(mp);
+		fibril_rwlock_write_unlock(&namespace_rwlock);
+		return rc;
+	}
+	
+	vfs_node_forget(mp->node->mount);
+	vfs_node_put(mp->node);
+	mp->node->mount = NULL;
+	
+	fibril_rwlock_write_unlock(&namespace_rwlock);
+	
+	fibril_mutex_lock(&mtab_list_lock);
+	int found = 0;
+
+	list_foreach(mtab_list, link, mtab_ent_t, mtab_ent) {
+		// FIXME: mp name
+		if (str_cmp(mtab_ent->mp, "fixme") == 0) {
+			list_remove(&mtab_ent->link);
+			mtab_size--;
+			free(mtab_ent);
+			found = 1;
+			break;
+		}
+	}
+	assert(found);
+	fibril_mutex_unlock(&mtab_list_lock);
+	
+	vfs_file_put(mp);
+	return EOK;
+}
+
+int vfs_op_wait_handle(bool high_fd)
+{
+	return vfs_wait_handle_internal(high_fd);
+}
+
+static inline bool walk_flags_valid(int flags)
+{
+	if ((flags&~WALK_ALL_FLAGS) != 0) {
+		return false;
+	}
+	if ((flags&WALK_MAY_CREATE) && (flags&WALK_MUST_CREATE)) {
+		return false;
+	}
+	if ((flags&WALK_REGULAR) && (flags&WALK_DIRECTORY)) {
+		return false;
+	}
+	if ((flags&WALK_MAY_CREATE) || (flags&WALK_MUST_CREATE)) {
+		if (!(flags&WALK_DIRECTORY) && !(flags&WALK_REGULAR)) {
+			return false;
+		}
+	}
+	return true;
+}
+
+static inline int walk_lookup_flags(int flags)
+{
+	int lflags = 0;
+	if (flags&WALK_MAY_CREATE || flags&WALK_MUST_CREATE) {
+		lflags |= L_CREATE;
+	}
+	if (flags&WALK_MUST_CREATE) {
+		lflags |= L_EXCLUSIVE;
+	}
+	if (flags&WALK_REGULAR) {
+		lflags |= L_FILE;
+	}
+	if (flags&WALK_DIRECTORY) {
+		lflags |= L_DIRECTORY;
+	}
+	if (flags&WALK_MOUNT_POINT) {
+		lflags |= L_MP;
+	}
+	return lflags;
+}
+
+int vfs_op_walk(int parentfd, int flags, char *path, int *out_fd)
+{
+	if (!walk_flags_valid(flags)) {
+		return EINVAL;
+	}
+	
+	vfs_file_t *parent = vfs_file_get(parentfd);
+	if (!parent) {
+		return EBADF;
+	}
+	
+	fibril_rwlock_read_lock(&namespace_rwlock);
+	
+	vfs_lookup_res_t lr;
+	int rc = vfs_lookup_internal(parent->node, path,
+	    walk_lookup_flags(flags), &lr);
+
+	if (rc != EOK) {
+		fibril_rwlock_read_unlock(&namespace_rwlock);
+		vfs_file_put(parent);
+		return rc;
+	}
+	
+	vfs_node_t *node = vfs_node_get(&lr);
+	
+	vfs_file_t *file;
+	int fd = vfs_fd_alloc(&file, false);
+	if (fd < 0) {
+		vfs_node_put(node);
+		vfs_file_put(parent);
+		return fd;
+	}
+	assert(file != NULL);
+	
+	file->node = node;
+	file->permissions = parent->permissions;
+	file->open_read = false;
+	file->open_write = false;
+	
+	vfs_file_put(file);
+	vfs_file_put(parent);
+	
+	fibril_rwlock_read_unlock(&namespace_rwlock);
+
+	*out_fd = fd;
+	return EOK;
+}
+
+int vfs_op_write(int fd, size_t *out_bytes)
+{
+	return vfs_rdwr(fd, false, rdwr_ipc_client, out_bytes);
 }
 
Index: uspace/srv/vfs/vfs_register.c
===================================================================
--- uspace/srv/vfs/vfs_register.c	(revision 5126f801cf167ce675ecc93b5079c64358dcbacb)
+++ uspace/srv/vfs/vfs_register.c	(revision 0d35511b07352cce59e443fae082937725227cae)
@@ -296,5 +296,5 @@
  *
  */
-fs_handle_t fs_name_to_handle(unsigned int instance, char *name, bool lock)
+fs_handle_t fs_name_to_handle(unsigned int instance, const char *name, bool lock)
 {
 	int handle = 0;
