Import 2.3.11pre5
[davej-history.git] / include / linux / file.h
blob914fca925890ca85a2439cdff41feb93cb703eb7
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 * Install a file pointer in the fd array.
61 extern inline void fd_install(unsigned int fd, struct file * file)
63 struct files_struct *files = current->files;
65 write_lock(&files->file_lock);
66 files->fd[fd] = file;
67 write_unlock(&files->file_lock);
71 * 23/12/1998 Marcin Dalecki <dalecki@cs.net.pl>:
73 * Since those functions where calling other functions, it was compleatly
74 * bogous to make them all "extern inline".
76 * The removal of this pseudo optimization saved me scandaleous:
78 * 3756 (i386 arch)
80 * precious bytes from my kernel, even without counting all the code compiled
81 * as module!
83 * I suspect there are many other similar "optimizations" across the
84 * kernel...
86 extern inline void fput(struct file * file)
88 if (atomic_dec_and_test(&file->f_count))
89 _fput(file);
91 extern void put_filp(struct file *);
93 #endif /* __LINUX_FILE_H */