patch-2.1.90 linux/fs/open.c
Next file: linux/fs/proc/array.c
Previous file: linux/fs/ntfs/fs.c
Back to the patch index
Back to the overall index
- Lines: 65
- Date:
Tue Mar 10 13:28:05 1998
- Orig file:
v2.1.89/linux/fs/open.c
- Orig date:
Tue Mar 10 10:03:34 1998
diff -u --recursive --new-file v2.1.89/linux/fs/open.c linux/fs/open.c
@@ -681,24 +681,37 @@
}
/*
- * 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 @@
{
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();
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov