Import 2.1.118
[davej-history.git] / include / linux / file.h
blob0884fad2ffe2b7762e629fe9d70598285a6b555d
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 *);
9 extern void insert_file_free(struct file *file);
12 * Check whether the specified task has the fd open. Since the task
13 * may not have a files_struct, we must test for p->files != NULL.
15 extern inline struct file * fcheck_task(struct task_struct *p, unsigned int fd)
17 struct file * file = NULL;
19 if (p->files && fd < p->files->max_fds)
20 file = p->files->fd[fd];
21 return file;
25 * Check whether the specified fd has an open file.
27 extern inline struct file * fcheck(unsigned int fd)
29 struct file * file = NULL;
31 if (fd < current->files->max_fds)
32 file = current->files->fd[fd];
33 return file;
36 extern inline struct file * fget(unsigned int fd)
38 struct file * file = fcheck(fd);
40 if (file)
41 file->f_count++;
42 return file;
46 * Install a file pointer in the fd array.
48 extern inline void fd_install(unsigned int fd, struct file *file)
50 current->files->fd[fd] = file;
53 /* It does not matter which list it is on. */
54 extern inline void remove_filp(struct file *file)
56 if(file->f_next)
57 file->f_next->f_pprev = file->f_pprev;
58 *file->f_pprev = file->f_next;
61 extern inline void fput(struct file *file)
63 int count = file->f_count-1;
65 if (!count) {
66 locks_remove_flock(file);
67 __fput(file);
68 file->f_count = 0;
69 remove_filp(file);
70 insert_file_free(file);
71 } else
72 file->f_count = count;
75 extern inline void put_filp(struct file *file)
77 if(--file->f_count == 0) {
78 remove_filp(file);
79 insert_file_free(file);
83 #endif