Index: uspace/srv/vfs/vfs.h
===================================================================
--- uspace/srv/vfs/vfs.h	(revision 9246016f2cd9a449613c5c8a7e45dcdc5c78a8f5)
+++ uspace/srv/vfs/vfs.h	(revision 6ad454f83f303511323abee84bc0e5d4eb8aaf28)
@@ -194,10 +194,10 @@
 
 extern void vfs_op_pass_handle(task_id_t, task_id_t, int);
-extern int vfs_wait_handle_internal(bool);
+extern int vfs_wait_handle_internal(bool, int *);
 
 extern vfs_file_t *vfs_file_get(int);
 extern void vfs_file_put(vfs_file_t *);
 extern int vfs_fd_assign(vfs_file_t *, int);
-extern int vfs_fd_alloc(vfs_file_t **file, bool desc);
+extern int vfs_fd_alloc(vfs_file_t **file, bool desc, int *);
 extern int vfs_fd_free(int);
 
@@ -220,5 +220,5 @@
 extern int vfs_op_unlink(int parentfd, int expectfd, char *path);
 extern int vfs_op_unmount(int mpfd);
-extern int vfs_op_wait_handle(bool high_fd);
+extern int vfs_op_wait_handle(bool high_fd, int *out_fd);
 extern int vfs_op_walk(int parentfd, int flags, char *path, int *out_fd);
 extern int vfs_op_write(int fd, aoff64_t, size_t *out_bytes);
Index: uspace/srv/vfs/vfs_file.c
===================================================================
--- uspace/srv/vfs/vfs_file.c	(revision 9246016f2cd9a449613c5c8a7e45dcdc5c78a8f5)
+++ uspace/srv/vfs/vfs_file.c	(revision 6ad454f83f303511323abee84bc0e5d4eb8aaf28)
@@ -192,5 +192,5 @@
 }
 
-static int _vfs_fd_alloc(vfs_client_data_t *vfs_data, vfs_file_t **file, bool desc)
+static int _vfs_fd_alloc(vfs_client_data_t *vfs_data, vfs_file_t **file, bool desc, int *out_fd)
 {
 	if (!vfs_files_init(vfs_data))
@@ -223,5 +223,6 @@
 			
 			fibril_mutex_unlock(&vfs_data->lock);
-			return (int) i;
+			*out_fd = (int) i;
+			return EOK;
 		}
 		
@@ -249,10 +250,11 @@
  *             in a descending order.
  *
- * @return First available file descriptor or a negative error
- *         code.
- */
-int vfs_fd_alloc(vfs_file_t **file, bool desc)
-{
-	return _vfs_fd_alloc(VFS_DATA, file, desc);
+ * @param[out] out_fd  First available file descriptor
+ *
+ * @return Error code.
+ */
+int vfs_fd_alloc(vfs_file_t **file, bool desc, int *out_fd)
+{
+	return _vfs_fd_alloc(VFS_DATA, file, desc, out_fd);
 }
 
@@ -427,5 +429,5 @@
 }
 
-int vfs_wait_handle_internal(bool high_fd)
+int vfs_wait_handle_internal(bool high_fd, int *out_fd)
 {
 	vfs_client_data_t *vfs_data = VFS_DATA;	
@@ -441,9 +443,9 @@
 
 	vfs_file_t *file;
-	int fd = _vfs_fd_alloc(vfs_data, &file, high_fd);
-	if (fd < 0) {
+	int rc = _vfs_fd_alloc(vfs_data, &file, high_fd, out_fd);
+	if (rc != EOK) {
 		vfs_node_delref(bh->node);
 		free(bh);
-		return fd;
+		return rc;
 	}
 	
@@ -452,5 +454,5 @@
 	vfs_file_put(file);
 	free(bh);
-	return fd;
+	return EOK;
 }
 
Index: uspace/srv/vfs/vfs_ipc.c
===================================================================
--- uspace/srv/vfs/vfs_ipc.c	(revision 9246016f2cd9a449613c5c8a7e45dcdc5c78a8f5)
+++ uspace/srv/vfs/vfs_ipc.c	(revision 6ad454f83f303511323abee84bc0e5d4eb8aaf28)
@@ -280,6 +280,7 @@
 {
 	bool high_fd = IPC_GET_ARG1(*request);
-	int fd = vfs_op_wait_handle(high_fd);
-	async_answer_1(rid, EOK, fd);
+	int fd = -1;
+	int rc = vfs_op_wait_handle(high_fd, &fd);
+	async_answer_1(rid, rc, fd);
 }
 
Index: uspace/srv/vfs/vfs_ops.c
===================================================================
--- uspace/srv/vfs/vfs_ops.c	(revision 9246016f2cd9a449613c5c8a7e45dcdc5c78a8f5)
+++ uspace/srv/vfs/vfs_ops.c	(revision 6ad454f83f303511323abee84bc0e5d4eb8aaf28)
@@ -104,8 +104,9 @@
 		/* Assign the old file to newfd. */
 		rc = vfs_fd_assign(oldfile, newfd);
+		*out_fd = newfd;
 	} else {
 		vfs_file_t *newfile;
-		int newfd = vfs_fd_alloc(&newfile, desc);
-		if (newfd >= 0) {
+		rc = vfs_fd_alloc(&newfile, desc, out_fd);
+		if (rc == EOK) {
 			newfile->node = oldfile->node;
 			newfile->permissions = oldfile->permissions;
@@ -114,14 +115,8 @@
 			vfs_file_put(newfile);
 		}
-		rc = newfd;
 	}
 	vfs_file_put(oldfile);
 	
-	if (rc < 0) {
-		return rc;
-	}
-	
-	*out_fd = rc;
-	return EOK;
+	return rc;
 }
 
@@ -228,10 +223,10 @@
 
 int vfs_op_mount(int mpfd, unsigned service_id, unsigned flags,
-    unsigned instance, const char *opts, const char *fs_name, int *outfd)
+    unsigned instance, const char *opts, const char *fs_name, int *out_fd)
 {
 	int rc;
 	vfs_file_t *mp = NULL;
 	vfs_file_t *file = NULL;
-	int fd = -1;
+	*out_fd = -1;
 	
 	if (!(flags & VFS_MOUNT_CONNECT_ONLY)) {
@@ -259,7 +254,6 @@
 	
 	if (!(flags & VFS_MOUNT_NO_REF)) {
-		fd = vfs_fd_alloc(&file, false);
-		if (fd < 0) {
-			rc = fd;
+		rc = vfs_fd_alloc(&file, false, out_fd);
+		if (rc != EOK) {
 			goto out;
 		}
@@ -300,10 +294,9 @@
 		vfs_file_put(file);
 
-	if (rc != EOK && fd >= 0) {
-		vfs_fd_free(fd);
-		fd = 0;
-	}
-	
-	*outfd = fd;
+	if (rc != EOK && *out_fd >= 0) {
+		vfs_fd_free(*out_fd);
+		*out_fd = -1;
+	}
+	
 	return rc;
 }
@@ -833,7 +826,7 @@
 }
 
-int vfs_op_wait_handle(bool high_fd)
-{
-	return vfs_wait_handle_internal(high_fd);
+int vfs_op_wait_handle(bool high_fd, int *out_fd)
+{
+	return vfs_wait_handle_internal(high_fd, out_fd);
 }
 
@@ -897,9 +890,9 @@
 	
 	vfs_file_t *file;
-	int fd = vfs_fd_alloc(&file, false);
-	if (fd < 0) {
+	rc = vfs_fd_alloc(&file, false, out_fd);
+	if (rc != EOK) {
 		vfs_node_put(node);
 		vfs_file_put(parent);
-		return fd;
+		return rc;
 	}
 	assert(file != NULL);
@@ -915,5 +908,4 @@
 	fibril_rwlock_read_unlock(&namespace_rwlock);
 
-	*out_fd = fd;
 	return EOK;
 }
