summaryrefslogtreecommitdiffstats
path: root/include/linux/file.h
blob: b8cc01f0a05eea43b671370909e6b2d951b83a7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef __LINUX_FILE_H
#define __LINUX_FILE_H

extern inline struct file * fget(unsigned long fd)
{
	struct file * file = NULL;
	if (fd < NR_OPEN) {
		file = current->files->fd[fd];
		if (file)
			file->f_count++;
	}
	return file;
}

extern int __fput(struct file *);
extern void insert_file_free(struct file *file);

/* It does not matter which list it is on. */
extern inline void remove_filp(struct file *file)
{
	if(file->f_next)
		file->f_next->f_pprev = file->f_pprev;
	*file->f_pprev = file->f_next;
}

extern inline int fput(struct file *file)
{
	int count = file->f_count-1;
	int error = 0;

	if (!count) {
		error = __fput(file);
		file->f_count = 0;
		remove_filp(file);
		insert_file_free(file);
	} else
		file->f_count = count;
	return error;
}

extern inline void put_filp(struct file *file)
{
	if(--file->f_count == 0) {
		remove_filp(file);
		insert_file_free(file);
	}
}

#endif