Wrap accesses to the fd_sets in struct fdtable
authorDavid Howells <dhowells@redhat.com>
Thu, 16 Feb 2012 17:49:42 +0000 (17:49 +0000)
committerGrazvydas Ignotas <notasas@gmail.com>
Wed, 25 Apr 2012 22:24:43 +0000 (01:24 +0300)
commit3168aaa6dea06d0462a1b2629004ca3cdc08657e
tree287204de06823a7f4b3aa1d933cbab62a4e85706
parent232af932114e72f6572997b31bf5583966c27610
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>
Documentation/filesystems/files.txt
arch/powerpc/platforms/cell/spufs/coredump.c
drivers/staging/android/binder.c
fs/autofs4/dev-ioctl.c
fs/exec.c
fs/fcntl.c
fs/file.c
fs/open.c
fs/proc/base.c
include/linux/fdtable.h