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 31 32 33 34 35 36 37 38 39
struct fd {
	struct file *file;
	int need_put;
};

static inline void fdput(struct fd fd)
{
	if (fd.need_put)
		fput(fd.file);
}

40 41
extern struct file *fget(unsigned int fd);
extern struct file *fget_light(unsigned int fd, int *fput_needed);
A
Al Viro 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

static inline struct fd fdget(unsigned int fd)
{
	int b;
	struct file *f = fget_light(fd, &b);
	return (struct fd){f,b};
}

static inline struct fd fdget_raw(unsigned int fd)
{
	int b;
	struct file *f = fget_raw_light(fd, &b);
	return (struct fd){f,b};
}

57 58
extern struct file *fget_raw(unsigned int fd);
extern struct file *fget_raw_light(unsigned int fd, int *fput_needed);
59
extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);
A
Al Viro 已提交
60
extern int replace_fd(unsigned fd, struct file *file, unsigned flags);
61
extern void set_close_on_exec(unsigned int fd, int flag);
62
extern bool get_close_on_exec(unsigned int fd);
L
Linus Torvalds 已提交
63
extern void put_filp(struct file *);
A
Al Viro 已提交
64 65
extern int get_unused_fd_flags(unsigned flags);
#define get_unused_fd() get_unused_fd_flags(0)
66
extern void put_unused_fd(unsigned int fd);
L
Linus Torvalds 已提交
67

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

A
Al Viro 已提交
70 71 72
extern void flush_delayed_fput(void);
extern void __fput_sync(struct file *);

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