summaryrefslogtreecommitdiffstats
path: root/fs/open.c
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>1998-03-18 17:17:51 +0000
committerRalf Baechle <ralf@linux-mips.org>1998-03-18 17:17:51 +0000
commitf1382dc4850bb459d24a81c6cb0ef93ea7bd4a79 (patch)
tree225271a3d5dcd4e9dea5ee393556abd754c964b1 /fs/open.c
parent135b00fc2e90e605ac2a96b20b0ebd93851a3f89 (diff)
o Merge with Linux 2.1.90.
o Divide L1 cache sizes by 1024 before printing, makes the numbers a bit more credible ...
Diffstat (limited to 'fs/open.c')
-rw-r--r--fs/open.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/fs/open.c b/fs/open.c
index 5b0ff9924..204294cc3 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -681,24 +681,37 @@ out:
}
/*
- * Find an empty file descriptor entry, and mark it busy
+ * Find an empty file descriptor entry, and mark it busy.
*/
int get_unused_fd(void)
{
- int fd;
struct files_struct * files = current->files;
+ int fd, error;
+ error = -EMFILE;
fd = find_first_zero_bit(&files->open_fds, NR_OPEN);
/*
* N.B. For clone tasks sharing a files structure, this test
* will limit the total number of files that can be opened.
*/
- if (fd < current->rlim[RLIMIT_NOFILE].rlim_cur) {
- FD_SET(fd, &files->open_fds);
- FD_CLR(fd, &files->close_on_exec);
- return fd;
+ if (fd >= current->rlim[RLIMIT_NOFILE].rlim_cur)
+ goto out;
+
+ /* Check here for fd > files->max_fds to do dynamic expansion */
+
+ FD_SET(fd, &files->open_fds);
+ FD_CLR(fd, &files->close_on_exec);
+#if 1
+ /* Sanity check */
+ if (files->fd[fd] != NULL) {
+ printk("get_unused_fd: slot %d not NULL!\n", fd);
+ files->fd[fd] = NULL;
}
- return -EMFILE;
+#endif
+ error = fd;
+
+out:
+ return error;
}
inline void put_unused_fd(unsigned int fd)
@@ -796,15 +809,15 @@ asmlinkage int sys_close(unsigned int fd)
{
int error;
struct file * filp;
- struct files_struct * files;
lock_kernel();
- files = current->files;
error = -EBADF;
- if (fd < NR_OPEN && (filp = files->fd[fd]) != NULL) {
+ filp = fcheck(fd);
+ if (filp) {
+ struct files_struct * files = current->files;
+ files->fd[fd] = NULL;
put_unused_fd(fd);
FD_CLR(fd, &files->close_on_exec);
- files->fd[fd] = NULL;
error = close_fp(filp, files);
}
unlock_kernel();