2 * linux/fs/isofs/inode.c
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
12 #include <linux/config.h>
13 #include <linux/module.h>
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>
21 #include <linux/string.h>
22 #include <linux/locks.h>
23 #include <linux/malloc.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>
31 #include <asm/system.h>
32 #include <asm/uaccess.h>
35 * We have no support for "multi volume" CDs, but more and more disks carry
36 * wrong information within the volume descriptors.
38 #define IGNORE_WRONG_MULTI_VOLUME_SPECS
42 static int check_malloc
= 0;
43 static int check_bread
= 0;
46 static int isofs_hashi(struct dentry
*parent
, struct qstr
*qstr
);
47 static int isofs_hash(struct dentry
*parent
, struct qstr
*qstr
);
48 static int isofs_cmpi(struct dentry
*dentry
, struct qstr
*a
, struct qstr
*b
);
49 static int isofs_cmp(struct dentry
*dentry
, struct qstr
*a
, struct qstr
*b
);
52 static int isofs_hashi_ms(struct dentry
*parent
, struct qstr
*qstr
);
53 static int isofs_hash_ms(struct dentry
*parent
, struct qstr
*qstr
);
54 static int isofs_cmpi_ms(struct dentry
*dentry
, struct qstr
*a
, struct qstr
*b
);
55 static int isofs_cmp_ms(struct dentry
*dentry
, struct qstr
*a
, struct qstr
*b
);
58 static void isofs_put_super(struct super_block
*sb
)
61 if (sb
->u
.isofs_sb
.s_nls_iocharset
) {
62 unload_nls(sb
->u
.isofs_sb
.s_nls_iocharset
);
63 sb
->u
.isofs_sb
.s_nls_iocharset
= NULL
;
68 printk("Outstanding mallocs:%d, outstanding buffers: %d\n",
69 check_malloc
, check_bread
);
76 static void isofs_read_inode(struct inode
*);
77 static int isofs_statfs (struct super_block
*, struct statfs
*, int);
79 static struct super_operations isofs_sops
= {
80 read_inode
: isofs_read_inode
,
81 put_super
: isofs_put_super
,
85 static struct dentry_operations isofs_dentry_ops
[] = {
87 NULL
, /* d_revalidate */
93 NULL
, /* d_revalidate */
100 NULL
, /* d_revalidate */
106 NULL
, /* d_revalidate */
114 struct iso9660_options
{
121 unsigned int blocksize
;
133 * Compute the hash for the isofs name corresponding to the dentry.
136 isofs_hash_common(struct dentry
*dentry
, struct qstr
*qstr
, int ms
)
144 while (len
&& name
[len
-1] == '.')
148 qstr
->hash
= full_name_hash(name
, len
);
154 * Compute the hash for the isofs name corresponding to the dentry.
157 isofs_hashi_common(struct dentry
*dentry
, struct qstr
*qstr
, int ms
)
167 while (len
&& name
[len
-1] == '.')
171 hash
= init_name_hash();
173 c
= tolower(*name
++);
174 hash
= partial_name_hash(tolower(c
), hash
);
176 qstr
->hash
= end_name_hash(hash
);
182 * Case insensitive compare of two isofs names.
185 isofs_cmpi_common(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
,int ms
)
189 /* A filename cannot end in '.' or we treat it like it has none */
193 while (alen
&& a
->name
[alen
-1] == '.')
195 while (blen
&& b
->name
[blen
-1] == '.')
199 if (strnicmp(a
->name
, b
->name
, alen
) == 0)
206 * Case sensitive compare of two isofs names.
209 isofs_cmp_common(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
,int ms
)
213 /* A filename cannot end in '.' or we treat it like it has none */
217 while (alen
&& a
->name
[alen
-1] == '.')
219 while (blen
&& b
->name
[blen
-1] == '.')
223 if (strncmp(a
->name
, b
->name
, alen
) == 0)
230 isofs_hash(struct dentry
*dentry
, struct qstr
*qstr
)
232 return isofs_hash_common(dentry
, qstr
, 0);
236 isofs_hashi(struct dentry
*dentry
, struct qstr
*qstr
)
238 return isofs_hashi_common(dentry
, qstr
, 0);
242 isofs_cmp(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
)
244 return isofs_cmp_common(dentry
, a
, b
, 0);
248 isofs_cmpi(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
)
250 return isofs_cmpi_common(dentry
, a
, b
, 0);
255 isofs_hash_ms(struct dentry
*dentry
, struct qstr
*qstr
)
257 return isofs_hash_common(dentry
, qstr
, 1);
261 isofs_hashi_ms(struct dentry
*dentry
, struct qstr
*qstr
)
263 return isofs_hashi_common(dentry
, qstr
, 1);
267 isofs_cmp_ms(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
)
269 return isofs_cmp_common(dentry
, a
, b
, 1);
273 isofs_cmpi_ms(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
)
275 return isofs_cmpi_common(dentry
, a
, b
, 1);
279 static int parse_options(char *options
, struct iso9660_options
* popt
)
281 char *this_char
,*value
;
288 popt
->check
= 'u'; /* unset */
289 popt
->blocksize
= 1024;
290 popt
->mode
= S_IRUGO
| S_IXUGO
; /* r-x for all. The disc could
291 be shared with DOS machines so
292 virtually anything could be
293 a valid executable. */
296 popt
->iocharset
= NULL
;
300 if (!options
) return 1;
301 for (this_char
= strtok(options
,","); this_char
; this_char
= strtok(NULL
,",")) {
302 if (strncmp(this_char
,"norock",6) == 0) {
306 if (strncmp(this_char
,"nojoliet",8) == 0) {
310 if (strncmp(this_char
,"unhide",6) == 0) {
314 if (strncmp(this_char
,"cruft",5) == 0) {
318 if (strncmp(this_char
,"utf8",4) == 0) {
322 if ((value
= strchr(this_char
,'=')) != NULL
)
326 if (!strcmp(this_char
,"iocharset") && value
) {
327 popt
->iocharset
= value
;
328 while (*value
&& *value
!= ',')
330 if (value
== popt
->iocharset
)
335 if (!strcmp(this_char
,"map") && value
) {
336 if (value
[0] && !value
[1] && strchr("ano",*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';
343 if (!strcmp(this_char
,"session") && value
) {
345 unsigned int ivalue
= simple_strtoul(vpnt
, &vpnt
, 0);
346 if(ivalue
< 0 || ivalue
>99) return 0;
347 popt
->session
=ivalue
+1;
349 if (!strcmp(this_char
,"sbsector") && value
) {
351 unsigned int ivalue
= simple_strtoul(vpnt
, &vpnt
, 0);
352 if(ivalue
< 0 || ivalue
>660*512) return 0;
353 popt
->sbsector
=ivalue
;
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';
362 else if (!strcmp(this_char
,"conv") && value
) {
363 /* no conversion is done anymore;
364 we still accept the same mount options,
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")) ;
374 (!strcmp(this_char
,"block") ||
375 !strcmp(this_char
,"mode") ||
376 !strcmp(this_char
,"uid") ||
377 !strcmp(this_char
,"gid"))) {
379 unsigned int ivalue
= simple_strtoul(vpnt
, &vpnt
, 0);
385 && ivalue
!= 2048) return 0;
386 popt
->blocksize
= ivalue
;
405 * look if the driver can tell the multi session redirection value
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.
415 * A broken CDwriter software or drive firmware does not set new standards,
416 * at least not if conflicting with the existing ones.
420 #define WE_OBEY_THE_WRITTEN_STANDARDS 1
422 static unsigned int isofs_get_last_session(struct super_block
*sb
,s32 session
)
424 struct cdrom_multisession ms_info
;
425 unsigned int vol_desc_start
;
426 struct block_device
*bdev
= sb
->s_bdev
;
427 kdev_t dev
= sb
->s_dev
;
431 ms_info
.addr_format
=CDROM_LBA
;
432 /* If a minor device was explicitly opened, set session to the
433 * minor number. For instance, if /dev/hdc1 is mounted, session
434 * 1 on the CD-ROM is selected. CD_PART_MAX gives access to
435 * a max of 64 sessions on IDE. SCSI drives must still use
436 * the session option to mount.
438 if ((MINOR(dev
) % CD_PART_MAX
) && (MAJOR(dev
) != SCSI_CDROM_MAJOR
))
439 session
= MINOR(dev
) % CD_PART_MAX
;
440 if(session
>= 0 && session
<= 99) {
441 struct cdrom_tocentry Te
;
442 Te
.cdte_track
=session
;
443 Te
.cdte_format
=CDROM_LBA
;
444 i
= ioctl_by_bdev(bdev
, CDROMREADTOCENTRY
, (unsigned long) &Te
);
446 printk(KERN_DEBUG
"Session %d start %d type %d\n",
447 session
, Te
.cdte_addr
.lba
,
448 Te
.cdte_ctrl
&CDROM_DATA_TRACK
);
449 if ((Te
.cdte_ctrl
&CDROM_DATA_TRACK
) == 4)
450 return Te
.cdte_addr
.lba
;
453 printk(KERN_ERR
"Invalid session number or type of track\n");
455 i
= ioctl_by_bdev(bdev
, CDROMMULTISESSION
, (unsigned long) &ms_info
);
456 if(session
> 0) printk(KERN_ERR
"Invalid session number\n");
458 printk("isofs.inode: CDROMMULTISESSION: rc=%d\n",i
);
460 printk("isofs.inode: XA disk: %s\n",ms_info
.xa_flag
?"yes":"no");
461 printk("isofs.inode: vol_desc_start = %d\n", ms_info
.addr
.lba
);
465 #if WE_OBEY_THE_WRITTEN_STANDARDS
466 if (ms_info
.xa_flag
) /* necessary for a valid ms_info.addr */
468 vol_desc_start
=ms_info
.addr
.lba
;
469 return vol_desc_start
;
473 * Initialize the superblock and read the root inode.
475 * Note: a check_disk_change() has been done immediately prior
476 * to this call, so we don't need to check again.
478 static struct super_block
*isofs_read_super(struct super_block
*s
, void *data
,
481 kdev_t dev
= s
->s_dev
;
482 struct buffer_head
* bh
= NULL
, *pri_bh
= NULL
;
483 struct hs_primary_descriptor
* h_pri
= NULL
;
484 struct iso_primary_descriptor
* pri
= NULL
;
485 struct iso_supplementary_descriptor
*sec
= NULL
;
486 struct iso_directory_record
* rootp
;
487 int joliet_level
= 0;
489 int iso_blknum
, block
;
492 unsigned int blocksize
, blocksize_bits
;
493 unsigned int vol_desc_start
;
494 unsigned long first_data_zone
;
495 struct inode
* inode
;
496 struct iso9660_options opt
;
499 /* lock before any blocking operations */
502 if (!parse_options((char *) data
, &opt
))
506 printk("map = %c\n", opt
.map
);
507 printk("rock = %c\n", opt
.rock
);
508 printk("joliet = %c\n", opt
.joliet
);
509 printk("check = %c\n", opt
.check
);
510 printk("cruft = %c\n", opt
.cruft
);
511 printk("unhide = %c\n", opt
.unhide
);
512 printk("blocksize = %d\n", opt
.blocksize
);
513 printk("gid = %d\n", opt
.gid
);
514 printk("uid = %d\n", opt
.uid
);
515 printk("iocharset = %s\n", opt
.iocharset
);
519 * First of all, get the hardware blocksize for this device.
520 * If we don't know what it is, or the hardware blocksize is
521 * larger than the blocksize the user specified, then use
524 blocksize
= get_hardblocksize(dev
);
526 && (blocksize
> opt
.blocksize
) )
529 * Force the blocksize we are going to use to be the
530 * hardware blocksize.
532 opt
.blocksize
= blocksize
;
537 int i
= opt
.blocksize
;
544 set_blocksize(dev
, opt
.blocksize
);
546 s
->u
.isofs_sb
.s_high_sierra
= high_sierra
= 0; /* default is iso9660 */
548 vol_desc_start
= (opt
.sbsector
!= -1) ?
549 opt
.sbsector
: isofs_get_last_session(s
,opt
.session
);
551 for (iso_blknum
= vol_desc_start
+16;
552 iso_blknum
< vol_desc_start
+100; iso_blknum
++)
554 struct hs_volume_descriptor
* hdp
;
555 struct iso_volume_descriptor
* vdp
;
557 block
= iso_blknum
<< (ISOFS_BLOCK_BITS
-blocksize_bits
);
558 if (!(bh
= bread(dev
, block
, opt
.blocksize
)))
561 vdp
= (struct iso_volume_descriptor
*)bh
->b_data
;
562 hdp
= (struct hs_volume_descriptor
*)bh
->b_data
;
564 /* Due to the overlapping physical location of the descriptors,
565 * ISO CDs can match hdp->id==HS_STANDARD_ID as well. To ensure
566 * proper identification in this case, we first check for ISO.
568 if (strncmp (vdp
->id
, ISO_STANDARD_ID
, sizeof vdp
->id
) == 0) {
569 if (isonum_711 (vdp
->type
) == ISO_VD_END
)
571 if (isonum_711 (vdp
->type
) == ISO_VD_PRIMARY
) {
573 pri
= (struct iso_primary_descriptor
*)vdp
;
574 /* Save the buffer in case we need it ... */
580 else if (isonum_711 (vdp
->type
) == ISO_VD_SUPPLEMENTARY
) {
581 sec
= (struct iso_supplementary_descriptor
*)vdp
;
582 if (sec
->escape
[0] == 0x25 && sec
->escape
[1] == 0x2f) {
583 if (opt
.joliet
== 'y') {
584 if (sec
->escape
[2] == 0x40) {
586 } else if (sec
->escape
[2] == 0x43) {
588 } else if (sec
->escape
[2] == 0x45) {
591 printk(KERN_DEBUG
"ISO 9660 Extensions: Microsoft Joliet Level %d\n",
596 /* Unknown supplementary volume descriptor */
602 if (strncmp (hdp
->id
, HS_STANDARD_ID
, sizeof hdp
->id
) == 0) {
603 if (isonum_711 (hdp
->type
) != ISO_VD_PRIMARY
)
606 s
->u
.isofs_sb
.s_high_sierra
= 1;
609 h_pri
= (struct hs_primary_descriptor
*)vdp
;
614 /* Just skip any volume descriptors we don't recognize */
620 * If we fall through, either no volume descriptor was found,
621 * or else we passed a primary descriptor looking for others.
624 goto out_unknown_format
;
632 if (joliet_level
&& opt
.rock
== 'n') {
633 /* This is the case of Joliet with the norock mount flag.
634 * A disc with both Joliet and Rock Ridge is handled later
636 pri
= (struct iso_primary_descriptor
*) sec
;
640 rootp
= (struct iso_directory_record
*) h_pri
->root_directory_record
;
641 #ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
642 if (isonum_723 (h_pri
->volume_set_size
) != 1)
644 #endif IGNORE_WRONG_MULTI_VOLUME_SPECS
645 s
->u
.isofs_sb
.s_nzones
= isonum_733 (h_pri
->volume_space_size
);
646 s
->u
.isofs_sb
.s_log_zone_size
= isonum_723 (h_pri
->logical_block_size
);
647 s
->u
.isofs_sb
.s_max_size
= isonum_733(h_pri
->volume_space_size
);
649 rootp
= (struct iso_directory_record
*) pri
->root_directory_record
;
650 #ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
651 if (isonum_723 (pri
->volume_set_size
) != 1)
653 #endif IGNORE_WRONG_MULTI_VOLUME_SPECS
654 s
->u
.isofs_sb
.s_nzones
= isonum_733 (pri
->volume_space_size
);
655 s
->u
.isofs_sb
.s_log_zone_size
= isonum_723 (pri
->logical_block_size
);
656 s
->u
.isofs_sb
.s_max_size
= isonum_733(pri
->volume_space_size
);
659 s
->u
.isofs_sb
.s_ninodes
= 0; /* No way to figure this out easily */
661 orig_zonesize
= s
-> u
.isofs_sb
.s_log_zone_size
;
663 * If the zone size is smaller than the hardware sector size,
664 * this is a fatal error. This would occur if the disc drive
665 * had sectors that were 2048 bytes, but the filesystem had
666 * blocks that were 512 bytes (which should only very rarely
669 if(blocksize
!= 0 && orig_zonesize
< blocksize
)
672 /* RDE: convert log zone size to bit shift */
673 switch (s
-> u
.isofs_sb
.s_log_zone_size
)
674 { case 512: s
-> u
.isofs_sb
.s_log_zone_size
= 9; break;
675 case 1024: s
-> u
.isofs_sb
.s_log_zone_size
= 10; break;
676 case 2048: s
-> u
.isofs_sb
.s_log_zone_size
= 11; break;
679 goto out_bad_zone_size
;
682 s
->s_magic
= ISOFS_SUPER_MAGIC
;
684 /* The CDROM is read-only, has no nodes (devices) on it, and since
685 all of the files appear to be owned by root, we really do not want
686 to allow suid. (suid or devices will not show up unless we have
687 Rock Ridge extensions) */
689 s
->s_flags
|= MS_RDONLY
/* | MS_NODEV | MS_NOSUID */;
691 /* RDE: data zone now byte offset! */
693 first_data_zone
= ((isonum_733 (rootp
->extent
) +
694 isonum_711 (rootp
->ext_attr_length
))
695 << s
-> u
.isofs_sb
.s_log_zone_size
);
696 s
->u
.isofs_sb
.s_firstdatazone
= first_data_zone
;
698 printk(KERN_DEBUG
"Max size:%ld Log zone size:%ld\n",
699 s
->u
.isofs_sb
.s_max_size
,
700 1UL << s
->u
.isofs_sb
.s_log_zone_size
);
701 printk(KERN_DEBUG
"First datazone:%ld Root inode number:%ld\n",
702 s
->u
.isofs_sb
.s_firstdatazone
>> s
-> u
.isofs_sb
.s_log_zone_size
,
703 s
->u
.isofs_sb
.s_firstdatazone
);
705 printk(KERN_DEBUG
"Disc in High Sierra format.\n");
709 * If the Joliet level is set, we _may_ decide to use the
710 * secondary descriptor, but can't be sure until after we
711 * read the root inode. But before reading the root inode
712 * we may need to change the device blocksize, and would
713 * rather release the old buffer first. So, we cache the
714 * first_data_zone value from the secondary descriptor.
717 pri
= (struct iso_primary_descriptor
*) sec
;
718 rootp
= (struct iso_directory_record
*)
719 pri
->root_directory_record
;
720 first_data_zone
= ((isonum_733 (rootp
->extent
) +
721 isonum_711 (rootp
->ext_attr_length
))
722 << s
-> u
.isofs_sb
.s_log_zone_size
);
726 * We're all done using the volume descriptor, and may need
727 * to change the device blocksize, so release the buffer now.
732 * Force the blocksize to 512 for 512 byte sectors. The file
733 * read primitives really get it wrong in a bad way if we don't
736 * Note - we should never be setting the blocksize to something
737 * less than the hardware sector size for the device. If we
738 * do, we would end up having to read larger buffers and split
739 * out portions to satisfy requests.
741 * Note2- the idea here is that we want to deal with the optimal
742 * zonesize in the filesystem. If we have it set to something less,
743 * then we have horrible problems with trying to piece together
744 * bits of adjacent blocks in order to properly read directory
745 * entries. By forcing the blocksize in this way, we ensure
746 * that we will never be required to do this.
748 if ( orig_zonesize
!= opt
.blocksize
) {
749 set_blocksize(dev
, orig_zonesize
);
752 "ISOFS: Forcing new log zone size:%d\n", orig_zonesize
);
755 s
->s_blocksize
= orig_zonesize
;
756 s
->s_blocksize_bits
= s
-> u
.isofs_sb
.s_log_zone_size
;
758 s
->u
.isofs_sb
.s_nls_iocharset
= NULL
;
761 if (joliet_level
&& opt
.utf8
== 0) {
762 char * p
= opt
.iocharset
? opt
.iocharset
: "iso8859-1";
763 s
->u
.isofs_sb
.s_nls_iocharset
= load_nls(p
);
764 if (! s
->u
.isofs_sb
.s_nls_iocharset
) {
765 /* Fail only if explicit charset specified */
768 s
->u
.isofs_sb
.s_nls_iocharset
= load_nls_default();
772 s
->s_op
= &isofs_sops
;
773 s
->u
.isofs_sb
.s_mapping
= opt
.map
;
774 s
->u
.isofs_sb
.s_rock
= (opt
.rock
== 'y' ? 2 : 0);
775 s
->u
.isofs_sb
.s_cruft
= opt
.cruft
;
776 s
->u
.isofs_sb
.s_unhide
= opt
.unhide
;
777 s
->u
.isofs_sb
.s_uid
= opt
.uid
;
778 s
->u
.isofs_sb
.s_gid
= opt
.gid
;
779 s
->u
.isofs_sb
.s_utf8
= opt
.utf8
;
781 * It would be incredibly stupid to allow people to mark every file on the disk
782 * as suid, so we merely allow them to set the default permissions.
784 s
->u
.isofs_sb
.s_mode
= opt
.mode
& 0777;
787 * Read the root inode, which _may_ result in changing
788 * the s_rock flag. Once we have the final s_rock value,
789 * we then decide whether to use the Joliet descriptor.
791 inode
= iget(s
, s
->u
.isofs_sb
.s_firstdatazone
);
794 * If this disk has both Rock Ridge and Joliet on it, then we
795 * want to use Rock Ridge by default. This can be overridden
796 * by using the norock mount option. There is still one other
797 * possibility that is not taken into account: a Rock Ridge
798 * CD with Unicode names. Until someone sees such a beast, it
799 * will not be supported.
801 if (s
->u
.isofs_sb
.s_rock
== 1) {
803 } else if (joliet_level
) {
804 s
->u
.isofs_sb
.s_rock
= 0;
805 if (s
->u
.isofs_sb
.s_firstdatazone
!= first_data_zone
) {
806 s
->u
.isofs_sb
.s_firstdatazone
= first_data_zone
;
808 "ISOFS: changing to secondary root\n");
810 inode
= iget(s
, s
->u
.isofs_sb
.s_firstdatazone
);
814 if (opt
.check
== 'u') {
815 /* Only Joliet is case insensitive by default */
816 if (joliet_level
) opt
.check
= 'r';
817 else opt
.check
= 's';
819 s
->u
.isofs_sb
.s_joliet_level
= joliet_level
;
821 /* check the root inode */
826 /* get the root dentry */
827 s
->s_root
= d_alloc_root(inode
);
832 if (joliet_level
) table
+= 2;
833 if (opt
.check
== 'r') table
++;
834 s
->s_root
->d_op
= &isofs_dentry_ops
[table
];
840 * Display error messages and free resources.
843 printk(KERN_WARNING
"isofs_read_super: root inode not initialized\n");
846 printk(KERN_WARNING
"isofs_read_super: get root inode failed\n");
850 if (s
->u
.isofs_sb
.s_nls_iocharset
)
851 unload_nls(s
->u
.isofs_sb
.s_nls_iocharset
);
855 printk(KERN_WARNING
"isofs_read_super: "
856 "bread failed, dev=%s, iso_blknum=%d, block=%d\n",
857 kdevname(dev
), iso_blknum
, block
);
860 printk(KERN_WARNING
"Bad logical zone size %ld\n",
861 s
->u
.isofs_sb
.s_log_zone_size
);
864 printk(KERN_WARNING
"Logical zone size(%d) < hardware blocksize(%u)\n",
865 orig_zonesize
, blocksize
);
867 #ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
869 printk(KERN_WARNING
"Multi-volume disks not supported.\n");
874 printk(KERN_WARNING
"Unable to identify CD-ROM format.\n");
885 static int isofs_statfs (struct super_block
*sb
, struct statfs
*buf
, int bufsiz
)
889 tmp
.f_type
= ISOFS_SUPER_MAGIC
;
890 tmp
.f_bsize
= sb
->s_blocksize
;
891 tmp
.f_blocks
= (sb
->u
.isofs_sb
.s_nzones
892 << (sb
->u
.isofs_sb
.s_log_zone_size
- sb
->s_blocksize_bits
));
895 tmp
.f_files
= sb
->u
.isofs_sb
.s_ninodes
;
897 tmp
.f_namelen
= NAME_MAX
;
898 return copy_to_user(buf
, &tmp
, bufsiz
) ? -EFAULT
: 0;
901 /* Life is simpler than for other filesystem since we never
902 * have to create a new block, only find an existing one.
904 int isofs_get_block(struct inode
*inode
, long iblock
,
905 struct buffer_head
*bh_result
, int create
)
908 unsigned offset
, sect_size
;
909 unsigned int firstext
;
910 unsigned long nextino
;
917 goto abort_create_attempted
;
925 /* If we are *way* beyond the end of the file, print a message.
926 * Access beyond the end of the file up to the next page boundary
927 * is normal, however because of the way the page cache works.
928 * In this case, we just return 0 so that we can properly fill
929 * the page with useless information without generating any
932 if (b_off
> ((inode
->i_size
+ PAGE_SIZE
- 1) >> ISOFS_BUFFER_BITS(inode
)))
933 goto abort_beyond_end
;
936 firstext
= inode
->u
.isofs_i
.i_first_extent
;
937 sect_size
= inode
->u
.isofs_i
.i_section_size
>> ISOFS_BUFFER_BITS(inode
);
938 nextino
= inode
->u
.isofs_i
.i_next_section_ino
;
942 while (b_off
>= (offset
+ sect_size
)) {
943 struct inode
*ninode
;
948 ninode
= iget(inode
->i_sb
, nextino
);
951 firstext
= ninode
->u
.isofs_i
.i_first_extent
;
952 sect_size
= ninode
->u
.isofs_i
.i_section_size
;
953 nextino
= ninode
->u
.isofs_i
.i_next_section_ino
;
957 goto abort_too_many_sections
;
961 bh_result
->b_dev
= inode
->i_dev
;
962 bh_result
->b_blocknr
= firstext
+ b_off
- offset
;
963 bh_result
->b_state
|= (1UL << BH_Mapped
);
970 abort_create_attempted
:
971 printk("_isofs_bmap: Kernel tries to allocate a block\n");
975 printk("_isofs_bmap: block < 0\n");
979 printk("_isofs_bmap: block >= EOF (%ld, %ld)\n",
980 iblock
, (unsigned long) inode
->i_size
);
983 abort_too_many_sections
:
984 printk("isofs_bmap: More than 100 file sections ?!?, aborting...\n");
985 printk("isofs_bmap: ino=%lu block=%ld firstext=%u sect_size=%u nextino=%lu\n",
986 inode
->i_ino
, iblock
, firstext
, (unsigned) sect_size
, nextino
);
990 int isofs_bmap(struct inode
*inode
, int block
)
992 struct buffer_head dummy
;
996 dummy
.b_blocknr
= -1000;
997 error
= isofs_get_block(inode
, block
, &dummy
, 0);
999 return dummy
.b_blocknr
;
1003 static int isofs_readpage(struct dentry
*dentry
, struct page
*page
)
1005 return block_read_full_page(page
,isofs_get_block
);
1007 static int _isofs_bmap(struct address_space
*mapping
, long block
)
1009 return generic_block_bmap(mapping
,block
,isofs_get_block
);
1011 static struct address_space_operations isofs_aops
= {
1012 readpage
: isofs_readpage
,
1016 static void test_and_set_uid(uid_t
*p
, uid_t value
)
1021 printk("Resetting to %d\n", value
);
1026 static int isofs_read_level3_size(struct inode
* inode
)
1028 unsigned long ino
= inode
->i_ino
;
1029 unsigned long bufsize
= ISOFS_BUFFER_SIZE(inode
);
1030 int high_sierra
= inode
->i_sb
->u
.isofs_sb
.s_high_sierra
;
1031 struct buffer_head
* bh
= NULL
;
1034 int more_entries
= 0;
1036 struct iso_directory_record
* raw_inode
;
1039 inode
->u
.isofs_i
.i_next_section_ino
= 0;
1042 unsigned int reclen
;
1043 int offset
= (ino
& (bufsize
- 1));
1046 /* Check whether to update our buffer */
1047 if (block
!= ino
>> ISOFS_BUFFER_BITS(inode
)) {
1048 block
= ino
>> ISOFS_BUFFER_BITS(inode
);
1050 bh
= bread(inode
->i_dev
, block
, bufsize
);
1054 pnt
= ((unsigned char *) bh
->b_data
+ offset
);
1056 * Note: this is invariant even if the record
1057 * spans buffers and must be copied ...
1061 /* N.B. this test doesn't trigger the i++ code ... */
1063 ino
= (ino
& ~(ISOFS_BLOCK_SIZE
- 1)) + ISOFS_BLOCK_SIZE
;
1066 raw_inode
= ((struct iso_directory_record
*) pnt
);
1068 /* Check whether the raw inode spans the buffer ... */
1069 if (offset
+ reclen
> bufsize
){
1070 int frag1
= bufsize
- offset
;
1072 cpnt
= kmalloc(reclen
, GFP_KERNEL
);
1075 memcpy(cpnt
, pnt
, frag1
);
1077 bh
= bread(inode
->i_dev
, ++block
, bufsize
);
1080 offset
+= reclen
- bufsize
;
1081 memcpy((char *)cpnt
+frag1
, bh
->b_data
, offset
);
1082 raw_inode
= ((struct iso_directory_record
*) cpnt
);
1085 inode
->i_size
+= isonum_733 (raw_inode
->size
);
1086 if(i
== 1) inode
->u
.isofs_i
.i_next_section_ino
= ino
;
1088 more_entries
= raw_inode
->flags
[-high_sierra
] & 0x80;
1096 } while(more_entries
);
1102 printk(KERN_INFO
"ISOFS: NoMem ISO inode %lu\n", inode
->i_ino
);
1106 printk(KERN_INFO
"ISOFS: unable to read i-node block %d\n", block
);
1111 printk(KERN_INFO
"isofs_read_level3_size: "
1112 "More than 100 file sections ?!?, aborting...\n"
1113 "isofs_read_level3_size: inode=%lu ino=%lu\n",
1118 static void isofs_read_inode(struct inode
* inode
)
1120 struct super_block
*sb
= inode
->i_sb
;
1121 unsigned long bufsize
= ISOFS_BUFFER_SIZE(inode
);
1122 int block
= inode
->i_ino
>> ISOFS_BUFFER_BITS(inode
);
1123 int high_sierra
= sb
->u
.isofs_sb
.s_high_sierra
;
1124 struct buffer_head
* bh
;
1125 struct iso_directory_record
* raw_inode
;
1127 int volume_seq_no
, i
;
1129 bh
= bread(inode
->i_dev
, block
, bufsize
);
1131 printk(KERN_WARNING
"ISOFS: unable to read i-node block\n");
1135 pnt
= ((unsigned char *) bh
->b_data
1136 + (inode
->i_ino
& (bufsize
- 1)));
1137 raw_inode
= ((struct iso_directory_record
*) pnt
);
1139 if (raw_inode
->flags
[-high_sierra
] & 2) {
1140 inode
->i_mode
= S_IRUGO
| S_IXUGO
| S_IFDIR
;
1141 inode
->i_nlink
= 1; /* Set to 1. We know there are 2, but
1142 the find utility tries to optimize
1143 if it is 2, and it screws up. It is
1144 easier to give 1 which tells find to
1145 do it the hard way. */
1147 /* Everybody gets to read the file. */
1148 inode
->i_mode
= inode
->i_sb
->u
.isofs_sb
.s_mode
;
1150 inode
->i_mode
|= S_IFREG
;
1151 /* If there are no periods in the name,
1152 * then set the execute permission bit
1154 for(i
=0; i
< raw_inode
->name_len
[0]; i
++)
1155 if(raw_inode
->name
[i
]=='.' || raw_inode
->name
[i
]==';')
1157 if(i
== raw_inode
->name_len
[0] || raw_inode
->name
[i
] == ';')
1158 inode
->i_mode
|= S_IXUGO
; /* execute permission */
1160 inode
->i_uid
= inode
->i_sb
->u
.isofs_sb
.s_uid
;
1161 inode
->i_gid
= inode
->i_sb
->u
.isofs_sb
.s_gid
;
1162 inode
->i_blocks
= inode
->i_blksize
= 0;
1165 inode
->u
.isofs_i
.i_section_size
= isonum_733 (raw_inode
->size
);
1166 if(raw_inode
->flags
[-high_sierra
] & 0x80) {
1167 if(isofs_read_level3_size(inode
)) goto fail
;
1169 inode
->i_size
= isonum_733 (raw_inode
->size
);
1172 /* There are defective discs out there - we do this to protect
1173 ourselves. A cdrom will never contain more than 800Mb
1174 .. but a DVD may be up to 1Gig (Ulrich Habel) */
1175 if((inode
->i_size
< 0 || inode
->i_size
> 1073741824) &&
1176 inode
->i_sb
->u
.isofs_sb
.s_cruft
== 'n') {
1177 printk(KERN_WARNING
"Warning: defective CD-ROM. Enabling \"cruft\" mount option.\n");
1178 inode
->i_sb
->u
.isofs_sb
.s_cruft
= 'y';
1181 /* Some dipshit decided to store some other bit of information in the high
1182 byte of the file length. Catch this and holler. WARNING: this will make
1183 it impossible for a file to be > 16Mb on the CDROM!!!*/
1185 if(inode
->i_sb
->u
.isofs_sb
.s_cruft
== 'y' &&
1186 inode
->i_size
& 0xff000000){
1187 /* printk("Illegal format on cdrom. Pester manufacturer.\n"); */
1188 inode
->i_size
&= 0x00ffffff;
1191 if (raw_inode
->interleave
[0]) {
1192 printk("Interleaved files not (yet) supported.\n");
1196 /* I have no idea what file_unit_size is used for, so
1197 we will flag it for now */
1198 if(raw_inode
->file_unit_size
[0] != 0){
1199 printk("File unit size != 0 for ISO file (%ld).\n",inode
->i_ino
);
1202 /* I have no idea what other flag bits are used for, so
1203 we will flag it for now */
1205 if((raw_inode
->flags
[-high_sierra
] & ~2)!= 0){
1206 printk("Unusual flag settings for ISO file (%ld %x).\n",
1207 inode
->i_ino
, raw_inode
->flags
[-high_sierra
]);
1212 printk("Get inode %x: %d %d: %d\n",inode
->i_ino
, block
,
1213 ((int)pnt
) & 0x3ff, inode
->i_size
);
1216 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
=
1217 iso_date(raw_inode
->date
, high_sierra
);
1219 inode
->u
.isofs_i
.i_first_extent
= (isonum_733 (raw_inode
->extent
) +
1220 isonum_711 (raw_inode
->ext_attr_length
));
1222 /* Now test for possible Rock Ridge extensions which will override some of
1223 these numbers in the inode structure. */
1226 parse_rock_ridge_inode(raw_inode
, inode
);
1227 /* hmm..if we want uid or gid set, override the rock ridge setting */
1228 test_and_set_uid(&inode
->i_uid
, inode
->i_sb
->u
.isofs_sb
.s_uid
);
1232 printk("Inode: %x extent: %x\n",inode
->i_ino
, inode
->u
.isofs_i
.i_first_extent
);
1235 /* get the volume sequence number */
1236 volume_seq_no
= isonum_723 (raw_inode
->volume_sequence_number
) ;
1239 * All done with buffer ... no more references to buffer memory!
1244 * Disable checking if we see any volume number other than 0 or 1.
1245 * We could use the cruft option, but that has multiple purposes, one
1246 * of which is limiting the file size to 16Mb. Thus we silently allow
1247 * volume numbers of 0 to go through without complaining.
1249 if (inode
->i_sb
->u
.isofs_sb
.s_cruft
== 'n' &&
1250 (volume_seq_no
!= 0) && (volume_seq_no
!= 1)) {
1251 printk(KERN_WARNING
"Warning: defective CD-ROM (volume sequence number). Enabling \"cruft\" mount option.\n");
1252 inode
->i_sb
->u
.isofs_sb
.s_cruft
= 'y';
1255 /* Install the inode operations vector */
1256 #ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
1257 if (inode
->i_sb
->u
.isofs_sb
.s_cruft
!= 'y' &&
1258 (volume_seq_no
!= 0) && (volume_seq_no
!= 1)) {
1259 printk(KERN_WARNING
"Multi-volume CD somehow got mounted.\n");
1261 #endif IGNORE_WRONG_MULTI_VOLUME_SPECS
1263 if (S_ISREG(inode
->i_mode
)) {
1264 inode
->i_fop
= &generic_ro_fops
;
1265 inode
->i_data
.a_ops
= &isofs_aops
;
1266 } else if (S_ISDIR(inode
->i_mode
)) {
1267 inode
->i_op
= &isofs_dir_inode_operations
;
1268 inode
->i_fop
= &isofs_dir_operations
;
1269 } else if (S_ISLNK(inode
->i_mode
)) {
1270 inode
->i_op
= &page_symlink_inode_operations
;
1271 inode
->i_data
.a_ops
= &isofs_symlink_aops
;
1273 /* XXX - parse_rock_ridge_inode() had already set i_rdev. */
1274 init_special_inode(inode
, inode
->i_mode
, kdev_t_to_nr(inode
->i_rdev
));
1279 /* With a data error we return this information */
1280 make_bad_inode(inode
);
1284 /* There are times when we need to know the inode number of a parent of
1285 a particular directory. When control passes through a routine that
1286 has access to the parent information, it fills it into the inode structure,
1287 but sometimes the inode gets flushed out of the queue, and someone
1288 remembers the number. When they try to open up again, we have lost
1289 the information. The '..' entry on the disc points to the data area
1290 for a particular inode, so we can follow these links back up, but since
1291 we do not know the inode number, we do not actually know how large the
1292 directory is. The disc is almost always correct, and there is
1293 enough error checking on the drive itself, but an open ended search
1294 makes me a little nervous.
1296 The BSD iso filesystem uses the extent number for an inode, and this
1297 would work really nicely for us except that the read_inode function
1298 would not have any clean way of finding the actual directory record
1299 that goes with the file. If we had such info, then it would pay
1300 to change the inode numbers and eliminate this function.
1303 int isofs_lookup_grandparent(struct inode
* parent
, int extent
)
1305 unsigned long bufsize
= ISOFS_BUFFER_SIZE(parent
);
1306 unsigned char bufbits
= ISOFS_BUFFER_BITS(parent
);
1307 unsigned int block
,offset
;
1308 int parent_dir
, inode_number
;
1311 struct buffer_head
* bh
;
1312 struct iso_directory_record
* de
;
1315 block
= extent
<< (ISOFS_ZONE_BITS(parent
) - bufbits
);
1316 if (!(bh
= bread(parent
->i_dev
, block
, bufsize
))) return -1;
1319 de
= (struct iso_directory_record
*) (bh
->b_data
+ offset
);
1320 if (*((unsigned char *) de
) == 0)
1323 printk("Directory .. not found\n");
1327 offset
+= *((unsigned char *) de
);
1329 if (offset
>= bufsize
)
1331 printk(".. Directory not in first block"
1332 " of directory.\n");
1337 if (de
->name_len
[0] == 1 && de
->name
[0] == 1)
1339 parent_dir
= find_rock_ridge_relocation(de
, parent
);
1340 directory_size
= isonum_733 (de
->size
);
1346 printk("Parent dir:%x\n",parent_dir
);
1348 /* Now we know the extent where the parent dir starts on. */
1353 block
= parent_dir
<< (ISOFS_ZONE_BITS(parent
) - bufbits
);
1354 if (!block
|| !(bh
= bread(parent
->i_dev
,block
, bufsize
)))
1361 de
= (struct iso_directory_record
*) (bh
->b_data
+ offset
);
1362 inode_number
= (block
<< bufbits
)+(offset
& (bufsize
- 1));
1364 /* If the length byte is zero, we should move on to the next
1365 CDROM sector. If we are at the end of the directory, we
1366 kick out of the while loop. */
1368 if ((*((unsigned char *) de
) == 0) || (offset
== bufsize
) )
1373 directory_size
-= bufsize
;
1374 if(directory_size
< 0) return -1;
1375 if((block
& 1) && (ISOFS_ZONE_BITS(parent
) - bufbits
) == 1)
1379 if((block
& 3) && (ISOFS_ZONE_BITS(parent
) - bufbits
) == 2)
1384 || !(bh
= bread(parent
->i_dev
,block
, bufsize
)))
1391 /* Make sure that the entire directory record is in the current
1392 bh block. If not, we malloc a buffer, and put the two
1393 halves together, so that we can cleanly read the block. */
1395 offset
+= *((unsigned char *) de
);
1397 if (offset
> bufsize
)
1399 printk("Directory overrun\n");
1403 if (find_rock_ridge_relocation(de
, parent
) == extent
){
1404 result
= inode_number
;
1410 /* We go here for any condition we cannot handle.
1411 We also drop through to here at the end of the directory. */
1416 printk("Resultant Inode %d\n",result
);
1427 void * leak_check_malloc(unsigned int size
){
1430 tmp
= kmalloc(size
, GFP_KERNEL
);
1434 void leak_check_free_s(void * obj
, int size
){
1436 return kfree_s(obj
, size
);
1439 struct buffer_head
* leak_check_bread(int dev
, int block
, int size
){
1441 return bread(dev
, block
, size
);
1444 void leak_check_brelse(struct buffer_head
* bh
){
1451 static struct file_system_type iso9660_fs_type
= {
1458 int __init
init_iso9660_fs(void)
1460 return register_filesystem(&iso9660_fs_type
);
1466 int init_module(void)
1468 return init_iso9660_fs();
1471 void cleanup_module(void)
1473 unregister_filesystem(&iso9660_fs_type
);