[PATCH] make osf_select() use core_sys_select()
[deliverable/linux.git] / include / linux / file.h
CommitLineData
1da177e4
LT
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#include <asm/atomic.h>
9#include <linux/posix_types.h>
10#include <linux/compiler.h>
11#include <linux/spinlock.h>
ab2af1f5 12#include <linux/rcupdate.h>
0c9e63fd 13#include <linux/types.h>
1da177e4
LT
14
15/*
16 * The default fd array needs to be at least BITS_PER_LONG,
17 * as this is the granularity returned by copy_fdset().
18 */
19#define NR_OPEN_DEFAULT BITS_PER_LONG
20
0c9e63fd
ED
21/*
22 * The embedded_fd_set is a small fd_set,
23 * suitable for most tasks (which open <= BITS_PER_LONG files)
24 */
25struct embedded_fd_set {
26 unsigned long fds_bits[1];
27};
28
badf1662
DS
29struct fdtable {
30 unsigned int max_fds;
badf1662
DS
31 struct file ** fd; /* current fd array */
32 fd_set *close_on_exec;
33 fd_set *open_fds;
ab2af1f5 34 struct rcu_head rcu;
ab2af1f5 35 struct fdtable *next;
badf1662
DS
36};
37
1da177e4
LT
38/*
39 * Open file table structure
40 */
41struct files_struct {
0c9e63fd
ED
42 /*
43 * read mostly part
44 */
95e861db 45 atomic_t count;
ab2af1f5 46 struct fdtable *fdt;
badf1662 47 struct fdtable fdtab;
0c9e63fd
ED
48 /*
49 * written part on a separate cache line in SMP
50 */
51 spinlock_t file_lock ____cacheline_aligned_in_smp;
52 int next_fd;
53 struct embedded_fd_set close_on_exec_init;
54 struct embedded_fd_set open_fds_init;
95e861db 55 struct file * fd_array[NR_OPEN_DEFAULT];
1da177e4
LT
56};
57
ab2af1f5 58#define files_fdtable(files) (rcu_dereference((files)->fdt))
badf1662 59
8b7d91eb
CL
60extern struct kmem_cache *filp_cachep;
61
b3c97528
HH
62extern void __fput(struct file *);
63extern void fput(struct file *);
aceaf78d 64extern void drop_file_write_access(struct file *file);
1da177e4 65
ce8d2cdf
DH
66struct file_operations;
67struct vfsmount;
68struct dentry;
69extern int init_file(struct file *, struct vfsmount *mnt,
70 struct dentry *dentry, mode_t mode,
71 const struct file_operations *fop);
72extern struct file *alloc_file(struct vfsmount *, struct dentry *dentry,
73 mode_t mode, const struct file_operations *fop);
74
1da177e4
LT
75static inline void fput_light(struct file *file, int fput_needed)
76{
77 if (unlikely(fput_needed))
78 fput(file);
79}
80
b3c97528
HH
81extern struct file *fget(unsigned int fd);
82extern struct file *fget_light(unsigned int fd, int *fput_needed);
83extern void set_close_on_exec(unsigned int fd, int flag);
1da177e4
LT
84extern void put_filp(struct file *);
85extern int get_unused_fd(void);
4a19542e 86extern int get_unused_fd_flags(int flags);
b3c97528 87extern void put_unused_fd(unsigned int fd);
2109a2d1 88struct kmem_cache;
1da177e4 89
1da177e4 90extern int expand_files(struct files_struct *, int nr);
4fd45812 91extern void free_fdtable_rcu(struct rcu_head *rcu);
ab2af1f5 92extern void __init files_defer_init(void);
1da177e4 93
01b2d93c
VL
94static inline void free_fdtable(struct fdtable *fdt)
95{
96 call_rcu(&fdt->rcu, free_fdtable_rcu);
97}
98
1da177e4
LT
99static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd)
100{
101 struct file * file = NULL;
badf1662 102 struct fdtable *fdt = files_fdtable(files);
1da177e4 103
badf1662 104 if (fd < fdt->max_fds)
ab2af1f5 105 file = rcu_dereference(fdt->fd[fd]);
1da177e4
LT
106 return file;
107}
108
109/*
110 * Check whether the specified fd has an open file.
111 */
112#define fcheck(fd) fcheck_files(current->files, fd)
113
b3c97528 114extern void fd_install(unsigned int fd, struct file *file);
1da177e4
LT
115
116struct task_struct;
117
118struct files_struct *get_files_struct(struct task_struct *);
b3c97528 119void put_files_struct(struct files_struct *fs);
3b125388
AV
120void reset_files_struct(struct files_struct *);
121int unshare_files(struct files_struct **);
1da177e4 122
5d6538fc
CL
123extern struct kmem_cache *files_cachep;
124
1da177e4 125#endif /* __LINUX_FILE_H */
This page took 0.565224 seconds and 5 git commands to generate.