Minor patches to sys_getcwd and fs/proc/inode.c

Jeremy Fitzhardinge (jeremy@zip.com.au)
Fri, 03 Apr 1998 12:36:35 +1000


This is a multi-part message in MIME format.
--------------B219A34C75DC45E3BFAB1947
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Two changes to sys_getcwd:
- a memory leak plugged
- it returns ENOENT if . has been unlinked, since there's no way for
the caller to distinguish between an unlinked "." and a directory named
"foo (deleted)". You can always readlink /proc/self/cwd if you want the
pretty version.

It might also be an idea to change its name. Well, the only user should
be the getcwd library function, but its very hard to use
__syscall2(getcwd, ...) with the standard getcwd() prototype in scope.

fs/proc/inode.c:

I've noticed that sometimes processes can have null fs pointers. I'm
not quite sure how that can happen, but I've seen it on shutdown. The
fs/proc/inode.c patch is a quick workaround.

J
--------------B219A34C75DC45E3BFAB1947
Content-Type: text/plain; charset=us-ascii; name="dcache.c.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="dcache.c.diff"

--- ../2.1/fs/dcache.c Thu Apr 2 12:12:37 1998
+++ fs/dcache.c Fri Apr 3 11:55:57 1998
@@ -781,8 +781,15 @@
{
int error;
unsigned long len;
- char * page = (char *) __get_free_page(GFP_USER);
- char * cwd = d_path(current->fs->pwd, page, PAGE_SIZE);
+ char * page;
+ struct dentry *pwd = current->fs->pwd;
+ char * cwd;
+
+ if (pwd->d_parent != pwd && list_empty(&pwd->d_hash))
+ return -ENOENT;
+
+ page = (char *) __get_free_page(GFP_USER);
+ cwd = d_path(pwd, page, PAGE_SIZE);

error = -ERANGE;
len = PAGE_SIZE + page - cwd;
@@ -791,6 +798,9 @@
if (copy_to_user(buf, cwd, len))
error = -EFAULT;
}
+
+ free_page(page);
+
return error;
}

--------------B219A34C75DC45E3BFAB1947
Content-Type: text/plain; charset=us-ascii; name="proc_inode.c.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="proc_inode.c.diff"

--- ../2.1/fs/proc/inode.c Thu Apr 2 12:12:37 1998
+++ fs/proc/inode.c Fri Apr 3 12:21:46 1998
@@ -198,7 +198,7 @@
read_lock(&tasklist_lock);
p = find_task_by_pid(pid);

- if (p != NULL)
+ if (p != NULL && p->fs != NULL)
de = p->fs->root;
read_unlock(&tasklist_lock);

--------------B219A34C75DC45E3BFAB1947--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu