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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 *  linux/fs/isofs/inode.c
3
 *
4
 *  (C) 1991  Linus Torvalds - minix filesystem
5
 *      1992, 1993, 1994  Eric Youngdale Modified for ISO 9660 filesystem.
6
 *      1994  Eberhard Moenkeberg - multi session handling.
7
 *      1995  Mark Dobie - allow mounting of some weird VideoCDs and PhotoCDs.
8
 *      1997  Gordon Chaffee - Joliet CDs
9
 *      1998  Eric Lammerts - ISO 9660 Level 3
10
 */
11
 
12
#include <linux/config.h>
13
#include <linux/module.h>
14
 
15
#include <linux/stat.h>
16
#include <linux/sched.h>
17
#include <linux/iso_fs.h>
18
#include <linux/kernel.h>
19
#include <linux/major.h>
20
#include <linux/mm.h>
21
#include <linux/string.h>
22
#include <linux/locks.h>
23
#include <linux/slab.h>
24
#include <linux/errno.h>
25
#include <linux/cdrom.h>
26
#include <linux/init.h>
27
#include <linux/nls.h>
28
#include <linux/ctype.h>
29
#include <linux/smp_lock.h>
30
#include <linux/blkdev.h>
31
 
32
#include <asm/system.h>
33
#include <asm/uaccess.h>
34
 
35
#include "zisofs.h"
36
 
37
/*
38
 * We have no support for "multi volume" CDs, but more and more disks carry
39
 * wrong information within the volume descriptors.
40
 */
41
#define IGNORE_WRONG_MULTI_VOLUME_SPECS
42
#define BEQUIET
43
 
44
#ifdef LEAK_CHECK
45
static int check_malloc = 0;
46
static int check_bread = 0;
47
#endif
48
 
49
static int isofs_hashi(struct dentry *parent, struct qstr *qstr);
50
static int isofs_hash(struct dentry *parent, struct qstr *qstr);
51
static int isofs_dentry_cmpi(struct dentry *dentry, struct qstr *a, struct qstr *b);
52
static int isofs_dentry_cmp(struct dentry *dentry, struct qstr *a, struct qstr *b);
53
 
54
#ifdef CONFIG_JOLIET
55
static int isofs_hashi_ms(struct dentry *parent, struct qstr *qstr);
56
static int isofs_hash_ms(struct dentry *parent, struct qstr *qstr);
57
static int isofs_dentry_cmpi_ms(struct dentry *dentry, struct qstr *a, struct qstr *b);
58
static int isofs_dentry_cmp_ms(struct dentry *dentry, struct qstr *a, struct qstr *b);
59
#endif
60
 
61
static void isofs_put_super(struct super_block *sb)
62
{
63
#ifdef CONFIG_JOLIET
64
        if (sb->u.isofs_sb.s_nls_iocharset) {
65
                unload_nls(sb->u.isofs_sb.s_nls_iocharset);
66
                sb->u.isofs_sb.s_nls_iocharset = NULL;
67
        }
68
#endif
69
 
70
#ifdef LEAK_CHECK
71
        printk("Outstanding mallocs:%d, outstanding buffers: %d\n",
72
               check_malloc, check_bread);
73
#endif
74
 
75
        return;
76
}
77
 
78
static void isofs_read_inode(struct inode *);
79
static int isofs_statfs (struct super_block *, struct statfs *);
80
 
81
static struct super_operations isofs_sops = {
82
        read_inode:     isofs_read_inode,
83
        put_super:      isofs_put_super,
84
        statfs:         isofs_statfs,
85
};
86
 
87
static struct dentry_operations isofs_dentry_ops[] = {
88
        {
89
                d_hash:         isofs_hash,
90
                d_compare:      isofs_dentry_cmp,
91
        },
92
        {
93
                d_hash:         isofs_hashi,
94
                d_compare:      isofs_dentry_cmpi,
95
        },
96
#ifdef CONFIG_JOLIET
97
        {
98
                d_hash:         isofs_hash_ms,
99
                d_compare:      isofs_dentry_cmp_ms,
100
        },
101
        {
102
                d_hash:         isofs_hashi_ms,
103
                d_compare:      isofs_dentry_cmpi_ms,
104
        }
105
#endif
106
};
107
 
108
struct iso9660_options{
109
        char map;
110
        char rock;
111
        char joliet;
112
        char cruft;
113
        char unhide;
114
        char nocompress;
115
        unsigned char check;
116
        unsigned int blocksize;
117
        mode_t mode;
118
        gid_t gid;
119
        uid_t uid;
120
        char *iocharset;
121
        unsigned char utf8;
122
        /* LVE */
123
        s32 session;
124
        s32 sbsector;
125
};
126
 
127
/*
128
 * Compute the hash for the isofs name corresponding to the dentry.
129
 */
130
static int
131
isofs_hash_common(struct dentry *dentry, struct qstr *qstr, int ms)
132
{
133
        const char *name;
134
        int len;
135
 
136
        len = qstr->len;
137
        name = qstr->name;
138
        if (ms) {
139
                while (len && name[len-1] == '.')
140
                        len--;
141
        }
142
 
143
        qstr->hash = full_name_hash(name, len);
144
 
145
        return 0;
146
}
147
 
148
/*
149
 * Compute the hash for the isofs name corresponding to the dentry.
150
 */
151
static int
152
isofs_hashi_common(struct dentry *dentry, struct qstr *qstr, int ms)
153
{
154
        const char *name;
155
        int len;
156
        char c;
157
        unsigned long hash;
158
 
159
        len = qstr->len;
160
        name = qstr->name;
161
        if (ms) {
162
                while (len && name[len-1] == '.')
163
                        len--;
164
        }
165
 
166
        hash = init_name_hash();
167
        while (len--) {
168
                c = tolower(*name++);
169
                hash = partial_name_hash(tolower(c), hash);
170
        }
171
        qstr->hash = end_name_hash(hash);
172
 
173
        return 0;
174
}
175
 
176
/*
177
 * Case insensitive compare of two isofs names.
178
 */
179
static int
180
isofs_dentry_cmpi_common(struct dentry *dentry,struct qstr *a,struct qstr *b,int ms)
181
{
182
        int alen, blen;
183
 
184
        /* A filename cannot end in '.' or we treat it like it has none */
185
        alen = a->len;
186
        blen = b->len;
187
        if (ms) {
188
                while (alen && a->name[alen-1] == '.')
189
                        alen--;
190
                while (blen && b->name[blen-1] == '.')
191
                        blen--;
192
        }
193
        if (alen == blen) {
194
                if (strnicmp(a->name, b->name, alen) == 0)
195
                        return 0;
196
        }
197
        return 1;
198
}
199
 
200
/*
201
 * Case sensitive compare of two isofs names.
202
 */
203
static int
204
isofs_dentry_cmp_common(struct dentry *dentry,struct qstr *a,struct qstr *b,int ms)
205
{
206
        int alen, blen;
207
 
208
        /* A filename cannot end in '.' or we treat it like it has none */
209
        alen = a->len;
210
        blen = b->len;
211
        if (ms) {
212
                while (alen && a->name[alen-1] == '.')
213
                        alen--;
214
                while (blen && b->name[blen-1] == '.')
215
                        blen--;
216
        }
217
        if (alen == blen) {
218
                if (strncmp(a->name, b->name, alen) == 0)
219
                        return 0;
220
        }
221
        return 1;
222
}
223
 
224
static int
225
isofs_hash(struct dentry *dentry, struct qstr *qstr)
226
{
227
        return isofs_hash_common(dentry, qstr, 0);
228
}
229
 
230
static int
231
isofs_hashi(struct dentry *dentry, struct qstr *qstr)
232
{
233
        return isofs_hashi_common(dentry, qstr, 0);
234
}
235
 
236
static int
237
isofs_dentry_cmp(struct dentry *dentry,struct qstr *a,struct qstr *b)
238
{
239
        return isofs_dentry_cmp_common(dentry, a, b, 0);
240
}
241
 
242
static int
243
isofs_dentry_cmpi(struct dentry *dentry,struct qstr *a,struct qstr *b)
244
{
245
        return isofs_dentry_cmpi_common(dentry, a, b, 0);
246
}
247
 
248
#ifdef CONFIG_JOLIET
249
static int
250
isofs_hash_ms(struct dentry *dentry, struct qstr *qstr)
251
{
252
        return isofs_hash_common(dentry, qstr, 1);
253
}
254
 
255
static int
256
isofs_hashi_ms(struct dentry *dentry, struct qstr *qstr)
257
{
258
        return isofs_hashi_common(dentry, qstr, 1);
259
}
260
 
261
static int
262
isofs_dentry_cmp_ms(struct dentry *dentry,struct qstr *a,struct qstr *b)
263
{
264
        return isofs_dentry_cmp_common(dentry, a, b, 1);
265
}
266
 
267
static int
268
isofs_dentry_cmpi_ms(struct dentry *dentry,struct qstr *a,struct qstr *b)
269
{
270
        return isofs_dentry_cmpi_common(dentry, a, b, 1);
271
}
272
#endif
273
 
274
static int parse_options(char *options, struct iso9660_options * popt)
275
{
276
        char *this_char,*value;
277
 
278
        popt->map = 'n';
279
        popt->rock = 'y';
280
        popt->joliet = 'y';
281
        popt->cruft = 'n';
282
        popt->unhide = 'n';
283
        popt->check = 'u';              /* unset */
284
        popt->nocompress = 0;
285
        popt->blocksize = 1024;
286
        popt->mode = S_IRUGO | S_IXUGO; /* r-x for all.  The disc could
287
                                           be shared with DOS machines so
288
                                           virtually anything could be
289
                                           a valid executable. */
290
        popt->gid = 0;
291
        popt->uid = 0;
292
        popt->iocharset = NULL;
293
        popt->utf8 = 0;
294
        popt->session=-1;
295
        popt->sbsector=-1;
296
        if (!options) return 1;
297
        for (this_char = strtok(options,","); this_char; this_char = strtok(NULL,",")) {
298
                if (strncmp(this_char,"norock",6) == 0) {
299
                  popt->rock = 'n';
300
                  continue;
301
                }
302
                if (strncmp(this_char,"nojoliet",8) == 0) {
303
                  popt->joliet = 'n';
304
                  continue;
305
                }
306
                if (strncmp(this_char,"unhide",6) == 0) {
307
                  popt->unhide = 'y';
308
                  continue;
309
                }
310
                if (strncmp(this_char,"cruft",5) == 0) {
311
                  popt->cruft = 'y';
312
                  continue;
313
                }
314
                if (strncmp(this_char,"utf8",4) == 0) {
315
                  popt->utf8 = 1;
316
                  continue;
317
                }
318
                if (strncmp(this_char,"nocompress",10) == 0) {
319
                  popt->nocompress = 1;
320
                  continue;
321
                }
322
                if ((value = strchr(this_char,'=')) != NULL)
323
                        *value++ = 0;
324
 
325
#ifdef CONFIG_JOLIET
326
                if (!strcmp(this_char,"iocharset") && value) {
327
                        popt->iocharset = value;
328
                        while (*value && *value != ',')
329
                                value++;
330
                        if (value == popt->iocharset)
331
                                return 0;
332
                        *value = 0;
333
                } else
334
#endif
335
                if (!strcmp(this_char,"map") && value) {
336
                        if (value[0] && !value[1] && strchr("ano",*value))
337
                                popt->map = *value;
338
                        else if (!strcmp(value,"off")) popt->map = 'o';
339
                        else if (!strcmp(value,"normal")) popt->map = 'n';
340
                        else if (!strcmp(value,"acorn")) popt->map = 'a';
341
                        else return 0;
342
                }
343
                if (!strcmp(this_char,"session") && value) {
344
                        char * vpnt = value;
345
                        unsigned int ivalue = simple_strtoul(vpnt, &vpnt, 0);
346
                        if(ivalue < 0 || ivalue >99) return 0;
347
                        popt->session=ivalue+1;
348
                }
349
                if (!strcmp(this_char,"sbsector") && value) {
350
                        char * vpnt = value;
351
                        unsigned int ivalue = simple_strtoul(vpnt, &vpnt, 0);
352
                        if(ivalue < 0 || ivalue >660*512) return 0;
353
                        popt->sbsector=ivalue;
354
                }
355
                else if (!strcmp(this_char,"check") && value) {
356
                        if (value[0] && !value[1] && strchr("rs",*value))
357
                                popt->check = *value;
358
                        else if (!strcmp(value,"relaxed")) popt->check = 'r';
359
                        else if (!strcmp(value,"strict")) popt->check = 's';
360
                        else return 0;
361
                }
362
                else if (!strcmp(this_char,"conv") && value) {
363
                        /* no conversion is done anymore;
364
                           we still accept the same mount options,
365
                           but ignore them */
366
                        if (value[0] && !value[1] && strchr("btma",*value)) ;
367
                        else if (!strcmp(value,"binary")) ;
368
                        else if (!strcmp(value,"text")) ;
369
                        else if (!strcmp(value,"mtext")) ;
370
                        else if (!strcmp(value,"auto")) ;
371
                        else return 0;
372
                }
373
                else if (value &&
374
                         (!strcmp(this_char,"block") ||
375
                          !strcmp(this_char,"mode") ||
376
                          !strcmp(this_char,"uid") ||
377
                          !strcmp(this_char,"gid"))) {
378
                  char * vpnt = value;
379
                  unsigned int ivalue = simple_strtoul(vpnt, &vpnt, 0);
380
                  if (*vpnt) return 0;
381
                  switch(*this_char) {
382
                  case 'b':
383
                    if (   ivalue != 512
384
                        && ivalue != 1024
385
                        && ivalue != 2048) return 0;
386
                    popt->blocksize = ivalue;
387
                    break;
388
                  case 'u':
389
                    popt->uid = ivalue;
390
                    break;
391
                  case 'g':
392
                    popt->gid = ivalue;
393
                    break;
394
                  case 'm':
395
                    popt->mode = ivalue;
396
                    break;
397
                  }
398
                }
399
                else return 1;
400
        }
401
        return 1;
402
}
403
 
404
/*
405
 * look if the driver can tell the multi session redirection value
406
 *
407
 * don't change this if you don't know what you do, please!
408
 * Multisession is legal only with XA disks.
409
 * A non-XA disk with more than one volume descriptor may do it right, but
410
 * usually is written in a nowhere standardized "multi-partition" manner.
411
 * Multisession uses absolute addressing (solely the first frame of the whole
412
 * track is #0), multi-partition uses relative addressing (each first frame of
413
 * each track is #0), and a track is not a session.
414
 *
415
 * A broken CDwriter software or drive firmware does not set new standards,
416
 * at least not if conflicting with the existing ones.
417
 *
418
 * emoenke@gwdg.de
419
 */
420
#define WE_OBEY_THE_WRITTEN_STANDARDS 1
421
 
422
static unsigned int isofs_get_last_session(struct super_block *sb,s32 session )
423
{
424
        struct cdrom_multisession ms_info;
425
        unsigned int vol_desc_start;
426
        struct block_device *bdev = sb->s_bdev;
427
        int i;
428
 
429
        vol_desc_start=0;
430
        ms_info.addr_format=CDROM_LBA;
431
        if(session >= 0 && session <= 99) {
432
                struct cdrom_tocentry Te;
433
                Te.cdte_track=session;
434
                Te.cdte_format=CDROM_LBA;
435
                i = ioctl_by_bdev(bdev, CDROMREADTOCENTRY, (unsigned long) &Te);
436
                if (!i) {
437
                        printk(KERN_DEBUG "Session %d start %d type %d\n",
438
                               session, Te.cdte_addr.lba,
439
                               Te.cdte_ctrl&CDROM_DATA_TRACK);
440
                        if ((Te.cdte_ctrl&CDROM_DATA_TRACK) == 4)
441
                                return Te.cdte_addr.lba;
442
                }
443
 
444
                printk(KERN_ERR "Invalid session number or type of track\n");
445
        }
446
        i = ioctl_by_bdev(bdev, CDROMMULTISESSION, (unsigned long) &ms_info);
447
        if(session > 0) printk(KERN_ERR "Invalid session number\n");
448
#if 0
449
        printk("isofs.inode: CDROMMULTISESSION: rc=%d\n",i);
450
        if (i==0) {
451
                printk("isofs.inode: XA disk: %s\n",ms_info.xa_flag?"yes":"no");
452
                printk("isofs.inode: vol_desc_start = %d\n", ms_info.addr.lba);
453
        }
454
#endif
455
        if (i==0)
456
#if WE_OBEY_THE_WRITTEN_STANDARDS
457
        if (ms_info.xa_flag) /* necessary for a valid ms_info.addr */
458
#endif
459
                vol_desc_start=ms_info.addr.lba;
460
        return vol_desc_start;
461
}
462
 
463
/*
464
 * Initialize the superblock and read the root inode.
465
 *
466
 * Note: a check_disk_change() has been done immediately prior
467
 * to this call, so we don't need to check again.
468
 */
469
static struct super_block *isofs_read_super(struct super_block *s, void *data,
470
                                            int silent)
471
{
472
        kdev_t                          dev = s->s_dev;
473
        struct buffer_head            * bh = NULL, *pri_bh = NULL;
474
        struct hs_primary_descriptor  * h_pri = NULL;
475
        struct iso_primary_descriptor * pri = NULL;
476
        struct iso_supplementary_descriptor *sec = NULL;
477
        struct iso_directory_record   * rootp;
478
        int                             joliet_level = 0;
479
        int                             high_sierra;
480
        int                             iso_blknum, block;
481
        int                             orig_zonesize;
482
        int                             table;
483
        unsigned int                    blocksize, blocksize_bits;
484
        unsigned int                    vol_desc_start;
485
        unsigned long                   first_data_zone;
486
        struct inode                  * inode;
487
        struct iso9660_options          opt;
488
 
489
        if (!parse_options((char *) data, &opt))
490
                goto out_unlock;
491
 
492
#if 0
493
        printk("map = %c\n", opt.map);
494
        printk("rock = %c\n", opt.rock);
495
        printk("joliet = %c\n", opt.joliet);
496
        printk("check = %c\n", opt.check);
497
        printk("cruft = %c\n", opt.cruft);
498
        printk("unhide = %c\n", opt.unhide);
499
        printk("blocksize = %d\n", opt.blocksize);
500
        printk("gid = %d\n", opt.gid);
501
        printk("uid = %d\n", opt.uid);
502
        printk("iocharset = %s\n", opt.iocharset);
503
#endif
504
 
505
        /*
506
         * First of all, get the hardware blocksize for this device.
507
         * If we don't know what it is, or the hardware blocksize is
508
         * larger than the blocksize the user specified, then use
509
         * that value.
510
         */
511
        blocksize = get_hardsect_size(dev);
512
        if(blocksize > opt.blocksize) {
513
            /*
514
             * Force the blocksize we are going to use to be the
515
             * hardware blocksize.
516
             */
517
            opt.blocksize = blocksize;
518
        }
519
 
520
        blocksize_bits = 0;
521
        {
522
          int i = opt.blocksize;
523
          while (i != 1){
524
            blocksize_bits++;
525
            i >>=1;
526
          }
527
        }
528
 
529
        set_blocksize(dev, opt.blocksize);
530
        s->s_blocksize = opt.blocksize;
531
 
532
        s->u.isofs_sb.s_high_sierra = high_sierra = 0; /* default is iso9660 */
533
 
534
        vol_desc_start = (opt.sbsector != -1) ?
535
                opt.sbsector : isofs_get_last_session(s,opt.session);
536
 
537
        for (iso_blknum = vol_desc_start+16;
538
             iso_blknum < vol_desc_start+100; iso_blknum++)
539
        {
540
            struct hs_volume_descriptor   * hdp;
541
            struct iso_volume_descriptor  * vdp;
542
 
543
            block = iso_blknum << (ISOFS_BLOCK_BITS-blocksize_bits);
544
            if (!(bh = sb_bread(s, block)))
545
                goto out_no_read;
546
 
547
            vdp = (struct iso_volume_descriptor *)bh->b_data;
548
            hdp = (struct hs_volume_descriptor *)bh->b_data;
549
 
550
            /* Due to the overlapping physical location of the descriptors,
551
             * ISO CDs can match hdp->id==HS_STANDARD_ID as well. To ensure
552
             * proper identification in this case, we first check for ISO.
553
             */
554
            if (strncmp (vdp->id, ISO_STANDARD_ID, sizeof vdp->id) == 0) {
555
                if (isonum_711 (vdp->type) == ISO_VD_END)
556
                    break;
557
                if (isonum_711 (vdp->type) == ISO_VD_PRIMARY) {
558
                    if (pri == NULL) {
559
                        pri = (struct iso_primary_descriptor *)vdp;
560
                        /* Save the buffer in case we need it ... */
561
                        pri_bh = bh;
562
                        bh = NULL;
563
                    }
564
                }
565
#ifdef CONFIG_JOLIET
566
                else if (isonum_711 (vdp->type) == ISO_VD_SUPPLEMENTARY) {
567
                    sec = (struct iso_supplementary_descriptor *)vdp;
568
                    if (sec->escape[0] == 0x25 && sec->escape[1] == 0x2f) {
569
                        if (opt.joliet == 'y') {
570
                            if (sec->escape[2] == 0x40) {
571
                                joliet_level = 1;
572
                            } else if (sec->escape[2] == 0x43) {
573
                                joliet_level = 2;
574
                            } else if (sec->escape[2] == 0x45) {
575
                                joliet_level = 3;
576
                            }
577
                            printk(KERN_DEBUG"ISO 9660 Extensions: Microsoft Joliet Level %d\n",
578
                                   joliet_level);
579
                        }
580
                        goto root_found;
581
                    } else {
582
                        /* Unknown supplementary volume descriptor */
583
                        sec = NULL;
584
                    }
585
                }
586
#endif
587
            } else {
588
                if (strncmp (hdp->id, HS_STANDARD_ID, sizeof hdp->id) == 0) {
589
                    if (isonum_711 (hdp->type) != ISO_VD_PRIMARY)
590
                        goto out_freebh;
591
 
592
                    s->u.isofs_sb.s_high_sierra = 1;
593
                    high_sierra = 1;
594
                    opt.rock = 'n';
595
                    h_pri = (struct hs_primary_descriptor *)vdp;
596
                    goto root_found;
597
                }
598
            }
599
 
600
            /* Just skip any volume descriptors we don't recognize */
601
 
602
            brelse(bh);
603
            bh = NULL;
604
        }
605
        /*
606
         * If we fall through, either no volume descriptor was found,
607
         * or else we passed a primary descriptor looking for others.
608
         */
609
        if (!pri)
610
                goto out_unknown_format;
611
        brelse(bh);
612
        bh = pri_bh;
613
        pri_bh = NULL;
614
 
615
root_found:
616
 
617
        if (joliet_level && (pri == NULL || opt.rock == 'n')) {
618
            /* This is the case of Joliet with the norock mount flag.
619
             * A disc with both Joliet and Rock Ridge is handled later
620
             */
621
            pri = (struct iso_primary_descriptor *) sec;
622
        }
623
 
624
        if(high_sierra){
625
          rootp = (struct iso_directory_record *) h_pri->root_directory_record;
626
#ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
627
          if (isonum_723 (h_pri->volume_set_size) != 1)
628
                goto out_no_support;
629
#endif /* IGNORE_WRONG_MULTI_VOLUME_SPECS */
630
          s->u.isofs_sb.s_nzones = isonum_733 (h_pri->volume_space_size);
631
          s->u.isofs_sb.s_log_zone_size = isonum_723 (h_pri->logical_block_size);
632
          s->u.isofs_sb.s_max_size = isonum_733(h_pri->volume_space_size);
633
        } else {
634
          rootp = (struct iso_directory_record *) pri->root_directory_record;
635
#ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
636
          if (isonum_723 (pri->volume_set_size) != 1)
637
                goto out_no_support;
638
#endif /* IGNORE_WRONG_MULTI_VOLUME_SPECS */
639
          s->u.isofs_sb.s_nzones = isonum_733 (pri->volume_space_size);
640
          s->u.isofs_sb.s_log_zone_size = isonum_723 (pri->logical_block_size);
641
          s->u.isofs_sb.s_max_size = isonum_733(pri->volume_space_size);
642
        }
643
 
644
        s->u.isofs_sb.s_ninodes = 0; /* No way to figure this out easily */
645
 
646
        orig_zonesize = s -> u.isofs_sb.s_log_zone_size;
647
        /*
648
         * If the zone size is smaller than the hardware sector size,
649
         * this is a fatal error.  This would occur if the disc drive
650
         * had sectors that were 2048 bytes, but the filesystem had
651
         * blocks that were 512 bytes (which should only very rarely
652
         * happen.)
653
         */
654
        if(blocksize != 0 && orig_zonesize < blocksize)
655
                goto out_bad_size;
656
 
657
        /* RDE: convert log zone size to bit shift */
658
        switch (s -> u.isofs_sb.s_log_zone_size)
659
          { case  512: s -> u.isofs_sb.s_log_zone_size =  9; break;
660
            case 1024: s -> u.isofs_sb.s_log_zone_size = 10; break;
661
            case 2048: s -> u.isofs_sb.s_log_zone_size = 11; break;
662
 
663
            default:
664
                goto out_bad_zone_size;
665
          }
666
 
667
        s->s_magic = ISOFS_SUPER_MAGIC;
668
 
669
        /* The CDROM is read-only, has no nodes (devices) on it, and since
670
           all of the files appear to be owned by root, we really do not want
671
           to allow suid.  (suid or devices will not show up unless we have
672
           Rock Ridge extensions) */
673
 
674
        s->s_flags |= MS_RDONLY /* | MS_NODEV | MS_NOSUID */;
675
 
676
        /* Set this for reference. Its not currently used except on write
677
           which we don't have .. */
678
 
679
        /* RDE: data zone now byte offset! */
680
 
681
        first_data_zone = ((isonum_733 (rootp->extent) +
682
                          isonum_711 (rootp->ext_attr_length))
683
                         << s -> u.isofs_sb.s_log_zone_size);
684
        s->u.isofs_sb.s_firstdatazone = first_data_zone;
685
#ifndef BEQUIET
686
        printk(KERN_DEBUG "Max size:%ld   Log zone size:%ld\n",
687
               s->u.isofs_sb.s_max_size,
688
               1UL << s->u.isofs_sb.s_log_zone_size);
689
        printk(KERN_DEBUG "First datazone:%ld   Root inode number:%ld\n",
690
               s->u.isofs_sb.s_firstdatazone >> s -> u.isofs_sb.s_log_zone_size,
691
               s->u.isofs_sb.s_firstdatazone);
692
        if(high_sierra)
693
                printk(KERN_DEBUG "Disc in High Sierra format.\n");
694
#endif
695
 
696
        /*
697
         * If the Joliet level is set, we _may_ decide to use the
698
         * secondary descriptor, but can't be sure until after we
699
         * read the root inode. But before reading the root inode
700
         * we may need to change the device blocksize, and would
701
         * rather release the old buffer first. So, we cache the
702
         * first_data_zone value from the secondary descriptor.
703
         */
704
        if (joliet_level) {
705
                pri = (struct iso_primary_descriptor *) sec;
706
                rootp = (struct iso_directory_record *)
707
                        pri->root_directory_record;
708
                first_data_zone = ((isonum_733 (rootp->extent) +
709
                                isonum_711 (rootp->ext_attr_length))
710
                                 << s -> u.isofs_sb.s_log_zone_size);
711
        }
712
 
713
        /*
714
         * We're all done using the volume descriptor, and may need
715
         * to change the device blocksize, so release the buffer now.
716
         */
717
        brelse(pri_bh);
718
        brelse(bh);
719
 
720
        /*
721
         * Force the blocksize to 512 for 512 byte sectors.  The file
722
         * read primitives really get it wrong in a bad way if we don't
723
         * do this.
724
         *
725
         * Note - we should never be setting the blocksize to something
726
         * less than the hardware sector size for the device.  If we
727
         * do, we would end up having to read larger buffers and split
728
         * out portions to satisfy requests.
729
         *
730
         * Note2- the idea here is that we want to deal with the optimal
731
         * zonesize in the filesystem.  If we have it set to something less,
732
         * then we have horrible problems with trying to piece together
733
         * bits of adjacent blocks in order to properly read directory
734
         * entries.  By forcing the blocksize in this way, we ensure
735
         * that we will never be required to do this.
736
         */
737
        if ( orig_zonesize != opt.blocksize ) {
738
                set_blocksize(dev, orig_zonesize);
739
#ifndef BEQUIET
740
                printk(KERN_DEBUG
741
                        "ISOFS: Forcing new log zone size:%d\n", orig_zonesize);
742
#endif
743
        }
744
        s->s_blocksize = orig_zonesize;
745
        s->s_blocksize_bits = s -> u.isofs_sb.s_log_zone_size;
746
 
747
        s->u.isofs_sb.s_nls_iocharset = NULL;
748
 
749
#ifdef CONFIG_JOLIET
750
        if (joliet_level && opt.utf8 == 0) {
751
                char * p = opt.iocharset ? opt.iocharset : "iso8859-1";
752
                s->u.isofs_sb.s_nls_iocharset = load_nls(p);
753
                if (! s->u.isofs_sb.s_nls_iocharset) {
754
                        /* Fail only if explicit charset specified */
755
                        if (opt.iocharset)
756
                                goto out_unlock;
757
                        s->u.isofs_sb.s_nls_iocharset = load_nls_default();
758
                }
759
        }
760
#endif
761
        s->s_op = &isofs_sops;
762
        s->u.isofs_sb.s_mapping = opt.map;
763
        s->u.isofs_sb.s_rock = (opt.rock == 'y' ? 2 : 0);
764
        s->u.isofs_sb.s_rock_offset = -1; /* initial offset, will guess until SP is found*/
765
        s->u.isofs_sb.s_cruft = opt.cruft;
766
        s->u.isofs_sb.s_unhide = opt.unhide;
767
        s->u.isofs_sb.s_uid = opt.uid;
768
        s->u.isofs_sb.s_gid = opt.gid;
769
        s->u.isofs_sb.s_utf8 = opt.utf8;
770
        s->u.isofs_sb.s_nocompress = opt.nocompress;
771
        /*
772
         * It would be incredibly stupid to allow people to mark every file
773
         * on the disk as suid, so we merely allow them to set the default
774
         * permissions.
775
         */
776
        s->u.isofs_sb.s_mode = opt.mode & 0777;
777
 
778
        /*
779
         * Read the root inode, which _may_ result in changing
780
         * the s_rock flag. Once we have the final s_rock value,
781
         * we then decide whether to use the Joliet descriptor.
782
         */
783
        inode = iget(s, s->u.isofs_sb.s_firstdatazone);
784
 
785
        /*
786
         * If this disk has both Rock Ridge and Joliet on it, then we
787
         * want to use Rock Ridge by default.  This can be overridden
788
         * by using the norock mount option.  There is still one other
789
         * possibility that is not taken into account: a Rock Ridge
790
         * CD with Unicode names.  Until someone sees such a beast, it
791
         * will not be supported.
792
         */
793
        if (s->u.isofs_sb.s_rock == 1) {
794
                joliet_level = 0;
795
        } else if (joliet_level) {
796
                s->u.isofs_sb.s_rock = 0;
797
                if (s->u.isofs_sb.s_firstdatazone != first_data_zone) {
798
                        s->u.isofs_sb.s_firstdatazone = first_data_zone;
799
                        printk(KERN_DEBUG
800
                                "ISOFS: changing to secondary root\n");
801
                        iput(inode);
802
                        inode = iget(s, s->u.isofs_sb.s_firstdatazone);
803
                }
804
        }
805
 
806
        if (opt.check == 'u') {
807
                /* Only Joliet is case insensitive by default */
808
                if (joliet_level) opt.check = 'r';
809
                else opt.check = 's';
810
        }
811
        s->u.isofs_sb.s_joliet_level = joliet_level;
812
 
813
        /* check the root inode */
814
        if (!inode)
815
                goto out_no_root;
816
        if (!inode->i_op)
817
                goto out_bad_root;
818
        /* get the root dentry */
819
        s->s_root = d_alloc_root(inode);
820
        if (!(s->s_root))
821
                goto out_no_root;
822
 
823
        table = 0;
824
        if (joliet_level) table += 2;
825
        if (opt.check == 'r') table++;
826
        s->s_root->d_op = &isofs_dentry_ops[table];
827
 
828
        return s;
829
 
830
        /*
831
         * Display error messages and free resources.
832
         */
833
out_bad_root:
834
        printk(KERN_WARNING "isofs_read_super: root inode not initialized\n");
835
        goto out_iput;
836
out_no_root:
837
        printk(KERN_WARNING "isofs_read_super: get root inode failed\n");
838
out_iput:
839
        iput(inode);
840
#ifdef CONFIG_JOLIET
841
        if (s->u.isofs_sb.s_nls_iocharset)
842
                unload_nls(s->u.isofs_sb.s_nls_iocharset);
843
#endif
844
        goto out_unlock;
845
out_no_read:
846
        printk(KERN_WARNING "isofs_read_super: "
847
                "bread failed, dev=%s, iso_blknum=%d, block=%d\n",
848
                kdevname(dev), iso_blknum, block);
849
        goto out_unlock;
850
out_bad_zone_size:
851
        printk(KERN_WARNING "Bad logical zone size %ld\n",
852
                s->u.isofs_sb.s_log_zone_size);
853
        goto out_freebh;
854
out_bad_size:
855
        printk(KERN_WARNING "Logical zone size(%d) < hardware blocksize(%u)\n",
856
                orig_zonesize, blocksize);
857
        goto out_freebh;
858
#ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
859
out_no_support:
860
        printk(KERN_WARNING "Multi-volume disks not supported.\n");
861
        goto out_freebh;
862
#endif
863
out_unknown_format:
864
        if (!silent)
865
                printk(KERN_WARNING "Unable to identify CD-ROM format.\n");
866
 
867
out_freebh:
868
        brelse(bh);
869
out_unlock:
870
        return NULL;
871
}
872
 
873
static int isofs_statfs (struct super_block *sb, struct statfs *buf)
874
{
875
        buf->f_type = ISOFS_SUPER_MAGIC;
876
        buf->f_bsize = sb->s_blocksize;
877
        buf->f_blocks = (sb->u.isofs_sb.s_nzones
878
                  << (sb->u.isofs_sb.s_log_zone_size - sb->s_blocksize_bits));
879
        buf->f_bfree = 0;
880
        buf->f_bavail = 0;
881
        buf->f_files = sb->u.isofs_sb.s_ninodes;
882
        buf->f_ffree = 0;
883
        buf->f_namelen = NAME_MAX;
884
        return 0;
885
}
886
 
887
/*
888
 * Get a set of blocks; filling in buffer_heads if already allocated
889
 * or getblk() if they are not.  Returns the number of blocks inserted
890
 * (0 == error.)
891
 */
892
int isofs_get_blocks(struct inode *inode, long iblock,
893
                     struct buffer_head **bh_result, unsigned long nblocks)
894
{
895
        unsigned long b_off;
896
        unsigned offset, sect_size;
897
        unsigned int firstext;
898
        unsigned long nextino;
899
        int section, rv;
900
 
901
        lock_kernel();
902
 
903
        rv = 0;
904
        if (iblock < 0) {
905
                printk("isofs_get_blocks: block < 0\n");
906
                goto abort;
907
        }
908
 
909
        b_off = iblock;
910
 
911
        offset    = 0;
912
        firstext  = inode->u.isofs_i.i_first_extent;
913
        sect_size = inode->u.isofs_i.i_section_size >> ISOFS_BUFFER_BITS(inode);
914
        nextino   = inode->u.isofs_i.i_next_section_ino;
915
        section   = 0;
916
 
917
        while ( nblocks ) {
918
                /* If we are *way* beyond the end of the file, print a message.
919
                 * Access beyond the end of the file up to the next page boundary
920
                 * is normal, however because of the way the page cache works.
921
                 * In this case, we just return 0 so that we can properly fill
922
                 * the page with useless information without generating any
923
                 * I/O errors.
924
                 */
925
                if (b_off > ((inode->i_size + PAGE_CACHE_SIZE - 1) >> ISOFS_BUFFER_BITS(inode))) {
926
                        printk("isofs_get_blocks: block >= EOF (%ld, %ld)\n",
927
                               iblock, (unsigned long) inode->i_size);
928
                        goto abort;
929
                }
930
 
931
                if (nextino) {
932
                        while (b_off >= (offset + sect_size)) {
933
                                struct inode *ninode;
934
 
935
                                offset += sect_size;
936
                                if (nextino == 0)
937
                                        goto abort;
938
                                ninode = iget(inode->i_sb, nextino);
939
                                if (!ninode)
940
                                        goto abort;
941
                                firstext  = ninode->u.isofs_i.i_first_extent;
942
                                sect_size = ninode->u.isofs_i.i_section_size;
943
                                nextino   = ninode->u.isofs_i.i_next_section_ino;
944
                                iput(ninode);
945
 
946
                                if (++section > 100) {
947
                                        printk("isofs_get_blocks: More than 100 file sections ?!?, aborting...\n");
948
                                        printk("isofs_get_blocks: ino=%lu block=%ld firstext=%u sect_size=%u nextino=%lu\n",
949
                                               inode->i_ino, iblock, firstext, (unsigned) sect_size, nextino);
950
                                        goto abort;
951
                                }
952
                        }
953
                }
954
 
955
                if ( *bh_result ) {
956
                        (*bh_result)->b_dev      = inode->i_dev;
957
                        (*bh_result)->b_blocknr  = firstext + b_off - offset;
958
                        (*bh_result)->b_state   |= (1UL << BH_Mapped);
959
                } else {
960
                        *bh_result = sb_getblk(inode->i_sb, firstext+b_off-offset);
961
                        if ( !*bh_result )
962
                                goto abort;
963
                }
964
                bh_result++;    /* Next buffer head */
965
                b_off++;        /* Next buffer offset */
966
                nblocks--;
967
                rv++;
968
        }
969
 
970
 
971
abort:
972
        unlock_kernel();
973
        return rv;
974
}
975
 
976
/*
977
 * Used by the standard interfaces.
978
 */
979
static int isofs_get_block(struct inode *inode, long iblock,
980
                    struct buffer_head *bh_result, int create)
981
{
982
        if ( create ) {
983
                printk("isofs_get_block: Kernel tries to allocate a block\n");
984
                return -EROFS;
985
        }
986
 
987
        return isofs_get_blocks(inode, iblock, &bh_result, 1) ? 0 : -EIO;
988
}
989
 
990
static int isofs_bmap(struct inode *inode, int block)
991
{
992
        struct buffer_head dummy;
993
        int error;
994
 
995
        dummy.b_state = 0;
996
        dummy.b_blocknr = -1000;
997
        error = isofs_get_block(inode, block, &dummy, 0);
998
        if (!error)
999
                return dummy.b_blocknr;
1000
        return 0;
1001
}
1002
 
1003
struct buffer_head *isofs_bread(struct inode *inode, unsigned int block)
1004
{
1005
        unsigned int blknr = isofs_bmap(inode, block);
1006
        if (!blknr)
1007
                return NULL;
1008
        return sb_bread(inode->i_sb, blknr);
1009
}
1010
 
1011
static int isofs_readpage(struct file *file, struct page *page)
1012
{
1013
        return block_read_full_page(page,isofs_get_block);
1014
}
1015
 
1016
static int _isofs_bmap(struct address_space *mapping, long block)
1017
{
1018
        return generic_block_bmap(mapping,block,isofs_get_block);
1019
}
1020
 
1021
static struct address_space_operations isofs_aops = {
1022
        readpage: isofs_readpage,
1023
        sync_page: block_sync_page,
1024
        bmap: _isofs_bmap
1025
};
1026
 
1027
static inline void test_and_set_uid(uid_t *p, uid_t value)
1028
{
1029
        if(value) {
1030
                *p = value;
1031
        }
1032
}
1033
 
1034
static inline void test_and_set_gid(gid_t *p, gid_t value)
1035
{
1036
        if(value) {
1037
                *p = value;
1038
        }
1039
}
1040
 
1041
static int isofs_read_level3_size(struct inode * inode)
1042
{
1043
        unsigned long f_pos = inode->i_ino;
1044
        unsigned long bufsize = ISOFS_BUFFER_SIZE(inode);
1045
        int high_sierra = inode->i_sb->u.isofs_sb.s_high_sierra;
1046
        struct buffer_head * bh = NULL;
1047
        unsigned long block, offset;
1048
        int i = 0;
1049
        int more_entries = 0;
1050
        struct iso_directory_record * tmpde = NULL;
1051
 
1052
        inode->i_size = 0;
1053
        inode->u.isofs_i.i_next_section_ino = 0;
1054
 
1055
        block = f_pos >> ISOFS_BUFFER_BITS(inode);
1056
        offset = f_pos & (bufsize-1);
1057
 
1058
        do {
1059
                struct iso_directory_record * de;
1060
                unsigned int de_len;
1061
 
1062
                if (!bh) {
1063
                        bh = sb_bread(inode->i_sb, block);
1064
                        if (!bh)
1065
                                goto out_noread;
1066
                }
1067
                de = (struct iso_directory_record *) (bh->b_data + offset);
1068
                de_len = *(unsigned char *) de;
1069
 
1070
                if (de_len == 0) {
1071
                        brelse(bh);
1072
                        bh = NULL;
1073
                        f_pos = (f_pos + ISOFS_BLOCK_SIZE) & ~(ISOFS_BLOCK_SIZE - 1);
1074
                        block = f_pos >> ISOFS_BUFFER_BITS(inode);
1075
                        offset = 0;
1076
                        continue;
1077
                }
1078
 
1079
                offset += de_len;
1080
 
1081
                /* Make sure we have a full directory entry */
1082
                if (offset >= bufsize) {
1083
                        int slop = bufsize - offset + de_len;
1084
                        if (!tmpde) {
1085
                                tmpde = kmalloc(256, GFP_KERNEL);
1086
                                if (!tmpde)
1087
                                        goto out_nomem;
1088
                        }
1089
                        memcpy(tmpde, de, slop);
1090
                        offset &= bufsize - 1;
1091
                        block++;
1092
                        brelse(bh);
1093
                        bh = NULL;
1094
                        if (offset) {
1095
                                bh = sb_bread(inode->i_sb, block);
1096
                                if (!bh)
1097
                                        goto out_noread;
1098
                                memcpy((void *) tmpde + slop, bh->b_data, offset);
1099
                        }
1100
                        de = tmpde;
1101
                }
1102
 
1103
                inode->i_size += isonum_733(de->size);
1104
                if (i == 1)
1105
                        inode->u.isofs_i.i_next_section_ino = f_pos;
1106
 
1107
                more_entries = de->flags[-high_sierra] & 0x80;
1108
 
1109
                f_pos += de_len;
1110
                i++;
1111
                if(i > 100)
1112
                        goto out_toomany;
1113
        } while(more_entries);
1114
out:
1115
        if (tmpde)
1116
                kfree(tmpde);
1117
        if (bh)
1118
                brelse(bh);
1119
        return 0;
1120
 
1121
out_nomem:
1122
        if (bh)
1123
                brelse(bh);
1124
        return -ENOMEM;
1125
 
1126
out_noread:
1127
        printk(KERN_INFO "ISOFS: unable to read i-node block %lu\n", block);
1128
        if (tmpde)
1129
                kfree(tmpde);
1130
        return -EIO;
1131
 
1132
out_toomany:
1133
        printk(KERN_INFO "isofs_read_level3_size: "
1134
                "More than 100 file sections ?!?, aborting...\n"
1135
                "isofs_read_level3_size: inode=%lu ino=%lu\n",
1136
                inode->i_ino, f_pos);
1137
        goto out;
1138
}
1139
 
1140
static void isofs_read_inode(struct inode * inode)
1141
{
1142
        struct super_block *sb = inode->i_sb;
1143
        unsigned long bufsize = ISOFS_BUFFER_SIZE(inode);
1144
        int block = inode->i_ino >> ISOFS_BUFFER_BITS(inode);
1145
        int high_sierra = sb->u.isofs_sb.s_high_sierra;
1146
        struct buffer_head * bh = NULL;
1147
        struct iso_directory_record * de;
1148
        struct iso_directory_record * tmpde = NULL;
1149
        unsigned int de_len;
1150
        unsigned long offset;
1151
        int volume_seq_no, i;
1152
 
1153
        bh = sb_bread(inode->i_sb, block);
1154
        if (!bh)
1155
                goto out_badread;
1156
 
1157
        offset = (inode->i_ino & (bufsize - 1));
1158
        de = (struct iso_directory_record *) (bh->b_data + offset);
1159
        de_len = *(unsigned char *) de;
1160
 
1161
        if (offset + de_len > bufsize) {
1162
                int frag1 = bufsize - offset;
1163
 
1164
                tmpde = kmalloc(de_len, GFP_KERNEL);
1165
                if (tmpde == NULL) {
1166
                        printk(KERN_INFO "isofs_read_inode: out of memory\n");
1167
                        goto fail;
1168
                }
1169
                memcpy(tmpde, bh->b_data + offset, frag1);
1170
                brelse(bh);
1171
                bh = sb_bread(inode->i_sb, ++block);
1172
                if (!bh)
1173
                        goto out_badread;
1174
                memcpy((char *)tmpde+frag1, bh->b_data, de_len - frag1);
1175
                de = tmpde;
1176
        }
1177
 
1178
        /* Assume it is a normal-format file unless told otherwise */
1179
        inode->u.isofs_i.i_file_format = isofs_file_normal;
1180
 
1181
        if (de->flags[-high_sierra] & 2) {
1182
                inode->i_mode = S_IRUGO | S_IXUGO | S_IFDIR;
1183
                inode->i_nlink = 1; /* Set to 1.  We know there are 2, but
1184
                                       the find utility tries to optimize
1185
                                       if it is 2, and it screws up.  It is
1186
                                       easier to give 1 which tells find to
1187
                                       do it the hard way. */
1188
        } else {
1189
                /* Everybody gets to read the file. */
1190
                inode->i_mode = inode->i_sb->u.isofs_sb.s_mode;
1191
                inode->i_nlink = 1;
1192
                inode->i_mode |= S_IFREG;
1193
                /* If there are no periods in the name,
1194
                 * then set the execute permission bit
1195
                 */
1196
                for(i=0; i< de->name_len[0]; i++)
1197
                        if(de->name[i]=='.' || de->name[i]==';')
1198
                                break;
1199
                if(i == de->name_len[0] || de->name[i] == ';')
1200
                        inode->i_mode |= S_IXUGO; /* execute permission */
1201
        }
1202
        inode->i_uid = inode->i_sb->u.isofs_sb.s_uid;
1203
        inode->i_gid = inode->i_sb->u.isofs_sb.s_gid;
1204
        inode->i_blocks = inode->i_blksize = 0;
1205
 
1206
 
1207
        inode->u.isofs_i.i_section_size = isonum_733 (de->size);
1208
        if(de->flags[-high_sierra] & 0x80) {
1209
                if(isofs_read_level3_size(inode)) goto fail;
1210
        } else {
1211
                inode->i_size = isonum_733 (de->size);
1212
        }
1213
 
1214
        /*
1215
         * The ISO-9660 filesystem only stores 32 bits for file size.
1216
         * mkisofs handles files up to 2GB-2 = 2147483646 = 0x7FFFFFFE bytes
1217
         * in size. This is according to the large file summit paper from 1996.
1218
         * WARNING: ISO-9660 filesystems > 1 GB and even > 2 GB are fully
1219
         *          legal. Do not prevent to use DVD's schilling@fokus.gmd.de
1220
         */
1221
        if ((inode->i_size < 0 || inode->i_size > 0x7FFFFFFE) &&
1222
            inode->i_sb->u.isofs_sb.s_cruft == 'n') {
1223
                printk(KERN_WARNING "Warning: defective CD-ROM.  "
1224
                       "Enabling \"cruft\" mount option.\n");
1225
                inode->i_sb->u.isofs_sb.s_cruft = 'y';
1226
        }
1227
 
1228
        /*
1229
         * Some dipshit decided to store some other bit of information
1230
         * in the high byte of the file length.  Catch this and holler.
1231
         * WARNING: this will make it impossible for a file to be > 16MB
1232
         * on the CDROM.
1233
         */
1234
 
1235
        if (inode->i_sb->u.isofs_sb.s_cruft == 'y' &&
1236
            inode->i_size & 0xff000000) {
1237
                inode->i_size &= 0x00ffffff;
1238
        }
1239
 
1240
        if (de->interleave[0]) {
1241
                printk("Interleaved files not (yet) supported.\n");
1242
                inode->i_size = 0;
1243
        }
1244
 
1245
        /* I have no idea what file_unit_size is used for, so
1246
           we will flag it for now */
1247
        if (de->file_unit_size[0] != 0) {
1248
                printk("File unit size != 0 for ISO file (%ld).\n",
1249
                       inode->i_ino);
1250
        }
1251
 
1252
        /* I have no idea what other flag bits are used for, so
1253
           we will flag it for now */
1254
#ifdef DEBUG
1255
        if((de->flags[-high_sierra] & ~2)!= 0){
1256
                printk("Unusual flag settings for ISO file (%ld %x).\n",
1257
                       inode->i_ino, de->flags[-high_sierra]);
1258
        }
1259
#endif
1260
 
1261
        inode->i_mtime = inode->i_atime = inode->i_ctime =
1262
                iso_date(de->date, high_sierra);
1263
 
1264
        inode->u.isofs_i.i_first_extent = (isonum_733 (de->extent) +
1265
                                           isonum_711 (de->ext_attr_length));
1266
 
1267
        /* Set the number of blocks for stat() - should be done before RR */
1268
        inode->i_blksize = PAGE_CACHE_SIZE; /* For stat() only */
1269
        inode->i_blocks  = (inode->i_size + 511) >> 9;
1270
 
1271
        /*
1272
         * Now test for possible Rock Ridge extensions which will override
1273
         * some of these numbers in the inode structure.
1274
         */
1275
 
1276
        if (!high_sierra) {
1277
                parse_rock_ridge_inode(de, inode);
1278
                /* if we want uid/gid set, override the rock ridge setting */
1279
                test_and_set_uid(&inode->i_uid, inode->i_sb->u.isofs_sb.s_uid);
1280
                test_and_set_gid(&inode->i_gid, inode->i_sb->u.isofs_sb.s_gid);
1281
        }
1282
 
1283
        /* get the volume sequence number */
1284
        volume_seq_no = isonum_723 (de->volume_sequence_number) ;
1285
 
1286
    /*
1287
     * Multi volume means tagging a group of CDs with info in their headers.
1288
     * All CDs of a group must share the same vol set name and vol set size
1289
     * and have different vol set seq num. Deciding that data is wrong based
1290
     * in that three fields is wrong. The fields are informative, for
1291
     * cataloging purposes in a big jukebox, ie. Read sections 4.17, 4.18, 6.6
1292
     * of ftp://ftp.ecma.ch/ecma-st/Ecma-119.pdf (ECMA 119 2nd Ed = ISO 9660)
1293
     */
1294
#ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
1295
        /*
1296
         * Disable checking if we see any volume number other than 0 or 1.
1297
         * We could use the cruft option, but that has multiple purposes, one
1298
         * of which is limiting the file size to 16Mb.  Thus we silently allow
1299
         * volume numbers of 0 to go through without complaining.
1300
         */
1301
        if (inode->i_sb->u.isofs_sb.s_cruft == 'n' &&
1302
            (volume_seq_no != 0) && (volume_seq_no != 1)) {
1303
                printk(KERN_WARNING "Warning: defective CD-ROM "
1304
                       "(volume sequence number %d). "
1305
                       "Enabling \"cruft\" mount option.\n", volume_seq_no);
1306
                inode->i_sb->u.isofs_sb.s_cruft = 'y';
1307
        }
1308
#endif /*IGNORE_WRONG_MULTI_VOLUME_SPECS */
1309
 
1310
        /* Install the inode operations vector */
1311
#ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
1312
        if (inode->i_sb->u.isofs_sb.s_cruft != 'y' &&
1313
            (volume_seq_no != 0) && (volume_seq_no != 1)) {
1314
                printk(KERN_WARNING "Multi-volume CD somehow got mounted.\n");
1315
        } else
1316
#endif /*IGNORE_WRONG_MULTI_VOLUME_SPECS */
1317
        {
1318
                if (S_ISREG(inode->i_mode)) {
1319
                        inode->i_fop = &generic_ro_fops;
1320
                        switch ( inode->u.isofs_i.i_file_format ) {
1321
#ifdef CONFIG_ZISOFS
1322
                        case isofs_file_compressed:
1323
                                inode->i_data.a_ops = &zisofs_aops;
1324
                                break;
1325
#endif
1326
                        default:
1327
                                inode->i_data.a_ops = &isofs_aops;
1328
                                break;
1329
                        }
1330
                } else if (S_ISDIR(inode->i_mode)) {
1331
                        inode->i_op = &isofs_dir_inode_operations;
1332
                        inode->i_fop = &isofs_dir_operations;
1333
                } else if (S_ISLNK(inode->i_mode)) {
1334
                        inode->i_op = &page_symlink_inode_operations;
1335
                        inode->i_data.a_ops = &isofs_symlink_aops;
1336
                } else
1337
                        /* XXX - parse_rock_ridge_inode() had already set i_rdev. */
1338
                        init_special_inode(inode, inode->i_mode,
1339
                                           kdev_t_to_nr(inode->i_rdev));
1340
        }
1341
 out:
1342
        if (tmpde)
1343
                kfree(tmpde);
1344
        if (bh)
1345
                brelse(bh);
1346
        return;
1347
 
1348
 out_badread:
1349
        printk(KERN_WARNING "ISOFS: unable to read i-node block\n");
1350
 fail:
1351
        make_bad_inode(inode);
1352
        goto out;
1353
}
1354
 
1355
#ifdef LEAK_CHECK
1356
#undef malloc
1357
#undef free_s
1358
#undef sb_bread
1359
#undef brelse
1360
 
1361
void * leak_check_malloc(unsigned int size){
1362
  void * tmp;
1363
  check_malloc++;
1364
  tmp = kmalloc(size, GFP_KERNEL);
1365
  return tmp;
1366
}
1367
 
1368
void leak_check_free_s(void * obj, int size){
1369
  check_malloc--;
1370
  return kfree(obj);
1371
}
1372
 
1373
struct buffer_head * leak_check_bread(struct super_block *sb, int block){
1374
  check_bread++;
1375
  return sb_bread(sb, block);
1376
}
1377
 
1378
void leak_check_brelse(struct buffer_head * bh){
1379
  check_bread--;
1380
  return brelse(bh);
1381
}
1382
 
1383
#endif
1384
 
1385
static DECLARE_FSTYPE_DEV(iso9660_fs_type, "iso9660", isofs_read_super);
1386
 
1387
static int __init init_iso9660_fs(void)
1388
{
1389
#ifdef CONFIG_ZISOFS
1390
        int err;
1391
 
1392
        err = zisofs_init();
1393
        if ( err )
1394
                return err;
1395
#endif
1396
        return register_filesystem(&iso9660_fs_type);
1397
}
1398
 
1399
static void __exit exit_iso9660_fs(void)
1400
{
1401
        unregister_filesystem(&iso9660_fs_type);
1402
#ifdef CONFIG_ZISOFS
1403
        zisofs_cleanup();
1404
#endif
1405
}
1406
 
1407
EXPORT_NO_SYMBOLS;
1408
 
1409
module_init(init_iso9660_fs)
1410
module_exit(exit_iso9660_fs)
1411
MODULE_LICENSE("GPL");
1412
 

powered by: WebSVN 2.1.0

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