This source file includes following definitions.
- insert_file_free
- remove_file_free
- put_last_free
- grow_files
- file_table_init
- get_empty_filp
- add_dquot_ref
- reset_dquot_ptrs
1
2
3
4
5
6
7 #include <linux/config.h>
8 #include <linux/fs.h>
9 #include <linux/string.h>
10 #include <linux/mm.h>
11
12
13
14
15
16
17 struct file * first_file = NULL;
18 int nr_files = 0;
19
20
21
22
23 static inline void insert_file_free(struct file *file)
24 {
25 file->f_count = 0;
26 file->f_next = first_file;
27 file->f_prev = first_file->f_prev;
28 file->f_next->f_prev = file;
29 file->f_prev->f_next = file;
30 first_file = file;
31 }
32
33
34
35
36 static inline void remove_file_free(struct file *file)
37 {
38 if (first_file == file)
39 first_file = first_file->f_next;
40 file->f_next->f_prev = file->f_prev;
41 file->f_prev->f_next = file->f_next;
42 file->f_next = file->f_prev = NULL;
43 }
44
45
46
47
48 static inline void put_last_free(struct file *file)
49 {
50 file->f_prev = first_file->f_prev;
51 file->f_prev->f_next = file;
52 file->f_next = first_file;
53 file->f_next->f_prev = file;
54 }
55
56
57
58
59
60
61 static int grow_files(void)
62 {
63 struct file * file;
64 int i;
65
66
67
68
69
70
71
72 file = (struct file *) __get_free_page(GFP_KERNEL);
73
74 if (!file)
75 return 0;
76
77 nr_files += i = PAGE_SIZE/sizeof(struct file);
78
79 if (!first_file)
80 file->f_count = 0,
81 file->f_next = file->f_prev = first_file = file++,
82 i--;
83
84 for (; i ; i--)
85 insert_file_free(file++);
86
87 return 1;
88 }
89
90 unsigned long file_table_init(unsigned long start, unsigned long end)
91 {
92 return start;
93 }
94
95
96
97
98
99
100 struct file * get_empty_filp(void)
101 {
102 int i;
103 struct file * f;
104
105
106 if (!first_file && !grow_files())
107 return NULL;
108
109 do {
110 for (f = first_file, i=0; i < nr_files; i++, f = f->f_next)
111 if (!f->f_count) {
112 remove_file_free(f);
113 memset(f,0,sizeof(*f));
114 put_last_free(f);
115 f->f_count = 1;
116 f->f_version = ++event;
117 return f;
118 }
119 } while (nr_files < NR_FILE && grow_files());
120
121 return NULL;
122 }
123
124 #ifdef CONFIG_QUOTA
125
126 void add_dquot_ref(dev_t dev, short type)
127 {
128 struct file *filp;
129 int cnt;
130
131 for (filp = first_file, cnt = 0; cnt < nr_files; cnt++, filp = filp->f_next) {
132 if (!filp->f_count || !filp->f_inode || filp->f_inode->i_dev != dev)
133 continue;
134 if (filp->f_mode & FMODE_WRITE && filp->f_inode->i_sb->dq_op) {
135 filp->f_inode->i_sb->dq_op->initialize(filp->f_inode, type);
136 filp->f_inode->i_flags |= S_WRITE;
137 }
138 }
139 }
140
141 void reset_dquot_ptrs(dev_t dev, short type)
142 {
143 struct file *filp;
144 int cnt;
145
146 for (filp = first_file, cnt = 0; cnt < nr_files; cnt++, filp = filp->f_next) {
147 if (!filp->f_count || !filp->f_inode || filp->f_inode->i_dev != dev)
148 continue;
149 if (IS_WRITABLE(filp->f_inode)) {
150 filp->f_inode->i_dquot[type] = NODQUOT;
151 filp->f_inode->i_flags &= ~S_WRITE;
152 }
153 }
154 }
155
156 #endif