This source file includes following definitions.
- parent_inode_number
- isofs_name_translate
- do_isofs_readdir
- isofs_readdir
1
2
3
4
5
6
7
8
9
10
11 #include <linux/errno.h>
12 #include <linux/fs.h>
13 #include <linux/iso_fs.h>
14 #include <linux/kernel.h>
15 #include <linux/stat.h>
16 #include <linux/string.h>
17 #include <linux/mm.h>
18 #include <linux/malloc.h>
19 #include <linux/sched.h>
20 #include <linux/locks.h>
21
22 #include <asm/segment.h>
23
24 static int isofs_readdir(struct inode *, struct file *, void *, filldir_t);
25
26 static struct file_operations isofs_dir_operations =
27 {
28 NULL,
29 NULL,
30 NULL,
31 isofs_readdir,
32 NULL,
33 NULL,
34 NULL,
35 NULL,
36 NULL
37 };
38
39
40
41
42 struct inode_operations isofs_dir_inode_operations =
43 {
44 &isofs_dir_operations,
45 NULL,
46 isofs_lookup,
47 NULL,
48 NULL,
49 NULL,
50 NULL,
51 NULL,
52 NULL,
53 NULL,
54 NULL,
55 NULL,
56 NULL,
57 NULL,
58 isofs_bmap,
59 NULL,
60 NULL
61 };
62
63 static int parent_inode_number(struct inode * inode, struct iso_directory_record * de)
64 {
65 int inode_number = inode->i_ino;
66
67 if ((inode->i_sb->u.isofs_sb.s_firstdatazone) != inode->i_ino)
68 inode_number = inode->u.isofs_i.i_backlink;
69
70 if (inode_number != -1)
71 return inode_number;
72
73
74 return isofs_lookup_grandparent(inode, find_rock_ridge_relocation(de, inode));
75 }
76
77 static int isofs_name_translate(char * old, int len, char * new)
78 {
79 int i, c;
80
81 for (i = 0; i < len; i++) {
82 c = old[i];
83 if (!c)
84 break;
85 if (c >= 'A' && c <= 'Z')
86 c |= 0x20;
87
88
89 if (c == '.' && i == len - 3 && old[i + 1] == ';' && old[i + 2] == '1')
90 break;
91
92
93 if (c == ';' && i == len - 2 && old[i + 1] == '1')
94 break;
95
96
97 if (c == ';')
98 c = '.';
99
100 new[i] = c;
101 }
102 return i;
103 }
104
105
106
107
108 static int do_isofs_readdir(struct inode *inode, struct file *filp,
109 void *dirent, filldir_t filldir,
110 char * tmpname, struct iso_directory_record * tmpde)
111 {
112 unsigned long bufsize = ISOFS_BUFFER_SIZE(inode);
113 unsigned char bufbits = ISOFS_BUFFER_BITS(inode);
114 unsigned int block, offset;
115 int inode_number;
116 struct buffer_head *bh;
117 int len, rrflag;
118 int high_sierra = 0;
119 char *name;
120 struct iso_directory_record *de;
121
122 offset = filp->f_pos & (bufsize - 1);
123 block = isofs_bmap(inode, filp->f_pos >> bufbits);
124
125 if (!block)
126 return 0;
127
128 if (!(bh = breada(inode->i_dev, block, bufsize, filp->f_pos, inode->i_size)))
129 return 0;
130
131 while (filp->f_pos < inode->i_size) {
132 int de_len, next_offset;
133 #ifdef DEBUG
134 printk("Block, offset, f_pos: %x %x %x\n",
135 block, offset, filp->f_pos);
136 #endif
137
138 if (offset >= bufsize) {
139 brelse(bh);
140 offset = 0;
141 block = isofs_bmap(inode, (filp->f_pos) >> bufbits);
142 if (!block)
143 return 0;
144 bh = breada(inode->i_dev, block, bufsize, filp->f_pos, inode->i_size);
145 if (!bh)
146 return 0;
147 continue;
148 }
149
150 de = (struct iso_directory_record *) (bh->b_data + offset);
151 inode_number = (block << bufbits) + (offset & (bufsize - 1));
152
153 de_len = *(unsigned char *) de;
154
155
156
157
158
159 if (de_len == 0) {
160 brelse(bh);
161 filp->f_pos = ((filp->f_pos & ~(ISOFS_BLOCK_SIZE - 1))
162 + ISOFS_BLOCK_SIZE);
163 offset = 0;
164 block = isofs_bmap(inode, (filp->f_pos) >> bufbits);
165 if (!block)
166 return 0;
167 bh = breada(inode->i_dev, block, bufsize, filp->f_pos, inode->i_size);
168 if (!bh)
169 return 0;
170 continue;
171 }
172
173
174
175
176 next_offset = offset + de_len;
177 if (next_offset > bufsize) {
178 next_offset &= (bufsize - 1);
179 memcpy(tmpde, de, bufsize - offset);
180 brelse(bh);
181 block = isofs_bmap(inode, (filp->f_pos + de_len) >> bufbits);
182 if (!block)
183 return 0;
184 bh = breada(inode->i_dev, block, bufsize, filp->f_pos+de_len, inode->i_size);
185 if (!bh)
186 return 0;
187 memcpy(bufsize - offset + (char *) tmpde, bh->b_data, next_offset);
188 de = tmpde;
189 }
190 offset = next_offset;
191
192
193 if (de->name_len[0] == 1 && de->name[0] == 0) {
194 if (filldir(dirent, ".", 1, filp->f_pos, inode->i_ino) < 0)
195 break;
196 filp->f_pos += de_len;
197 continue;
198 }
199
200
201 if (de->name_len[0] == 1 && de->name[0] == 1) {
202 inode_number = parent_inode_number(inode, de);
203 if (inode_number == -1)
204 break;
205 if (filldir(dirent, "..", 2, filp->f_pos, inode_number) < 0)
206 break;
207 filp->f_pos += de_len;
208 continue;
209 }
210
211
212
213
214 if (inode->i_sb->u.isofs_sb.s_unhide == 'n') {
215
216 high_sierra = inode->i_sb->u.isofs_sb.s_high_sierra;
217 if (de->flags[-high_sierra] & 5) {
218 filp->f_pos += de_len;
219 continue;
220 }
221 }
222
223
224 len = de->name_len[0];
225 name = de->name;
226 rrflag = get_rock_ridge_filename(de, &name, &len, inode);
227 if (rrflag) {
228
229 if (rrflag == 1) {
230 rrflag = filldir(dirent, name, len, filp->f_pos, inode_number);
231 dcache_add(inode, name, len, inode_number);
232 kfree(name);
233 if (rrflag < 0)
234 break;
235 }
236 filp->f_pos += de_len;
237 continue;
238 }
239
240 if (inode->i_sb->u.isofs_sb.s_mapping == 'n') {
241 len = isofs_name_translate(name, len, tmpname);
242 if (filldir(dirent, tmpname, len, filp->f_pos, inode_number) < 0)
243 break;
244 dcache_add(inode, tmpname, len, inode_number);
245 filp->f_pos += de_len;
246 continue;
247 }
248
249 if (filldir(dirent, name, len, filp->f_pos, inode_number) < 0)
250 break;
251
252 dcache_add(inode, name, len, inode_number);
253 filp->f_pos += de_len;
254 continue;
255 }
256 brelse(bh);
257 return 0;
258 }
259
260
261
262
263
264
265 static int isofs_readdir(struct inode *inode, struct file *filp,
266 void *dirent, filldir_t filldir)
267 {
268 int result;
269 char * tmpname;
270 struct iso_directory_record * tmpde;
271
272 if (!inode || !S_ISDIR(inode->i_mode))
273 return -EBADF;
274
275 tmpname = (char *) __get_free_page(GFP_KERNEL);
276 if (!tmpname)
277 return -ENOMEM;
278 tmpde = (struct iso_directory_record *) (tmpname+256);
279
280 result = do_isofs_readdir(inode, filp, dirent, filldir, tmpname, tmpde);
281
282 free_page((unsigned long) tmpname);
283 return result;
284 }