aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/filesystems/files.txt4
-rw-r--r--arch/powerpc/platforms/cell/spufs/coredump.c2
-rw-r--r--drivers/staging/android/binder.c10
-rw-r--r--fs/autofs4/dev-ioctl.c2
-rw-r--r--fs/exec.c4
-rw-r--r--fs/fcntl.c18
-rw-r--r--fs/file.c8
-rw-r--r--fs/open.c4
-rw-r--r--fs/proc/base.c2
-rw-r--r--include/linux/fdtable.h30
10 files changed, 57 insertions, 27 deletions
diff --git a/Documentation/filesystems/files.txt b/Documentation/filesystems/files.txt
index ac2facc50d2a..46dfc6b038c3 100644
--- a/Documentation/filesystems/files.txt
+++ b/Documentation/filesystems/files.txt
@@ -113,8 +113,8 @@ the fdtable structure -
113 if (fd >= 0) { 113 if (fd >= 0) {
114 /* locate_fd() may have expanded fdtable, load the ptr */ 114 /* locate_fd() may have expanded fdtable, load the ptr */
115 fdt = files_fdtable(files); 115 fdt = files_fdtable(files);
116 FD_SET(fd, fdt->open_fds); 116 __set_open_fd(fd, fdt);
117 FD_CLR(fd, fdt->close_on_exec); 117 __clear_close_on_exec(fd, fdt);
118 spin_unlock(&files->file_lock); 118 spin_unlock(&files->file_lock);
119 ..... 119 .....
120 120
diff --git a/arch/powerpc/platforms/cell/spufs/coredump.c b/arch/powerpc/platforms/cell/spufs/coredump.c
index 03c5fce2a5b3..c2c5b078ba80 100644
--- a/arch/powerpc/platforms/cell/spufs/coredump.c
+++ b/arch/powerpc/platforms/cell/spufs/coredump.c
@@ -122,7 +122,7 @@ static struct spu_context *coredump_next_context(int *fd)
122 struct spu_context *ctx = NULL; 122 struct spu_context *ctx = NULL;
123 123
124 for (; *fd < fdt->max_fds; (*fd)++) { 124 for (; *fd < fdt->max_fds; (*fd)++) {
125 if (!FD_ISSET(*fd, fdt->open_fds)) 125 if (!fd_is_open(*fd, fdt))
126 continue; 126 continue;
127 127
128 file = fcheck(*fd); 128 file = fcheck(*fd);
diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c
index 7491801a661c..35dd9c370e55 100644
--- a/drivers/staging/android/binder.c
+++ b/drivers/staging/android/binder.c
@@ -408,11 +408,11 @@ repeat:
408 goto repeat; 408 goto repeat;
409 } 409 }
410 410
411 FD_SET(fd, fdt->open_fds); 411 __set_open_fd(fd, fdt);
412 if (flags & O_CLOEXEC) 412 if (flags & O_CLOEXEC)
413 FD_SET(fd, fdt->close_on_exec); 413 __set_close_on_exec(fd, fdt);
414 else 414 else
415 FD_CLR(fd, fdt->close_on_exec); 415 __clear_close_on_exec(fd, fdt);
416 files->next_fd = fd + 1; 416 files->next_fd = fd + 1;
417#if 1 417#if 1
418 /* Sanity check */ 418 /* Sanity check */
@@ -453,7 +453,7 @@ static void task_fd_install(
453static void __put_unused_fd(struct files_struct *files, unsigned int fd) 453static void __put_unused_fd(struct files_struct *files, unsigned int fd)
454{ 454{
455 struct fdtable *fdt = files_fdtable(files); 455 struct fdtable *fdt = files_fdtable(files);
456 __FD_CLR(fd, fdt->open_fds); 456 __clear_open_fd(fd, fdt);
457 if (fd < files->next_fd) 457 if (fd < files->next_fd)
458 files->next_fd = fd; 458 files->next_fd = fd;
459} 459}
@@ -479,7 +479,7 @@ static long task_close_fd(struct binder_proc *proc, unsigned int fd)
479 if (!filp) 479 if (!filp)
480 goto out_unlock; 480 goto out_unlock;
481 rcu_assign_pointer(fdt->fd[fd], NULL); 481 rcu_assign_pointer(fdt->fd[fd], NULL);
482 FD_CLR(fd, fdt->close_on_exec); 482 __clear_close_on_exec(fd, fdt);
483 __put_unused_fd(files, fd); 483 __put_unused_fd(files, fd);
484 spin_unlock(&files->file_lock); 484 spin_unlock(&files->file_lock);
485 retval = filp_close(filp, files); 485 retval = filp_close(filp, files);
diff --git a/fs/autofs4/dev-ioctl.c b/fs/autofs4/dev-ioctl.c
index 76741d8d7786..3dfd615afb6b 100644
--- a/fs/autofs4/dev-ioctl.c
+++ b/fs/autofs4/dev-ioctl.c
@@ -230,7 +230,7 @@ static void autofs_dev_ioctl_fd_install(unsigned int fd, struct file *file)
230 fdt = files_fdtable(files); 230 fdt = files_fdtable(files);
231 BUG_ON(fdt->fd[fd] != NULL); 231 BUG_ON(fdt->fd[fd] != NULL);
232 rcu_assign_pointer(fdt->fd[fd], file); 232 rcu_assign_pointer(fdt->fd[fd], file);
233 FD_SET(fd, fdt->close_on_exec); 233 __set_close_on_exec(fd, fdt);
234 spin_unlock(&files->file_lock); 234 spin_unlock(&files->file_lock);
235} 235}
236 236
diff --git a/fs/exec.c b/fs/exec.c
index 92ce83a11e90..22cc38d9e79f 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -2078,8 +2078,8 @@ static int umh_pipe_setup(struct subprocess_info *info, struct cred *new)
2078 fd_install(0, rp); 2078 fd_install(0, rp);
2079 spin_lock(&cf->file_lock); 2079 spin_lock(&cf->file_lock);
2080 fdt = files_fdtable(cf); 2080 fdt = files_fdtable(cf);
2081 FD_SET(0, fdt->open_fds); 2081 __set_open_fd(0, fdt);
2082 FD_CLR(0, fdt->close_on_exec); 2082 __clear_close_on_exec(0, fdt);
2083 spin_unlock(&cf->file_lock); 2083 spin_unlock(&cf->file_lock);
2084 2084
2085 /* and disallow core files too */ 2085 /* and disallow core files too */
diff --git a/fs/fcntl.c b/fs/fcntl.c
index 22764c7c8382..75e7c1f3a080 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -32,20 +32,20 @@ void set_close_on_exec(unsigned int fd, int flag)
32 spin_lock(&files->file_lock); 32 spin_lock(&files->file_lock);
33 fdt = files_fdtable(files); 33 fdt = files_fdtable(files);
34 if (flag) 34 if (flag)
35 FD_SET(fd, fdt->close_on_exec); 35 __set_close_on_exec(fd, fdt);
36 else 36 else
37 FD_CLR(fd, fdt->close_on_exec); 37 __clear_close_on_exec(fd, fdt);
38 spin_unlock(&files->file_lock); 38 spin_unlock(&files->file_lock);
39} 39}
40 40
41static int get_close_on_exec(unsigned int fd) 41static bool get_close_on_exec(unsigned int fd)
42{ 42{
43 struct files_struct *files = current->files; 43 struct files_struct *files = current->files;
44 struct fdtable *fdt; 44 struct fdtable *fdt;
45 int res; 45 bool res;
46 rcu_read_lock(); 46 rcu_read_lock();
47 fdt = files_fdtable(files); 47 fdt = files_fdtable(files);
48 res = FD_ISSET(fd, fdt->close_on_exec); 48 res = close_on_exec(fd, fdt);
49 rcu_read_unlock(); 49 rcu_read_unlock();
50 return res; 50 return res;
51} 51}
@@ -90,15 +90,15 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
90 err = -EBUSY; 90 err = -EBUSY;
91 fdt = files_fdtable(files); 91 fdt = files_fdtable(files);
92 tofree = fdt->fd[newfd]; 92 tofree = fdt->fd[newfd];
93 if (!tofree && FD_ISSET(newfd, fdt->open_fds)) 93 if (!tofree && fd_is_open(newfd, fdt))
94 goto out_unlock; 94 goto out_unlock;
95 get_file(file); 95 get_file(file);
96 rcu_assign_pointer(fdt->fd[newfd], file); 96 rcu_assign_pointer(fdt->fd[newfd], file);
97 FD_SET(newfd, fdt->open_fds); 97 __set_open_fd(newfd, fdt);
98 if (flags & O_CLOEXEC) 98 if (flags & O_CLOEXEC)
99 FD_SET(newfd, fdt->close_on_exec); 99 __set_close_on_exec(newfd, fdt);
100 else 100 else
101 FD_CLR(newfd, fdt->close_on_exec); 101 __clear_close_on_exec(newfd, fdt);
102 spin_unlock(&files->file_lock); 102 spin_unlock(&files->file_lock);
103 103
104 if (tofree) 104 if (tofree)
diff --git a/fs/file.c b/fs/file.c
index 4c6992d8f3ba..114fea0a2cec 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -366,7 +366,7 @@ struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)
366 * is partway through open(). So make sure that this 366 * is partway through open(). So make sure that this
367 * fd is available to the new process. 367 * fd is available to the new process.
368 */ 368 */
369 FD_CLR(open_files - i, new_fdt->open_fds); 369 __clear_open_fd(open_files - i, new_fdt);
370 } 370 }
371 rcu_assign_pointer(*new_fds++, f); 371 rcu_assign_pointer(*new_fds++, f);
372 } 372 }
@@ -460,11 +460,11 @@ repeat:
460 if (start <= files->next_fd) 460 if (start <= files->next_fd)
461 files->next_fd = fd + 1; 461 files->next_fd = fd + 1;
462 462
463 FD_SET(fd, fdt->open_fds); 463 __set_open_fd(fd, fdt);
464 if (flags & O_CLOEXEC) 464 if (flags & O_CLOEXEC)
465 FD_SET(fd, fdt->close_on_exec); 465 __set_close_on_exec(fd, fdt);
466 else 466 else
467 FD_CLR(fd, fdt->close_on_exec); 467 __clear_close_on_exec(fd, fdt);
468 error = fd; 468 error = fd;
469#if 1 469#if 1
470 /* Sanity check */ 470 /* Sanity check */
diff --git a/fs/open.c b/fs/open.c
index 77becc041149..5720854156db 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -836,7 +836,7 @@ EXPORT_SYMBOL(dentry_open);
836static void __put_unused_fd(struct files_struct *files, unsigned int fd) 836static void __put_unused_fd(struct files_struct *files, unsigned int fd)
837{ 837{
838 struct fdtable *fdt = files_fdtable(files); 838 struct fdtable *fdt = files_fdtable(files);
839 __FD_CLR(fd, fdt->open_fds); 839 __clear_open_fd(fd, fdt);
840 if (fd < files->next_fd) 840 if (fd < files->next_fd)
841 files->next_fd = fd; 841 files->next_fd = fd;
842} 842}
@@ -1080,7 +1080,7 @@ SYSCALL_DEFINE1(close, unsigned int, fd)
1080 if (!filp) 1080 if (!filp)
1081 goto out_unlock; 1081 goto out_unlock;
1082 rcu_assign_pointer(fdt->fd[fd], NULL); 1082 rcu_assign_pointer(fdt->fd[fd], NULL);
1083 FD_CLR(fd, fdt->close_on_exec); 1083 __clear_close_on_exec(fd, fdt);
1084 __put_unused_fd(files, fd); 1084 __put_unused_fd(files, fd);
1085 spin_unlock(&files->file_lock); 1085 spin_unlock(&files->file_lock);
1086 retval = filp_close(filp, files); 1086 retval = filp_close(filp, files);
diff --git a/fs/proc/base.c b/fs/proc/base.c
index d4548dd49b02..db6ab4b36a0b 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1754,7 +1754,7 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
1754 1754
1755 fdt = files_fdtable(files); 1755 fdt = files_fdtable(files);
1756 f_flags = file->f_flags & ~O_CLOEXEC; 1756 f_flags = file->f_flags & ~O_CLOEXEC;
1757 if (FD_ISSET(fd, fdt->close_on_exec)) 1757 if (close_on_exec(fd, fdt))
1758 f_flags |= O_CLOEXEC; 1758 f_flags |= O_CLOEXEC;
1759 1759
1760 if (path) { 1760 if (path) {
diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
index 82163c4b32c9..7675da2c18f7 100644
--- a/include/linux/fdtable.h
+++ b/include/linux/fdtable.h
@@ -38,6 +38,36 @@ struct fdtable {
38 struct fdtable *next; 38 struct fdtable *next;
39}; 39};
40 40
41static inline void __set_close_on_exec(int fd, struct fdtable *fdt)
42{
43 FD_SET(fd, fdt->close_on_exec);
44}
45
46static inline void __clear_close_on_exec(int fd, struct fdtable *fdt)
47{
48 FD_CLR(fd, fdt->close_on_exec);
49}
50
51static inline bool close_on_exec(int fd, const struct fdtable *fdt)
52{
53 return FD_ISSET(fd, fdt->close_on_exec);
54}
55
56static inline void __set_open_fd(int fd, struct fdtable *fdt)
57{
58 FD_SET(fd, fdt->open_fds);
59}
60
61static inline void __clear_open_fd(int fd, struct fdtable *fdt)
62{
63 FD_CLR(fd, fdt->open_fds);
64}
65
66static inline bool fd_is_open(int fd, const struct fdtable *fdt)
67{
68 return FD_ISSET(fd, fdt->open_fds);
69}
70
41/* 71/*
42 * Open file table structure 72 * Open file table structure
43 */ 73 */