Index: uspace/lib/c/generic/vfs/vfs.c
===================================================================
--- uspace/lib/c/generic/vfs/vfs.c	(revision b1bd89ea1c886a89bb5827e967627d37001aa4f2)
+++ uspace/lib/c/generic/vfs/vfs.c	(revision f2b3d3ea3dc1fbb7a2312b326613bcc88a3bfaf5)
@@ -58,9 +58,16 @@
 static async_sess_t *vfs_sess = NULL;
 
+/* Current (working) directory. */
 static FIBRIL_MUTEX_INITIALIZE(cwd_mutex);
-
 static int cwd_fd = -1;
 static char *cwd_path = NULL;
 static size_t cwd_size = 0;
+
+/* Previous directory. */
+static FIBRIL_MUTEX_INITIALIZE(pwd_mutex);
+static int pwd_fd = -1;
+static char *pwd_path = NULL;
+static size_t pwd_size = 0;
+
 
 /** Start an async exchange on the VFS session.
@@ -751,11 +758,21 @@
 	fibril_mutex_lock(&cwd_mutex);
 	
-	if (cwd_fd >= 0)
-		close(cwd_fd);
-	
-	
-	if (cwd_path)
-		free(cwd_path);
-	
+
+	fibril_mutex_lock(&pwd_mutex);
+
+	if (pwd_fd >= 0)
+		close(pwd_fd);
+
+
+	if (pwd_path)
+		free(pwd_path);
+
+
+	pwd_fd = cwd_fd;
+	pwd_path = cwd_path;
+	pwd_size = cwd_size;
+
+	fibril_mutex_unlock(&pwd_mutex);
+
 	cwd_fd = fd;
 	cwd_path = abs;
@@ -781,4 +798,23 @@
 	fibril_mutex_unlock(&cwd_mutex);
 	
+	return buf;
+}
+
+
+char *getprevwd(char *buf, size_t size)
+{
+	if (size == 0)
+		return NULL;
+
+	fibril_mutex_lock(&pwd_mutex);
+
+	if ((pwd_size == 0) || (size < pwd_size + 1)) {
+		fibril_mutex_unlock(&pwd_mutex);
+		return NULL;
+	}
+
+	str_cpy(buf, size, pwd_path);
+	fibril_mutex_unlock(&pwd_mutex);
+
 	return buf;
 }
Index: uspace/lib/c/include/unistd.h
===================================================================
--- uspace/lib/c/include/unistd.h	(revision b1bd89ea1c886a89bb5827e967627d37001aa4f2)
+++ uspace/lib/c/include/unistd.h	(revision f2b3d3ea3dc1fbb7a2312b326613bcc88a3bfaf5)
@@ -58,5 +58,5 @@
 #define getpagesize()  (PAGE_SIZE)
 
-extern int dup2(int oldfd, int newfd);
+extern int dup2(int, int);
 
 extern ssize_t write(int, const void *, size_t);
@@ -73,5 +73,6 @@
 extern int unlink(const char *);
 
-extern char *getcwd(char *buf, size_t);
+extern char *getcwd(char *, size_t);
+extern char *getprevwd(char *, size_t);
 extern int rmdir(const char *);
 extern int chdir(const char *);
