1 /*
2  * Wrapper functions for accessing the file_struct fd array.
3  */
4 
5 #ifndef __LINUX_FILE_H
6 #define __LINUX_FILE_H
7 
8 extern void FASTCALL(fput(struct file *));
9 extern struct file * FASTCALL(fget(unsigned int fd));
10 
get_close_on_exec(unsigned int fd)11 static inline int get_close_on_exec(unsigned int fd)
12 {
13 	struct files_struct *files = current->files;
14 	int res;
15 	read_lock(&files->file_lock);
16 	res = FD_ISSET(fd, files->close_on_exec);
17 	read_unlock(&files->file_lock);
18 	return res;
19 }
20 
set_close_on_exec(unsigned int fd,int flag)21 static inline void set_close_on_exec(unsigned int fd, int flag)
22 {
23 	struct files_struct *files = current->files;
24 	write_lock(&files->file_lock);
25 	if (flag)
26 		FD_SET(fd, files->close_on_exec);
27 	else
28 		FD_CLR(fd, files->close_on_exec);
29 	write_unlock(&files->file_lock);
30 }
31 
fcheck_files(struct files_struct * files,unsigned int fd)32 static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd)
33 {
34 	struct file * file = NULL;
35 
36 	if (fd < files->max_fds)
37 		file = files->fd[fd];
38 	return file;
39 }
40 
41 /*
42  * Check whether the specified fd has an open file.
43  */
fcheck(unsigned int fd)44 static inline struct file * fcheck(unsigned int fd)
45 {
46 	struct file * file = NULL;
47 	struct files_struct *files = current->files;
48 
49 	if (fd < files->max_fds)
50 		file = files->fd[fd];
51 	return file;
52 }
53 
54 extern void put_filp(struct file *);
55 
56 extern int get_unused_fd(void);
57 
__put_unused_fd(struct files_struct * files,unsigned int fd)58 static inline void __put_unused_fd(struct files_struct *files, unsigned int fd)
59 {
60 	FD_CLR(fd, files->open_fds);
61 	if (fd < files->next_fd)
62 		files->next_fd = fd;
63 }
64 
put_unused_fd(unsigned int fd)65 static inline void put_unused_fd(unsigned int fd)
66 {
67 	struct files_struct *files = current->files;
68 
69 	write_lock(&files->file_lock);
70 	__put_unused_fd(files, fd);
71 	write_unlock(&files->file_lock);
72 }
73 
74 void fd_install(unsigned int fd, struct file * file);
75 void put_files_struct(struct files_struct *fs);
76 
77 #endif /* __LINUX_FILE_H */
78