Import 2.3.25pre1
[davej-history.git] / include / linux / file.h
blob1a11904b64e055f85add6281927f16ca9000914a
1 /*
2 * Wrapper functions for accessing the file_struct fd array.
3 */
5 #ifndef __LINUX_FILE_H
6 #define __LINUX_FILE_H
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];
20 return file;
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)
32 file = files->fd[fd];
33 return file;
36 extern inline struct file * frip(unsigned int fd)
38 struct file * file = NULL;
40 if (fd < current->files->max_fds)
41 file = xchg(&current->files->fd[fd], NULL);
42 return file;
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);
51 file = fcheck(fd);
52 if (file)
53 get_file(file);
54 read_unlock(&files->file_lock);
55 return file;
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:
66 * 3756 (i386 arch)
68 * precious bytes from my kernel, even without counting all the code compiled
69 * as module!
71 * I suspect there are many other similar "optimizations" across the
72 * kernel...
74 extern inline void fput(struct file * file)
76 if (atomic_dec_and_test(&file->f_count))
77 _fput(file);
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;
94 struct file * result;
96 write_lock(&files->file_lock);
97 result = xchg(&files->fd[fd], file);
98 write_unlock(&files->file_lock);
99 if (result)
100 fput(result);
103 #endif /* __LINUX_FILE_H */