2 * Wrapper functions for accessing the file_struct fd array.
8 extern void FASTCALL(fput(struct file
*));
9 extern struct file
* FASTCALL(fget(unsigned int fd
));
11 static inline int get_close_on_exec(unsigned int fd
)
13 struct files_struct
*files
= current
->files
;
15 read_lock(&files
->file_lock
);
16 res
= FD_ISSET(fd
, files
->close_on_exec
);
17 read_unlock(&files
->file_lock
);
21 static inline void set_close_on_exec(unsigned int fd
, int flag
)
23 struct files_struct
*files
= current
->files
;
24 write_lock(&files
->file_lock
);
26 FD_SET(fd
, files
->close_on_exec
);
28 FD_CLR(fd
, files
->close_on_exec
);
29 write_unlock(&files
->file_lock
);
32 static inline struct file
* fcheck_files(struct files_struct
*files
, unsigned int fd
)
34 struct file
* file
= NULL
;
36 if (fd
< files
->max_fds
)
42 * Check whether the specified fd has an open file.
44 static inline struct file
* fcheck(unsigned int fd
)
46 struct file
* file
= NULL
;
47 struct files_struct
*files
= current
->files
;
49 if (fd
< files
->max_fds
)
54 extern void put_filp(struct file
*);
56 extern int get_unused_fd(void);
58 static inline void __put_unused_fd(struct files_struct
*files
, unsigned int fd
)
60 FD_CLR(fd
, files
->open_fds
);
61 if (fd
< files
->next_fd
)
65 static inline void put_unused_fd(unsigned int fd
)
67 struct files_struct
*files
= current
->files
;
69 write_lock(&files
->file_lock
);
70 __put_unused_fd(files
, fd
);
71 write_unlock(&files
->file_lock
);
75 * Install a file pointer in the fd array.
77 * The VFS is full of places where we drop the files lock between
78 * setting the open_fds bitmap and installing the file in the file
79 * array. At any such point, we are vulnerable to a dup2() race
80 * installing a file in the array before us. We need to detect this and
81 * fput() the struct file we are about to overwrite in this case.
83 * It should never happen - if we allow dup2() do it, _really_ bad things
87 static inline void fd_install(unsigned int fd
, struct file
* file
)
89 struct files_struct
*files
= current
->files
;
91 write_lock(&files
->file_lock
);
95 write_unlock(&files
->file_lock
);
98 void put_files_struct(struct files_struct
*fs
);
100 #endif /* __LINUX_FILE_H */