OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [fs/] [isofs/] [rock.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 *  linux/fs/isofs/rock.c
3
 *
4
 *  (C) 1992, 1993  Eric Youngdale
5
 *
6
 *  Rock Ridge Extensions to iso9660
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/slab.h>
15
#include <linux/pagemap.h>
16
#include <linux/smp_lock.h>
17
#include <asm/page.h>
18
 
19
#include "rock.h"
20
 
21
/* These functions are designed to read the system areas of a directory record
22
 * and extract relevant information.  There are different functions provided
23
 * depending upon what information we need at the time.  One function fills
24
 * out an inode structure, a second one extracts a filename, a third one
25
 * returns a symbolic link name, and a fourth one returns the extent number
26
 * for the file. */
27
 
28
#define SIG(A,B) ((A) | ((B) << 8)) /* isonum_721() */
29
 
30
 
31
/* This is a way of ensuring that we have something in the system
32
   use fields that is compatible with Rock Ridge */
33
#define CHECK_SP(FAIL)                          \
34
      if(rr->u.SP.magic[0] != 0xbe) FAIL;        \
35
      if(rr->u.SP.magic[1] != 0xef) FAIL;       \
36
      inode->i_sb->u.isofs_sb.s_rock_offset=rr->u.SP.skip;
37
/* We define a series of macros because each function must do exactly the
38
   same thing in certain places.  We use the macros to ensure that everything
39
   is done correctly */
40
 
41
#define CONTINUE_DECLS \
42
  int cont_extent = 0, cont_offset = 0, cont_size = 0;   \
43
  void * buffer = 0
44
 
45
#define CHECK_CE                                \
46
      {cont_extent = isonum_733(rr->u.CE.extent); \
47
      cont_offset = isonum_733(rr->u.CE.offset); \
48
      cont_size = isonum_733(rr->u.CE.size);}
49
 
50
#define SETUP_ROCK_RIDGE(DE,CHR,LEN)                            \
51
  {LEN= sizeof(struct iso_directory_record) + DE->name_len[0];   \
52
  if(LEN & 1) LEN++;                                            \
53
  CHR = ((unsigned char *) DE) + LEN;                           \
54
  LEN = *((unsigned char *) DE) - LEN;                          \
55
  if (inode->i_sb->u.isofs_sb.s_rock_offset!=-1)                \
56
  {                                                             \
57
     LEN-=inode->i_sb->u.isofs_sb.s_rock_offset;                \
58
     CHR+=inode->i_sb->u.isofs_sb.s_rock_offset;                \
59
     if (LEN<0) LEN=0;                                          \
60
  }                                                             \
61
}
62
 
63
#define MAYBE_CONTINUE(LABEL,DEV) \
64
  {if (buffer) kfree(buffer); \
65
  if (cont_extent){ \
66
    int block, offset, offset1; \
67
    struct buffer_head * pbh; \
68
    buffer = kmalloc(cont_size,GFP_KERNEL); \
69
    if (!buffer) goto out; \
70
    block = cont_extent; \
71
    offset = cont_offset; \
72
    offset1 = 0; \
73
    pbh = sb_bread(DEV->i_sb, block); \
74
    if(pbh){       \
75
      memcpy(buffer + offset1, pbh->b_data + offset, cont_size - offset1); \
76
      brelse(pbh); \
77
      chr = (unsigned char *) buffer; \
78
      len = cont_size; \
79
      cont_extent = 0; \
80
      cont_size = 0; \
81
      cont_offset = 0; \
82
      goto LABEL; \
83
    }    \
84
    printk("Unable to read rock-ridge attributes\n");    \
85
  }}
86
 
87
/* This is the inner layer of the get filename routine, and is called
88
   for each system area and continuation record related to the file */
89
 
90
int find_rock_ridge_relocation(struct iso_directory_record * de,
91
                               struct inode * inode) {
92
  int flag;
93
  int len;
94
  int retval;
95
  unsigned char * chr;
96
  CONTINUE_DECLS;
97
  flag = 0;
98
 
99
  /* If this is a '..' then we are looking for the parent, otherwise we
100
     are looking for the child */
101
 
102
  if (de->name[0]==1 && de->name_len[0]==1) flag = 1;
103
  /* Return value if we do not find appropriate record. */
104
  retval = isonum_733 (de->extent);
105
 
106
  if (!inode->i_sb->u.isofs_sb.s_rock) return retval;
107
 
108
  SETUP_ROCK_RIDGE(de, chr, len);
109
 repeat:
110
  {
111
    int rrflag, sig;
112
    struct rock_ridge * rr;
113
 
114
    while (len > 1){ /* There may be one byte for padding somewhere */
115
      rr = (struct rock_ridge *) chr;
116
      if (rr->len == 0) goto out; /* Something got screwed up here */
117
      sig = isonum_721(chr);
118
      chr += rr->len;
119
      len -= rr->len;
120
 
121
      switch(sig){
122
      case SIG('R','R'):
123
        rrflag = rr->u.RR.flags[0];
124
        if (flag && !(rrflag & RR_PL)) goto out;
125
        if (!flag && !(rrflag & RR_CL)) goto out;
126
        break;
127
      case SIG('S','P'):
128
        CHECK_SP(goto out);
129
        break;
130
      case SIG('C','L'):
131
        if (flag == 0) {
132
          retval = isonum_733(rr->u.CL.location);
133
          goto out;
134
        }
135
        break;
136
      case SIG('P','L'):
137
        if (flag != 0) {
138
          retval = isonum_733(rr->u.PL.location);
139
          goto out;
140
        }
141
        break;
142
      case SIG('C','E'):
143
        CHECK_CE; /* This tells is if there is a continuation record */
144
        break;
145
      default:
146
        break;
147
      }
148
    }
149
  }
150
  MAYBE_CONTINUE(repeat, inode);
151
  return retval;
152
 out:
153
  if(buffer) kfree(buffer);
154
  return retval;
155
}
156
 
157
/* return length of name field; 0: not found, -1: to be ignored */
158
int get_rock_ridge_filename(struct iso_directory_record * de,
159
                            char * retname, struct inode * inode)
160
{
161
  int len;
162
  unsigned char * chr;
163
  CONTINUE_DECLS;
164
  int retnamlen = 0, truncate=0;
165
 
166
  if (!inode->i_sb->u.isofs_sb.s_rock) return 0;
167
  *retname = 0;
168
 
169
  SETUP_ROCK_RIDGE(de, chr, len);
170
 repeat:
171
  {
172
    struct rock_ridge * rr;
173
    int sig;
174
 
175
    while (len > 1){ /* There may be one byte for padding somewhere */
176
      rr = (struct rock_ridge *) chr;
177
      if (rr->len == 0) goto out; /* Something got screwed up here */
178
      sig = isonum_721(chr);
179
      chr += rr->len;
180
      len -= rr->len;
181
 
182
      switch(sig){
183
      case SIG('R','R'):
184
        if((rr->u.RR.flags[0] & RR_NM) == 0) goto out;
185
        break;
186
      case SIG('S','P'):
187
        CHECK_SP(goto out);
188
        break;
189
      case SIG('C','E'):
190
        CHECK_CE;
191
        break;
192
      case SIG('N','M'):
193
        if (truncate) break;
194
        /*
195
         * If the flags are 2 or 4, this indicates '.' or '..'.
196
         * We don't want to do anything with this, because it
197
         * screws up the code that calls us.  We don't really
198
         * care anyways, since we can just use the non-RR
199
         * name.
200
         */
201
        if (rr->u.NM.flags & 6) {
202
          break;
203
        }
204
 
205
        if (rr->u.NM.flags & ~1) {
206
          printk("Unsupported NM flag settings (%d)\n",rr->u.NM.flags);
207
          break;
208
        }
209
        if((strlen(retname) + rr->len - 5) >= 254) {
210
          truncate = 1;
211
          break;
212
        }
213
        strncat(retname, rr->u.NM.name, rr->len - 5);
214
        retnamlen += rr->len - 5;
215
        break;
216
      case SIG('R','E'):
217
        if (buffer) kfree(buffer);
218
        return -1;
219
      default:
220
        break;
221
      }
222
    }
223
  }
224
  MAYBE_CONTINUE(repeat,inode);
225
  return retnamlen; /* If 0, this file did not have a NM field */
226
 out:
227
  if(buffer) kfree(buffer);
228
  return 0;
229
}
230
 
231
int parse_rock_ridge_inode_internal(struct iso_directory_record * de,
232
                                    struct inode * inode,int regard_xa){
233
  int len;
234
  unsigned char * chr;
235
  int symlink_len = 0;
236
  CONTINUE_DECLS;
237
 
238
  if (!inode->i_sb->u.isofs_sb.s_rock) return 0;
239
 
240
  SETUP_ROCK_RIDGE(de, chr, len);
241
  if (regard_xa)
242
   {
243
     chr+=14;
244
     len-=14;
245
     if (len<0) len=0;
246
   };
247
 
248
 repeat:
249
  {
250
    int cnt, sig;
251
    struct inode * reloc;
252
    struct rock_ridge * rr;
253
    int rootflag;
254
 
255
    while (len > 1){ /* There may be one byte for padding somewhere */
256
      rr = (struct rock_ridge *) chr;
257
      if (rr->len == 0) goto out; /* Something got screwed up here */
258
      sig = isonum_721(chr);
259
      chr += rr->len;
260
      len -= rr->len;
261
 
262
      switch(sig){
263
#ifndef CONFIG_ZISOFS           /* No flag for SF or ZF */
264
      case SIG('R','R'):
265
        if((rr->u.RR.flags[0] &
266
            (RR_PX | RR_TF | RR_SL | RR_CL)) == 0) goto out;
267
        break;
268
#endif
269
      case SIG('S','P'):
270
        CHECK_SP(goto out);
271
        break;
272
      case SIG('C','E'):
273
        CHECK_CE;
274
        break;
275
      case SIG('E','R'):
276
        inode->i_sb->u.isofs_sb.s_rock = 1;
277
        printk(KERN_DEBUG "ISO 9660 Extensions: ");
278
        { int p;
279
          for(p=0;p<rr->u.ER.len_id;p++) printk("%c",rr->u.ER.data[p]);
280
        }
281
          printk("\n");
282
        break;
283
      case SIG('P','X'):
284
        inode->i_mode  = isonum_733(rr->u.PX.mode);
285
        inode->i_nlink = isonum_733(rr->u.PX.n_links);
286
        inode->i_uid   = isonum_733(rr->u.PX.uid);
287
        inode->i_gid   = isonum_733(rr->u.PX.gid);
288
        break;
289
      case SIG('P','N'):
290
        { int high, low;
291
          high = isonum_733(rr->u.PN.dev_high);
292
          low = isonum_733(rr->u.PN.dev_low);
293
          /*
294
           * The Rock Ridge standard specifies that if sizeof(dev_t) <= 4,
295
           * then the high field is unused, and the device number is completely
296
           * stored in the low field.  Some writers may ignore this subtlety,
297
           * and as a result we test to see if the entire device number is
298
           * stored in the low field, and use that.
299
           */
300
          if((low & ~0xff) && high == 0) {
301
            inode->i_rdev = MKDEV(low >> 8, low & 0xff);
302
          } else {
303
            inode->i_rdev = MKDEV(high, low);
304
          }
305
        }
306
        break;
307
      case SIG('T','F'):
308
        /* Some RRIP writers incorrectly place ctime in the TF_CREATE field.
309
           Try to handle this correctly for either case. */
310
        cnt = 0; /* Rock ridge never appears on a High Sierra disk */
311
        if(rr->u.TF.flags & TF_CREATE)
312
          inode->i_ctime = iso_date(rr->u.TF.times[cnt++].time, 0);
313
        if(rr->u.TF.flags & TF_MODIFY)
314
          inode->i_mtime = iso_date(rr->u.TF.times[cnt++].time, 0);
315
        if(rr->u.TF.flags & TF_ACCESS)
316
          inode->i_atime = iso_date(rr->u.TF.times[cnt++].time, 0);
317
        if(rr->u.TF.flags & TF_ATTRIBUTES)
318
          inode->i_ctime = iso_date(rr->u.TF.times[cnt++].time, 0);
319
        break;
320
      case SIG('S','L'):
321
        {int slen;
322
         struct SL_component * slp;
323
         struct SL_component * oldslp;
324
         slen = rr->len - 5;
325
         slp = &rr->u.SL.link;
326
         inode->i_size = symlink_len;
327
         while (slen > 1){
328
           rootflag = 0;
329
           switch(slp->flags &~1){
330
           case 0:
331
             inode->i_size += slp->len;
332
             break;
333
           case 2:
334
             inode->i_size += 1;
335
             break;
336
           case 4:
337
             inode->i_size += 2;
338
             break;
339
           case 8:
340
             rootflag = 1;
341
             inode->i_size += 1;
342
             break;
343
           default:
344
             printk("Symlink component flag not implemented\n");
345
           }
346
           slen -= slp->len + 2;
347
           oldslp = slp;
348
           slp = (struct SL_component *) (((char *) slp) + slp->len + 2);
349
 
350
           if(slen < 2) {
351
             if(    ((rr->u.SL.flags & 1) != 0)
352
                    && ((oldslp->flags & 1) == 0) ) inode->i_size += 1;
353
             break;
354
           }
355
 
356
           /*
357
            * If this component record isn't continued, then append a '/'.
358
            */
359
           if (!rootflag && (oldslp->flags & 1) == 0)
360
                   inode->i_size += 1;
361
         }
362
        }
363
        symlink_len = inode->i_size;
364
        break;
365
      case SIG('R','E'):
366
        printk(KERN_WARNING "Attempt to read inode for relocated directory\n");
367
        goto out;
368
      case SIG('C','L'):
369
        inode->u.isofs_i.i_first_extent = isonum_733(rr->u.CL.location);
370
        reloc = iget(inode->i_sb,
371
                     (inode->u.isofs_i.i_first_extent <<
372
                      inode -> i_sb -> u.isofs_sb.s_log_zone_size));
373
        if (!reloc)
374
                goto out;
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_blocks = reloc->i_blocks;
382
        inode->i_atime = reloc->i_atime;
383
        inode->i_ctime = reloc->i_ctime;
384
        inode->i_mtime = reloc->i_mtime;
385
        iput(reloc);
386
        break;
387
#ifdef CONFIG_ZISOFS
388
      case SIG('Z','F'):
389
              if ( !inode->i_sb->u.isofs_sb.s_nocompress ) {
390
                      int algo;
391
                      algo = isonum_721(rr->u.ZF.algorithm);
392
                      if ( algo == SIG('p','z') ) {
393
                              int block_shift = isonum_711(&rr->u.ZF.parms[1]);
394
                              if ( block_shift < PAGE_CACHE_SHIFT || block_shift > 17 ) {
395
                                      printk(KERN_WARNING "isofs: Can't handle ZF block size of 2^%d\n", block_shift);
396
                              } else {
397
                                /* Note: we don't change i_blocks here */
398
                                      inode->u.isofs_i.i_file_format = isofs_file_compressed;
399
                                /* Parameters to compression algorithm (header size, block size) */
400
                                      inode->u.isofs_i.i_format_parm[0] = isonum_711(&rr->u.ZF.parms[0]);
401
                                      inode->u.isofs_i.i_format_parm[1] = isonum_711(&rr->u.ZF.parms[1]);
402
                                      inode->i_size = isonum_733(rr->u.ZF.real_size);
403
                              }
404
                      } else {
405
                              printk(KERN_WARNING "isofs: Unknown ZF compression algorithm: %c%c\n",
406
                                     rr->u.ZF.algorithm[0], rr->u.ZF.algorithm[1]);
407
                      }
408
              }
409
              break;
410
#endif
411
      default:
412
        break;
413
      }
414
    }
415
  }
416
  MAYBE_CONTINUE(repeat,inode);
417
  return 0;
418
 out:
419
  if(buffer) kfree(buffer);
420
  return 0;
421
}
422
 
423
static char *get_symlink_chunk(char *rpnt, struct rock_ridge *rr, char *plimit)
424
{
425
        int slen;
426
        int rootflag;
427
        struct SL_component *oldslp;
428
        struct SL_component *slp;
429
        slen = rr->len - 5;
430
        slp = &rr->u.SL.link;
431
        while (slen > 1) {
432
                rootflag = 0;
433
                switch (slp->flags & ~1) {
434
                case 0:
435
                        if (slp->len > plimit - rpnt)
436
                                return NULL;
437
                        memcpy(rpnt, slp->text, slp->len);
438
                        rpnt+=slp->len;
439
                        break;
440
                case 2:
441
                        if (rpnt >= plimit)
442
                                return NULL;
443
                        *rpnt++='.';
444
                        break;
445
                case 4:
446
                        if (2 > plimit - rpnt)
447
                                return NULL;
448
                        *rpnt++='.';
449
                        *rpnt++='.';
450
                        break;
451
                case 8:
452
                        if (rpnt >= plimit)
453
                                return NULL;
454
                        rootflag = 1;
455
                        *rpnt++='/';
456
                        break;
457
                default:
458
                        printk("Symlink component flag not implemented (%d)\n",
459
                             slp->flags);
460
                }
461
                slen -= slp->len + 2;
462
                oldslp = slp;
463
                slp = (struct SL_component *) ((char *) slp + slp->len + 2);
464
 
465
                if (slen < 2) {
466
                        /*
467
                         * If there is another SL record, and this component
468
                         * record isn't continued, then add a slash.
469
                         */
470
                        if ((!rootflag) && (rr->u.SL.flags & 1) &&
471
                            !(oldslp->flags & 1)) {
472
                                if (rpnt >= plimit)
473
                                        return NULL;
474
                                *rpnt++='/';
475
                        }
476
                        break;
477
                }
478
 
479
                /*
480
                 * If this component record isn't continued, then append a '/'.
481
                 */
482
                if (!rootflag && !(oldslp->flags & 1)) {
483
                        if (rpnt >= plimit)
484
                                return NULL;
485
                        *rpnt++='/';
486
                }
487
        }
488
        return rpnt;
489
}
490
 
491
int parse_rock_ridge_inode(struct iso_directory_record * de,
492
                           struct inode * inode)
493
{
494
   int result=parse_rock_ridge_inode_internal(de,inode,0);
495
   /* if rockridge flag was reset and we didn't look for attributes
496
    * behind eventual XA attributes, have a look there */
497
   if ((inode->i_sb->u.isofs_sb.s_rock_offset==-1)
498
       &&(inode->i_sb->u.isofs_sb.s_rock==2))
499
     {
500
        result=parse_rock_ridge_inode_internal(de,inode,14);
501
     };
502
   return result;
503
};
504
 
505
/* readpage() for symlinks: reads symlink contents into the page and either
506
   makes it uptodate and returns 0 or returns error (-EIO) */
507
 
508
static int rock_ridge_symlink_readpage(struct file *file, struct page *page)
509
{
510
        struct inode *inode = page->mapping->host;
511
        char *link = kmap(page);
512
        unsigned long bufsize = ISOFS_BUFFER_SIZE(inode);
513
        unsigned char bufbits = ISOFS_BUFFER_BITS(inode);
514
        struct buffer_head *bh;
515
        char *rpnt = link;
516
        unsigned char *pnt;
517
        struct iso_directory_record *raw_inode;
518
        CONTINUE_DECLS;
519
        int block;
520
        int sig;
521
        int len;
522
        unsigned char *chr;
523
        struct rock_ridge *rr;
524
 
525
        if (!inode->i_sb->u.isofs_sb.s_rock)
526
                panic ("Cannot have symlink with high sierra variant of iso filesystem\n");
527
 
528
        block = inode->i_ino >> bufbits;
529
        lock_kernel();
530
        bh = sb_bread(inode->i_sb, block);
531
        if (!bh)
532
                goto out_noread;
533
 
534
        pnt = (unsigned char *) bh->b_data + (inode->i_ino & (bufsize - 1));
535
 
536
        raw_inode = (struct iso_directory_record *) pnt;
537
 
538
        /*
539
         * If we go past the end of the buffer, there is some sort of error.
540
         */
541
        if ((inode->i_ino & (bufsize - 1)) + *pnt > bufsize)
542
                goto out_bad_span;
543
 
544
        /* Now test for possible Rock Ridge extensions which will override
545
           some of these numbers in the inode structure. */
546
 
547
        SETUP_ROCK_RIDGE(raw_inode, chr, len);
548
 
549
      repeat:
550
        while (len > 1) { /* There may be one byte for padding somewhere */
551
                rr = (struct rock_ridge *) chr;
552
                if (rr->len == 0)
553
                        goto out;       /* Something got screwed up here */
554
                sig = isonum_721(chr);
555
                chr += rr->len;
556
                len -= rr->len;
557
 
558
                switch (sig) {
559
                case SIG('R', 'R'):
560
                        if ((rr->u.RR.flags[0] & RR_SL) == 0)
561
                                goto out;
562
                        break;
563
                case SIG('S', 'P'):
564
                        CHECK_SP(goto out);
565
                        break;
566
                case SIG('S', 'L'):
567
                        rpnt = get_symlink_chunk(rpnt, rr,
568
                                                 link + (PAGE_SIZE - 1));
569
                        if (rpnt == NULL)
570
                                goto out;
571
                        break;
572
                case SIG('C', 'E'):
573
                        /* This tells is if there is a continuation record */
574
                        CHECK_CE;
575
                default:
576
                        break;
577
                }
578
        }
579
        MAYBE_CONTINUE(repeat, inode);
580
 
581
        if (rpnt == link)
582
                goto fail;
583
        brelse(bh);
584
        *rpnt = '\0';
585
        unlock_kernel();
586
        SetPageUptodate(page);
587
        kunmap(page);
588
        UnlockPage(page);
589
        return 0;
590
 
591
        /* error exit from macro */
592
      out:
593
        if (buffer)
594
                kfree(buffer);
595
        goto fail;
596
      out_noread:
597
        printk("unable to read i-node block");
598
        goto fail;
599
      out_bad_span:
600
        printk("symlink spans iso9660 blocks\n");
601
      fail:
602
        brelse(bh);
603
        unlock_kernel();
604
        SetPageError(page);
605
        kunmap(page);
606
        UnlockPage(page);
607
        return -EIO;
608
}
609
 
610
struct address_space_operations isofs_symlink_aops = {
611
        readpage:       rock_ridge_symlink_readpage
612
};

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.