This source file includes following definitions.
- find_rock_ridge_relocation
- get_rock_ridge_filename
- parse_rock_ridge_inode
- get_rock_ridge_symlink
1
2
3
4
5
6
7
8 #include <linux/config.h>
9 #include <linux/stat.h>
10 #include <linux/sched.h>
11 #include <linux/iso_fs.h>
12 #include <linux/string.h>
13 #include <linux/mm.h>
14 #include <linux/malloc.h>
15
16 #include "rock.h"
17
18
19
20
21
22
23
24
25 #define SIG(A,B) ((A << 8) | B)
26
27
28
29
30 #define CHECK_SP(FAIL) \
31 if(rr->u.SP.magic[0] != 0xbe) FAIL; \
32 if(rr->u.SP.magic[1] != 0xef) FAIL;
33
34
35
36
37
38 #define CONTINUE_DECLS \
39 int cont_extent = 0, cont_offset = 0, cont_size = 0; \
40 void * buffer = 0
41
42 #define CHECK_CE \
43 {cont_extent = isonum_733(rr->u.CE.extent); \
44 cont_offset = isonum_733(rr->u.CE.offset); \
45 cont_size = isonum_733(rr->u.CE.size);}
46
47 #define SETUP_ROCK_RIDGE(DE,CHR,LEN) \
48 {LEN= sizeof(struct iso_directory_record) + DE->name_len[0]; \
49 if(LEN & 1) LEN++; \
50 CHR = ((unsigned char *) DE) + LEN; \
51 LEN = *((unsigned char *) DE) - LEN;}
52
53 #define MAYBE_CONTINUE(LABEL,DEV) \
54 {if (buffer) kfree(buffer); \
55 if (cont_extent){ \
56 int block, offset, offset1; \
57 struct buffer_head * bh; \
58 buffer = kmalloc(cont_size,GFP_KERNEL); \
59 block = cont_extent; \
60 offset = cont_offset; \
61 offset1 = 0; \
62 if(ISOFS_BUFFER_SIZE(DEV) == 1024) { \
63 block <<= 1; \
64 if (offset >= 1024) block++; \
65 offset &= 1023; \
66 if(offset + cont_size >= 1024) { \
67 bh = bread(DEV->i_dev, block++, ISOFS_BUFFER_SIZE(DEV)); \
68 if(!bh) {printk("Unable to read continuation Rock Ridge record\n"); \
69 kfree(buffer); \
70 buffer = NULL; } else { \
71 memcpy(buffer, bh->b_data + offset, 1024 - offset); \
72 brelse(bh); \
73 offset1 = 1024 - offset; \
74 offset = 0;} \
75 } \
76 }; \
77 if(buffer) { \
78 bh = bread(DEV->i_dev, block, ISOFS_BUFFER_SIZE(DEV)); \
79 if(bh){ \
80 memcpy(buffer + offset1, bh->b_data + offset, cont_size - offset1); \
81 brelse(bh); \
82 chr = (unsigned char *) buffer; \
83 len = cont_size; \
84 cont_extent = 0; \
85 cont_size = 0; \
86 cont_offset = 0; \
87 goto LABEL; \
88 }; \
89 } \
90 printk("Unable to read rock-ridge attributes\n"); \
91 }}
92
93
94
95
96 int find_rock_ridge_relocation(struct iso_directory_record * de,
97 struct inode * inode) {
98 int flag;
99 int len;
100 int retval;
101 unsigned char * chr;
102 CONTINUE_DECLS;
103 flag = 0;
104
105
106
107
108 if (de->name[0]==1 && de->name_len[0]==1) flag = 1;
109
110 retval = isonum_733 (de->extent);
111
112 if (!inode->i_sb->u.isofs_sb.s_rock) return retval;
113
114 SETUP_ROCK_RIDGE(de, chr, len);
115 repeat:
116 {
117 int rrflag, sig;
118 struct rock_ridge * rr;
119
120 while (len > 1){
121 rr = (struct rock_ridge *) chr;
122 if (rr->len == 0) goto out;
123 sig = (chr[0] << 8) + chr[1];
124 chr += rr->len;
125 len -= rr->len;
126
127 switch(sig){
128 case SIG('R','R'):
129 rrflag = rr->u.RR.flags[0];
130 if (flag && !(rrflag & RR_PL)) goto out;
131 if (!flag && !(rrflag & RR_CL)) goto out;
132 break;
133 case SIG('S','P'):
134 CHECK_SP(goto out);
135 break;
136 case SIG('C','L'):
137 #ifdef DEBUG
138 printk("RR: CL\n");
139 #endif
140 if (flag == 0) {
141 retval = isonum_733(rr->u.CL.location);
142 goto out;
143 };
144 break;
145 case SIG('P','L'):
146 #ifdef DEBUG
147 printk("RR: PL\n");
148 #endif
149 if (flag != 0) {
150 retval = isonum_733(rr->u.PL.location);
151 goto out;
152 };
153 break;
154 case SIG('C','E'):
155 CHECK_CE;
156 break;
157 default:
158 break;
159 }
160 };
161 };
162 MAYBE_CONTINUE(repeat, inode);
163 return retval;
164 out:
165 if(buffer) kfree(buffer);
166 return retval;
167 }
168
169 int get_rock_ridge_filename(struct iso_directory_record * de,
170 char ** name, int * namlen, struct inode * inode)
171 {
172 int len;
173 unsigned char * chr;
174 CONTINUE_DECLS;
175 char * retname = NULL;
176 int retnamlen = 0, truncate=0;
177
178 if (!inode->i_sb->u.isofs_sb.s_rock) return 0;
179
180 SETUP_ROCK_RIDGE(de, chr, len);
181 repeat:
182 {
183 struct rock_ridge * rr;
184 int sig;
185
186 while (len > 1){
187 rr = (struct rock_ridge *) chr;
188 if (rr->len == 0) goto out;
189 sig = (chr[0] << 8) + chr[1];
190 chr += rr->len;
191 len -= rr->len;
192
193 switch(sig){
194 case SIG('R','R'):
195 if((rr->u.RR.flags[0] & RR_NM) == 0) goto out;
196 break;
197 case SIG('S','P'):
198 CHECK_SP(goto out);
199 break;
200 case SIG('C','E'):
201 CHECK_CE;
202 break;
203 case SIG('N','M'):
204 if (truncate) break;
205 if (rr->u.NM.flags & ~1) {
206 printk("Unsupported NM flag settings (%d)\n",rr->u.NM.flags);
207 break;
208 };
209 if (!retname){
210 retname = (char *) kmalloc (255,GFP_KERNEL);
211
212
213
214
215
216
217 *retname = 0;
218 retnamlen = 0;
219 };
220 if((strlen(retname) + rr->len - 5) >= 254) {
221 truncate = 1;
222 break;
223 };
224 strncat(retname, rr->u.NM.name, rr->len - 5);
225 retnamlen += rr->len - 5;
226 break;
227 case SIG('R','E'):
228 #ifdef DEBUG
229 printk("RR: RE (%x)\n", inode->i_ino);
230 #endif
231 if (buffer) kfree(buffer);
232 if (retname) kfree(retname);
233 return -1;
234 default:
235 break;
236 }
237 };
238 }
239 MAYBE_CONTINUE(repeat,inode);
240 if(retname){
241 *name = retname;
242 *namlen = retnamlen;
243 return 1;
244 };
245 return 0;
246 out:
247 if(buffer) kfree(buffer);
248 if (retname) kfree(retname);
249 return 0;
250 }
251
252 int parse_rock_ridge_inode(struct iso_directory_record * de,
253 struct inode * inode){
254 int len;
255 unsigned char * chr;
256 CONTINUE_DECLS;
257
258 if (!inode->i_sb->u.isofs_sb.s_rock) return 0;
259
260 SETUP_ROCK_RIDGE(de, chr, len);
261 repeat:
262 {
263 int cnt, sig;
264 struct inode * reloc;
265 struct rock_ridge * rr;
266 int rootflag;
267
268 while (len > 1){
269 rr = (struct rock_ridge *) chr;
270 if (rr->len == 0) goto out;
271 sig = (chr[0] << 8) + chr[1];
272 chr += rr->len;
273 len -= rr->len;
274
275 switch(sig){
276 case SIG('R','R'):
277 if((rr->u.RR.flags[0] &
278 (RR_PX | RR_TF | RR_SL | RR_CL)) == 0) goto out;
279 break;
280 case SIG('S','P'):
281 CHECK_SP(goto out);
282 break;
283 case SIG('C','E'):
284 CHECK_CE;
285 break;
286 case SIG('E','R'):
287 printk("ISO9660 Extensions: ");
288 { int p;
289 for(p=0;p<rr->u.ER.len_id;p++) printk("%c",rr->u.ER.data[p]);
290 };
291 printk("\n");
292 break;
293 case SIG('P','X'):
294 inode->i_mode = isonum_733(rr->u.PX.mode);
295 inode->i_nlink = isonum_733(rr->u.PX.n_links);
296 inode->i_uid = isonum_733(rr->u.PX.uid);
297 inode->i_gid = isonum_733(rr->u.PX.gid);
298 break;
299 case SIG('P','N'):
300 { int high, low;
301 high = isonum_733(rr->u.PN.dev_high);
302 low = isonum_733(rr->u.PN.dev_low);
303 inode->i_rdev = ((high << 8) | (low & 0xff)) & 0xffff;
304 };
305 break;
306 case SIG('T','F'):
307
308
309 cnt = 0;
310 if(rr->u.TF.flags & TF_CREATE)
311 inode->i_ctime = iso_date(rr->u.TF.times[cnt++].time, 0);
312 if(rr->u.TF.flags & TF_MODIFY)
313 inode->i_mtime = iso_date(rr->u.TF.times[cnt++].time, 0);
314 if(rr->u.TF.flags & TF_ACCESS)
315 inode->i_atime = iso_date(rr->u.TF.times[cnt++].time, 0);
316 if(rr->u.TF.flags & TF_ATTRIBUTES)
317 inode->i_ctime = iso_date(rr->u.TF.times[cnt++].time, 0);
318 break;
319 case SIG('S','L'):
320 {int slen;
321 struct SL_component * slp;
322 slen = rr->len - 5;
323 slp = &rr->u.SL.link;
324 inode->i_size = 0;
325 while (slen > 1){
326 rootflag = 0;
327 switch(slp->flags &~1){
328 case 0:
329 inode->i_size += slp->len;
330 break;
331 case 2:
332 inode->i_size += 1;
333 break;
334 case 4:
335 inode->i_size += 2;
336 break;
337 case 8:
338 rootflag = 1;
339 inode->i_size += 1;
340 break;
341 default:
342 printk("Symlink component flag not implemented\n");
343 };
344 slen -= slp->len + 2;
345 slp = (struct SL_component *) (((char *) slp) + slp->len + 2);
346
347 if(slen < 2) break;
348 if(!rootflag) inode->i_size += 1;
349 };
350 };
351 break;
352 case SIG('R','E'):
353 printk("Attempt to read inode for relocated directory\n");
354 goto out;
355 case SIG('C','L'):
356 #ifdef DEBUG
357 printk("RR CL (%x)\n",inode->i_ino);
358 #endif
359 inode->u.isofs_i.i_first_extent = isonum_733(rr->u.CL.location) <<
360 (ISOFS_BLOCK_BITS - ISOFS_BUFFER_BITS(inode));
361 reloc = iget(inode->i_sb, inode->u.isofs_i.i_first_extent << ISOFS_BUFFER_BITS(inode));
362 inode->i_mode = reloc->i_mode;
363 inode->i_nlink = reloc->i_nlink;
364 inode->i_uid = reloc->i_uid;
365 inode->i_gid = reloc->i_gid;
366 inode->i_rdev = reloc->i_rdev;
367 inode->i_size = reloc->i_size;
368 inode->i_atime = reloc->i_atime;
369 inode->i_ctime = reloc->i_ctime;
370 inode->i_mtime = reloc->i_mtime;
371 iput(reloc);
372 break;
373 default:
374 break;
375 }
376 };
377 }
378 MAYBE_CONTINUE(repeat,inode);
379 return 0;
380 out:
381 if(buffer) kfree(buffer);
382 return 0;
383 }
384
385
386
387
388
389 char * get_rock_ridge_symlink(struct inode * inode)
390 {
391 unsigned long bufsize = ISOFS_BUFFER_SIZE(inode);
392 unsigned char bufbits = ISOFS_BUFFER_BITS(inode);
393 struct buffer_head * bh;
394 unsigned char * pnt;
395 void * cpnt = NULL;
396 char * rpnt;
397 struct iso_directory_record * raw_inode;
398 CONTINUE_DECLS;
399 int block;
400 int sig;
401 int rootflag;
402 int len;
403 unsigned char * chr;
404 struct rock_ridge * rr;
405
406 if (!inode->i_sb->u.isofs_sb.s_rock)
407 panic("Cannot have symlink with high sierra variant of iso filesystem\n");
408
409 rpnt = 0;
410
411 block = inode->i_ino >> bufbits;
412 if (!(bh=bread(inode->i_dev,block, bufsize))) {
413 printk("unable to read i-node block");
414 return NULL;
415 };
416
417 pnt = ((unsigned char *) bh->b_data) + (inode->i_ino & (bufsize - 1));
418
419 raw_inode = ((struct iso_directory_record *) pnt);
420
421 if ((inode->i_ino & (bufsize - 1)) + *pnt > bufsize){
422 int frag1, offset;
423
424 offset = (inode->i_ino & (bufsize - 1));
425 frag1 = bufsize - offset;
426 cpnt = kmalloc(*pnt,GFP_KERNEL);
427 if(!cpnt) return NULL;
428 memcpy(cpnt, bh->b_data + offset, frag1);
429 brelse(bh);
430 if (!(bh = bread(inode->i_dev,++block, bufsize))) {
431 kfree(cpnt);
432 printk("unable to read i-node block");
433 return NULL;
434 };
435 offset += *pnt - bufsize;
436 memcpy((char *)cpnt+frag1, bh->b_data, offset);
437 pnt = ((unsigned char *) cpnt);
438 raw_inode = ((struct iso_directory_record *) pnt);
439 };
440
441
442
443
444 SETUP_ROCK_RIDGE(raw_inode, chr, len);
445
446 repeat:
447 while (len > 1){
448 if (rpnt) break;
449 rr = (struct rock_ridge *) chr;
450 if (rr->len == 0) goto out;
451 sig = (chr[0] << 8) + chr[1];
452 chr += rr->len;
453 len -= rr->len;
454
455 switch(sig){
456 case SIG('R','R'):
457 if((rr->u.RR.flags[0] & RR_SL) == 0) goto out;
458 break;
459 case SIG('S','P'):
460 CHECK_SP(goto out);
461 break;
462 case SIG('S','L'):
463 {int slen;
464 struct SL_component * slp;
465 slen = rr->len - 5;
466 slp = &rr->u.SL.link;
467 while (slen > 1){
468 if (!rpnt){
469 rpnt = (char *) kmalloc (inode->i_size +1, GFP_KERNEL);
470 *rpnt = 0;
471 };
472 rootflag = 0;
473 switch(slp->flags &~1){
474 case 0:
475 strncat(rpnt,slp->text, slp->len);
476 break;
477 case 2:
478 strcat(rpnt,".");
479 break;
480 case 4:
481 strcat(rpnt,"..");
482 break;
483 case 8:
484 rootflag = 1;
485 strcat(rpnt,"/");
486 break;
487 default:
488 printk("Symlink component flag not implemented (%d)\n",slen);
489 };
490 slen -= slp->len + 2;
491 slp = (struct SL_component *) (((char *) slp) + slp->len + 2);
492
493 if(slen < 2) break;
494 if(!rootflag) strcat(rpnt,"/");
495 };
496 break;
497 default:
498 break;
499 }
500 };
501 };
502 MAYBE_CONTINUE(repeat,inode);
503 brelse(bh);
504
505 if (cpnt) {
506 kfree(cpnt);
507 cpnt = NULL;
508 };
509
510 return rpnt;
511 out:
512 if(buffer) kfree(buffer);
513 return 0;
514 }
515
516
517
518
519
520