Index: uspace/lib/c/generic/vfs/vfs.c
===================================================================
--- uspace/lib/c/generic/vfs/vfs.c	(revision 6afc9d780e775e54c1cfb5d3c57fb749979b18d2)
+++ uspace/lib/c/generic/vfs/vfs.c	(revision f9b2cb4cf365498e1fe141b1aa66950fbc3dcb17)
@@ -93,5 +93,5 @@
 }
 
-char *vfs_absolutize(const char *path, size_t *retlen)
+char *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 == NULL) {
+		if (!cwd_path) {
 			fibril_mutex_unlock(&cwd_mutex);
 			return NULL;
 		}
 		ncwd_path_nc = malloc(cwd_size + 1 + size + 1);
-		if (ncwd_path_nc == NULL) {
+		if (!ncwd_path_nc) {
 			fibril_mutex_unlock(&cwd_mutex);
 			return NULL;
@@ -115,5 +115,5 @@
 	} else {
 		ncwd_path_nc = malloc(size + 1);
-		if (ncwd_path_nc == NULL) {
+		if (!ncwd_path_nc) {
 			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 == NULL) {
+	if (!ncwd_path) {
 		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 == NULL) {
+	if (!ncwd_path) {
 		fibril_mutex_unlock(&cwd_mutex);
 		return NULL;
@@ -143,5 +143,5 @@
 }
 
-int vfs_mount(const char *fs_name, const char *mp, const char *fqsn,
+int 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 = vfs_absolutize(mp, &mpa_size);
-	if (mpa == NULL) {
+	char *mpa = absolutize(mp, &mpa_size);
+	if (!mpa) {
 		if (null_id != -1)
 			loc_null_destroy(null_id);
@@ -255,5 +255,5 @@
 }
 
-int vfs_unmount(const char *mp)
+int unmount(const char *mp)
 {
 	sysarg_t rc;
@@ -263,6 +263,6 @@
 	char *mpa;
 	
-	mpa = vfs_absolutize(mp, &mpa_size);
-	if (mpa == NULL)
+	mpa = absolutize(mp, &mpa_size);
+	if (!mpa)
 		return ENOMEM;
 	
@@ -289,16 +289,5 @@
 }
 
-/** 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)
+static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag)
 {
 	async_exch_t *exch = vfs_exchange_begin();
@@ -326,44 +315,20 @@
 	    return (int) rc;
 	
-	*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.
- */
+	return (int) IPC_GET_ARG1(answer);
+}
+
 int open(const char *path, int oflag, ...)
 {
 	size_t abs_size;
-	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);
+	char *abs = absolutize(path, &abs_size);
+	if (!abs)
+		return ENOMEM;
+	
+	int ret = open_internal(abs, abs_size, L_FILE, oflag);
 	free(abs);
 	
-	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.
- */
+	return ret;
+}
+
 int close(int fildes)
 {
@@ -374,27 +339,8 @@
 	vfs_exchange_end(exch);
 	
-	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)
+	return (int) rc;
+}
+
+ssize_t read(int fildes, void *buf, size_t nbyte)
 {
 	sysarg_t rc;
@@ -411,38 +357,22 @@
 	if (rc != EOK) {
 		vfs_exchange_end(exch);
-		
+
 		sysarg_t rc_orig;
 		async_wait_for(req, &rc_orig);
-		
-		if (rc_orig == EOK)
-			return rc;
-		else
-			return rc_orig;
-	}
-	
-	vfs_exchange_end(exch);
-	async_wait_for(req, &rc);
-	
-	if (rc != EOK)
+
+		if (rc_orig == EOK)
+			return (ssize_t) rc;
+		else
+			return (ssize_t) rc_orig;
+	}
+	vfs_exchange_end(exch);
+	async_wait_for(req, &rc);
+	if (rc == EOK)
+		return (ssize_t) IPC_GET_ARG1(answer);
+	else
 		return rc;
-	
-	*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)
+}
+
+ssize_t write(int fildes, const void *buf, size_t nbyte) 
 {
 	sysarg_t rc;
@@ -459,28 +389,25 @@
 	if (rc != EOK) {
 		vfs_exchange_end(exch);
-		
+
 		sysarg_t rc_orig;
 		async_wait_for(req, &rc_orig);
-		
-		if (rc_orig == EOK)
-			return rc;
-		else
-			return rc_orig;
-	}
-	
-	vfs_exchange_end(exch);
-	async_wait_for(req, &rc);
-	
-	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.
+
+		if (rc_orig == EOK)
+			return (ssize_t) rc;
+		else
+			return (ssize_t) 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).
  *
  * @param fildes	File descriptor
@@ -488,29 +415,26 @@
  * @param nbytes	Number of bytes to read
  *
- * @return		On success, nonnegative number of bytes read.
- *			On failure, -1 and sets errno.
+ * @return		On success, positive number of bytes read.
+ *			On failure, negative error code from read().
  */
-ssize_t read(int fildes, void *buf, size_t nbyte)
+ssize_t read_all(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;
-		rc = _read_short(fildes, bp, nbyte - nread, &cnt);
-	} while (rc == EOK && cnt > 0 && (nbyte - nread - cnt) > 0);
-	
-	if (rc != EOK) {
-		errno = rc;
-		return -1;
-	}
-	
+		cnt = read(fildes, bp, nbyte - nread);
+	} while (cnt > 0 && (nbyte - nread - cnt) > 0);
+
+	if (cnt < 0)
+		return cnt;
+
 	return nread + cnt;
 }
 
-/** Write data.
+/** Write entire buffer.
  *
  * This function fails if it cannot write exactly @a len bytes to the file.
@@ -520,33 +444,28 @@
  * @param nbytes	Number of bytes to write
  *
- * @return		On success, nonnegative number of bytes written.
- *			On failure, -1 and sets errno.
+ * @return		EOK on error, return value from write() if writing
+ *			failed.
  */
-ssize_t write(int fildes, const void *buf, size_t nbyte)
+ssize_t write_all(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;
-		rc = _write_short(fildes, bp, nbyte - nwritten, &cnt);
-	} while (rc == EOK && ((ssize_t )nbyte - nwritten - cnt) > 0);
-
-	if (rc != EOK) {
-		errno = rc;
-		return -1;
-	}
+		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;
 
 	return nbyte;
 }
 
-/** Synchronize file.
- *
- * @param fildes File descriptor
- * @return 0 on success. On error returns -1 and sets errno.
- */
 int fsync(int fildes)
 {
@@ -555,21 +474,7 @@
 	vfs_exchange_end(exch);
 	
-	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.
- */
+	return (int) rc;
+}
+
 off64_t lseek(int fildes, off64_t offset, int whence)
 {
@@ -584,21 +489,10 @@
 	vfs_exchange_end(exch);
 	
-	if (rc != EOK) {
-		errno = rc;
+	if (rc != EOK)
 		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)
 {
@@ -610,19 +504,7 @@
 	vfs_exchange_end(exch);
 	
-	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.
- */
+	return (int) rc;
+}
+
 int fstat(int fildes, struct stat *stat)
 {
@@ -636,36 +518,19 @@
 	if (rc != EOK) {
 		vfs_exchange_end(exch);
-		
+
 		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);
-	async_wait_for(req, &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.
- */
+
+		if (rc_orig == EOK)
+			return (ssize_t) rc;
+		else
+			return (ssize_t) rc_orig;
+	}
+	vfs_exchange_end(exch);
+	async_wait_for(req, &rc);
+
+	return rc;
+}
+
 int stat(const char *path, struct stat *stat)
 {
@@ -675,9 +540,7 @@
 	
 	size_t pa_size;
-	char *pa = vfs_absolutize(path, &pa_size);
-	if (pa == NULL) {
-		errno = ENOMEM;
-		return -1;
-	}
+	char *pa = absolutize(path, &pa_size);
+	if (!pa)
+		return ENOMEM;
 	
 	async_exch_t *exch = vfs_exchange_begin();
@@ -689,10 +552,8 @@
 		free(pa);
 		async_wait_for(req, &rc_orig);
-		if (rc_orig != EOK)
-			rc = rc_orig;
-		if (rc != EOK) {
-			errno = rc;
-			return -1;
-		}
+		if (rc_orig == EOK)
+			return (int) rc;
+		else
+			return (int) rc_orig;
 	}
 	rc = async_data_read_start(exch, stat, sizeof(struct stat));
@@ -701,110 +562,60 @@
 		free(pa);
 		async_wait_for(req, &rc_orig);
-		if (rc_orig != EOK)
-			rc = rc_orig;
-		if (rc != EOK) {
-			errno = rc;
-			return -1;
-		}
+		if (rc_orig == EOK)
+			return (int) rc;
+		else
+			return (int) rc_orig;
 	}
 	vfs_exchange_end(exch);
 	free(pa);
 	async_wait_for(req, &rc);
-	if (rc != EOK) {
-		errno = rc;
-		return -1;
-	}
+	return rc;
+}
+
+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);
 	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)
 {
@@ -813,9 +624,7 @@
 	
 	size_t pa_size;
-	char *pa = vfs_absolutize(path, &pa_size);
-	if (pa == NULL) {
-		errno = ENOMEM;
-		return -1;
-	}
+	char *pa = absolutize(path, &pa_size);
+	if (!pa)
+		return ENOMEM;
 	
 	async_exch_t *exch = vfs_exchange_begin();
@@ -826,37 +635,19 @@
 		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;
-	}
-	
+
+		if (rc_orig == EOK)
+			return (int) rc;
+		else
+			return (int) rc_orig;
+	}
 	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
- */
+	return rc;
+}
+
 static int _unlink(const char *path, int lflag)
 {
@@ -865,6 +656,6 @@
 	
 	size_t pa_size;
-	char *pa = vfs_absolutize(path, &pa_size);
-	if (pa == NULL)
+	char *pa = absolutize(path, &pa_size);
+	if (!pa)
 		return ENOMEM;
 	
@@ -891,47 +682,14 @@
 }
 
-/** 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;
-}
-
-/** Remove empty directory.
- *
- * @param path Path
- * @return 0 on success. On error returns -1 and sets errno.
- */
+	return _unlink(path, L_NONE);
+}
+
 int rmdir(const char *path)
 {
-	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.
- */
+	return _unlink(path, L_DIRECTORY);
+}
+
 int rename(const char *old, const char *new)
 {
@@ -941,16 +699,13 @@
 	
 	size_t olda_size;
-	char *olda = vfs_absolutize(old, &olda_size);
-	if (olda == NULL) {
-		errno = ENOMEM;
-		return -1;
-	}
+	char *olda = absolutize(old, &olda_size);
+	if (!olda)
+		return ENOMEM;
 
 	size_t newa_size;
-	char *newa = vfs_absolutize(new, &newa_size);
-	if (newa == NULL) {
+	char *newa = absolutize(new, &newa_size);
+	if (!newa) {
 		free(olda);
-		errno = ENOMEM;
-		return -1;
+		return ENOMEM;
 	}
 	
@@ -964,11 +719,8 @@
 		free(newa);
 		async_wait_for(req, &rc_orig);
-		if (rc_orig != EOK)
-			rc = rc_orig;
-		if (rc != EOK) {
-			errno = rc;
-			return -1;
-		}
-		return 0;
+		if (rc_orig == EOK)
+			return (int) rc;
+		else
+			return (int) rc_orig;
 	}
 	rc = async_data_write_start(exch, newa, newa_size);
@@ -978,11 +730,8 @@
 		free(newa);
 		async_wait_for(req, &rc_orig);
-		if (rc_orig != EOK)
-			rc = rc_orig;
-		if (rc != EOK) {
-			errno = rc;
-			return -1;
-		}
-		return 0;
+		if (rc_orig == EOK)
+			return (int) rc;
+		else
+			return (int) rc_orig;
 	}
 	vfs_exchange_end(exch);
@@ -990,18 +739,7 @@
 	free(newa);
 	async_wait_for(req, &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.
- */
+	return rc;
+}
+
 int remove(const char *path)
 {
@@ -1009,26 +747,16 @@
 }
 
-/** 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 = 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) {
+	char *abs = absolutize(path, &abs_size);
+	if (!abs)
+		return ENOMEM;
+	
+	int fd = open_internal(abs, abs_size, L_DIRECTORY, O_DESC);
+	
+	if (fd < 0) {
 		free(abs);
-		errno = rc;
-		return -1;
+		return ENOENT;
 	}
 	
@@ -1037,4 +765,5 @@
 	if (cwd_fd >= 0)
 		close(cwd_fd);
+	
 	
 	if (cwd_path)
@@ -1046,19 +775,11 @@
 	
 	fibril_mutex_unlock(&cwd_mutex);
-	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.
- */
+	return EOK;
+}
+
 char *getcwd(char *buf, size_t size)
 {
-	if (size == 0) {
-		errno = EINVAL;
+	if (size == 0)
 		return NULL;
-	}
 	
 	fibril_mutex_lock(&cwd_mutex);
@@ -1066,5 +787,4 @@
 	if ((cwd_size == 0) || (size < cwd_size + 1)) {
 		fibril_mutex_unlock(&cwd_mutex);
-		errno = ERANGE;
 		return NULL;
 	}
@@ -1076,34 +796,21 @@
 }
 
-/** 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)
+async_sess_t *fd_session(int fildes, iface_t iface)
 {
 	struct stat stat;
 	int rc = fstat(fildes, &stat);
-	if (rc != 0)
+	if (rc != 0) {
+		errno = rc;
 		return NULL;
-	
-	if (stat.service == 0)
+	}
+	
+	if (!stat.service) {
+		errno = ENOENT;
 		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)
 {
@@ -1116,15 +823,10 @@
 	
 	if (rc == EOK)
-		rc = ret;
-	
-	if (rc != EOK) {
-		errno = rc;
-		return -1;
-	}
-	
-	return 0;
-}
-
-int vfs_fd_wait(void)
+		return (int) ret;
+	
+	return (int) rc;
+}
+
+int fd_wait(void)
 {
 	async_exch_t *exch = vfs_exchange_begin();
@@ -1141,5 +843,5 @@
 }
 
-int vfs_get_mtab_list(list_t *mtab_list)
+int get_mtab_list(list_t *mtab_list)
 {
 	sysarg_t rc;
@@ -1161,5 +863,5 @@
 
 		mtab_ent = malloc(sizeof(mtab_ent_t));
-		if (mtab_ent == NULL) {
+		if (!mtab_ent) {
 			rc = ENOMEM;
 			goto exit;
@@ -1202,10 +904,4 @@
 }
 
-/** 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)
 {
@@ -1214,9 +910,7 @@
 	size_t pa_size;
 
-	char *pa = vfs_absolutize(path, &pa_size);
-	if (pa == NULL) {
-		errno = ENOMEM;
-		return -1;
-	}
+	char *pa = absolutize(path, &pa_size);
+	if (!pa)
+		return ENOMEM;
 
 	async_exch_t *exch = vfs_exchange_begin();
@@ -1233,12 +927,5 @@
 	free(pa);
 	async_wait_for(req, &rc_orig);
-	rc = (rc_orig != EOK ? rc_orig : rc);
-
-	if (rc != EOK) {
-		errno = rc;
-		return -1;
-	}
-
-	return 0;
+	return (int) (rc_orig != EOK ? rc_orig : rc);
 }
 
