file.h 1.7 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8
/*
 * Wrapper functions for accessing the file_struct fd array.
 */

#ifndef __LINUX_FILE_H
#define __LINUX_FILE_H

#include <linux/compiler.h>
9
#include <linux/types.h>
A
Al Viro 已提交
10
#include <linux/posix_types.h>
L
Linus Torvalds 已提交
11

A
Al Viro 已提交
12
struct file;
13

14
extern void fput(struct file *);
L
Linus Torvalds 已提交
15

16 17 18
struct file_operations;
struct vfsmount;
struct dentry;
19 20 21
struct path;
extern struct file *alloc_file(struct path *, fmode_t mode,
	const struct file_operations *fop);
22

L
Linus Torvalds 已提交
23 24
static inline void fput_light(struct file *file, int fput_needed)
{
25
	if (fput_needed)
L
Linus Torvalds 已提交
26 27 28
		fput(file);
}

A
Al Viro 已提交
29 30
struct fd {
	struct file *file;
31
	unsigned int flags;
A
Al Viro 已提交
32
};
33 34
#define FDPUT_FPUT       1
#define FDPUT_POS_UNLOCK 2
A
Al Viro 已提交
35 36 37

static inline void fdput(struct fd fd)
{
38
	if (fd.flags & FDPUT_FPUT)
A
Al Viro 已提交
39 40 41
		fput(fd.file);
}

42
extern struct file *fget(unsigned int fd);
A
Al Viro 已提交
43 44 45 46
extern struct file *fget_raw(unsigned int fd);
extern unsigned long __fdget(unsigned int fd);
extern unsigned long __fdget_raw(unsigned int fd);
extern unsigned long __fdget_pos(unsigned int fd);
A
Al Viro 已提交
47

A
Al Viro 已提交
48
static inline struct fd __to_fd(unsigned long v)
A
Al Viro 已提交
49
{
A
Al Viro 已提交
50
	return (struct fd){(struct file *)(v & ~3),v & 3};
A
Al Viro 已提交
51 52
}

A
Al Viro 已提交
53 54 55 56
static inline struct fd fdget(unsigned int fd)
{
	return __to_fd(__fdget(fd));
}
57

A
Al Viro 已提交
58 59
static inline struct fd fdget_raw(unsigned int fd)
{
A
Al Viro 已提交
60
	return __to_fd(__fdget_raw(fd));
A
Al Viro 已提交
61 62
}

63
extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);
A
Al Viro 已提交
64
extern int replace_fd(unsigned fd, struct file *file, unsigned flags);
65
extern void set_close_on_exec(unsigned int fd, int flag);
66
extern bool get_close_on_exec(unsigned int fd);
L
Linus Torvalds 已提交
67
extern void put_filp(struct file *);
A
Al Viro 已提交
68
extern int get_unused_fd_flags(unsigned flags);
69
extern void put_unused_fd(unsigned int fd);
L
Linus Torvalds 已提交
70

71
extern void fd_install(unsigned int fd, struct file *file);
L
Linus Torvalds 已提交
72

A
Al Viro 已提交
73 74 75
extern void flush_delayed_fput(void);
extern void __fput_sync(struct file *);

L
Linus Torvalds 已提交
76
#endif /* __LINUX_FILE_H */