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