patch-2.1.93 linux/fs/dcache.c

Next file: linux/fs/devpts/Makefile
Previous file: linux/fs/coda/inode.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.92/linux/fs/dcache.c linux/fs/dcache.c
@@ -780,16 +780,26 @@
 asmlinkage int sys_getcwd(char *buf, unsigned long size)
 {
 	int error;
-	unsigned long len;
-	char * page = (char *) __get_free_page(GFP_USER);
-	char * cwd = d_path(current->fs->pwd, page, PAGE_SIZE);
+	struct dentry *pwd = current->fs->pwd; 
 
-	error = -ERANGE;
-	len = PAGE_SIZE + page - cwd;
-	if (len <= size) {
-		error = len;
-		if (copy_to_user(buf, cwd, len))
-			error = -EFAULT;
+	error = -ENOENT;
+	/* Has the current directory has been unlinked? */
+	if (pwd->d_parent != pwd && list_empty(&pwd->d_hash)) {
+		char *page = (char *) __get_free_page(GFP_USER);
+		error = -ENOMEM;
+		if (page) {
+			unsigned long len;
+			char * cwd = d_path(pwd, page, PAGE_SIZE);
+
+			error = -ERANGE;
+			len = PAGE_SIZE + page - cwd;
+			if (len <= size) {
+				error = len;
+				if (copy_to_user(buf, cwd, len))
+					error = -EFAULT;
+			}
+			free_page((unsigned long) page);
+		}
 	}
 	return error;
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov