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_dentry_cmpi(struct dentry
*dentry
, struct qstr
*a
, struct qstr
*b
);
49 static int isofs_dentry_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_dentry_cmpi_ms(struct dentry
*dentry
, struct qstr
*a
, struct qstr
*b
);
55 static int isofs_dentry_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
);
75 static void isofs_read_inode(struct inode
*);
76 static int isofs_statfs (struct super_block
*, struct statfs
*);
78 static struct super_operations isofs_sops
= {
79 read_inode
: isofs_read_inode
,
80 put_super
: isofs_put_super
,
84 static struct dentry_operations isofs_dentry_ops
[] = {
87 d_compare
: isofs_dentry_cmp
,
91 d_compare
: isofs_dentry_cmpi
,
95 d_hash
: isofs_hash_ms
,
96 d_compare
: isofs_dentry_cmp_ms
,
99 d_hash
: isofs_hashi_ms
,
100 d_compare
: isofs_dentry_cmpi_ms
,
105 struct iso9660_options
{
112 unsigned int blocksize
;
124 * Compute the hash for the isofs name corresponding to the dentry.
127 isofs_hash_common(struct dentry
*dentry
, struct qstr
*qstr
, int ms
)
135 while (len
&& name
[len
-1] == '.')
139 qstr
->hash
= full_name_hash(name
, len
);
145 * Compute the hash for the isofs name corresponding to the dentry.
148 isofs_hashi_common(struct dentry
*dentry
, struct qstr
*qstr
, int ms
)
158 while (len
&& name
[len
-1] == '.')
162 hash
= init_name_hash();
164 c
= tolower(*name
++);
165 hash
= partial_name_hash(tolower(c
), hash
);
167 qstr
->hash
= end_name_hash(hash
);
173 * Case insensitive compare of two isofs names.
176 isofs_dentry_cmpi_common(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
,int ms
)
180 /* A filename cannot end in '.' or we treat it like it has none */
184 while (alen
&& a
->name
[alen
-1] == '.')
186 while (blen
&& b
->name
[blen
-1] == '.')
190 if (strnicmp(a
->name
, b
->name
, alen
) == 0)
197 * Case sensitive compare of two isofs names.
200 isofs_dentry_cmp_common(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
,int ms
)
204 /* A filename cannot end in '.' or we treat it like it has none */
208 while (alen
&& a
->name
[alen
-1] == '.')
210 while (blen
&& b
->name
[blen
-1] == '.')
214 if (strncmp(a
->name
, b
->name
, alen
) == 0)
221 isofs_hash(struct dentry
*dentry
, struct qstr
*qstr
)
223 return isofs_hash_common(dentry
, qstr
, 0);
227 isofs_hashi(struct dentry
*dentry
, struct qstr
*qstr
)
229 return isofs_hashi_common(dentry
, qstr
, 0);
233 isofs_dentry_cmp(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
)
235 return isofs_dentry_cmp_common(dentry
, a
, b
, 0);
239 isofs_dentry_cmpi(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
)
241 return isofs_dentry_cmpi_common(dentry
, a
, b
, 0);
246 isofs_hash_ms(struct dentry
*dentry
, struct qstr
*qstr
)
248 return isofs_hash_common(dentry
, qstr
, 1);
252 isofs_hashi_ms(struct dentry
*dentry
, struct qstr
*qstr
)
254 return isofs_hashi_common(dentry
, qstr
, 1);
258 isofs_dentry_cmp_ms(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
)
260 return isofs_dentry_cmp_common(dentry
, a
, b
, 1);
264 isofs_dentry_cmpi_ms(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
)
266 return isofs_dentry_cmpi_common(dentry
, a
, b
, 1);
270 static int parse_options(char *options
, struct iso9660_options
* popt
)
272 char *this_char
,*value
;
279 popt
->check
= 'u'; /* unset */
280 popt
->blocksize
= 1024;
281 popt
->mode
= S_IRUGO
| S_IXUGO
; /* r-x for all. The disc could
282 be shared with DOS machines so
283 virtually anything could be
284 a valid executable. */
287 popt
->iocharset
= NULL
;
291 if (!options
) return 1;
292 for (this_char
= strtok(options
,","); this_char
; this_char
= strtok(NULL
,",")) {
293 if (strncmp(this_char
,"norock",6) == 0) {
297 if (strncmp(this_char
,"nojoliet",8) == 0) {
301 if (strncmp(this_char
,"unhide",6) == 0) {
305 if (strncmp(this_char
,"cruft",5) == 0) {
309 if (strncmp(this_char
,"utf8",4) == 0) {
313 if ((value
= strchr(this_char
,'=')) != NULL
)
317 if (!strcmp(this_char
,"iocharset") && value
) {
318 popt
->iocharset
= value
;
319 while (*value
&& *value
!= ',')
321 if (value
== popt
->iocharset
)
326 if (!strcmp(this_char
,"map") && value
) {
327 if (value
[0] && !value
[1] && strchr("ano",*value
))
329 else if (!strcmp(value
,"off")) popt
->map
= 'o';
330 else if (!strcmp(value
,"normal")) popt
->map
= 'n';
331 else if (!strcmp(value
,"acorn")) popt
->map
= 'a';
334 if (!strcmp(this_char
,"session") && value
) {
336 unsigned int ivalue
= simple_strtoul(vpnt
, &vpnt
, 0);
337 if(ivalue
< 0 || ivalue
>99) return 0;
338 popt
->session
=ivalue
+1;
340 if (!strcmp(this_char
,"sbsector") && value
) {
342 unsigned int ivalue
= simple_strtoul(vpnt
, &vpnt
, 0);
343 if(ivalue
< 0 || ivalue
>660*512) return 0;
344 popt
->sbsector
=ivalue
;
346 else if (!strcmp(this_char
,"check") && value
) {
347 if (value
[0] && !value
[1] && strchr("rs",*value
))
348 popt
->check
= *value
;
349 else if (!strcmp(value
,"relaxed")) popt
->check
= 'r';
350 else if (!strcmp(value
,"strict")) popt
->check
= 's';
353 else if (!strcmp(this_char
,"conv") && value
) {
354 /* no conversion is done anymore;
355 we still accept the same mount options,
357 if (value
[0] && !value
[1] && strchr("btma",*value
)) ;
358 else if (!strcmp(value
,"binary")) ;
359 else if (!strcmp(value
,"text")) ;
360 else if (!strcmp(value
,"mtext")) ;
361 else if (!strcmp(value
,"auto")) ;
365 (!strcmp(this_char
,"block") ||
366 !strcmp(this_char
,"mode") ||
367 !strcmp(this_char
,"uid") ||
368 !strcmp(this_char
,"gid"))) {
370 unsigned int ivalue
= simple_strtoul(vpnt
, &vpnt
, 0);
376 && ivalue
!= 2048) return 0;
377 popt
->blocksize
= ivalue
;
396 * look if the driver can tell the multi session redirection value
398 * don't change this if you don't know what you do, please!
399 * Multisession is legal only with XA disks.
400 * A non-XA disk with more than one volume descriptor may do it right, but
401 * usually is written in a nowhere standardized "multi-partition" manner.
402 * Multisession uses absolute addressing (solely the first frame of the whole
403 * track is #0), multi-partition uses relative addressing (each first frame of
404 * each track is #0), and a track is not a session.
406 * A broken CDwriter software or drive firmware does not set new standards,
407 * at least not if conflicting with the existing ones.
411 #define WE_OBEY_THE_WRITTEN_STANDARDS 1
413 static unsigned int isofs_get_last_session(struct super_block
*sb
,s32 session
)
415 struct cdrom_multisession ms_info
;
416 unsigned int vol_desc_start
;
417 struct block_device
*bdev
= sb
->s_bdev
;
421 ms_info
.addr_format
=CDROM_LBA
;
422 if(session
>= 0 && session
<= 99) {
423 struct cdrom_tocentry Te
;
424 Te
.cdte_track
=session
;
425 Te
.cdte_format
=CDROM_LBA
;
426 i
= ioctl_by_bdev(bdev
, CDROMREADTOCENTRY
, (unsigned long) &Te
);
428 printk(KERN_DEBUG
"Session %d start %d type %d\n",
429 session
, Te
.cdte_addr
.lba
,
430 Te
.cdte_ctrl
&CDROM_DATA_TRACK
);
431 if ((Te
.cdte_ctrl
&CDROM_DATA_TRACK
) == 4)
432 return Te
.cdte_addr
.lba
;
435 printk(KERN_ERR
"Invalid session number or type of track\n");
437 i
= ioctl_by_bdev(bdev
, CDROMMULTISESSION
, (unsigned long) &ms_info
);
438 if(session
> 0) printk(KERN_ERR
"Invalid session number\n");
440 printk("isofs.inode: CDROMMULTISESSION: rc=%d\n",i
);
442 printk("isofs.inode: XA disk: %s\n",ms_info
.xa_flag
?"yes":"no");
443 printk("isofs.inode: vol_desc_start = %d\n", ms_info
.addr
.lba
);
447 #if WE_OBEY_THE_WRITTEN_STANDARDS
448 if (ms_info
.xa_flag
) /* necessary for a valid ms_info.addr */
450 vol_desc_start
=ms_info
.addr
.lba
;
451 return vol_desc_start
;
455 * Initialize the superblock and read the root inode.
457 * Note: a check_disk_change() has been done immediately prior
458 * to this call, so we don't need to check again.
460 static struct super_block
*isofs_read_super(struct super_block
*s
, void *data
,
463 kdev_t dev
= s
->s_dev
;
464 struct buffer_head
* bh
= NULL
, *pri_bh
= NULL
;
465 struct hs_primary_descriptor
* h_pri
= NULL
;
466 struct iso_primary_descriptor
* pri
= NULL
;
467 struct iso_supplementary_descriptor
*sec
= NULL
;
468 struct iso_directory_record
* rootp
;
469 int joliet_level
= 0;
471 int iso_blknum
, block
;
474 unsigned int blocksize
, blocksize_bits
;
475 unsigned int vol_desc_start
;
476 unsigned long first_data_zone
;
477 struct inode
* inode
;
478 struct iso9660_options opt
;
480 if (!parse_options((char *) data
, &opt
))
484 printk("map = %c\n", opt
.map
);
485 printk("rock = %c\n", opt
.rock
);
486 printk("joliet = %c\n", opt
.joliet
);
487 printk("check = %c\n", opt
.check
);
488 printk("cruft = %c\n", opt
.cruft
);
489 printk("unhide = %c\n", opt
.unhide
);
490 printk("blocksize = %d\n", opt
.blocksize
);
491 printk("gid = %d\n", opt
.gid
);
492 printk("uid = %d\n", opt
.uid
);
493 printk("iocharset = %s\n", opt
.iocharset
);
497 * First of all, get the hardware blocksize for this device.
498 * If we don't know what it is, or the hardware blocksize is
499 * larger than the blocksize the user specified, then use
502 blocksize
= get_hardblocksize(dev
);
503 if(blocksize
> opt
.blocksize
) {
505 * Force the blocksize we are going to use to be the
506 * hardware blocksize.
508 opt
.blocksize
= blocksize
;
513 int i
= opt
.blocksize
;
520 set_blocksize(dev
, opt
.blocksize
);
522 s
->u
.isofs_sb
.s_high_sierra
= high_sierra
= 0; /* default is iso9660 */
524 vol_desc_start
= (opt
.sbsector
!= -1) ?
525 opt
.sbsector
: isofs_get_last_session(s
,opt
.session
);
527 for (iso_blknum
= vol_desc_start
+16;
528 iso_blknum
< vol_desc_start
+100; iso_blknum
++)
530 struct hs_volume_descriptor
* hdp
;
531 struct iso_volume_descriptor
* vdp
;
533 block
= iso_blknum
<< (ISOFS_BLOCK_BITS
-blocksize_bits
);
534 if (!(bh
= bread(dev
, block
, opt
.blocksize
)))
537 vdp
= (struct iso_volume_descriptor
*)bh
->b_data
;
538 hdp
= (struct hs_volume_descriptor
*)bh
->b_data
;
540 /* Due to the overlapping physical location of the descriptors,
541 * ISO CDs can match hdp->id==HS_STANDARD_ID as well. To ensure
542 * proper identification in this case, we first check for ISO.
544 if (strncmp (vdp
->id
, ISO_STANDARD_ID
, sizeof vdp
->id
) == 0) {
545 if (isonum_711 (vdp
->type
) == ISO_VD_END
)
547 if (isonum_711 (vdp
->type
) == ISO_VD_PRIMARY
) {
549 pri
= (struct iso_primary_descriptor
*)vdp
;
550 /* Save the buffer in case we need it ... */
556 else if (isonum_711 (vdp
->type
) == ISO_VD_SUPPLEMENTARY
) {
557 sec
= (struct iso_supplementary_descriptor
*)vdp
;
558 if (sec
->escape
[0] == 0x25 && sec
->escape
[1] == 0x2f) {
559 if (opt
.joliet
== 'y') {
560 if (sec
->escape
[2] == 0x40) {
562 } else if (sec
->escape
[2] == 0x43) {
564 } else if (sec
->escape
[2] == 0x45) {
567 printk(KERN_DEBUG
"ISO 9660 Extensions: Microsoft Joliet Level %d\n",
572 /* Unknown supplementary volume descriptor */
578 if (strncmp (hdp
->id
, HS_STANDARD_ID
, sizeof hdp
->id
) == 0) {
579 if (isonum_711 (hdp
->type
) != ISO_VD_PRIMARY
)
582 s
->u
.isofs_sb
.s_high_sierra
= 1;
585 h_pri
= (struct hs_primary_descriptor
*)vdp
;
590 /* Just skip any volume descriptors we don't recognize */
596 * If we fall through, either no volume descriptor was found,
597 * or else we passed a primary descriptor looking for others.
600 goto out_unknown_format
;
607 if (joliet_level
&& (pri
== NULL
|| opt
.rock
== 'n')) {
608 /* This is the case of Joliet with the norock mount flag.
609 * A disc with both Joliet and Rock Ridge is handled later
611 pri
= (struct iso_primary_descriptor
*) sec
;
615 rootp
= (struct iso_directory_record
*) h_pri
->root_directory_record
;
616 #ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
617 if (isonum_723 (h_pri
->volume_set_size
) != 1)
619 #endif IGNORE_WRONG_MULTI_VOLUME_SPECS
620 s
->u
.isofs_sb
.s_nzones
= isonum_733 (h_pri
->volume_space_size
);
621 s
->u
.isofs_sb
.s_log_zone_size
= isonum_723 (h_pri
->logical_block_size
);
622 s
->u
.isofs_sb
.s_max_size
= isonum_733(h_pri
->volume_space_size
);
624 rootp
= (struct iso_directory_record
*) pri
->root_directory_record
;
625 #ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
626 if (isonum_723 (pri
->volume_set_size
) != 1)
628 #endif IGNORE_WRONG_MULTI_VOLUME_SPECS
629 s
->u
.isofs_sb
.s_nzones
= isonum_733 (pri
->volume_space_size
);
630 s
->u
.isofs_sb
.s_log_zone_size
= isonum_723 (pri
->logical_block_size
);
631 s
->u
.isofs_sb
.s_max_size
= isonum_733(pri
->volume_space_size
);
634 s
->u
.isofs_sb
.s_ninodes
= 0; /* No way to figure this out easily */
636 orig_zonesize
= s
-> u
.isofs_sb
.s_log_zone_size
;
638 * If the zone size is smaller than the hardware sector size,
639 * this is a fatal error. This would occur if the disc drive
640 * had sectors that were 2048 bytes, but the filesystem had
641 * blocks that were 512 bytes (which should only very rarely
644 if(blocksize
!= 0 && orig_zonesize
< blocksize
)
647 /* RDE: convert log zone size to bit shift */
648 switch (s
-> u
.isofs_sb
.s_log_zone_size
)
649 { case 512: s
-> u
.isofs_sb
.s_log_zone_size
= 9; break;
650 case 1024: s
-> u
.isofs_sb
.s_log_zone_size
= 10; break;
651 case 2048: s
-> u
.isofs_sb
.s_log_zone_size
= 11; break;
654 goto out_bad_zone_size
;
657 s
->s_magic
= ISOFS_SUPER_MAGIC
;
659 /* The CDROM is read-only, has no nodes (devices) on it, and since
660 all of the files appear to be owned by root, we really do not want
661 to allow suid. (suid or devices will not show up unless we have
662 Rock Ridge extensions) */
664 s
->s_flags
|= MS_RDONLY
/* | MS_NODEV | MS_NOSUID */;
666 /* RDE: data zone now byte offset! */
668 first_data_zone
= ((isonum_733 (rootp
->extent
) +
669 isonum_711 (rootp
->ext_attr_length
))
670 << s
-> u
.isofs_sb
.s_log_zone_size
);
671 s
->u
.isofs_sb
.s_firstdatazone
= first_data_zone
;
673 printk(KERN_DEBUG
"Max size:%ld Log zone size:%ld\n",
674 s
->u
.isofs_sb
.s_max_size
,
675 1UL << s
->u
.isofs_sb
.s_log_zone_size
);
676 printk(KERN_DEBUG
"First datazone:%ld Root inode number:%ld\n",
677 s
->u
.isofs_sb
.s_firstdatazone
>> s
-> u
.isofs_sb
.s_log_zone_size
,
678 s
->u
.isofs_sb
.s_firstdatazone
);
680 printk(KERN_DEBUG
"Disc in High Sierra format.\n");
684 * If the Joliet level is set, we _may_ decide to use the
685 * secondary descriptor, but can't be sure until after we
686 * read the root inode. But before reading the root inode
687 * we may need to change the device blocksize, and would
688 * rather release the old buffer first. So, we cache the
689 * first_data_zone value from the secondary descriptor.
692 pri
= (struct iso_primary_descriptor
*) sec
;
693 rootp
= (struct iso_directory_record
*)
694 pri
->root_directory_record
;
695 first_data_zone
= ((isonum_733 (rootp
->extent
) +
696 isonum_711 (rootp
->ext_attr_length
))
697 << s
-> u
.isofs_sb
.s_log_zone_size
);
701 * We're all done using the volume descriptor, and may need
702 * to change the device blocksize, so release the buffer now.
708 * Force the blocksize to 512 for 512 byte sectors. The file
709 * read primitives really get it wrong in a bad way if we don't
712 * Note - we should never be setting the blocksize to something
713 * less than the hardware sector size for the device. If we
714 * do, we would end up having to read larger buffers and split
715 * out portions to satisfy requests.
717 * Note2- the idea here is that we want to deal with the optimal
718 * zonesize in the filesystem. If we have it set to something less,
719 * then we have horrible problems with trying to piece together
720 * bits of adjacent blocks in order to properly read directory
721 * entries. By forcing the blocksize in this way, we ensure
722 * that we will never be required to do this.
724 if ( orig_zonesize
!= opt
.blocksize
) {
725 set_blocksize(dev
, orig_zonesize
);
728 "ISOFS: Forcing new log zone size:%d\n", orig_zonesize
);
731 s
->s_blocksize
= orig_zonesize
;
732 s
->s_blocksize_bits
= s
-> u
.isofs_sb
.s_log_zone_size
;
734 s
->u
.isofs_sb
.s_nls_iocharset
= NULL
;
737 if (joliet_level
&& opt
.utf8
== 0) {
738 char * p
= opt
.iocharset
? opt
.iocharset
: "iso8859-1";
739 s
->u
.isofs_sb
.s_nls_iocharset
= load_nls(p
);
740 if (! s
->u
.isofs_sb
.s_nls_iocharset
) {
741 /* Fail only if explicit charset specified */
744 s
->u
.isofs_sb
.s_nls_iocharset
= load_nls_default();
748 s
->s_op
= &isofs_sops
;
749 s
->u
.isofs_sb
.s_mapping
= opt
.map
;
750 s
->u
.isofs_sb
.s_rock
= (opt
.rock
== 'y' ? 2 : 0);
751 s
->u
.isofs_sb
.s_cruft
= opt
.cruft
;
752 s
->u
.isofs_sb
.s_unhide
= opt
.unhide
;
753 s
->u
.isofs_sb
.s_uid
= opt
.uid
;
754 s
->u
.isofs_sb
.s_gid
= opt
.gid
;
755 s
->u
.isofs_sb
.s_utf8
= opt
.utf8
;
757 * It would be incredibly stupid to allow people to mark every file
758 * on the disk as suid, so we merely allow them to set the default
761 s
->u
.isofs_sb
.s_mode
= opt
.mode
& 0777;
764 * Read the root inode, which _may_ result in changing
765 * the s_rock flag. Once we have the final s_rock value,
766 * we then decide whether to use the Joliet descriptor.
768 inode
= iget(s
, s
->u
.isofs_sb
.s_firstdatazone
);
771 * If this disk has both Rock Ridge and Joliet on it, then we
772 * want to use Rock Ridge by default. This can be overridden
773 * by using the norock mount option. There is still one other
774 * possibility that is not taken into account: a Rock Ridge
775 * CD with Unicode names. Until someone sees such a beast, it
776 * will not be supported.
778 if (s
->u
.isofs_sb
.s_rock
== 1) {
780 } else if (joliet_level
) {
781 s
->u
.isofs_sb
.s_rock
= 0;
782 if (s
->u
.isofs_sb
.s_firstdatazone
!= first_data_zone
) {
783 s
->u
.isofs_sb
.s_firstdatazone
= first_data_zone
;
785 "ISOFS: changing to secondary root\n");
787 inode
= iget(s
, s
->u
.isofs_sb
.s_firstdatazone
);
791 if (opt
.check
== 'u') {
792 /* Only Joliet is case insensitive by default */
793 if (joliet_level
) opt
.check
= 'r';
794 else opt
.check
= 's';
796 s
->u
.isofs_sb
.s_joliet_level
= joliet_level
;
798 /* check the root inode */
803 /* get the root dentry */
804 s
->s_root
= d_alloc_root(inode
);
809 if (joliet_level
) table
+= 2;
810 if (opt
.check
== 'r') table
++;
811 s
->s_root
->d_op
= &isofs_dentry_ops
[table
];
816 * Display error messages and free resources.
819 printk(KERN_WARNING
"isofs_read_super: root inode not initialized\n");
822 printk(KERN_WARNING
"isofs_read_super: get root inode failed\n");
826 if (s
->u
.isofs_sb
.s_nls_iocharset
)
827 unload_nls(s
->u
.isofs_sb
.s_nls_iocharset
);
831 printk(KERN_WARNING
"isofs_read_super: "
832 "bread failed, dev=%s, iso_blknum=%d, block=%d\n",
833 kdevname(dev
), iso_blknum
, block
);
836 printk(KERN_WARNING
"Bad logical zone size %ld\n",
837 s
->u
.isofs_sb
.s_log_zone_size
);
840 printk(KERN_WARNING
"Logical zone size(%d) < hardware blocksize(%u)\n",
841 orig_zonesize
, blocksize
);
843 #ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
845 printk(KERN_WARNING
"Multi-volume disks not supported.\n");
850 printk(KERN_WARNING
"Unable to identify CD-ROM format.\n");
858 static int isofs_statfs (struct super_block
*sb
, struct statfs
*buf
)
860 buf
->f_type
= ISOFS_SUPER_MAGIC
;
861 buf
->f_bsize
= sb
->s_blocksize
;
862 buf
->f_blocks
= (sb
->u
.isofs_sb
.s_nzones
863 << (sb
->u
.isofs_sb
.s_log_zone_size
- sb
->s_blocksize_bits
));
866 buf
->f_files
= sb
->u
.isofs_sb
.s_ninodes
;
868 buf
->f_namelen
= NAME_MAX
;
872 /* Life is simpler than for other filesystem since we never
873 * have to create a new block, only find an existing one.
875 static int isofs_get_block(struct inode
*inode
, long iblock
,
876 struct buffer_head
*bh_result
, int create
)
879 unsigned offset
, sect_size
;
880 unsigned int firstext
;
881 unsigned long nextino
;
888 goto abort_create_attempted
;
896 /* If we are *way* beyond the end of the file, print a message.
897 * Access beyond the end of the file up to the next page boundary
898 * is normal, however because of the way the page cache works.
899 * In this case, we just return 0 so that we can properly fill
900 * the page with useless information without generating any
903 if (b_off
> ((inode
->i_size
+ PAGE_SIZE
- 1) >> ISOFS_BUFFER_BITS(inode
)))
904 goto abort_beyond_end
;
907 firstext
= inode
->u
.isofs_i
.i_first_extent
;
908 sect_size
= inode
->u
.isofs_i
.i_section_size
>> ISOFS_BUFFER_BITS(inode
);
909 nextino
= inode
->u
.isofs_i
.i_next_section_ino
;
913 while (b_off
>= (offset
+ sect_size
)) {
914 struct inode
*ninode
;
919 ninode
= iget(inode
->i_sb
, nextino
);
922 firstext
= ninode
->u
.isofs_i
.i_first_extent
;
923 sect_size
= ninode
->u
.isofs_i
.i_section_size
;
924 nextino
= ninode
->u
.isofs_i
.i_next_section_ino
;
928 goto abort_too_many_sections
;
932 bh_result
->b_dev
= inode
->i_dev
;
933 bh_result
->b_blocknr
= firstext
+ b_off
- offset
;
934 bh_result
->b_state
|= (1UL << BH_Mapped
);
941 abort_create_attempted
:
942 printk("isofs_get_block: Kernel tries to allocate a block\n");
946 printk("isofs_get_block: block < 0\n");
950 printk("isofs_get_block: block >= EOF (%ld, %ld)\n",
951 iblock
, (unsigned long) inode
->i_size
);
954 abort_too_many_sections
:
955 printk("isofs_get_block: More than 100 file sections ?!?, aborting...\n");
956 printk("isofs_get_block: ino=%lu block=%ld firstext=%u sect_size=%u nextino=%lu\n",
957 inode
->i_ino
, iblock
, firstext
, (unsigned) sect_size
, nextino
);
961 static int isofs_bmap(struct inode
*inode
, int block
)
963 struct buffer_head dummy
;
967 dummy
.b_blocknr
= -1000;
968 error
= isofs_get_block(inode
, block
, &dummy
, 0);
970 return dummy
.b_blocknr
;
974 struct buffer_head
*isofs_bread(struct inode
*inode
, unsigned int bufsize
, unsigned int block
)
976 unsigned int blknr
= isofs_bmap(inode
, block
);
979 return bread(inode
->i_dev
, blknr
, bufsize
);
982 static int isofs_readpage(struct file
*file
, struct page
*page
)
984 return block_read_full_page(page
,isofs_get_block
);
987 static int _isofs_bmap(struct address_space
*mapping
, long block
)
989 return generic_block_bmap(mapping
,block
,isofs_get_block
);
992 static struct address_space_operations isofs_aops
= {
993 readpage
: isofs_readpage
,
994 sync_page
: block_sync_page
,
998 static inline void test_and_set_uid(uid_t
*p
, uid_t value
)
1005 static inline void test_and_set_gid(gid_t
*p
, gid_t value
)
1012 static int isofs_read_level3_size(struct inode
* inode
)
1014 unsigned long f_pos
= inode
->i_ino
;
1015 unsigned long bufsize
= ISOFS_BUFFER_SIZE(inode
);
1016 int high_sierra
= inode
->i_sb
->u
.isofs_sb
.s_high_sierra
;
1017 struct buffer_head
* bh
= NULL
;
1018 unsigned long block
, offset
;
1020 int more_entries
= 0;
1021 struct iso_directory_record
* tmpde
= NULL
;
1024 inode
->u
.isofs_i
.i_next_section_ino
= 0;
1026 block
= f_pos
>> ISOFS_BUFFER_BITS(inode
);
1027 offset
= f_pos
& (bufsize
-1);
1030 struct iso_directory_record
* de
;
1031 unsigned int de_len
;
1034 bh
= bread(inode
->i_dev
, block
, bufsize
);
1038 de
= (struct iso_directory_record
*) (bh
->b_data
+ offset
);
1039 de_len
= *(unsigned char *) de
;
1044 f_pos
= (f_pos
+ ISOFS_BLOCK_SIZE
) & ~(ISOFS_BLOCK_SIZE
- 1);
1045 block
= f_pos
>> ISOFS_BUFFER_BITS(inode
);
1052 /* Make sure we have a full directory entry */
1053 if (offset
>= bufsize
) {
1054 int slop
= bufsize
- offset
+ de_len
;
1056 tmpde
= kmalloc(256, GFP_KERNEL
);
1060 memcpy(tmpde
, de
, slop
);
1061 offset
&= bufsize
- 1;
1066 bh
= bread(inode
->i_dev
, block
, bufsize
);
1069 memcpy((void *) tmpde
+ slop
, bh
->b_data
, offset
);
1074 inode
->i_size
+= isonum_733(de
->size
);
1076 inode
->u
.isofs_i
.i_next_section_ino
= f_pos
;
1078 more_entries
= de
->flags
[-high_sierra
] & 0x80;
1084 } while(more_entries
);
1098 printk(KERN_INFO
"ISOFS: unable to read i-node block %lu\n", block
);
1104 printk(KERN_INFO
"isofs_read_level3_size: "
1105 "More than 100 file sections ?!?, aborting...\n"
1106 "isofs_read_level3_size: inode=%lu ino=%lu\n",
1107 inode
->i_ino
, f_pos
);
1111 static void isofs_read_inode(struct inode
* inode
)
1113 struct super_block
*sb
= inode
->i_sb
;
1114 unsigned long bufsize
= ISOFS_BUFFER_SIZE(inode
);
1115 int block
= inode
->i_ino
>> ISOFS_BUFFER_BITS(inode
);
1116 int high_sierra
= sb
->u
.isofs_sb
.s_high_sierra
;
1117 struct buffer_head
* bh
= NULL
;
1118 struct iso_directory_record
* de
;
1119 struct iso_directory_record
* tmpde
= NULL
;
1120 unsigned int de_len
;
1121 unsigned long offset
;
1122 int volume_seq_no
, i
;
1124 bh
= bread(inode
->i_dev
, block
, bufsize
);
1128 offset
= (inode
->i_ino
& (bufsize
- 1));
1129 de
= (struct iso_directory_record
*) (bh
->b_data
+ offset
);
1130 de_len
= *(unsigned char *) de
;
1132 if (offset
+ de_len
> bufsize
) {
1133 int frag1
= bufsize
- offset
;
1135 tmpde
= kmalloc(de_len
, GFP_KERNEL
);
1136 if (tmpde
== NULL
) {
1137 printk(KERN_INFO
"isofs_read_inode: out of memory\n");
1140 memcpy(tmpde
, bh
->b_data
+ offset
, frag1
);
1142 bh
= bread(inode
->i_dev
, ++block
, bufsize
);
1145 memcpy((char *)tmpde
+frag1
, bh
->b_data
, de_len
- frag1
);
1149 if (de
->flags
[-high_sierra
] & 2) {
1150 inode
->i_mode
= S_IRUGO
| S_IXUGO
| S_IFDIR
;
1151 inode
->i_nlink
= 1; /* Set to 1. We know there are 2, but
1152 the find utility tries to optimize
1153 if it is 2, and it screws up. It is
1154 easier to give 1 which tells find to
1155 do it the hard way. */
1157 /* Everybody gets to read the file. */
1158 inode
->i_mode
= inode
->i_sb
->u
.isofs_sb
.s_mode
;
1160 inode
->i_mode
|= S_IFREG
;
1161 /* If there are no periods in the name,
1162 * then set the execute permission bit
1164 for(i
=0; i
< de
->name_len
[0]; i
++)
1165 if(de
->name
[i
]=='.' || de
->name
[i
]==';')
1167 if(i
== de
->name_len
[0] || de
->name
[i
] == ';')
1168 inode
->i_mode
|= S_IXUGO
; /* execute permission */
1170 inode
->i_uid
= inode
->i_sb
->u
.isofs_sb
.s_uid
;
1171 inode
->i_gid
= inode
->i_sb
->u
.isofs_sb
.s_gid
;
1172 inode
->i_blocks
= inode
->i_blksize
= 0;
1175 inode
->u
.isofs_i
.i_section_size
= isonum_733 (de
->size
);
1176 if(de
->flags
[-high_sierra
] & 0x80) {
1177 if(isofs_read_level3_size(inode
)) goto fail
;
1179 inode
->i_size
= isonum_733 (de
->size
);
1182 /* There are defective discs out there - we do this to protect
1183 ourselves. A cdrom will never contain more than 800Mb
1184 .. but a DVD may be up to 1Gig (Ulrich Habel) */
1186 if ((inode
->i_size
< 0 || inode
->i_size
> 1073741824) &&
1187 inode
->i_sb
->u
.isofs_sb
.s_cruft
== 'n') {
1188 printk(KERN_WARNING
"Warning: defective CD-ROM. "
1189 "Enabling \"cruft\" mount option.\n");
1190 inode
->i_sb
->u
.isofs_sb
.s_cruft
= 'y';
1194 * Some dipshit decided to store some other bit of information
1195 * in the high byte of the file length. Catch this and holler.
1196 * WARNING: this will make it impossible for a file to be > 16MB
1200 if (inode
->i_sb
->u
.isofs_sb
.s_cruft
== 'y' &&
1201 inode
->i_size
& 0xff000000) {
1202 inode
->i_size
&= 0x00ffffff;
1205 if (de
->interleave
[0]) {
1206 printk("Interleaved files not (yet) supported.\n");
1210 /* I have no idea what file_unit_size is used for, so
1211 we will flag it for now */
1212 if (de
->file_unit_size
[0] != 0) {
1213 printk("File unit size != 0 for ISO file (%ld).\n",
1217 /* I have no idea what other flag bits are used for, so
1218 we will flag it for now */
1220 if((de
->flags
[-high_sierra
] & ~2)!= 0){
1221 printk("Unusual flag settings for ISO file (%ld %x).\n",
1222 inode
->i_ino
, de
->flags
[-high_sierra
]);
1226 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
=
1227 iso_date(de
->date
, high_sierra
);
1229 inode
->u
.isofs_i
.i_first_extent
= (isonum_733 (de
->extent
) +
1230 isonum_711 (de
->ext_attr_length
));
1233 * Now test for possible Rock Ridge extensions which will override
1234 * some of these numbers in the inode structure.
1238 parse_rock_ridge_inode(de
, inode
);
1239 /* if we want uid/gid set, override the rock ridge setting */
1240 test_and_set_uid(&inode
->i_uid
, inode
->i_sb
->u
.isofs_sb
.s_uid
);
1241 test_and_set_gid(&inode
->i_gid
, inode
->i_sb
->u
.isofs_sb
.s_gid
);
1244 /* get the volume sequence number */
1245 volume_seq_no
= isonum_723 (de
->volume_sequence_number
) ;
1248 * Disable checking if we see any volume number other than 0 or 1.
1249 * We could use the cruft option, but that has multiple purposes, one
1250 * of which is limiting the file size to 16Mb. Thus we silently allow
1251 * volume numbers of 0 to go through without complaining.
1253 if (inode
->i_sb
->u
.isofs_sb
.s_cruft
== 'n' &&
1254 (volume_seq_no
!= 0) && (volume_seq_no
!= 1)) {
1255 printk(KERN_WARNING
"Warning: defective CD-ROM "
1256 "(volume sequence number %d). "
1257 "Enabling \"cruft\" mount option.\n", volume_seq_no
);
1258 inode
->i_sb
->u
.isofs_sb
.s_cruft
= 'y';
1261 /* Install the inode operations vector */
1262 #ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
1263 if (inode
->i_sb
->u
.isofs_sb
.s_cruft
!= 'y' &&
1264 (volume_seq_no
!= 0) && (volume_seq_no
!= 1)) {
1265 printk(KERN_WARNING
"Multi-volume CD somehow got mounted.\n");
1267 #endif IGNORE_WRONG_MULTI_VOLUME_SPECS
1269 if (S_ISREG(inode
->i_mode
)) {
1270 inode
->i_fop
= &generic_ro_fops
;
1271 inode
->i_data
.a_ops
= &isofs_aops
;
1272 } else if (S_ISDIR(inode
->i_mode
)) {
1273 inode
->i_op
= &isofs_dir_inode_operations
;
1274 inode
->i_fop
= &isofs_dir_operations
;
1275 } else if (S_ISLNK(inode
->i_mode
)) {
1276 inode
->i_op
= &page_symlink_inode_operations
;
1277 inode
->i_data
.a_ops
= &isofs_symlink_aops
;
1279 /* XXX - parse_rock_ridge_inode() had already set i_rdev. */
1280 init_special_inode(inode
, inode
->i_mode
,
1281 kdev_t_to_nr(inode
->i_rdev
));
1291 printk(KERN_WARNING
"ISOFS: unable to read i-node block\n");
1293 make_bad_inode(inode
);
1303 void * leak_check_malloc(unsigned int size
){
1306 tmp
= kmalloc(size
, GFP_KERNEL
);
1310 void leak_check_free_s(void * obj
, int size
){
1315 struct buffer_head
* leak_check_bread(int dev
, int block
, int size
){
1317 return bread(dev
, block
, size
);
1320 void leak_check_brelse(struct buffer_head
* bh
){
1327 static DECLARE_FSTYPE_DEV(iso9660_fs_type
, "iso9660", isofs_read_super
);
1329 static int __init
init_iso9660_fs(void)
1331 return register_filesystem(&iso9660_fs_type
);
1334 static void __exit
exit_iso9660_fs(void)
1336 unregister_filesystem(&iso9660_fs_type
);
1341 module_init(init_iso9660_fs
)
1342 module_exit(exit_iso9660_fs
)