Index: uspace/srv/vfs/vfs_ops.c
===================================================================
--- uspace/srv/vfs/vfs_ops.c	(revision ed90317444652a29e89501a128d66020aaea52b5)
+++ uspace/srv/vfs/vfs_ops.c	(revision 1e4cadad49fbe94a308f6f74c331537fbfc59425)
@@ -38,6 +38,4 @@
 #include "vfs.h"
 #include <ipc/ipc.h>
-#include <macros.h>
-#include <limits.h>
 #include <async.h>
 #include <errno.h>
@@ -55,5 +53,5 @@
 
 /* Forward declarations of static functions. */
-static int vfs_truncate_internal(fs_handle_t, dev_handle_t, fs_index_t, aoff64_t);
+static int vfs_truncate_internal(fs_handle_t, dev_handle_t, fs_index_t, size_t);
 
 /**
@@ -94,5 +92,5 @@
 		}
 		
-		rc = vfs_lookup_internal(mp, L_MP, &mp_res, NULL);
+		rc = vfs_lookup_internal(mp, L_DIRECTORY, &mp_res, NULL);
 		if (rc != EOK) {
 			/* The lookup failed for some reason. */
@@ -268,21 +266,70 @@
 	
 	/* We want the client to send us the mount point. */
-	char *mp;
-	int rc = async_data_write_accept((void **) &mp, true, 0, MAX_PATH_LEN,
-	    0, NULL);
-	if (rc != EOK) {
-		ipc_answer_0(rid, rc);
-		return;
-	}
+	ipc_callid_t callid;
+	size_t size;
+	if (!async_data_write_receive(&callid, &size)) {
+		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(rid, EINVAL);
+		return;
+	}
+	
+	/* Check whether size is reasonable wrt. the mount point. */
+	if ((size < 1) || (size > MAX_PATH_LEN)) {
+		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(rid, EINVAL);
+		return;
+	}
+	
+	/* Allocate buffer for the mount point data being received. */
+	char *mp = malloc(size + 1);
+	if (!mp) {
+		ipc_answer_0(callid, ENOMEM);
+		ipc_answer_0(rid, ENOMEM);
+		return;
+	}
+	
+	/* Deliver the mount point. */
+	ipcarg_t retval = async_data_write_finalize(callid, mp, size);
+	if (retval != EOK) {
+		ipc_answer_0(rid, retval);
+		free(mp);
+		return;
+	}
+	mp[size] = '\0';
 	
 	/* Now we expect to receive the mount options. */
-	char *opts;
-	rc = async_data_write_accept((void **) &opts, true, 0, MAX_MNTOPTS_LEN,
-	    0, NULL);
-	if (rc != EOK) {
+	if (!async_data_write_receive(&callid, &size)) {
+		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(rid, EINVAL);
 		free(mp);
-		ipc_answer_0(rid, rc);
-		return;
-	}
+		return;
+	}
+
+	/* Check the offered options size. */
+	if (size > MAX_MNTOPTS_LEN) {
+		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(rid, EINVAL);
+		free(mp);
+		return;
+	}
+
+	/* Allocate buffer for the mount options. */
+	char *opts = (char *) malloc(size + 1);
+	if (!opts) {
+		ipc_answer_0(callid, ENOMEM);
+		ipc_answer_0(rid, ENOMEM);
+		free(mp);
+		return;
+	}
+
+	/* Deliver the mount options. */
+	retval = async_data_write_finalize(callid, opts, size);
+	if (retval != EOK) {
+		ipc_answer_0(rid, retval);
+		free(mp);
+		free(opts);
+		return;
+	}
+	opts[size] = '\0';
 	
 	/*
@@ -290,14 +337,47 @@
 	 * system.
 	 */
-	char *fs_name;
-	rc = async_data_write_accept((void **) &fs_name, true, 0, FS_NAME_MAXLEN,
-	    0, NULL);
-	if (rc != EOK) {
+	if (!async_data_write_receive(&callid, &size)) {
+		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(rid, EINVAL);
 		free(mp);
 		free(opts);
-		ipc_answer_0(rid, rc);
-		return;
-	}
-	
+		return;
+	}
+	
+	/*
+	 * Don't receive more than is necessary for storing a full file system
+	 * name.
+	 */
+	if ((size < 1) || (size > FS_NAME_MAXLEN)) {
+		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(rid, EINVAL);
+		free(mp);
+		free(opts);
+		return;
+	}
+	
+	/*
+	 * Allocate buffer for file system name.
+	 */
+	char *fs_name = (char *) malloc(size + 1);
+	if (fs_name == NULL) {
+		ipc_answer_0(callid, ENOMEM);
+		ipc_answer_0(rid, ENOMEM);
+		free(mp);
+		free(opts);
+		return;
+	}
+	
+	/* Deliver the file system name. */
+	retval = async_data_write_finalize(callid, fs_name, size);
+	if (retval != EOK) {
+		ipc_answer_0(rid, retval);
+		free(mp);
+		free(opts);
+		free(fs_name);
+		return;
+	}
+	fs_name[size] = '\0';
+
 	/*
 	 * Wait for IPC_M_PING so that we can return an error if we don't know
@@ -305,5 +385,5 @@
 	 */
 	ipc_call_t data;
-	ipc_callid_t callid = async_get_call(&data);
+	callid = async_get_call(&data);
 	if (IPC_GET_METHOD(data) != IPC_M_PING) {
 		ipc_answer_0(callid, ENOTSUP);
@@ -349,141 +429,4 @@
 }
 
-void vfs_unmount(ipc_callid_t rid, ipc_call_t *request)
-{
-	int rc;
-	char *mp;
-	vfs_lookup_res_t mp_res;
-	vfs_lookup_res_t mr_res;
-	vfs_node_t *mr_node;
-	int phone;
-
-	/*
-	 * Receive the mount point path.
-	 */
-	rc = async_data_write_accept((void **) &mp, true, 0, MAX_PATH_LEN,
-	    0, NULL);
-	if (rc != EOK)
-		ipc_answer_0(rid, rc);
-
-	/*
-	 * Taking the namespace lock will do two things for us. First, it will
-	 * prevent races with other lookup operations. Second, it will stop new
-	 * references to already existing VFS nodes and creation of new VFS
-	 * nodes. This is because new references are added as a result of some
-	 * lookup operation or at least of some operation which is protected by
-	 * the namespace lock.
-	 */
-	fibril_rwlock_write_lock(&namespace_rwlock);
-	
-	/*
-	 * Lookup the mounted root and instantiate it.
-	 */
-	rc = vfs_lookup_internal(mp, L_ROOT, &mr_res, NULL);
-	if (rc != EOK) {
-		fibril_rwlock_write_unlock(&namespace_rwlock);
-		free(mp);
-		ipc_answer_0(rid, rc);
-		return;
-	}
-	mr_node = vfs_node_get(&mr_res);
-	if (!mr_node) {
-		fibril_rwlock_write_unlock(&namespace_rwlock);
-		free(mp);
-		ipc_answer_0(rid, ENOMEM);
-		return;
-	}
-
-	/*
-	 * Count the total number of references for the mounted file system. We
-	 * are expecting at least two. One which we got above and one which we
-	 * got when the file system was mounted. 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(mr_node->fs_handle,
-	    mr_node->dev_handle) != 2) {
-		fibril_rwlock_write_unlock(&namespace_rwlock);
-		vfs_node_put(mr_node);
-		free(mp);
-		ipc_answer_0(rid, EBUSY);
-		return;
-	}
-
-	if (str_cmp(mp, "/") == 0) {
-
-		/*
-		 * Unmounting the root file system.
-		 *
-		 * In this case, there is no mount point node and we send
-		 * VFS_OUT_UNMOUNTED directly to the mounted file system.
-		 */
-
-		free(mp);
-		phone = vfs_grab_phone(mr_node->fs_handle);
-		rc = async_req_1_0(phone, VFS_OUT_UNMOUNTED,
-		    mr_node->dev_handle);
-		vfs_release_phone(phone);
-		if (rc != EOK) {
-			fibril_rwlock_write_unlock(&namespace_rwlock);
-			vfs_node_put(mr_node);
-			ipc_answer_0(rid, rc);
-			return;
-		}
-		rootfs.fs_handle = 0;
-		rootfs.dev_handle = 0;
-	} else {
-
-		/*
-		 * Unmounting a non-root file system.
-		 *
-		 * We have a regular mount point node representing the parent
-		 * file system, so we delegate the operation to it.
-		 */
-
-		rc = vfs_lookup_internal(mp, L_MP, &mp_res, NULL);
-		free(mp);
-		if (rc != EOK) {
-			fibril_rwlock_write_unlock(&namespace_rwlock);
-			vfs_node_put(mr_node);
-			ipc_answer_0(rid, rc);
-			return;
-		}
-		vfs_node_t *mp_node = vfs_node_get(&mp_res);
-		if (!mp_node) {
-			fibril_rwlock_write_unlock(&namespace_rwlock);
-			vfs_node_put(mr_node);
-			ipc_answer_0(rid, ENOMEM);
-			return;
-		}
-
-		phone = vfs_grab_phone(mp_node->fs_handle);
-		rc = async_req_2_0(phone, VFS_OUT_UNMOUNT, mp_node->dev_handle,
-		    mp_node->index);
-		vfs_release_phone(phone);
-		if (rc != EOK) {
-			fibril_rwlock_write_unlock(&namespace_rwlock);
-			vfs_node_put(mp_node);
-			vfs_node_put(mr_node);
-			ipc_answer_0(rid, rc);
-			return;
-		}
-
-		/* Drop the reference we got above. */
-		vfs_node_put(mp_node);
-		/* Drop the reference from when the file system was mounted. */
-		vfs_node_put(mp_node);
-	}
-
-
-	/*
-	 * All went well, the mounted file system was successfully unmounted.
-	 * The only thing left is to forget the unmounted root VFS node.
-	 */
-	vfs_node_forget(mr_node);
-
-	fibril_rwlock_write_unlock(&namespace_rwlock);
-	ipc_answer_0(rid, EOK);
-}
-
 void vfs_open(ipc_callid_t rid, ipc_call_t *request)
 {
@@ -504,4 +447,5 @@
 	int oflag = IPC_GET_ARG2(*request);
 	int mode = IPC_GET_ARG3(*request);
+	size_t len;
 
 	/* Ignore mode for now. */
@@ -510,10 +454,9 @@
 	/*
 	 * Make sure that we are called with exactly one of L_FILE and
-	 * L_DIRECTORY. Make sure that the user does not pass L_OPEN,
-	 * L_ROOT or L_MP.
+	 * L_DIRECTORY. Make sure that the user does not pass L_OPEN.
 	 */
 	if (((lflag & (L_FILE | L_DIRECTORY)) == 0) ||
 	    ((lflag & (L_FILE | L_DIRECTORY)) == (L_FILE | L_DIRECTORY)) ||
-	    (lflag & (L_OPEN | L_ROOT | L_MP))) {
+	    ((lflag & L_OPEN) != 0)) {
 		ipc_answer_0(rid, EINVAL);
 		return;
@@ -525,10 +468,25 @@
 		lflag |= L_EXCLUSIVE;
 	
-	char *path;
-	int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
-	if (rc != EOK) {
-		ipc_answer_0(rid, rc);
-		return;
-	}
+	ipc_callid_t callid;
+	if (!async_data_write_receive(&callid, &len)) {
+		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(rid, EINVAL);
+		return;
+	}
+	
+	char *path = malloc(len + 1);
+	if (!path) {
+		ipc_answer_0(callid, ENOMEM);
+		ipc_answer_0(rid, ENOMEM);
+		return;
+	}
+	
+	int rc;
+	if ((rc = async_data_write_finalize(callid, path, len))) {
+		ipc_answer_0(rid, rc);
+		free(path);
+		return;
+	}
+	path[len] = '\0';
 	
 	/*
@@ -721,5 +679,5 @@
 }
 
-int vfs_close_internal(vfs_file_t *file)
+static int vfs_close_internal(vfs_file_t *file)
 {
 	/*
@@ -798,4 +756,20 @@
 	
 	/*
+	 * 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 = async_data_read_receive(&callid, NULL);
+	else 
+		res = async_data_write_receive(&callid, NULL);
+	if (!res) {
+		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(rid, EINVAL);
+		return;
+	}
+	
+	/*
 	 * Lock the open file structure so that no other thread can manipulate
 	 * the same open file at a time.
@@ -821,32 +795,30 @@
 	}
 	
-	int fs_phone = vfs_grab_phone(file->node->fs_handle);
-	
-	/*
-	 * Make a VFS_READ/VFS_WRITE request at the destination FS server
-	 * and forward the IPC_M_DATA_READ/IPC_M_DATA_WRITE request to the
+	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;
+	if (!read && file->append)
+		file->pos = file->node->size;
+	msg = async_send_3(fs_phone, read ? VFS_OUT_READ : VFS_OUT_WRITE,
+	    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);
+
+	/* Wait for reply from the FS server. */
 	ipcarg_t rc;
-	ipc_call_t answer;
-	if (read) {
-		if (file->append)
-			file->pos = file->node->size;
-		
-		rc = async_data_read_forward_3_1(fs_phone, VFS_OUT_READ,
-		    file->node->dev_handle, file->node->index, file->pos,
-		    &answer);
-	} else {
-		rc = async_data_write_forward_3_1(fs_phone, VFS_OUT_WRITE,
-		    file->node->dev_handle, file->node->index, file->pos,
-		    &answer);
-	}
+	async_wait_for(msg, &rc);
 	
 	vfs_release_phone(fs_phone);
 	
 	size_t bytes = IPC_GET_ARG1(answer);
-	
+
 	if (file->node->type == VFS_NODE_DIRECTORY)
 		fibril_rwlock_read_unlock(&namespace_rwlock);
@@ -887,8 +859,8 @@
 {
 	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);
-	
+	off_t off = (off_t) IPC_GET_ARG2(*request);
+	int whence = (int) IPC_GET_ARG3(*request);
+
+
 	/* Lookup the file structure corresponding to the file descriptor. */
 	vfs_file_t *file = vfs_file_get(fd);
@@ -897,69 +869,46 @@
 		return;
 	}
-	
+
+	off_t newpos;
 	fibril_mutex_lock(&file->lock);
-	
-	off64_t newoff;
-	switch (whence) {
-		case SEEK_SET:
-			if (off >= 0) {
-				file->pos = (aoff64_t) off;
-				fibril_mutex_unlock(&file->lock);
-				ipc_answer_1(rid, EOK, off);
-				return;
-			}
-			break;
-		case SEEK_CUR:
-			if ((off >= 0) && (file->pos + off < file->pos)) {
-				fibril_mutex_unlock(&file->lock);
-				ipc_answer_0(rid, EOVERFLOW);
-				return;
-			}
-			
-			if ((off < 0) && (file->pos < (aoff64_t) -off)) {
-				fibril_mutex_unlock(&file->lock);
-				ipc_answer_0(rid, EOVERFLOW);
-				return;
-			}
-			
-			file->pos += off;
-			newoff = (file->pos > OFF64_MAX) ? OFF64_MAX : file->pos;
-			
+	if (whence == SEEK_SET) {
+		file->pos = off;
+		fibril_mutex_unlock(&file->lock);
+		ipc_answer_1(rid, EOK, off);
+		return;
+	}
+	if (whence == SEEK_CUR) {
+		if (file->pos + off < file->pos) {
 			fibril_mutex_unlock(&file->lock);
-			ipc_answer_2(rid, EOK, LOWER32(newoff), UPPER32(newoff));
+			ipc_answer_0(rid, EOVERFLOW);
 			return;
-		case SEEK_END:
-			fibril_rwlock_read_lock(&file->node->contents_rwlock);
-			aoff64_t size = file->node->size;
-			
-			if ((off >= 0) && (size + off < size)) {
-				fibril_rwlock_read_unlock(&file->node->contents_rwlock);
-				fibril_mutex_unlock(&file->lock);
-				ipc_answer_0(rid, EOVERFLOW);
-				return;
-			}
-			
-			if ((off < 0) && (size < (aoff64_t) -off)) {
-				fibril_rwlock_read_unlock(&file->node->contents_rwlock);
-				fibril_mutex_unlock(&file->lock);
-				ipc_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);
+		}
+		file->pos += off;
+		newpos = file->pos;
+		fibril_mutex_unlock(&file->lock);
+		ipc_answer_1(rid, EOK, newpos);
+		return;
+	}
+	if (whence == SEEK_END) {
+		fibril_rwlock_read_lock(&file->node->contents_rwlock);
+		size_t size = file->node->size;
+		fibril_rwlock_read_unlock(&file->node->contents_rwlock);
+		if (size + off < size) {
 			fibril_mutex_unlock(&file->lock);
-			ipc_answer_2(rid, EOK, LOWER32(newoff), UPPER32(newoff));
+			ipc_answer_0(rid, EOVERFLOW);
 			return;
-	}
-	
+		}
+		newpos = size + off;
+		fibril_mutex_unlock(&file->lock);
+		ipc_answer_1(rid, EOK, newpos);
+		return;
+	}
 	fibril_mutex_unlock(&file->lock);
 	ipc_answer_0(rid, EINVAL);
 }
 
-int vfs_truncate_internal(fs_handle_t fs_handle, dev_handle_t dev_handle,
-    fs_index_t index, aoff64_t size)
+int
+vfs_truncate_internal(fs_handle_t fs_handle, dev_handle_t dev_handle,
+    fs_index_t index, size_t size)
 {
 	ipcarg_t rc;
@@ -967,6 +916,6 @@
 	
 	fs_phone = vfs_grab_phone(fs_handle);
-	rc = async_req_4_0(fs_phone, VFS_OUT_TRUNCATE, (ipcarg_t) dev_handle,
-	    (ipcarg_t) index, LOWER32(size), UPPER32(size));
+	rc = async_req_3_0(fs_phone, VFS_OUT_TRUNCATE, (ipcarg_t)dev_handle,
+	    (ipcarg_t)index, (ipcarg_t)size);
 	vfs_release_phone(fs_phone);
 	return (int)rc;
@@ -976,6 +925,5 @@
 {
 	int fd = IPC_GET_ARG1(*request);
-	aoff64_t size =
-	    (aoff64_t) MERGE_LOUP32(IPC_GET_ARG2(*request), IPC_GET_ARG3(*request));
+	size_t size = IPC_GET_ARG2(*request);
 	int rc;
 
@@ -1033,12 +981,26 @@
 void vfs_stat(ipc_callid_t rid, ipc_call_t *request)
 {
-	char *path;
-	int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
-	if (rc != EOK) {
-		ipc_answer_0(rid, rc);
-		return;
-	}
-	
+	size_t len;
 	ipc_callid_t callid;
+
+	if (!async_data_write_receive(&callid, &len)) {
+		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(rid, EINVAL);
+		return;
+	}
+	char *path = malloc(len + 1);
+	if (!path) {
+		ipc_answer_0(callid, ENOMEM);
+		ipc_answer_0(rid, ENOMEM);
+		return;
+	}
+	int rc;
+	if ((rc = async_data_write_finalize(callid, path, len))) {
+		ipc_answer_0(rid, rc);
+		free(path);
+		return;
+	}
+	path[len] = '\0';
+
 	if (!async_data_read_receive(&callid, NULL)) {
 		free(path);
@@ -1086,12 +1048,27 @@
 {
 	int mode = IPC_GET_ARG1(*request);
-	
-	char *path;
-	int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
-	if (rc != EOK) {
-		ipc_answer_0(rid, rc);
-		return;
-	}
-	
+
+	size_t len;
+	ipc_callid_t callid;
+
+	if (!async_data_write_receive(&callid, &len)) {
+		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(rid, EINVAL);
+		return;
+	}
+	char *path = malloc(len + 1);
+	if (!path) {
+		ipc_answer_0(callid, ENOMEM);
+		ipc_answer_0(rid, ENOMEM);
+		return;
+	}
+	int rc;
+	if ((rc = async_data_write_finalize(callid, path, len))) {
+		ipc_answer_0(rid, rc);
+		free(path);
+		return;
+	}
+	path[len] = '\0';
+
 	/* Ignore mode for now. */
 	(void) mode;
@@ -1108,11 +1085,26 @@
 {
 	int lflag = IPC_GET_ARG1(*request);
-	
-	char *path;
-	int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL);
-	if (rc != EOK) {
-		ipc_answer_0(rid, rc);
-		return;
-	}
+
+	size_t len;
+	ipc_callid_t callid;
+
+	if (!async_data_write_receive(&callid, &len)) {
+		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(rid, EINVAL);
+		return;
+	}
+	char *path = malloc(len + 1);
+	if (!path) {
+		ipc_answer_0(callid, ENOMEM);
+		ipc_answer_0(rid, ENOMEM);
+		return;
+	}
+	int rc;
+	if ((rc = async_data_write_finalize(callid, path, len))) {
+		ipc_answer_0(rid, rc);
+		free(path);
+		return;
+	}
+	path[len] = '\0';
 	
 	fibril_rwlock_write_lock(&namespace_rwlock);
@@ -1143,27 +1135,52 @@
 void vfs_rename(ipc_callid_t rid, ipc_call_t *request)
 {
+	size_t olen, nlen;
+	ipc_callid_t callid;
+	int rc;
+
 	/* Retrieve the old path. */
-	char *old;
-	int rc = async_data_write_accept((void **) &old, true, 0, 0, 0, NULL);
-	if (rc != EOK) {
-		ipc_answer_0(rid, rc);
-		return;
-	}
+	if (!async_data_write_receive(&callid, &olen)) {
+		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(rid, EINVAL);
+		return;
+	}
+	char *old = malloc(olen + 1);
+	if (!old) {
+		ipc_answer_0(callid, ENOMEM);
+		ipc_answer_0(rid, ENOMEM);
+		return;
+	}
+	if ((rc = async_data_write_finalize(callid, old, olen))) {
+		ipc_answer_0(rid, rc);
+		free(old);
+		return;
+	}
+	old[olen] = '\0';
 	
 	/* Retrieve the new path. */
-	char *new;
-	rc = async_data_write_accept((void **) &new, true, 0, 0, 0, NULL);
-	if (rc != EOK) {
+	if (!async_data_write_receive(&callid, &nlen)) {
+		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(rid, EINVAL);
 		free(old);
-		ipc_answer_0(rid, rc);
-		return;
-	}
-	
-	size_t olen;
-	size_t nlen;
+		return;
+	}
+	char *new = malloc(nlen + 1);
+	if (!new) {
+		ipc_answer_0(callid, ENOMEM);
+		ipc_answer_0(rid, ENOMEM);
+		free(old);
+		return;
+	}
+	if ((rc = async_data_write_finalize(callid, new, nlen))) {
+		ipc_answer_0(rid, rc);
+		free(old);
+		free(new);
+		return;
+	}
+	new[nlen] = '\0';
+
 	char *oldc = canonify(old, &olen);
 	char *newc = canonify(new, &nlen);
-	
-	if ((!oldc) || (!newc)) {
+	if (!oldc || !newc) {
 		ipc_answer_0(rid, EINVAL);
 		free(old);
@@ -1171,8 +1188,6 @@
 		return;
 	}
-	
 	oldc[olen] = '\0';
 	newc[nlen] = '\0';
-	
 	if ((!str_lcmp(newc, oldc, str_length(oldc))) &&
 	    ((newc[str_length(oldc)] == '/') ||
@@ -1195,5 +1210,4 @@
 	vfs_lookup_res_t new_par_lr;
 	fibril_rwlock_write_lock(&namespace_rwlock);
-	
 	/* Lookup the node belonging to the old file name. */
 	rc = vfs_lookup_internal(oldc, L_NONE, &old_lr, NULL);
@@ -1205,5 +1219,4 @@
 		return;
 	}
-	
 	vfs_node_t *old_node = vfs_node_get(&old_lr);
 	if (!old_node) {
@@ -1214,5 +1227,4 @@
 		return;
 	}
-	
 	/* Determine the path to the parent of the node with the new name. */
 	char *parentc = str_dup(newc);
@@ -1224,5 +1236,4 @@
 		return;
 	}
-	
 	char *lastsl = str_rchr(parentc + 1, '/');
 	if (lastsl)
@@ -1230,5 +1241,4 @@
 	else
 		parentc[1] = '\0';
-	
 	/* Lookup parent of the new file name. */
 	rc = vfs_lookup_internal(parentc, L_NONE, &new_par_lr, NULL);
@@ -1241,5 +1251,4 @@
 		return;
 	}
-	
 	/* Check whether linking to the same file system instance. */
 	if ((old_node->fs_handle != new_par_lr.triplet.fs_handle) ||
@@ -1251,9 +1260,7 @@
 		return;
 	}
-	
 	/* Destroy the old link for the new name. */
 	vfs_node_t *new_node = NULL;
 	rc = vfs_lookup_internal(newc, L_UNLINK, &new_lr, NULL);
-	
 	switch (rc) {
 	case ENOENT:
@@ -1280,5 +1287,4 @@
 		return;
 	}
-	
 	/* Create the new link for the new name. */
 	rc = vfs_lookup_internal(newc, L_LINK, NULL, NULL, old_node->index);
@@ -1292,9 +1298,7 @@
 		return;
 	}
-	
 	fibril_mutex_lock(&nodes_mutex);
 	old_node->lnkcnt++;
 	fibril_mutex_unlock(&nodes_mutex);
-	
 	/* Destroy the link for the old name. */
 	rc = vfs_lookup_internal(oldc, L_UNLINK, NULL, NULL);
@@ -1309,5 +1313,4 @@
 		return;
 	}
-	
 	fibril_mutex_lock(&nodes_mutex);
 	old_node->lnkcnt--;
@@ -1315,8 +1318,6 @@
 	fibril_rwlock_write_unlock(&namespace_rwlock);
 	vfs_node_put(old_node);
-	
 	if (new_node)
 		vfs_node_put(new_node);
-	
 	free(old);
 	free(new);
