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