diff options
author | David Howells <dhowells@redhat.com> | 2012-02-16 12:49:42 -0500 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2012-02-19 13:30:52 -0500 |
commit | 1dce27c5aa6770e9d195f2bb7db1db3d4dde5591 (patch) | |
tree | 4ad3ffeee95cb5b10e047b7cb9bdbb48cfc734e0 /fs/fcntl.c | |
parent | 8b3d1cda4f5ff0d7c2ae910ea8fd03493996912f (diff) |
Wrap accesses to the fd_sets in struct fdtable
Wrap accesses to the fd_sets in struct fdtable (for recording open files and
close-on-exec flags) so that we can move away from using fd_sets since we
abuse the fd_set structs by not allocating the full-sized structure under
normal circumstances and by non-core code looking at the internals of the
fd_sets.
The first abuse means that use of FD_ZERO() on these fd_sets is not permitted,
since that cannot be told about their abnormal lengths.
This introduces six wrapper functions for setting, clearing and testing
close-on-exec flags and fd-is-open flags:
void __set_close_on_exec(int fd, struct fdtable *fdt);
void __clear_close_on_exec(int fd, struct fdtable *fdt);
bool close_on_exec(int fd, const struct fdtable *fdt);
void __set_open_fd(int fd, struct fdtable *fdt);
void __clear_open_fd(int fd, struct fdtable *fdt);
bool fd_is_open(int fd, const struct fdtable *fdt);
Note that I've prepended '__' to the names of the set/clear functions because
they require the caller to hold a lock to use them.
Note also that I haven't added wrappers for looking behind the scenes at the
the array. Possibly that should exist too.
Signed-off-by: David Howells <dhowells@redhat.com>
Link: http://lkml.kernel.org/r/20120216174942.23314.1364.stgit@warthog.procyon.org.uk
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/fcntl.c')
-rw-r--r-- | fs/fcntl.c | 18 |
1 files changed, 9 insertions, 9 deletions
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 | ||
41 | static int get_close_on_exec(unsigned int fd) | 41 | static 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) |