Index: kernel/generic/src/console/console.c
===================================================================
--- kernel/generic/src/console/console.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ kernel/generic/src/console/console.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -437,5 +437,5 @@
 	}
 
-	return size;
+	return EOK;
 }
 
Index: uspace/app/bdsh/cmds/builtins/cd/cd.c
===================================================================
--- uspace/app/bdsh/cmds/builtins/cd/cd.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/bdsh/cmds/builtins/cd/cd.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -57,8 +57,6 @@
 	previous_directory_set = true;
 
-	int rc = chdir(new_dir);
-	if (rc != EOK) {
-		return rc;
-	}
+	if (chdir(new_dir) != 0)
+		return errno;
 
 	str_cpy(previous_directory, PATH_MAX, previous_directory_tmp);
Index: uspace/app/bdsh/cmds/modules/cat/cat.c
===================================================================
--- uspace/app/bdsh/cmds/modules/cat/cat.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/bdsh/cmds/modules/cat/cat.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -244,5 +244,4 @@
 		
 		bytes = read(fd, buff + copied_bytes, bytes_to_read);
-		bytes += copied_bytes;
 		copied_bytes = 0;
 
Index: uspace/app/bdsh/cmds/modules/cp/cp.c
===================================================================
--- uspace/app/bdsh/cmds/modules/cp/cp.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/bdsh/cmds/modules/cp/cp.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -27,4 +27,5 @@
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -84,5 +85,5 @@
 	int r = stat(path, &s);
 
-	if (r)
+	if (r != 0)
 		return TYPE_NONE;
 	else if (s.is_directory)
@@ -234,5 +235,5 @@
 			 */
 			if (force && !interactive) {
-				if (unlink(dest_path)) {
+				if (unlink(dest_path) != 0) {
 					printf("Unable to remove %s\n",
 					    dest_path);
@@ -245,5 +246,5 @@
 				if (overwrite) {
 					printf("Overwriting file: %s\n", dest_path);
-					if (unlink(dest_path)) {
+					if (unlink(dest_path) != 0) {
 						printf("Unable to remove %s\n", dest_path);
 						goto exit;
@@ -294,5 +295,5 @@
 				merge_paths(dest_path, PATH_MAX, src_dirname);
 
-				if (mkdir(dest_path, 0) == -1) {
+				if (mkdir(dest_path, 0) != 0) {
 					printf("Unable to create "
 					    "dest directory %s\n", dest_path);
@@ -308,5 +309,5 @@
 			 * e.g. cp -r /src /data/new_dir_src
 			 */
-			if (mkdir(dest_path, 0)) {
+			if (mkdir(dest_path, 0) != 0) {
 				printf("Unable to create "
 				    "dest directory %s\n", dest_path);
@@ -405,6 +406,6 @@
 	}
 
-	while ((bytes = read_all(fd1, buff, blen)) > 0) {
-		if ((bytes = write_all(fd2, buff, bytes)) < 0)
+	while ((bytes = read(fd1, buff, blen)) > 0) {
+		if ((bytes = write(fd2, buff, bytes)) < 0)
 			break;
 		copied += bytes;
@@ -412,5 +413,5 @@
 
 	if (bytes < 0) {
-		printf("\nError copying %s, (%d)\n", src, bytes);
+		printf("\nError copying %s, (%d)\n", src, errno);
 		copied = bytes;
 	}
Index: uspace/app/bdsh/cmds/modules/ls/ls.c
===================================================================
--- uspace/app/bdsh/cmds/modules/ls/ls.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/bdsh/cmds/modules/ls/ls.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -31,4 +31,5 @@
  * As more stuff is completed and exposed in libc, this will improve */
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -187,5 +188,5 @@
 		if (rc != 0) {
 			printf("ls: skipping bogus node %s\n", buff);
-			printf("rc=%d\n", rc);
+			printf("error=%d\n", errno);
 			goto out;
 		}
@@ -314,5 +315,5 @@
 static unsigned int ls_scope(const char *path, struct dir_elem_t *de)
 {
-	if (stat(path, &de->s)) {
+	if (stat(path, &de->s) != 0) {
 		cli_error(CL_ENOENT, "%s", path);
 		return LS_BOGUS;
@@ -376,18 +377,23 @@
 		}
 	}
-	
+
 	argc -= optind;
-	
+
 	de.name = (char *) malloc(PATH_MAX);
 	if (!de.name) {
-		cli_error(CL_ENOMEM, "%s: ", cmdname);
+		cli_error(CL_ENOMEM, "%s: Out of memory", cmdname);
 		return CMD_FAILURE;
 	}
 	memset(de.name, 0, PATH_MAX);
-	
-	if (argc == 0)
-		getcwd(de.name, PATH_MAX);
-	else
+
+	if (argc == 0) {
+		if (getcwd(de.name, PATH_MAX) == NULL) {
+			cli_error(CL_EFAIL, "%s: Failed determining working "
+			    "directory", cmdname);
+			return CMD_FAILURE;
+		}
+	} else {
 		str_cpy(de.name, PATH_MAX, argv[optind]);
+	}
 
 	scope = ls_scope(de.name, &de);
Index: uspace/app/bdsh/cmds/modules/mkdir/mkdir.c
===================================================================
--- uspace/app/bdsh/cmds/modules/mkdir/mkdir.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/bdsh/cmds/modules/mkdir/mkdir.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -89,5 +89,5 @@
 {
 	/* Ensure we would always work with absolute and canonified path. */
-	char *path = absolutize(user_path, NULL);
+	char *path = vfs_absolutize(user_path, NULL);
 	if (path == NULL) {
 		cli_error(CL_ENOMEM, "%s: path too big?", cmdname);
@@ -95,12 +95,10 @@
 	}
 
-	int rc;
 	int ret = 0;
 
 	if (!create_parents) {
-		rc = mkdir(path, 0);
-		if (rc != EOK) {
+		if (mkdir(path, 0) != 0) {
 			cli_error(CL_EFAIL, "%s: could not create %s (%s)",
-			    cmdname, path, str_error(rc));
+			    cmdname, path, str_error(errno));
 			ret = 1;
 		}
@@ -137,12 +135,8 @@
 			char slash_char = path[prev_off];
 			path[prev_off] = 0;
-			rc = mkdir(path, 0);
-			if (rc == EEXIST) {
-				rc = EOK;
-			}
-
-			if (rc != EOK) {
+
+			if (mkdir(path, 0) != 0 && errno != EEXIST) {
 				cli_error(CL_EFAIL, "%s: could not create %s (%s)",
-				    cmdname, path, str_error(rc));
+				    cmdname, path, str_error(errno));
 				ret = 1;
 				goto leave;
@@ -152,8 +146,7 @@
 		}
 		/* Create the final directory. */
-		rc = mkdir(path, 0);
-		if (rc != EOK) {
+		if (mkdir(path, 0) != 0) {
 			cli_error(CL_EFAIL, "%s: could not create %s (%s)",
-			    cmdname, path, str_error(rc));
+			    cmdname, path, str_error(errno));
 			ret = 1;
 		}
@@ -214,5 +207,6 @@
 
 	if (follow && (argv[optind] != NULL)) {
-		chdir(argv[optind]);
+		if (chdir(argv[optind]) != 0)
+			printf("%s: Error switching to directory.", cmdname);
 	}
 
Index: uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
===================================================================
--- uspace/app/bdsh/cmds/modules/mkfile/mkfile.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/bdsh/cmds/modules/mkfile/mkfile.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -27,4 +27,5 @@
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -166,8 +167,10 @@
 
 		if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0)
-			goto exit;
+			goto error;
 
 		rc2 = write(fd, &byte, sizeof(char));
-		goto exit;
+		if (rc2 < 0)
+			goto error;
+		return CMD_SUCCESS;
 	}
 
@@ -183,5 +186,5 @@
 		rc = write(fd, buffer, to_write);
 		if (rc <= 0) {
-			printf("%s: Error writing file (%zd).\n", cmdname, rc);
+			printf("%s: Error writing file (%d).\n", cmdname, errno);
 			close(fd);
 			return CMD_FAILURE;
@@ -191,12 +194,11 @@
 
 	free(buffer);
-exit:
-	rc = close(fd);
-
-	if (rc != 0 || rc2 < 0) {
-		printf("%s: Error writing file (%zd).\n", cmdname, rc);
-		return CMD_FAILURE;
-	}
+
+	if (close(fd) < 0)
+		goto error;
 
 	return CMD_SUCCESS;
+error:
+	printf("%s: Error writing file (%d).\n", cmdname, errno);
+	return CMD_FAILURE;
 }
Index: uspace/app/bdsh/cmds/modules/mount/mount.c
===================================================================
--- uspace/app/bdsh/cmds/modules/mount/mount.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/bdsh/cmds/modules/mount/mount.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -72,5 +72,5 @@
 	int rc;
 
-	get_mtab_list(&mtab_list);
+	vfs_get_mtab_list(&mtab_list);
 
 	list_foreach(mtab_list, link, mtab_ent_t, mtab_ent) {
@@ -150,5 +150,5 @@
 		mopts = t_argv[4];
 
-	rc = mount(t_argv[1], t_argv[2], dev, mopts, 0, instance);
+	rc = vfs_mount(t_argv[1], t_argv[2], dev, mopts, 0, instance);
 	if (rc != EOK) {
 		printf("Unable to mount %s filesystem to %s on %s (rc=%d)\n",
Index: uspace/app/bdsh/cmds/modules/mv/mv.c
===================================================================
--- uspace/app/bdsh/cmds/modules/mv/mv.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/bdsh/cmds/modules/mv/mv.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -60,7 +60,7 @@
 
 	rc = rename(argv[1], argv[2]);
-	if (rc != EOK) {
-		printf("Unable to rename %s to %s (rc=%d)\n",
-		    argv[1], argv[2], rc);
+	if (rc != 0) {
+		printf("Unable to rename %s to %s (error=%d)\n",
+		    argv[1], argv[2], errno);
 		return CMD_FAILURE;
 	}
Index: uspace/app/bdsh/cmds/modules/pwd/pwd.c
===================================================================
--- uspace/app/bdsh/cmds/modules/pwd/pwd.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/bdsh/cmds/modules/pwd/pwd.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -56,7 +56,6 @@
 
 	memset(buff, 0, PATH_MAX);
-	getcwd(buff, PATH_MAX);
 
-	if (! buff) {
+	if (getcwd(buff, PATH_MAX) == NULL) {
 		cli_error(CL_EFAIL,
 			"Unable to determine the current working directory");
Index: uspace/app/bdsh/cmds/modules/rm/rm.c
===================================================================
--- uspace/app/bdsh/cmds/modules/rm/rm.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/bdsh/cmds/modules/rm/rm.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -27,4 +27,5 @@
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -131,5 +132,5 @@
 static unsigned int rm_single(const char *path)
 {
-	if (unlink(path)) {
+	if (unlink(path) != 0) {
 		cli_error(CL_EFAIL, "rm: could not remove file %s", path);
 		return 1;
@@ -150,5 +151,5 @@
 
 	fd = open(path, O_RDONLY);
-	if (fd > 0) {
+	if (fd >= 0) {
 		close(fd);
 		return RM_FILE;
@@ -210,5 +211,5 @@
 	rc = rmdir(path);
 	if (rc == 0)
-		return ret;
+		return errno;
 
 	cli_error(CL_ENOTSUP, "Can not remove %s", path);
Index: uspace/app/bdsh/cmds/modules/touch/touch.c
===================================================================
--- uspace/app/bdsh/cmds/modules/touch/touch.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/bdsh/cmds/modules/touch/touch.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -123,5 +123,5 @@
 		
 		/* Check whether file exists if -c (--no-create) option is given */
-		if ((!no_create) || ((no_create) && (stat(buff, &file_stat) == EOK)))
+		if ((!no_create) || ((no_create) && (stat(buff, &file_stat) == 0)))
 			fd = open(buff, O_RDWR | O_CREAT);
 		
Index: uspace/app/bdsh/cmds/modules/unmount/unmount.c
===================================================================
--- uspace/app/bdsh/cmds/modules/unmount/unmount.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/bdsh/cmds/modules/unmount/unmount.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -66,5 +66,5 @@
 	}
 
-	rc = unmount(argv[1]);
+	rc = vfs_unmount(argv[1]);
 	if (rc != EOK) {
 		printf("Unable to unmount %s (rc=%d)\n", argv[1], rc);
Index: uspace/app/bdsh/compl.c
===================================================================
--- uspace/app/bdsh/compl.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/bdsh/compl.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -360,5 +360,5 @@
 				asprintf(&ent_path, "%s/%s", *cs->path, dent->d_name);
 				struct stat ent_stat;
-				if (stat(ent_path, &ent_stat) != EOK) {
+				if (stat(ent_path, &ent_stat) != 0) {
 					/* Error */
 					free(ent_path);
Index: uspace/app/bdsh/exec.c
===================================================================
--- uspace/app/bdsh/exec.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/bdsh/exec.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -61,5 +61,5 @@
 
 	fd = open(f, O_RDONLY);
-	if (fd > -1) {
+	if (fd >= 0) {
 		close(fd);
 		return 0;
@@ -113,5 +113,5 @@
 	
 	for (i = 0; i < 3 && files[i] != NULL; i++) {
-		if (fhandle(files[i], &file_handles[i]) == EOK) {
+		if (vfs_fhandle(files[i], &file_handles[i]) == EOK) {
 			file_handles_p[i] = &file_handles[i];
 		}
Index: uspace/app/df/df.c
===================================================================
--- uspace/app/df/df.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/df/df.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -119,10 +119,14 @@
 
 	LIST_INITIALIZE(mtab_list);
-	get_mtab_list(&mtab_list);
+	vfs_get_mtab_list(&mtab_list);
 
 	print_header();
 	list_foreach(mtab_list, link, mtab_ent_t, mtab_ent) {
-		statfs(mtab_ent->mp, &st);
-		print_statfs(&st, mtab_ent->fs_name, mtab_ent->mp);
+		if (statfs(mtab_ent->mp, &st) == 0) {
+			print_statfs(&st, mtab_ent->fs_name, mtab_ent->mp);
+		} else {
+			fprintf(stderr, "Cannot get information for '%s' (%d).\n",
+			    mtab_ent->mp, errno);
+		}
 	}
 
Index: uspace/app/init/init.c
===================================================================
--- uspace/app/init/init.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/init/init.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -126,5 +126,5 @@
 		opts = "restore";
 	
-	int rc = mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts,
+	int rc = vfs_mount(fstype, ROOT_MOUNT_POINT, ROOT_DEVICE, opts,
 	    IPC_FLAG_BLOCKING, 0);
 	return mount_report("Root filesystem", ROOT_MOUNT_POINT, fstype,
@@ -143,5 +143,5 @@
 static bool mount_locfs(void)
 {
-	int rc = mount(LOCFS_FS_TYPE, LOCFS_MOUNT_POINT, "", "",
+	int rc = vfs_mount(LOCFS_FS_TYPE, LOCFS_MOUNT_POINT, "", "",
 	    IPC_FLAG_BLOCKING, 0);
 	return mount_report("Location service filesystem", LOCFS_MOUNT_POINT,
@@ -152,5 +152,5 @@
 {
 	struct stat s;
-	if (stat(path, &s) == ENOENT) {
+	if (stat(path, &s) != 0) {
 		printf("%s: Unable to stat %s\n", NAME, path);
 		return ENOENT;
@@ -299,5 +299,5 @@
 static bool mount_tmpfs(void)
 {
-	int rc = mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0, 0);
+	int rc = vfs_mount(TMPFS_FS_TYPE, TMPFS_MOUNT_POINT, "", "", 0, 0);
 	return mount_report("Temporary filesystem", TMPFS_MOUNT_POINT,
 	    TMPFS_FS_TYPE, NULL, rc);
Index: uspace/app/taskdump/elf_core.c
===================================================================
--- uspace/app/taskdump/elf_core.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/taskdump/elf_core.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -207,5 +207,5 @@
 	}
 
-	rc = write_all(fd, &elf_hdr, sizeof(elf_hdr));
+	rc = write(fd, &elf_hdr, sizeof(elf_hdr));
 	if (rc != sizeof(elf_hdr)) {
 		printf("Failed writing ELF header.\n");
@@ -215,5 +215,5 @@
 
 	for (i = 0; i < n_ph; ++i) {
-		rc = write_all(fd, &p_hdr[i], sizeof(p_hdr[i]));
+		rc = write(fd, &p_hdr[i], sizeof(p_hdr[i]));
 		if (rc != sizeof(p_hdr[i])) {
 			printf("Failed writing program header.\n");
@@ -236,5 +236,5 @@
 	note.type = NT_PRSTATUS;
 
-	rc = write_all(fd, &note, sizeof(elf_note_t));
+	rc = write(fd, &note, sizeof(elf_note_t));
 	if (rc != sizeof(elf_note_t)) {
 		printf("Failed writing note header.\n");
@@ -243,5 +243,5 @@
 	}
 
-	rc = write_all(fd, "CORE", note.namesz);
+	rc = write(fd, "CORE", note.namesz);
 	if (rc != (ssize_t) note.namesz) {
 		printf("Failed writing note header.\n");
@@ -257,5 +257,5 @@
 	}
 
-	rc = write_all(fd, &pr_status, sizeof(elf_prstatus_t));
+	rc = write(fd, &pr_status, sizeof(elf_prstatus_t));
 	if (rc != sizeof(elf_prstatus_t)) {
 		printf("Failed writing register data.\n");
@@ -321,5 +321,5 @@
 		}
 
-		rc = write_all(fd, buffer, to_copy);
+		rc = write(fd, buffer, to_copy);
 		if (rc != (ssize_t) to_copy) {
 			printf("Failed writing memory contents.\n");
Index: uspace/app/taskdump/symtab.c
===================================================================
--- uspace/app/taskdump/symtab.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/taskdump/symtab.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -88,5 +88,5 @@
 	}
 
-	rc = read_all(fd, &elf_hdr, sizeof(elf_header_t));
+	rc = read(fd, &elf_hdr, sizeof(elf_header_t));
 	if (rc != sizeof(elf_header_t)) {
 		printf("failed reading elf header\n");
@@ -310,5 +310,5 @@
 		return EIO;
 
-	rc = read_all(fd, sec_hdr, sizeof(elf_section_header_t));
+	rc = read(fd, sec_hdr, sizeof(elf_section_header_t));
 	if (rc != sizeof(elf_section_header_t))
 		return EIO;
@@ -346,5 +346,5 @@
 	}
 
-	rc = read_all(fd, *ptr, size);
+	rc = read(fd, *ptr, size);
 	if (rc != (ssize_t) size) {
 		printf("failed reading chunk\n");
Index: uspace/app/tester/hw/misc/virtchar1.c
===================================================================
--- uspace/app/tester/hw/misc/virtchar1.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/tester/hw/misc/virtchar1.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -58,5 +58,5 @@
 	int fd = open(path, O_RDONLY);
 	if (fd < 0) {
-		TPRINTF("   ...error: %s\n", str_error(fd));
+		TPRINTF("   ...error: %s\n", str_error(errno));
 		if (fd == ENOENT) {
 			TPRINTF("   (error was ENOENT: " \
@@ -69,5 +69,5 @@
 	
 	TPRINTF(" Asking for session...\n");
-	async_sess_t *sess = fd_session(fd, INTERFACE_DDF);
+	async_sess_t *sess = vfs_fd_session(fd, INTERFACE_DDF);
 	if (!sess) {
 		close(fd);
Index: uspace/app/tester/vfs/vfs1.c
===================================================================
--- uspace/app/tester/vfs/vfs1.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/tester/vfs/vfs1.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -70,7 +70,6 @@
 const char *test_vfs1(void)
 {
-	int rc;
-	if ((rc = mkdir(TEST_DIRECTORY, 0)) != 0) {
-		TPRINTF("rc=%d\n", rc);
+	if (mkdir(TEST_DIRECTORY, 0) != 0) {
+		TPRINTF("rc=%d\n", errno);
 		return "mkdir() failed";
 	}
@@ -93,5 +92,7 @@
 	
 	char buf[BUF_SIZE];
+	TPRINTF("read..\n");
 	while ((cnt = read(fd0, buf, BUF_SIZE))) {
+		TPRINTF("read returns %zd\n", cnt);
 		if (cnt < 0)
 			return "read() failed";
@@ -112,13 +113,13 @@
 		return rv;
 	
-	if (rename(TEST_FILE, TEST_FILE2))
+	if (rename(TEST_FILE, TEST_FILE2) != 0)
 		return "rename() failed";
 	TPRINTF("Renamed %s to %s\n", TEST_FILE, TEST_FILE2);
 	
-	if (unlink(TEST_FILE2))
+	if (unlink(TEST_FILE2) != 0)
 		return "unlink() failed";
 	TPRINTF("Unlinked %s\n", TEST_FILE2);
 	
-	if (rmdir(TEST_DIRECTORY))
+	if (rmdir(TEST_DIRECTORY) != 0)
 		return "rmdir() failed";
 	TPRINTF("Removed directory %s\n", TEST_DIRECTORY);
Index: uspace/app/trace/trace.c
===================================================================
--- uspace/app/trace/trace.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/trace/trace.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -57,5 +57,5 @@
 #include "proto.h"
 #include <ipc/services.h>
-#include "../../srv/vfs/vfs.h"
+#include <ipc/vfs.h>
 #include <ipc/console.h>
 
@@ -528,15 +528,15 @@
 	int fd_stderr;
 	
-	if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK))
+	if ((stdin != NULL) && (vfs_fhandle(stdin, &fd_stdin) == EOK))
 		files[0] = &fd_stdin;
 	else
 		files[0] = NULL;
 	
-	if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK))
+	if ((stdout != NULL) && (vfs_fhandle(stdout, &fd_stdout) == EOK))
 		files[1] = &fd_stdout;
 	else
 		files[1] = NULL;
 	
-	if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK))
+	if ((stderr != NULL) && (vfs_fhandle(stderr, &fd_stderr) == EOK))
 		files[2] = &fd_stderr;
 	else
Index: uspace/app/untar/main.c
===================================================================
--- uspace/app/untar/main.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/untar/main.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -103,13 +103,10 @@
 static int handle_directory(const tar_header_t *header, FILE *tarfile)
 {
-	int rc = mkdir(header->filename, 0755);
-	if (rc == EEXIST) {
-		// printf("Note: directory %s already exists.\n", header->filename);
-		rc = EOK;
-	}
-	if (rc != EOK) {
-		fprintf(stderr, "Failed to create directory %s: %s.\n",
-		    header->filename, str_error(rc));
-		return rc;
+	if (mkdir(header->filename, 0755) != 0) {
+		if (errno != EEXIST) {
+			fprintf(stderr, "Failed to create directory %s: %s.\n",
+			    header->filename, str_error(errno));
+			return errno;
+		}
 	}
 
Index: uspace/app/viewer/viewer.c
===================================================================
--- uspace/app/viewer/viewer.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/app/viewer/viewer.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -98,10 +98,10 @@
 {
 	int fd = open(fname, O_RDONLY);
-	if (fd < 0)
+	if (fd != 0)
 		return false;
 	
 	struct stat stat;
 	int rc = fstat(fd, &stat);
-	if (rc != EOK) {
+	if (rc != 0) {
 		close(fd);
 		return false;
@@ -114,5 +114,5 @@
 	}
 	
-	ssize_t rd = read_all(fd, tga, stat.size);
+	ssize_t rd = read(fd, tga, stat.size);
 	if ((rd < 0) || (rd != (ssize_t) stat.size)) {
 		free(tga);
Index: uspace/drv/bus/isa/isa.c
===================================================================
--- uspace/drv/bus/isa/isa.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/drv/bus/isa/isa.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -270,5 +270,5 @@
 	}
 
-	r = read_all(fd, buf, len);
+	r = read(fd, buf, len);
 	if (r < 0) {
 		ddf_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);
Index: uspace/lib/bithenge/src/file.c
===================================================================
--- uspace/lib/bithenge/src/file.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/bithenge/src/file.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -114,5 +114,5 @@
 	struct stat stat;
 	int rc = fstat(fd, &stat);
-	if (rc != EOK) {
+	if (rc != 0) {
 		if (needs_close)
 			close(fd);
@@ -157,5 +157,5 @@
 	int fd = open(filename, O_RDONLY);
 	if (fd < 0)
-		return fd;
+		return errno;
 
 	return new_file_blob(out, fd, true);
Index: uspace/lib/c/generic/elf/elf_load.c
===================================================================
--- uspace/lib/c/generic/elf/elf_load.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/c/generic/elf/elf_load.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -97,5 +97,5 @@
 	int fd;
 	int rc;
-	
+
 	fd = open(file_name, O_RDONLY);
 	if (fd < 0) {
@@ -147,5 +147,5 @@
 	int i, rc;
 
-	rc = read_all(elf->fd, header, sizeof(elf_header_t));
+	rc = read(elf->fd, header, sizeof(elf_header_t));
 	if (rc != sizeof(elf_header_t)) {
 		DPRINTF("Read error.\n"); 
@@ -209,5 +209,5 @@
 		        + i * sizeof(elf_segment_header_t), SEEK_SET);
 
-		rc = read_all(elf->fd, &segment_hdr,
+		rc = read(elf->fd, &segment_hdr,
 		    sizeof(elf_segment_header_t));
 		if (rc != sizeof(elf_segment_header_t)) {
@@ -231,5 +231,5 @@
 		    + i * sizeof(elf_section_header_t), SEEK_SET);
 
-		rc = read_all(elf->fd, &section_hdr,
+		rc = read(elf->fd, &section_hdr,
 		    sizeof(elf_section_header_t));
 		if (rc != sizeof(elf_section_header_t)) {
@@ -399,5 +399,5 @@
 		if (now > left) now = left;
 
-		rc = read_all(elf->fd, dp, now);
+		rc = read(elf->fd, dp, now);
 
 		if (rc != (ssize_t) now) { 
Index: uspace/lib/c/generic/io/console.c
===================================================================
--- uspace/lib/c/generic/io/console.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/c/generic/io/console.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -49,5 +49,5 @@
 		return NULL;
 	
-	ctrl->input_sess = fsession(ifile, INTERFACE_CONSOLE);
+	ctrl->input_sess = vfs_fsession(ifile, INTERFACE_CONSOLE);
 	if (!ctrl->input_sess) {
 		free(ctrl);
@@ -55,5 +55,5 @@
 	}
 	
-	ctrl->output_sess = fsession(ofile, INTERFACE_CONSOLE);
+	ctrl->output_sess = vfs_fsession(ofile, INTERFACE_CONSOLE);
 	if (!ctrl->output_sess) {
 		free(ctrl);
Index: uspace/lib/c/generic/io/io.c
===================================================================
--- uspace/lib/c/generic/io/io.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/c/generic/io/io.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -231,5 +231,5 @@
 	if (stream->buf == NULL) {
 		errno = ENOMEM;
-		return -1;
+		return EOF;
 	}
 	
@@ -365,4 +365,7 @@
  * @param nmemb  Number of records to read.
  * @param stream Pointer to the stream.
+ *
+ * @return Number of elements successfully read. On error this is less than
+ *         nmemb, stream error indicator is set and errno is set.
  */
 static size_t _fread(void *buf, size_t size, size_t nmemb, FILE *stream)
@@ -379,9 +382,10 @@
 		ssize_t rd = read(stream->fd, buf + done, left);
 		
-		if (rd < 0)
+		if (rd < 0) {
+			/* errno was set by read() */
 			stream->error = true;
-		else if (rd == 0)
+		} else if (rd == 0) {
 			stream->eof = true;
-		else {
+		} else {
 			left -= rd;
 			done += rd;
@@ -398,4 +402,7 @@
  * @param nmemb  Number of records to write.
  * @param stream Pointer to the stream.
+ *
+ * @return Number of elements successfully written. On error this is less than
+ *         nmemb, stream error indicator is set and errno is set.
  */
 static size_t _fwrite(const void *buf, size_t size, size_t nmemb, FILE *stream)
@@ -403,4 +410,5 @@
 	size_t left;
 	size_t done;
+	int rc;
 
 	if (size == 0 || nmemb == 0)
@@ -412,15 +420,29 @@
 	while ((left > 0) && (!stream->error)) {
 		ssize_t wr;
+		size_t uwr;
 		
-		if (stream->kio)
-			wr = kio_write(buf + done, left);
-		else
+		if (stream->kio) {
+			uwr = 0;
+			rc = kio_write(buf + done, left, &uwr);
+			if (rc != EOK)
+				errno = rc;
+		} else {
 			wr = write(stream->fd, buf + done, left);
+			if (wr >= 0) {
+				uwr = (size_t)wr;
+				rc = EOK;
+			} else {
+				/* errno was set by write */
+				uwr = 0;
+				rc = errno;
+			}
+		}
 		
-		if (wr <= 0)
+		if (rc != EOK) {
+			/* errno was set above */
 			stream->error = true;
-		else {
-			left -= wr;
-			done += wr;
+		} else {
+			left -= uwr;
+			done += uwr;
 		}
 	}
@@ -432,5 +454,8 @@
 }
 
-/** Read some data in stream buffer. */
+/** Read some data in stream buffer.
+ *
+ * On error, stream error indicator is set and errno is set.
+ */
 static void _ffillbuf(FILE *stream)
 {
@@ -441,4 +466,5 @@
 	rc = read(stream->fd, stream->buf, stream->buf_size);
 	if (rc < 0) {
+		/* errno was set by read() */
 		stream->error = true;
 		return;
@@ -465,10 +491,21 @@
 
 	/* If buffer has prefetched read data, we need to seek back. */
-	if (bytes_used > 0 && stream->buf_state == _bs_read)
-		lseek(stream->fd, - (ssize_t) bytes_used, SEEK_CUR);
+	if (bytes_used > 0 && stream->buf_state == _bs_read) {
+		off64_t rc;
+		rc = lseek(stream->fd, - (ssize_t) bytes_used, SEEK_CUR);
+		if (rc == (off64_t)-1) {
+			/* errno was set by lseek */
+			stream->error = 1;
+			return;
+		}
+	}
 
 	/* If buffer has unwritten data, we need to write them out. */
-	if (bytes_used > 0 && stream->buf_state == _bs_write)
+	if (bytes_used > 0 && stream->buf_state == _bs_write) {
 		(void) _fwrite(stream->buf_tail, 1, bytes_used, stream);
+		/* On error stream error indicator and errno are set by _fwrite */
+		if (stream->error)
+			return;
+	}
 
 	stream->buf_head = stream->buf;
@@ -528,6 +565,8 @@
 			_ffillbuf(stream);
 
-		if (stream->error || stream->eof)
+		if (stream->error || stream->eof) {
+			/* On error errno was set by _ffillbuf() */
 			break;
+		}
 
 		data_avail = stream->buf_head - stream->buf_tail;
@@ -584,5 +623,4 @@
 	if (stream->buf_state == _bs_read)
 		_fflushbuf(stream);
-
 
 	/* Perform lazy allocation of stream buffer. */
@@ -622,5 +660,6 @@
 			/* Only need to drain buffer. */
 			_fflushbuf(stream);
-			need_flush = false;
+			if (!stream->error)
+				need_flush = false;
 		}
 	}
@@ -734,11 +773,19 @@
 	off64_t rc;
 
+	if (stream->error)
+		return EOF;
+
 	_fflushbuf(stream);
+	if (stream->error) {
+		/* errno was set by _fflushbuf() */
+		return EOF;
+	}
+
 	stream->ungetc_chars = 0;
 
 	rc = lseek(stream->fd, offset, whence);
 	if (rc == (off64_t) (-1)) {
-		/* errno has been set by lseek64. */
-		return -1;
+		/* errno has been set by lseek() */
+		return EOF;
 	}
 
@@ -749,6 +796,22 @@
 off64_t ftell(FILE *stream)
 {
+	off64_t pos;
+	
+	if (stream->error)
+		return EOF;
+	
 	_fflushbuf(stream);
-	return lseek(stream->fd, 0, SEEK_CUR) - stream->ungetc_chars;
+	if (stream->error) {
+		/* errno was set by _fflushbuf() */
+		return EOF;
+	}
+
+	pos = lseek(stream->fd, 0, SEEK_CUR);
+	if (pos == (off64_t) -1) {
+		/* errno was set by lseek */
+		return (off64_t) -1;
+	}
+	
+	return pos - stream->ungetc_chars;
 }
 
@@ -760,9 +823,16 @@
 int fflush(FILE *stream)
 {
+	if (stream->error)
+		return EOF;
+	
 	_fflushbuf(stream);
+	if (stream->error) {
+		/* errno was set by _fflushbuf() */
+		return EOF;
+	}
 	
 	if (stream->kio) {
 		kio_update();
-		return EOK;
+		return 0;
 	}
 	
@@ -773,8 +843,13 @@
 		 */
 		stream->need_sync = false;
-		return fsync(stream->fd);
-	}
-	
-	return ENOENT;
+		if (fsync(stream->fd) != 0) {
+			/* errno was set by fsync() */
+			return EOF;
+		}
+
+		return 0;
+	}
+	
+	return 0;
 }
 
@@ -799,5 +874,5 @@
 	if (stream->kio) {
 		errno = EBADF;
-		return -1;
+		return EOF;
 	}
 	
@@ -805,9 +880,9 @@
 }
 
-async_sess_t *fsession(FILE *stream, iface_t iface)
+async_sess_t *vfs_fsession(FILE *stream, iface_t iface)
 {
 	if (stream->fd >= 0) {
 		if (stream->sess == NULL)
-			stream->sess = fd_session(stream->fd, iface);
+			stream->sess = vfs_fd_session(stream->fd, iface);
 		
 		return stream->sess;
@@ -817,5 +892,5 @@
 }
 
-int fhandle(FILE *stream, int *handle)
+int vfs_fhandle(FILE *stream, int *handle)
 {
 	if (stream->fd >= 0) {
Index: uspace/lib/c/generic/io/kio.c
===================================================================
--- uspace/lib/c/generic/io/kio.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/c/generic/io/kio.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -43,12 +43,11 @@
 #include <io/printf_core.h>
 
-size_t kio_write(const void *buf, size_t size)
+int kio_write(const void *buf, size_t size, size_t *nwritten)
 {
-	ssize_t ret = (ssize_t) __SYSCALL3(SYS_KIO, KIO_WRITE, (sysarg_t) buf, size);
+	int rc = (int) __SYSCALL3(SYS_KIO, KIO_WRITE, (sysarg_t) buf, size);
 	
-	if (ret >= 0)
-		return (size_t) ret;
-	
-	return 0;
+	if (rc == EOK)
+		*nwritten = size;
+	return rc;
 }
 
@@ -84,5 +83,8 @@
 static int kio_vprintf_str_write(const char *str, size_t size, void *data)
 {
-	size_t wr = kio_write(str, size);
+	size_t wr;
+	
+	wr = 0;
+	(void) kio_write(str, size, &wr);
 	return str_nlength(str, wr);
 }
@@ -92,4 +94,5 @@
 	size_t offset = 0;
 	size_t chars = 0;
+	size_t wr;
 	
 	while (offset < size) {
@@ -98,5 +101,5 @@
 		
 		if (chr_encode(str[chars], buf, &sz, STR_BOUNDS(1)) == EOK)
-			kio_write(buf, sz);
+			kio_write(buf, sz, &wr);
 		
 		chars++;
Index: uspace/lib/c/generic/loader.c
===================================================================
--- uspace/lib/c/generic/loader.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/c/generic/loader.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -124,5 +124,5 @@
 		return ENOMEM;
 	
-	if (!getcwd(cwd, MAX_PATH_LEN + 1))
+	if (getcwd(cwd, MAX_PATH_LEN + 1) == NULL)
 		str_cpy(cwd, MAX_PATH_LEN + 1, "/");
 	
@@ -162,5 +162,5 @@
 {
 	size_t pa_len;
-	char *pa = absolutize(path, &pa_len);
+	char *pa = vfs_absolutize(path, &pa_len);
 	if (!pa)
 		return ENOMEM;
Index: uspace/lib/c/generic/task.c
===================================================================
--- uspace/lib/c/generic/task.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/c/generic/task.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -112,15 +112,15 @@
 	int fd_stderr;
 	
-	if ((stdin != NULL) && (fhandle(stdin, &fd_stdin) == EOK))
+	if ((stdin != NULL) && (vfs_fhandle(stdin, &fd_stdin) == EOK))
 		files[0] = &fd_stdin;
 	else
 		files[0] = NULL;
 	
-	if ((stdout != NULL) && (fhandle(stdout, &fd_stdout) == EOK))
+	if ((stdout != NULL) && (vfs_fhandle(stdout, &fd_stdout) == EOK))
 		files[1] = &fd_stdout;
 	else
 		files[1] = NULL;
 	
-	if ((stderr != NULL) && (fhandle(stderr, &fd_stderr) == EOK))
+	if ((stderr != NULL) && (vfs_fhandle(stderr, &fd_stderr) == EOK))
 		files[2] = &fd_stderr;
 	else
Index: uspace/lib/c/generic/vfs/vfs.c
===================================================================
--- uspace/lib/c/generic/vfs/vfs.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/c/generic/vfs/vfs.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -93,5 +93,5 @@
 }
 
-char *absolutize(const char *path, size_t *retlen)
+char *vfs_absolutize(const char *path, size_t *retlen)
 {
 	char *ncwd_path;
@@ -101,10 +101,10 @@
 	size_t size = str_size(path);
 	if (*path != '/') {
-		if (!cwd_path) {
+		if (cwd_path == NULL) {
 			fibril_mutex_unlock(&cwd_mutex);
 			return NULL;
 		}
 		ncwd_path_nc = malloc(cwd_size + 1 + size + 1);
-		if (!ncwd_path_nc) {
+		if (ncwd_path_nc == NULL) {
 			fibril_mutex_unlock(&cwd_mutex);
 			return NULL;
@@ -115,5 +115,5 @@
 	} else {
 		ncwd_path_nc = malloc(size + 1);
-		if (!ncwd_path_nc) {
+		if (ncwd_path_nc == NULL) {
 			fibril_mutex_unlock(&cwd_mutex);
 			return NULL;
@@ -123,5 +123,5 @@
 	str_append(ncwd_path_nc, cwd_size + 1 + size + 1, path);
 	ncwd_path = canonify(ncwd_path_nc, retlen);
-	if (!ncwd_path) {
+	if (ncwd_path == NULL) {
 		fibril_mutex_unlock(&cwd_mutex);
 		free(ncwd_path_nc);
@@ -135,5 +135,5 @@
 	ncwd_path = str_dup(ncwd_path);
 	free(ncwd_path_nc);
-	if (!ncwd_path) {
+	if (ncwd_path == NULL) {
 		fibril_mutex_unlock(&cwd_mutex);
 		return NULL;
@@ -143,5 +143,5 @@
 }
 
-int mount(const char *fs_name, const char *mp, const char *fqsn,
+int vfs_mount(const char *fs_name, const char *mp, const char *fqsn,
     const char *opts, unsigned int flags, unsigned int instance)
 {
@@ -171,6 +171,6 @@
 	
 	size_t mpa_size;
-	char *mpa = absolutize(mp, &mpa_size);
-	if (!mpa) {
+	char *mpa = vfs_absolutize(mp, &mpa_size);
+	if (mpa == NULL) {
 		if (null_id != -1)
 			loc_null_destroy(null_id);
@@ -255,5 +255,5 @@
 }
 
-int unmount(const char *mp)
+int vfs_unmount(const char *mp)
 {
 	sysarg_t rc;
@@ -263,6 +263,6 @@
 	char *mpa;
 	
-	mpa = absolutize(mp, &mpa_size);
-	if (!mpa)
+	mpa = vfs_absolutize(mp, &mpa_size);
+	if (mpa == NULL)
 		return ENOMEM;
 	
@@ -289,5 +289,16 @@
 }
 
-static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag)
+/** Open file (internal).
+ *
+ * @param abs Absolute path to file
+ * @param abs_size Size of @a abs string
+ * @param lflag L_xxx flags
+ * @param oflag O_xxx flags
+ * @param fd Place to store new file descriptor
+ *
+ * @return EOK on success, non-zero error code on error
+ */
+static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag,
+    int *fd)
 {
 	async_exch_t *exch = vfs_exchange_begin();
@@ -315,20 +326,44 @@
 	    return (int) rc;
 	
-	return (int) IPC_GET_ARG1(answer);
-}
-
+	*fd = (int) IPC_GET_ARG1(answer);
+	return EOK;
+}
+
+/** Open file.
+ *
+ * @param path File path
+ * @param oflag O_xxx flags
+ * @param mode File mode (only with O_CREAT)
+ *
+ * @return Nonnegative file descriptor on success. On error -1 is returned
+ *         and errno is set.
+ */
 int open(const char *path, int oflag, ...)
 {
 	size_t abs_size;
-	char *abs = absolutize(path, &abs_size);
-	if (!abs)
-		return ENOMEM;
-	
-	int ret = open_internal(abs, abs_size, L_FILE, oflag);
+	char *abs = vfs_absolutize(path, &abs_size);
+	int fd = -1;
+	
+	if (abs == NULL) {
+		errno = ENOMEM;
+		return -1;
+	}
+	
+	int rc = open_internal(abs, abs_size, L_FILE, oflag, &fd);
 	free(abs);
 	
-	return ret;
-}
-
+	if (rc != EOK) {
+		errno = rc;
+		return -1;
+	}
+	
+	return fd;
+}
+
+/** Close file.
+ *
+ * @param fildes File descriptor
+ * @return Zero on success. On error -1 is returned and errno is set.
+ */
 int close(int fildes)
 {
@@ -339,8 +374,27 @@
 	vfs_exchange_end(exch);
 	
-	return (int) rc;
-}
-
-ssize_t read(int fildes, void *buf, size_t nbyte)
+	if (rc != EOK) {
+		errno = rc;
+		return -1;
+	}
+	
+	return 0;
+}
+
+/** Read bytes from file.
+ *
+ * Read up to @a nbyte bytes from file. The actual number of bytes read
+ * may be lower, but greater than zero if there are any bytes available.
+ * If there are no bytes available for reading, then the function will
+ * return success with zero bytes read.
+ *
+ * @param fildes File descriptor
+ * @param buf Buffer
+ * @param nbyte Maximum number of bytes to read
+ * @param nread Place to store actual number of bytes read (0 or more)
+ *
+ * @return EOK on success, non-zero error code on error.
+ */
+static int _read_short(int fildes, void *buf, size_t nbyte, ssize_t *nread)
 {
 	sysarg_t rc;
@@ -357,22 +411,38 @@
 	if (rc != EOK) {
 		vfs_exchange_end(exch);
-
+		
 		sysarg_t rc_orig;
 		async_wait_for(req, &rc_orig);
-
+		
 		if (rc_orig == EOK)
-			return (ssize_t) rc;
+			return rc;
 		else
-			return (ssize_t) rc_orig;
-	}
+			return rc_orig;
+	}
+	
 	vfs_exchange_end(exch);
 	async_wait_for(req, &rc);
-	if (rc == EOK)
-		return (ssize_t) IPC_GET_ARG1(answer);
-	else
+	
+	if (rc != EOK)
 		return rc;
-}
-
-ssize_t write(int fildes, const void *buf, size_t nbyte) 
+	
+	*nread = (ssize_t) IPC_GET_ARG1(answer);
+	return EOK;
+}
+
+/** Write bytes to file.
+ *
+ * Write up to @a nbyte bytes from file. The actual number of bytes written
+ * may be lower, but greater than zero.
+ *
+ * @param fildes File descriptor
+ * @param buf Buffer
+ * @param nbyte Maximum number of bytes to write
+ * @param nread Place to store actual number of bytes written (0 or more)
+ *
+ * @return EOK on success, non-zero error code on error.
+ */
+static int _write_short(int fildes, const void *buf, size_t nbyte,
+    ssize_t *nwritten)
 {
 	sysarg_t rc;
@@ -389,25 +459,28 @@
 	if (rc != EOK) {
 		vfs_exchange_end(exch);
-
+		
 		sysarg_t rc_orig;
 		async_wait_for(req, &rc_orig);
-
+		
 		if (rc_orig == EOK)
-			return (ssize_t) rc;
+			return rc;
 		else
-			return (ssize_t) rc_orig;
-	}
+			return rc_orig;
+	}
+	
 	vfs_exchange_end(exch);
 	async_wait_for(req, &rc);
-	if (rc == EOK)
-		return (ssize_t) IPC_GET_ARG1(answer);
-	else
-		return -1;
-}
-
-/** Read entire buffer.
- *
- * In face of short reads this function continues reading until either
- * the entire buffer is read or no more data is available (at end of file).
+	
+	if (rc != EOK)
+		return rc;
+	
+	*nwritten = (ssize_t) IPC_GET_ARG1(answer);
+	return EOK;
+}
+
+/** Read data.
+ *
+ * Read up to @a nbytes bytes from file if available. This function always reads
+ * all the available bytes up to @a nbytes.
  *
  * @param fildes	File descriptor
@@ -415,26 +488,29 @@
  * @param nbytes	Number of bytes to read
  *
- * @return		On success, positive number of bytes read.
- *			On failure, negative error code from read().
- */
-ssize_t read_all(int fildes, void *buf, size_t nbyte)
+ * @return		On success, nonnegative number of bytes read.
+ *			On failure, -1 and sets errno.
+ */
+ssize_t read(int fildes, void *buf, size_t nbyte)
 {
 	ssize_t cnt = 0;
 	size_t nread = 0;
 	uint8_t *bp = (uint8_t *) buf;
-
+	int rc;
+	
 	do {
 		bp += cnt;
 		nread += cnt;
-		cnt = read(fildes, bp, nbyte - nread);
-	} while (cnt > 0 && (nbyte - nread - cnt) > 0);
-
-	if (cnt < 0)
-		return cnt;
-
+		rc = _read_short(fildes, bp, nbyte - nread, &cnt);
+	} while (rc == EOK && cnt > 0 && (nbyte - nread - cnt) > 0);
+	
+	if (rc != EOK) {
+		errno = rc;
+		return -1;
+	}
+	
 	return nread + cnt;
 }
 
-/** Write entire buffer.
+/** Write data.
  *
  * This function fails if it cannot write exactly @a len bytes to the file.
@@ -444,28 +520,33 @@
  * @param nbytes	Number of bytes to write
  *
- * @return		EOK on error, return value from write() if writing
- *			failed.
- */
-ssize_t write_all(int fildes, const void *buf, size_t nbyte)
+ * @return		On success, nonnegative number of bytes written.
+ *			On failure, -1 and sets errno.
+ */
+ssize_t write(int fildes, const void *buf, size_t nbyte)
 {
 	ssize_t cnt = 0;
 	ssize_t nwritten = 0;
 	const uint8_t *bp = (uint8_t *) buf;
+	int rc;
 
 	do {
 		bp += cnt;
 		nwritten += cnt;
-		cnt = write(fildes, bp, nbyte - nwritten);
-	} while (cnt > 0 && ((ssize_t )nbyte - nwritten - cnt) > 0);
-
-	if (cnt < 0)
-		return cnt;
-
-	if ((ssize_t)nbyte - nwritten - cnt > 0)
-		return EIO;
+		rc = _write_short(fildes, bp, nbyte - nwritten, &cnt);
+	} while (rc == EOK && ((ssize_t )nbyte - nwritten - cnt) > 0);
+
+	if (rc != EOK) {
+		errno = rc;
+		return -1;
+	}
 
 	return nbyte;
 }
 
+/** Synchronize file.
+ *
+ * @param fildes File descriptor
+ * @return 0 on success. On error returns -1 and sets errno.
+ */
 int fsync(int fildes)
 {
@@ -474,7 +555,21 @@
 	vfs_exchange_end(exch);
 	
-	return (int) rc;
-}
-
+	if (rc != EOK) {
+		errno = rc;
+		return -1;
+	}
+	
+	return 0;
+}
+
+/** Seek to a position.
+ *
+ * @param fildes File descriptor
+ * @param offset Offset
+ * @param whence SEEK_SET, SEEK_CUR or SEEK_END
+ *
+ * @return On success the nonnegative offset from start of file. On error
+ *         returns (off64_t)-1 and sets errno.
+ */
 off64_t lseek(int fildes, off64_t offset, int whence)
 {
@@ -489,10 +584,21 @@
 	vfs_exchange_end(exch);
 	
-	if (rc != EOK)
+	if (rc != EOK) {
+		errno = rc;
 		return (off64_t) -1;
+	}
 	
 	return (off64_t) MERGE_LOUP32(newoff_lo, newoff_hi);
 }
 
+/** Truncate file to a specified length.
+ *
+ * Truncate file so that its size is exactly @a length
+ *
+ * @param fildes File descriptor
+ * @param length Length
+ *
+ * @return 0 on success, -1 on error and sets errno.
+ */
 int ftruncate(int fildes, aoff64_t length)
 {
@@ -504,7 +610,19 @@
 	vfs_exchange_end(exch);
 	
-	return (int) rc;
-}
-
+	if (rc != EOK) {
+		errno = rc;
+		return -1;
+	}
+	
+	return 0;
+}
+
+/** Get file status.
+ *
+ * @param fildes File descriptor
+ * @param stat Place to store file information
+ *
+ * @return 0 on success, -1 on error and sets errno.
+ */
 int fstat(int fildes, struct stat *stat)
 {
@@ -518,19 +636,36 @@
 	if (rc != EOK) {
 		vfs_exchange_end(exch);
-
+		
 		sysarg_t rc_orig;
 		async_wait_for(req, &rc_orig);
-
-		if (rc_orig == EOK)
-			return (ssize_t) rc;
-		else
-			return (ssize_t) rc_orig;
-	}
+		
+		if (rc_orig != EOK)
+			rc = rc_orig;
+		if (rc != EOK) {
+			errno = rc;
+			return -1;
+		}
+		
+		return 0;
+	}
+	
 	vfs_exchange_end(exch);
 	async_wait_for(req, &rc);
-
-	return rc;
-}
-
+	
+	if (rc != EOK) {
+		errno = rc;
+		return -1;
+	}
+	
+	return 0;
+}
+
+/** Get file status.
+ *
+ * @param path Path to file
+ * @param stat Place to store file information
+ *
+ * @return 0 on success, -1 on error and sets errno.
+ */
 int stat(const char *path, struct stat *stat)
 {
@@ -540,7 +675,9 @@
 	
 	size_t pa_size;
-	char *pa = absolutize(path, &pa_size);
-	if (!pa)
-		return ENOMEM;
+	char *pa = vfs_absolutize(path, &pa_size);
+	if (pa == NULL) {
+		errno = ENOMEM;
+		return -1;
+	}
 	
 	async_exch_t *exch = vfs_exchange_begin();
@@ -552,4 +689,195 @@
 		free(pa);
 		async_wait_for(req, &rc_orig);
+		if (rc_orig != EOK)
+			rc = rc_orig;
+		if (rc != EOK) {
+			errno = rc;
+			return -1;
+		}
+	}
+	rc = async_data_read_start(exch, stat, sizeof(struct stat));
+	if (rc != EOK) {
+		vfs_exchange_end(exch);
+		free(pa);
+		async_wait_for(req, &rc_orig);
+		if (rc_orig != EOK)
+			rc = rc_orig;
+		if (rc != EOK) {
+			errno = rc;
+			return -1;
+		}
+	}
+	vfs_exchange_end(exch);
+	free(pa);
+	async_wait_for(req, &rc);
+	if (rc != EOK) {
+		errno = rc;
+		return -1;
+	}
+	return 0;
+}
+
+/** Open directory.
+ *
+ * @param dirname Directory pathname
+ *
+ * @return Non-NULL pointer on success. On error returns @c NULL and sets errno.
+ */
+DIR *opendir(const char *dirname)
+{
+	DIR *dirp = malloc(sizeof(DIR));
+	int fd = -1;
+	
+	if (dirp == NULL) {
+		errno = ENOMEM;
+		return NULL;
+	}
+	
+	size_t abs_size;
+	char *abs = vfs_absolutize(dirname, &abs_size);
+	if (abs == NULL) {
+		free(dirp);
+		errno = ENOMEM;
+		return NULL;
+	}
+	
+	int rc = open_internal(abs, abs_size, L_DIRECTORY, 0, &fd);
+	free(abs);
+	
+	if (rc != EOK) {
+		free(dirp);
+		errno = rc;
+		return NULL;
+	}
+	
+	dirp->fd = fd;
+	return dirp;
+}
+
+/** Read directory entry.
+ *
+ * @param dirp Open directory
+ * @return Non-NULL pointer to directory entry on success. On error returns
+ *         @c NULL and sets errno.
+ */
+struct dirent *readdir(DIR *dirp)
+{
+	int rc;
+	ssize_t len;
+	
+	rc = _read_short(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1, &len);
+	if (rc != EOK) {
+		errno = rc;
+		return NULL;
+	}
+	
+	(void) len;
+	return &dirp->res;
+}
+
+/** Rewind directory position to the beginning.
+ *
+ * @param dirp Open directory
+ */
+void rewinddir(DIR *dirp)
+{
+	(void) lseek(dirp->fd, 0, SEEK_SET);
+}
+
+/** Close directory.
+ *
+ * @param dirp Open directory
+ * @return 0 on success. On error returns -1 and sets errno.
+ */
+int closedir(DIR *dirp)
+{
+	int rc;
+	
+	rc = close(dirp->fd);
+	free(dirp);
+
+	/* On error errno was set by close() */
+	return rc;
+}
+
+/** Create directory.
+ *
+ * @param path Path
+ * @param mode File mode
+ * @return 0 on success. On error returns -1 and sets errno.
+ */
+int mkdir(const char *path, mode_t mode)
+{
+	sysarg_t rc;
+	aid_t req;
+	
+	size_t pa_size;
+	char *pa = vfs_absolutize(path, &pa_size);
+	if (pa == NULL) {
+		errno = ENOMEM;
+		return -1;
+	}
+	
+	async_exch_t *exch = vfs_exchange_begin();
+	
+	req = async_send_1(exch, VFS_IN_MKDIR, mode, NULL);
+	rc = async_data_write_start(exch, pa, pa_size);
+	if (rc != EOK) {
+		vfs_exchange_end(exch);
+		free(pa);
+		
+		sysarg_t rc_orig;
+		async_wait_for(req, &rc_orig);
+		
+		if (rc_orig != EOK)
+			rc = rc_orig;
+		
+		if (rc != EOK) {
+			errno = rc;
+			return -1;
+		}
+		
+		return 0;
+	}
+	
+	vfs_exchange_end(exch);
+	free(pa);
+	async_wait_for(req, &rc);
+	
+	if (rc != EOK) {
+		errno = rc;
+		return -1;
+	}
+	
+	return 0;
+}
+
+/** Unlink a file or directory.
+ *
+ * @param path Path to file or empty directory
+ * @param lflag L_xxx flag (L_NONE, L_FILE or L_DIRECTORY)
+ * @return EOK on success, non-zero error code on error
+ */
+static int _unlink(const char *path, int lflag)
+{
+	sysarg_t rc;
+	aid_t req;
+	
+	size_t pa_size;
+	char *pa = vfs_absolutize(path, &pa_size);
+	if (pa == NULL)
+		return ENOMEM;
+	
+	async_exch_t *exch = vfs_exchange_begin();
+	
+	req = async_send_1(exch, VFS_IN_UNLINK, lflag, NULL);
+	rc = async_data_write_start(exch, pa, pa_size);
+	if (rc != EOK) {
+		vfs_exchange_end(exch);
+		free(pa);
+
+		sysarg_t rc_orig;
+		async_wait_for(req, &rc_orig);
+
 		if (rc_orig == EOK)
 			return (int) rc;
@@ -557,14 +885,4 @@
 			return (int) rc_orig;
 	}
-	rc = async_data_read_start(exch, stat, sizeof(struct stat));
-	if (rc != EOK) {
-		vfs_exchange_end(exch);
-		free(pa);
-		async_wait_for(req, &rc_orig);
-		if (rc_orig == EOK)
-			return (int) rc;
-		else
-			return (int) rc_orig;
-	}
 	vfs_exchange_end(exch);
 	free(pa);
@@ -573,123 +891,47 @@
 }
 
-DIR *opendir(const char *dirname)
-{
-	DIR *dirp = malloc(sizeof(DIR));
-	if (!dirp)
-		return NULL;
-	
-	size_t abs_size;
-	char *abs = absolutize(dirname, &abs_size);
-	if (!abs) {
-		free(dirp);
-		return NULL;
-	}
-	
-	int ret = open_internal(abs, abs_size, L_DIRECTORY, 0);
-	free(abs);
-	
-	if (ret < 0) {
-		free(dirp);
-		return NULL;
-	}
-	
-	dirp->fd = ret;
-	return dirp;
-}
-
-struct dirent *readdir(DIR *dirp)
-{
-	ssize_t len = read(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1);
-	if (len <= 0)
-		return NULL;
-	return &dirp->res;
-}
-
-void rewinddir(DIR *dirp)
-{
-	(void) lseek(dirp->fd, 0, SEEK_SET);
-}
-
-int closedir(DIR *dirp)
-{
-	(void) close(dirp->fd);
-	free(dirp);
+/** Unlink file or directory.
+ *
+ * @param path Path
+ * @return EOk on success, error code on error
+ */
+int unlink(const char *path)
+{
+	int rc;
+
+	rc = _unlink(path, L_NONE);
+	if (rc != EOK) {
+		errno = rc;
+		return -1;
+	}
+
 	return 0;
 }
 
-int mkdir(const char *path, mode_t mode)
-{
-	sysarg_t rc;
-	aid_t req;
-	
-	size_t pa_size;
-	char *pa = absolutize(path, &pa_size);
-	if (!pa)
-		return ENOMEM;
-	
-	async_exch_t *exch = vfs_exchange_begin();
-	
-	req = async_send_1(exch, VFS_IN_MKDIR, mode, NULL);
-	rc = async_data_write_start(exch, pa, pa_size);
-	if (rc != EOK) {
-		vfs_exchange_end(exch);
-		free(pa);
-
-		sysarg_t rc_orig;
-		async_wait_for(req, &rc_orig);
-
-		if (rc_orig == EOK)
-			return (int) rc;
-		else
-			return (int) rc_orig;
-	}
-	vfs_exchange_end(exch);
-	free(pa);
-	async_wait_for(req, &rc);
-	return rc;
-}
-
-static int _unlink(const char *path, int lflag)
-{
-	sysarg_t rc;
-	aid_t req;
-	
-	size_t pa_size;
-	char *pa = absolutize(path, &pa_size);
-	if (!pa)
-		return ENOMEM;
-	
-	async_exch_t *exch = vfs_exchange_begin();
-	
-	req = async_send_1(exch, VFS_IN_UNLINK, lflag, NULL);
-	rc = async_data_write_start(exch, pa, pa_size);
-	if (rc != EOK) {
-		vfs_exchange_end(exch);
-		free(pa);
-
-		sysarg_t rc_orig;
-		async_wait_for(req, &rc_orig);
-
-		if (rc_orig == EOK)
-			return (int) rc;
-		else
-			return (int) rc_orig;
-	}
-	vfs_exchange_end(exch);
-	free(pa);
-	async_wait_for(req, &rc);
-	return rc;
-}
-
-int unlink(const char *path)
-{
-	return _unlink(path, L_NONE);
-}
-
+/** Remove empty directory.
+ *
+ * @param path Path
+ * @return 0 on success. On error returns -1 and sets errno.
+ */
 int rmdir(const char *path)
 {
-	return _unlink(path, L_DIRECTORY);
-}
-
+	int rc;
+
+	rc = _unlink(path, L_DIRECTORY);
+	if (rc != EOK) {
+		errno = rc;
+		return -1;
+	}
+
+	return 0;
+}
+
+/** Rename directory entry.
+ *
+ * @param old Old name
+ * @param new New name
+ *
+ * @return 0 on success. On error returns -1 and sets errno.
+ */
 int rename(const char *old, const char *new)
 {
@@ -699,13 +941,16 @@
 	
 	size_t olda_size;
-	char *olda = absolutize(old, &olda_size);
-	if (!olda)
-		return ENOMEM;
+	char *olda = vfs_absolutize(old, &olda_size);
+	if (olda == NULL) {
+		errno = ENOMEM;
+		return -1;
+	}
 
 	size_t newa_size;
-	char *newa = absolutize(new, &newa_size);
-	if (!newa) {
+	char *newa = vfs_absolutize(new, &newa_size);
+	if (newa == NULL) {
 		free(olda);
-		return ENOMEM;
+		errno = ENOMEM;
+		return -1;
 	}
 	
@@ -719,8 +964,11 @@
 		free(newa);
 		async_wait_for(req, &rc_orig);
-		if (rc_orig == EOK)
-			return (int) rc;
-		else
-			return (int) rc_orig;
+		if (rc_orig != EOK)
+			rc = rc_orig;
+		if (rc != EOK) {
+			errno = rc;
+			return -1;
+		}
+		return 0;
 	}
 	rc = async_data_write_start(exch, newa, newa_size);
@@ -730,8 +978,11 @@
 		free(newa);
 		async_wait_for(req, &rc_orig);
-		if (rc_orig == EOK)
-			return (int) rc;
-		else
-			return (int) rc_orig;
+		if (rc_orig != EOK)
+			rc = rc_orig;
+		if (rc != EOK) {
+			errno = rc;
+			return -1;
+		}
+		return 0;
 	}
 	vfs_exchange_end(exch);
@@ -739,7 +990,18 @@
 	free(newa);
 	async_wait_for(req, &rc);
-	return rc;
-}
-
+
+	if (rc != EOK) {
+		errno = rc;
+		return -1;
+	}
+
+	return 0;
+}
+
+/** Remove directory entry.
+ *
+ * @param path Path
+ * @return 0 on success. On error returns -1 and sets errno.
+ */
 int remove(const char *path)
 {
@@ -747,16 +1009,26 @@
 }
 
+/** Change working directory.
+ *
+ * @param path Path
+ * @return 0 on success. On error returns -1 and sets errno.
+ */
 int chdir(const char *path)
 {
 	size_t abs_size;
-	char *abs = absolutize(path, &abs_size);
-	if (!abs)
-		return ENOMEM;
-	
-	int fd = open_internal(abs, abs_size, L_DIRECTORY, O_DESC);
-	
-	if (fd < 0) {
+	char *abs = vfs_absolutize(path, &abs_size);
+	int fd = -1;
+	
+	if (abs == NULL) {
+		errno = ENOMEM;
+		return -1;
+	}
+	
+	int rc = open_internal(abs, abs_size, L_DIRECTORY, O_DESC, &fd);
+	
+	if (rc != EOK) {
 		free(abs);
-		return ENOENT;
+		errno = rc;
+		return -1;
 	}
 	
@@ -765,5 +1037,4 @@
 	if (cwd_fd >= 0)
 		close(cwd_fd);
-	
 	
 	if (cwd_path)
@@ -775,11 +1046,19 @@
 	
 	fibril_mutex_unlock(&cwd_mutex);
-	return EOK;
-}
-
+	return 0;
+}
+
+/** Get current working directory path.
+ *
+ * @param buf Buffer
+ * @param size Size of @a buf
+ * @return On success returns @a buf. On failure returns @c NULL and sets errno.
+ */
 char *getcwd(char *buf, size_t size)
 {
-	if (size == 0)
+	if (size == 0) {
+		errno = EINVAL;
 		return NULL;
+	}
 	
 	fibril_mutex_lock(&cwd_mutex);
@@ -787,4 +1066,5 @@
 	if ((cwd_size == 0) || (size < cwd_size + 1)) {
 		fibril_mutex_unlock(&cwd_mutex);
+		errno = ERANGE;
 		return NULL;
 	}
@@ -796,21 +1076,34 @@
 }
 
-async_sess_t *fd_session(int fildes, iface_t iface)
+/** Open session to service represented by a special file.
+ *
+ * Given that the file referred to by @a fildes represents a service,
+ * open a session to that service.
+ *
+ * @param fildes File descriptor
+ * @param iface Interface to connect to (XXX Should be automatic)
+ * @return On success returns session pointer. On error returns @c NULL.
+ */
+async_sess_t *vfs_fd_session(int fildes, iface_t iface)
 {
 	struct stat stat;
 	int rc = fstat(fildes, &stat);
-	if (rc != 0) {
-		errno = rc;
+	if (rc != 0)
 		return NULL;
-	}
-	
-	if (!stat.service) {
-		errno = ENOENT;
+	
+	if (stat.service == 0)
 		return NULL;
-	}
 	
 	return loc_service_connect(stat.service, iface, 0);
 }
 
+/** Duplicate open file.
+ *
+ * Duplicate open file under a new file descriptor.
+ *
+ * @param oldfd Old file descriptor
+ * @param newfd New file descriptor
+ * @return 0 on success. On error -1 is returned and errno is set
+ */
 int dup2(int oldfd, int newfd)
 {
@@ -823,10 +1116,15 @@
 	
 	if (rc == EOK)
-		return (int) ret;
-	
-	return (int) rc;
-}
-
-int fd_wait(void)
+		rc = ret;
+	
+	if (rc != EOK) {
+		errno = rc;
+		return -1;
+	}
+	
+	return 0;
+}
+
+int vfs_fd_wait(void)
 {
 	async_exch_t *exch = vfs_exchange_begin();
@@ -843,5 +1141,5 @@
 }
 
-int get_mtab_list(list_t *mtab_list)
+int vfs_get_mtab_list(list_t *mtab_list)
 {
 	sysarg_t rc;
@@ -863,5 +1161,5 @@
 
 		mtab_ent = malloc(sizeof(mtab_ent_t));
-		if (!mtab_ent) {
+		if (mtab_ent == NULL) {
 			rc = ENOMEM;
 			goto exit;
@@ -904,4 +1202,10 @@
 }
 
+/** Get filesystem statistics.
+ *
+ * @param path Mount point path
+ * @param st Buffer for storing information
+ * @return 0 on success. On error -1 is returned and errno is set.
+ */
 int statfs(const char *path, struct statfs *st)
 {
@@ -910,7 +1214,9 @@
 	size_t pa_size;
 
-	char *pa = absolutize(path, &pa_size);
-	if (!pa)
-		return ENOMEM;
+	char *pa = vfs_absolutize(path, &pa_size);
+	if (pa == NULL) {
+		errno = ENOMEM;
+		return -1;
+	}
 
 	async_exch_t *exch = vfs_exchange_begin();
@@ -927,5 +1233,12 @@
 	free(pa);
 	async_wait_for(req, &rc_orig);
-	return (int) (rc_orig != EOK ? rc_orig : rc);
+	rc = (rc_orig != EOK ? rc_orig : rc);
+
+	if (rc != EOK) {
+		errno = rc;
+		return -1;
+	}
+
+	return 0;
 }
 
Index: uspace/lib/c/include/io/kio.h
===================================================================
--- uspace/lib/c/include/io/kio.h	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/c/include/io/kio.h	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -40,5 +40,5 @@
 #include <io/verify.h>
 
-extern size_t kio_write(const void *, size_t);
+extern int kio_write(const void *, size_t, size_t *);
 extern void kio_update(void);
 extern void kio_command(const void *, size_t);
Index: uspace/lib/c/include/sys/statfs.h
===================================================================
--- uspace/lib/c/include/sys/statfs.h	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/c/include/sys/statfs.h	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -46,4 +46,5 @@
 
 extern int statfs(const char *, struct statfs *);
+
 #endif
 
Index: uspace/lib/c/include/unistd.h
===================================================================
--- uspace/lib/c/include/unistd.h	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/c/include/unistd.h	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -63,7 +63,4 @@
 extern ssize_t read(int, void *, size_t);
 
-extern ssize_t read_all(int, void *, size_t);
-extern ssize_t write_all(int, const void *, size_t);
-
 extern off64_t lseek(int, off64_t, int);
 extern int ftruncate(int, aoff64_t);
Index: uspace/lib/c/include/vfs/vfs.h
===================================================================
--- uspace/lib/c/include/vfs/vfs.h	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/c/include/vfs/vfs.h	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -50,17 +50,18 @@
 
 
-extern char *absolutize(const char *, size_t *);
+extern char *vfs_absolutize(const char *, size_t *);
 
-extern int mount(const char *, const char *, const char *, const char *,
+extern int vfs_mount(const char *, const char *, const char *, const char *,
     unsigned int, unsigned int);
-extern int unmount(const char *);
+extern int vfs_unmount(const char *);
 
-extern int fhandle(FILE *, int *);
+extern int vfs_fhandle(FILE *, int *);
 
-extern int fd_wait(void);
-extern int get_mtab_list(list_t *mtab_list);
+extern int vfs_fd_wait(void);
+extern int vfs_get_mtab_list(list_t *mtab_list);
 
 extern async_exch_t *vfs_exchange_begin(void);
 extern void vfs_exchange_end(async_exch_t *);
+
 #endif
 
Index: uspace/lib/c/include/vfs/vfs_sess.h
===================================================================
--- uspace/lib/c/include/vfs/vfs_sess.h	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/c/include/vfs/vfs_sess.h	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -39,6 +39,6 @@
 #include <stdio.h>
 
-extern async_sess_t *fd_session(int, iface_t);
-extern async_sess_t *fsession(FILE *, iface_t);
+extern async_sess_t *vfs_fd_session(int, iface_t);
+extern async_sess_t *vfs_fsession(FILE *, iface_t);
 
 #endif
Index: uspace/lib/pcut/src/os/helenos.c
===================================================================
--- uspace/lib/pcut/src/os/helenos.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/pcut/src/os/helenos.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -220,5 +220,5 @@
 	fibril_mutex_unlock(&forced_termination_mutex);
 
-	read_all(tempfile, extra_output_buffer, OUTPUT_BUFFER_SIZE);
+	read(tempfile, extra_output_buffer, OUTPUT_BUFFER_SIZE);
 
 leave_close_tempfile:
Index: uspace/lib/posix/source/fcntl.c
===================================================================
--- uspace/lib/posix/source/fcntl.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/posix/source/fcntl.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -112,11 +112,5 @@
 	}
 
-	int rc = open(pathname, flags, mode);
-	if (rc < 0) {
-		errno = -rc;
-		rc = -1;
-	}
-
-	return rc;
+	return negerrno(open, pathname, flags, mode);
 }
 
Index: uspace/lib/posix/source/internal/common.h
===================================================================
--- uspace/lib/posix/source/internal/common.h	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/posix/source/internal/common.h	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -48,5 +48,5 @@
 	} while (0)
 
-/* A little helper macro to avoid typing this over and over. */
+/* Convert negative error return value to positive errno */
 #define errnify(func, ...) ({ \
 	int rc = func(__VA_ARGS__); \
@@ -58,4 +58,13 @@
 })
 
+/* Convert negative errno to positive errno */
+#define negerrno(func, ...) ({ \
+	int rc = func(__VA_ARGS__); \
+	if (rc < 0) { \
+		errno = -errno; \
+	} \
+	rc; \
+})
+
 #endif /* LIBPOSIX_COMMON_H_ */
 
Index: uspace/lib/posix/source/stdio.c
===================================================================
--- uspace/lib/posix/source/stdio.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/posix/source/stdio.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -315,11 +315,5 @@
 int posix_fflush(FILE *stream)
 {
-	int rc = fflush(stream);
-	if (rc < 0) {
-		errno = -rc;
-		return EOF;
-	} else {
-		return 0;
-	}
+	return negerrno(fflush, stream);
 }
 
@@ -351,4 +345,6 @@
 {
 	ssize_t wr = write(*(int *) fd, str, size);
+	if (wr < 0)
+		return errno;
 	return str_nlength(str, wr);
 }
@@ -579,23 +575,5 @@
 int posix_remove(const char *path)
 {
-	struct stat st;
-	int rc = stat(path, &st);
-	
-	if (rc != EOK) {
-		errno = -rc;
-		return -1;
-	}
-	
-	if (st.is_directory) {
-		rc = rmdir(path);
-	} else {
-		rc = unlink(path);
-	}
-	
-	if (rc != EOK) {
-		errno = -rc;
-		return -1;
-	}
-	return 0;
+	return negerrno(remove, path);
 }
 
@@ -609,5 +587,5 @@
 int posix_rename(const char *old, const char *new)
 {
-	return errnify(rename, old, new);
+	return negerrno(rename, old, new);
 }
 
Index: uspace/lib/posix/source/stdlib.c
===================================================================
--- uspace/lib/posix/source/stdlib.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/posix/source/stdlib.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -278,5 +278,5 @@
 	 * to be updated when that support is implemented.
 	 */
-	char* absolute = absolutize(name, NULL);
+	char* absolute = vfs_absolutize(name, NULL);
 	
 	if (absolute == NULL) {
Index: uspace/lib/posix/source/sys/stat.c
===================================================================
--- uspace/lib/posix/source/sys/stat.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/posix/source/sys/stat.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -80,10 +80,7 @@
 {
 	struct stat hst;
-	int rc = fstat(fd, &hst);
-	if (rc < 0) {
-		/* fstat() returns negative error code instead of using errno. */
-		errno = -rc;
-		return -1;
-	}
+	int rc = negerrno(fstat, fd, &hst);
+	if (rc < 0)
+		return rc;
 	stat_to_posix(st, &hst);
 	return 0;
@@ -113,10 +110,7 @@
 {
 	struct stat hst;
-	int rc = stat(path, &hst);
-	if (rc < 0) {
-		/* stat() returns negative error code instead of using errno. */
-		errno = -rc;
-		return -1;
-	}
+	int rc = negerrno(stat, path, &hst);
+	if (rc < 0)
+		return rc;
 	stat_to_posix(st, &hst);
 	return 0;
Index: uspace/lib/posix/source/unistd.c
===================================================================
--- uspace/lib/posix/source/unistd.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/lib/posix/source/unistd.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -105,31 +105,12 @@
 char *posix_getcwd(char *buf, size_t size)
 {
-	/* Native getcwd() does not set any errno despite the fact that general
-	 * usage pattern of this function depends on it (caller is repeatedly
-	 * guessing the required size of the buffer by checking for ERANGE on
-	 * failure). */
-	if (size == 0) {
-		errno = EINVAL;
+	char *p = getcwd(buf, size);
+
+	if (p == NULL) {
+		errno = -errno;
 		return NULL;
 	}
-	
-	/* Save the original value to comply with the "no modification on
-	 * success" semantics.
-	 */
-	int orig_errno = errno;
-	errno = EOK;
-	
-	char *ret = getcwd(buf, size);
-	if (ret == NULL) {
-		/* Check errno to avoid shadowing other possible errors. */
-		if (errno == EOK) {
-			errno = ERANGE;
-		}
-	} else {
-		/* Success, restore previous errno value. */
-		errno = orig_errno;
-	}
-	
-	return ret;
+
+	return p;
 }
 
@@ -141,5 +122,5 @@
 int posix_chdir(const char *path)
 {
-	return errnify(chdir, path);
+	return negerrno(chdir, path);
 }
 
@@ -194,5 +175,5 @@
 int posix_close(int fildes)
 {
-	return errnify(close, fildes);
+	return negerrno(close, fildes);
 }
 
@@ -207,5 +188,5 @@
 ssize_t posix_read(int fildes, void *buf, size_t nbyte)
 {
-	return errnify(read, fildes, buf, nbyte);
+	return negerrno(read, fildes, buf, nbyte);
 }
 
@@ -220,5 +201,5 @@
 ssize_t posix_write(int fildes, const void *buf, size_t nbyte)
 {
-	return errnify(write, fildes, buf, nbyte);
+	return negerrno(write, fildes, buf, nbyte);
 }
 
@@ -234,5 +215,5 @@
 posix_off_t posix_lseek(int fildes, posix_off_t offset, int whence)
 {
-	return errnify(lseek, fildes, offset, whence);
+	return negerrno(lseek, fildes, offset, whence);
 }
 
@@ -245,5 +226,5 @@
 int posix_fsync(int fildes)
 {
-	return errnify(fsync, fildes);
+	return negerrno(fsync, fildes);
 }
 
@@ -257,5 +238,5 @@
 int posix_ftruncate(int fildes, posix_off_t length)
 {
-	return errnify(ftruncate, fildes, (aoff64_t) length);
+	return negerrno(ftruncate, fildes, (aoff64_t) length);
 }
 
@@ -268,5 +249,5 @@
 int posix_rmdir(const char *path)
 {
-	return errnify(rmdir, path);
+	return negerrno(rmdir, path);
 }
 
@@ -279,5 +260,5 @@
 int posix_unlink(const char *path)
 {
-	return errnify(unlink, path);
+	return negerrno(unlink, path);
 }
 
@@ -303,5 +284,5 @@
 int posix_dup2(int fildes, int fildes2)
 {
-	return errnify(dup2, fildes, fildes2);
+	return negerrno(dup2, fildes, fildes2);
 }
 
@@ -321,7 +302,7 @@
 		 * Check file existence by attempting to open it.
 		 */
-		int fd = open(path, O_RDONLY);
+		int fd = negerrno(open, path, O_RDONLY);
 		if (fd < 0) {
-			errno = -fd;
+			/* errno was set by open() */
 			return -1;
 		}
Index: uspace/srv/devman/driver.c
===================================================================
--- uspace/srv/devman/driver.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/srv/devman/driver.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -142,5 +142,5 @@
 	/* Check whether the driver's binary exists. */
 	struct stat s;
-	if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */
+	if (stat(drv->binary_path, &s) != 0) {
 		log_msg(LOG_DEFAULT, LVL_ERROR, "Driver not found at path `%s'.",
 		    drv->binary_path);
Index: uspace/srv/devman/match.c
===================================================================
--- uspace/srv/devman/match.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/srv/devman/match.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -31,4 +31,5 @@
  */
 
+#include <errno.h>
 #include <fcntl.h>
 #include <io/log.h>
@@ -197,5 +198,5 @@
 	if (fd < 0) {
 		log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to open `%s' for reading: %s.",
-		    conf_path, str_error(fd));
+		    conf_path, str_error(errno));
 		goto cleanup;
 	}
@@ -217,8 +218,8 @@
 	}
 	
-	ssize_t read_bytes = read_all(fd, buf, len);
+	ssize_t read_bytes = read(fd, buf, len);
 	if (read_bytes <= 0) {
-		log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to read file '%s' (%zd).", conf_path,
-		    read_bytes);
+		log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to read file '%s' (%d).", conf_path,
+		    errno);
 		goto cleanup;
 	}
Index: uspace/srv/loader/main.c
===================================================================
--- uspace/srv/loader/main.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/srv/loader/main.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -249,5 +249,5 @@
 		}
 		async_state_change_finalize(callid, vfs_exch);
-		fd = fd_wait();
+		fd = vfs_fd_wait();
 		assert(fd == (int) filc);
 	}
Index: uspace/srv/vfs/vfs.c
===================================================================
--- uspace/srv/vfs/vfs.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/srv/vfs/vfs.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -74,8 +74,8 @@
 			break;
 		case VFS_IN_MOUNT:
-			vfs_mount(callid, &call);
+			vfs_mount_srv(callid, &call);
 			break;
 		case VFS_IN_UNMOUNT:
-			vfs_unmount(callid, &call);
+			vfs_unmount_srv(callid, &call);
 			break;
 		case VFS_IN_OPEN:
Index: uspace/srv/vfs/vfs.h
===================================================================
--- uspace/srv/vfs/vfs.h	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/srv/vfs/vfs.h	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -205,6 +205,6 @@
 
 extern void vfs_register(ipc_callid_t, ipc_call_t *);
-extern void vfs_mount(ipc_callid_t, ipc_call_t *);
-extern void vfs_unmount(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_open(ipc_callid_t, ipc_call_t *);
 extern void vfs_sync(ipc_callid_t, ipc_call_t *);
Index: uspace/srv/vfs/vfs_ops.c
===================================================================
--- uspace/srv/vfs/vfs_ops.c	(revision f1f75844d9701b6afc8edf98cc50a32245497274)
+++ uspace/srv/vfs/vfs_ops.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
@@ -266,5 +266,5 @@
 }
 
-void vfs_mount(ipc_callid_t rid, ipc_call_t *request)
+void vfs_mount_srv(ipc_callid_t rid, ipc_call_t *request)
 {
 	service_id_t service_id;
@@ -405,5 +405,5 @@
 }
 
-void vfs_unmount(ipc_callid_t rid, ipc_call_t *request)
+void vfs_unmount_srv(ipc_callid_t rid, ipc_call_t *request)
 {
 	int rc;
