aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/fdtable.h
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2012-02-16 12:49:42 -0500
committerH. Peter Anvin <hpa@zytor.com>2012-02-19 13:30:52 -0500
commit1dce27c5aa6770e9d195f2bb7db1db3d4dde5591 (patch)
tree4ad3ffeee95cb5b10e047b7cb9bdbb48cfc734e0 /include/linux/fdtable.h
parent8b3d1cda4f5ff0d7c2ae910ea8fd03493996912f (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 'include/linux/fdtable.h')
-rw-r--r--include/linux/fdtable.h30
1 files changed, 30 insertions, 0 deletions
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 */