2 * Wrapper functions for accessing the file_struct fd array.
8 extern void _fput(struct file
*);
11 * Check whether the specified task has the fd open. Since the task
12 * may not have a files_struct, we must test for p->files != NULL.
14 extern inline struct file
* fcheck_task(struct task_struct
*p
, unsigned int fd
)
16 struct file
* file
= NULL
;
18 if (fd
< p
->files
->max_fds
)
19 file
= p
->files
->fd
[fd
];
24 * Check whether the specified fd has an open file.
26 extern inline struct file
* fcheck(unsigned int fd
)
28 struct file
* file
= NULL
;
29 struct files_struct
*files
= current
->files
;
31 if (fd
< files
->max_fds
)
36 extern inline struct file
* frip(unsigned int fd
)
38 struct file
* file
= NULL
;
40 if (fd
< current
->files
->max_fds
)
41 file
= xchg(¤t
->files
->fd
[fd
], NULL
);
45 extern inline struct file
* fget(unsigned int fd
)
47 struct file
* file
= NULL
;
48 struct files_struct
*files
= current
->files
;
50 read_lock(&files
->file_lock
);
54 read_unlock(&files
->file_lock
);
59 * 23/12/1998 Marcin Dalecki <dalecki@cs.net.pl>:
61 * Since those functions where calling other functions, it was compleatly
62 * bogous to make them all "extern inline".
64 * The removal of this pseudo optimization saved me scandaleous:
68 * precious bytes from my kernel, even without counting all the code compiled
71 * I suspect there are many other similar "optimizations" across the
74 extern inline void fput(struct file
* file
)
76 if (atomic_dec_and_test(&file
->f_count
))
79 extern void put_filp(struct file
*);
82 * Install a file pointer in the fd array.
84 * The VFS is full of places where we drop the files lock between
85 * setting the open_fds bitmap and installing the file in the file
86 * array. At any such point, we are vulnerable to a dup2() race
87 * installing a file in the array before us. We need to detect this and
88 * fput() the struct file we are about to overwrite in this case.
91 extern inline void fd_install(unsigned int fd
, struct file
* file
)
93 struct files_struct
*files
= current
->files
;
96 write_lock(&files
->file_lock
);
97 result
= xchg(&files
->fd
[fd
], file
);
98 write_unlock(&files
->file_lock
);
103 #endif /* __LINUX_FILE_H */