From d416bd00baf9ca9b619deb83ca905a2a4bee75e0 Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <hch@cloudius-systems.com>
Date: Fri, 22 Mar 2013 09:37:45 +0100
Subject: [PATCH] remove opendir/closedir leftovers

---
 fs/vfs/main.c         | 48 -------------------------------------------
 fs/vfs/vfs.h          |  2 --
 fs/vfs/vfs_syscalls.c | 48 ++-----------------------------------------
 3 files changed, 2 insertions(+), 96 deletions(-)

diff --git a/fs/vfs/main.c b/fs/vfs/main.c
index e2d69c1d1..3f7de55c9 100755
--- a/fs/vfs/main.c
+++ b/fs/vfs/main.c
@@ -354,51 +354,6 @@ int fstat(int fd, struct stat *st)
 }
 LFS64(fstat);
 
-#if 0
-static int
-fs_opendir(struct task *t, struct open_msg *msg)
-{
-	struct task *t = main_task;
-	char path[PATH_MAX];
-	file_t fp;
-	int fd, error;
-
-	/* Find empty slot for file descriptor. */
-	if ((fd = task_newfd(t)) == -1)
-		return EMFILE;
-
-	/* Get the mounted file system and node */
-	if ((error = task_conv(t, msg->path, VREAD, path)) != 0)
-		return error;
-
-	if ((error = sys_opendir(path, &fp)) != 0)
-		return error;
-	t->t_ofile[fd] = fp;
-	msg->fd = fd;
-	return 0;
-}
-
-static int
-fs_closedir(struct task *t, struct msg *msg)
-{
-	struct task *t = main_task;
-	file_t fp;
-	int fd, error;
-
-	fd = msg->data[0];
-	if (fd >= OPEN_MAX)
-		return EBADF;
-	fp = t->t_ofile[fd];
-	if (fp == NULL)
-		return EBADF;
-
-	if ((error = sys_closedir(fp)) != 0)
-		return error;
-	t->t_ofile[fd] = NULL;
-	return 0;
-}
-#endif
-
 int
 ll_readdir(int fd, struct dirent *d)
 {
@@ -544,12 +499,10 @@ int chdir(const char *pathname)
 		goto out_errno;
 
 	/* Check if directory exits */
-//	if ((error = sys_opendir(path, &fp)) != 0)
 	if ((error = sys_open(path, O_RDONLY, 0, &fp)) != 0)
 		goto out_errno;
 
 	if (t->t_cwdfp)
-//		sys_closedir(t->t_cwdfp);
 		sys_close(t->t_cwdfp);
 	t->t_cwdfp = fp;
 	strlcpy(t->t_cwd, path, sizeof(t->t_cwd));
@@ -570,7 +523,6 @@ int fchdir(int fd)
 		goto out_errno;
 
 	if (t->t_cwdfp)
-//		sys_closedir(t->t_cwdfp);
 		sys_close(t->t_cwdfp);
 	t->t_cwdfp = fp;
 	error = sys_fchdir(fp, t->t_cwd);
diff --git a/fs/vfs/vfs.h b/fs/vfs/vfs.h
index 691ddf994..a04cdec3e 100755
--- a/fs/vfs/vfs.h
+++ b/fs/vfs/vfs.h
@@ -95,8 +95,6 @@ int	 sys_fstatfs(struct file *fp, struct statfs *buf);
 int	 sys_fsync(file_t fp);
 int	 sys_ftruncate(file_t fp, off_t length);
 
-int	 sys_opendir(char *path, file_t * file);
-int	 sys_closedir(file_t fp);
 int	 sys_readdir(file_t fp, struct dirent *dirent);
 int	 sys_rewinddir(file_t fp);
 int	 sys_seekdir(file_t fp, long loc);
diff --git a/fs/vfs/vfs_syscalls.c b/fs/vfs/vfs_syscalls.c
index c8a0d4f3e..50c1731dc 100755
--- a/fs/vfs/vfs_syscalls.c
+++ b/fs/vfs/vfs_syscalls.c
@@ -363,7 +363,7 @@ check_dir_empty(char *path)
 
 	DPRINTF(VFSDB_SYSCALL, ("check_dir_empty\n"));
 
-	if ((error = sys_opendir(path, &fp)) != 0)
+	if ((error = sys_open(path, O_RDONLY, 0, &fp)) != 0)
 		return error;
 	do {
 		error = sys_readdir(fp, &dir);
@@ -371,7 +371,7 @@ check_dir_empty(char *path)
 			break;
 	} while (!strcmp(dir.d_name, ".") || !strcmp(dir.d_name, ".."));
 
-	sys_closedir(fp);
+	sys_close(fp);
 
 	if (error == ENOENT)
 		return 0;
@@ -380,50 +380,6 @@ check_dir_empty(char *path)
 	return error;
 }
 
-int
-sys_opendir(char *path, file_t *file)
-{
-	vnode_t dvp;
-	file_t fp;
-	int error;
-
-	DPRINTF(VFSDB_SYSCALL, ("sys_opendir: path=%s\n", path));
-
-	if ((error = sys_open(path, O_RDONLY, 0, &fp)) != 0)
-		return error;
-
-	dvp = fp->f_vnode;
-	vn_lock(dvp);
-	if (dvp->v_type != VDIR) {
-		vn_unlock(dvp);
-		sys_close(fp);
-		return ENOTDIR;
-	}
-	vn_unlock(dvp);
-
-	*file = fp;
-	return 0;
-}
-
-int
-sys_closedir(file_t fp)
-{
-	vnode_t dvp;
-	int error;
-
-	DPRINTF(VFSDB_SYSCALL, ("sys_closedir: fp=%x\n", fp));
-
-	dvp = fp->f_vnode;
-	vn_lock(dvp);
-	if (dvp->v_type != VDIR) {
-		vn_unlock(dvp);
-		return EBADF;
-	}
-	vn_unlock(dvp);
-	error = sys_close(fp);
-	return error;
-}
-
 int
 sys_readdir(file_t fp, struct dirent *dir)
 {
-- 
GitLab