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>
30 #include <asm/system.h>
31 #include <asm/uaccess.h>
34 * We have no support for "multi volume" CDs, but more and more disks carry
35 * wrong information within the volume descriptors.
37 #define IGNORE_WRONG_MULTI_VOLUME_SPECS
41 static int check_malloc
= 0;
42 static int check_bread
= 0;
45 static int isofs_hashi(struct dentry
*parent
, struct qstr
*qstr
);
46 static int isofs_hash(struct dentry
*parent
, struct qstr
*qstr
);
47 static int isofs_cmpi(struct dentry
*dentry
, struct qstr
*a
, struct qstr
*b
);
48 static int isofs_cmp(struct dentry
*dentry
, struct qstr
*a
, struct qstr
*b
);
51 static int isofs_hashi_ms(struct dentry
*parent
, struct qstr
*qstr
);
52 static int isofs_hash_ms(struct dentry
*parent
, struct qstr
*qstr
);
53 static int isofs_cmpi_ms(struct dentry
*dentry
, struct qstr
*a
, struct qstr
*b
);
54 static int isofs_cmp_ms(struct dentry
*dentry
, struct qstr
*a
, struct qstr
*b
);
57 void isofs_put_super(struct super_block
*sb
)
60 if (sb
->u
.isofs_sb
.s_nls_iocharset
) {
61 unload_nls(sb
->u
.isofs_sb
.s_nls_iocharset
);
62 sb
->u
.isofs_sb
.s_nls_iocharset
= NULL
;
67 printk("Outstanding mallocs:%d, outstanding buffers: %d\n",
68 check_malloc
, check_bread
);
75 static struct super_operations isofs_sops
= {
77 NULL
, /* write_inode */
79 NULL
, /* delete_inode */
80 NULL
, /* notify_change */
82 NULL
, /* write_super */
87 static struct dentry_operations isofs_dentry_ops
[] = {
89 NULL
, /* d_revalidate */
95 NULL
, /* d_revalidate */
102 NULL
, /* d_revalidate */
108 NULL
, /* d_revalidate */
116 struct iso9660_options
{
123 unsigned int blocksize
;
132 * Compute the hash for the isofs name corresponding to the dentry.
135 isofs_hash_common(struct dentry
*dentry
, struct qstr
*qstr
, int ms
)
143 while (len
&& name
[len
-1] == '.')
147 qstr
->hash
= full_name_hash(name
, len
);
153 * Compute the hash for the isofs name corresponding to the dentry.
156 isofs_hashi_common(struct dentry
*dentry
, struct qstr
*qstr
, int ms
)
166 while (len
&& name
[len
-1] == '.')
170 hash
= init_name_hash();
172 c
= tolower(*name
++);
173 hash
= partial_name_hash(tolower(c
), hash
);
175 qstr
->hash
= end_name_hash(hash
);
181 * Case insensitive compare of two isofs names.
184 isofs_cmpi_common(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
,int ms
)
188 /* A filename cannot end in '.' or we treat it like it has none */
192 while (alen
&& a
->name
[alen
-1] == '.')
194 while (blen
&& b
->name
[blen
-1] == '.')
198 if (strnicmp(a
->name
, b
->name
, alen
) == 0)
205 * Case sensitive compare of two isofs names.
208 isofs_cmp_common(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
,int ms
)
212 /* A filename cannot end in '.' or we treat it like it has none */
216 while (alen
&& a
->name
[alen
-1] == '.')
218 while (blen
&& b
->name
[blen
-1] == '.')
222 if (strncmp(a
->name
, b
->name
, alen
) == 0)
229 isofs_hash(struct dentry
*dentry
, struct qstr
*qstr
)
231 return isofs_hash_common(dentry
, qstr
, 0);
235 isofs_hashi(struct dentry
*dentry
, struct qstr
*qstr
)
237 return isofs_hashi_common(dentry
, qstr
, 0);
241 isofs_cmp(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
)
243 return isofs_cmp_common(dentry
, a
, b
, 0);
247 isofs_cmpi(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
)
249 return isofs_cmpi_common(dentry
, a
, b
, 0);
254 isofs_hash_ms(struct dentry
*dentry
, struct qstr
*qstr
)
256 return isofs_hash_common(dentry
, qstr
, 1);
260 isofs_hashi_ms(struct dentry
*dentry
, struct qstr
*qstr
)
262 return isofs_hashi_common(dentry
, qstr
, 1);
266 isofs_cmp_ms(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
)
268 return isofs_cmp_common(dentry
, a
, b
, 1);
272 isofs_cmpi_ms(struct dentry
*dentry
,struct qstr
*a
,struct qstr
*b
)
274 return isofs_cmpi_common(dentry
, a
, b
, 1);
278 static int parse_options(char *options
, struct iso9660_options
* popt
)
280 char *this_char
,*value
;
287 popt
->check
= 'u'; /* unset */
288 popt
->blocksize
= 1024;
289 popt
->mode
= S_IRUGO
| S_IXUGO
; /* r-x for all. The disc could
290 be shared with DOS machines so
291 virtually anything could be
292 a valid executable. */
295 popt
->iocharset
= NULL
;
297 if (!options
) return 1;
298 for (this_char
= strtok(options
,","); this_char
; this_char
= strtok(NULL
,",")) {
299 if (strncmp(this_char
,"norock",6) == 0) {
303 if (strncmp(this_char
,"nojoliet",8) == 0) {
307 if (strncmp(this_char
,"unhide",6) == 0) {
311 if (strncmp(this_char
,"cruft",5) == 0) {
315 if (strncmp(this_char
,"utf8",4) == 0) {
319 if ((value
= strchr(this_char
,'=')) != NULL
)
323 if (!strcmp(this_char
,"iocharset") && value
) {
324 popt
->iocharset
= value
;
325 while (*value
&& *value
!= ',')
327 if (value
== popt
->iocharset
)
332 if (!strcmp(this_char
,"map") && value
) {
333 if (value
[0] && !value
[1] && strchr("ano",*value
))
335 else if (!strcmp(value
,"off")) popt
->map
= 'o';
336 else if (!strcmp(value
,"normal")) popt
->map
= 'n';
337 else if (!strcmp(value
,"acorn")) popt
->map
= 'a';
340 else if (!strcmp(this_char
,"check") && value
) {
341 if (value
[0] && !value
[1] && strchr("rs",*value
))
342 popt
->check
= *value
;
343 else if (!strcmp(value
,"relaxed")) popt
->check
= 'r';
344 else if (!strcmp(value
,"strict")) popt
->check
= 's';
347 else if (!strcmp(this_char
,"conv") && value
) {
348 /* no conversion is done anymore;
349 we still accept the same mount options,
351 if (value
[0] && !value
[1] && strchr("btma",*value
)) ;
352 else if (!strcmp(value
,"binary")) ;
353 else if (!strcmp(value
,"text")) ;
354 else if (!strcmp(value
,"mtext")) ;
355 else if (!strcmp(value
,"auto")) ;
359 (!strcmp(this_char
,"block") ||
360 !strcmp(this_char
,"mode") ||
361 !strcmp(this_char
,"uid") ||
362 !strcmp(this_char
,"gid"))) {
364 unsigned int ivalue
= simple_strtoul(vpnt
, &vpnt
, 0);
370 && ivalue
!= 2048) return 0;
371 popt
->blocksize
= ivalue
;
390 * look if the driver can tell the multi session redirection value
392 * don't change this if you don't know what you do, please!
393 * Multisession is legal only with XA disks.
394 * A non-XA disk with more than one volume descriptor may do it right, but
395 * usually is written in a nowhere standardized "multi-partition" manner.
396 * Multisession uses absolute addressing (solely the first frame of the whole
397 * track is #0), multi-partition uses relative addressing (each first frame of
398 * each track is #0), and a track is not a session.
400 * A broken CDwriter software or drive firmware does not set new standards,
401 * at least not if conflicting with the existing ones.
405 #define WE_OBEY_THE_WRITTEN_STANDARDS 1
407 static unsigned int isofs_get_last_session(kdev_t dev
)
409 struct cdrom_multisession ms_info
;
410 unsigned int vol_desc_start
;
411 struct inode inode_fake
;
412 struct file_operations
*fops
;
413 extern struct file_operations
* get_blkfops(unsigned int);
417 fops
= get_blkfops(MAJOR(dev
));
418 if (fops
&& fops
->ioctl
)
420 /* Whoops. We must save the old FS, since otherwise
421 * we would destroy the kernels idea about FS on root
422 * mount in read_super... [chexum]
424 mm_segment_t old_fs
=get_fs();
425 inode_fake
.i_rdev
=dev
;
426 init_waitqueue_head(&inode_fake
.i_wait
);
427 ms_info
.addr_format
=CDROM_LBA
;
429 i
=get_blkfops(MAJOR(dev
))->ioctl(&inode_fake
,
432 (unsigned long) &ms_info
);
435 printk("isofs.inode: CDROMMULTISESSION: rc=%d\n",i
);
438 printk("isofs.inode: XA disk: %s\n", ms_info
.xa_flag
? "yes":"no");
439 printk("isofs.inode: vol_desc_start = %d\n", ms_info
.addr
.lba
);
443 #if WE_OBEY_THE_WRITTEN_STANDARDS
444 if (ms_info
.xa_flag
) /* necessary for a valid ms_info.addr */
446 vol_desc_start
=ms_info
.addr
.lba
;
448 return vol_desc_start
;
452 * Initialize the superblock and read the root inode.
454 * Note: a check_disk_change() has been done immediately prior
455 * to this call, so we don't need to check again.
457 struct super_block
*isofs_read_super(struct super_block
*s
, void *data
,
460 kdev_t dev
= s
->s_dev
;
461 struct buffer_head
* bh
= NULL
, *pri_bh
= NULL
;
462 struct hs_primary_descriptor
* h_pri
= NULL
;
463 struct iso_primary_descriptor
* pri
= NULL
;
464 struct iso_supplementary_descriptor
*sec
= NULL
;
465 struct iso_directory_record
* rootp
;
466 int joliet_level
= 0;
468 int iso_blknum
, block
;
471 unsigned int blocksize
, blocksize_bits
;
472 unsigned int vol_desc_start
;
473 unsigned long first_data_zone
;
474 struct inode
* inode
;
475 struct iso9660_options opt
;
478 /* lock before any blocking operations */
481 if (!parse_options((char *) data
, &opt
))
485 printk("map = %c\n", opt
.map
);
486 printk("rock = %c\n", opt
.rock
);
487 printk("joliet = %c\n", opt
.joliet
);
488 printk("check = %c\n", opt
.check
);
489 printk("cruft = %c\n", opt
.cruft
);
490 printk("unhide = %c\n", opt
.unhide
);
491 printk("blocksize = %d\n", opt
.blocksize
);
492 printk("gid = %d\n", opt
.gid
);
493 printk("uid = %d\n", opt
.uid
);
494 printk("iocharset = %s\n", opt
.iocharset
);
498 * First of all, get the hardware blocksize for this device.
499 * If we don't know what it is, or the hardware blocksize is
500 * larger than the blocksize the user specified, then use
503 blocksize
= get_hardblocksize(dev
);
505 && (blocksize
> opt
.blocksize
) )
508 * Force the blocksize we are going to use to be the
509 * hardware blocksize.
511 opt
.blocksize
= blocksize
;
516 int i
= opt
.blocksize
;
523 set_blocksize(dev
, opt
.blocksize
);
525 s
->u
.isofs_sb
.s_high_sierra
= high_sierra
= 0; /* default is iso9660 */
527 vol_desc_start
= isofs_get_last_session(dev
);
529 for (iso_blknum
= vol_desc_start
+16;
530 iso_blknum
< vol_desc_start
+100; iso_blknum
++)
532 struct hs_volume_descriptor
* hdp
;
533 struct iso_volume_descriptor
* vdp
;
535 block
= iso_blknum
<< (ISOFS_BLOCK_BITS
-blocksize_bits
);
536 if (!(bh
= bread(dev
, block
, opt
.blocksize
)))
539 vdp
= (struct iso_volume_descriptor
*)bh
->b_data
;
540 hdp
= (struct hs_volume_descriptor
*)bh
->b_data
;
542 /* Due to the overlapping physical location of the descriptors,
543 * ISO CDs can match hdp->id==HS_STANDARD_ID as well. To ensure
544 * proper identification in this case, we first check for ISO.
546 if (strncmp (vdp
->id
, ISO_STANDARD_ID
, sizeof vdp
->id
) == 0) {
547 if (isonum_711 (vdp
->type
) == ISO_VD_END
)
549 if (isonum_711 (vdp
->type
) == ISO_VD_PRIMARY
) {
551 pri
= (struct iso_primary_descriptor
*)vdp
;
552 /* Save the buffer in case we need it ... */
558 else if (isonum_711 (vdp
->type
) == ISO_VD_SUPPLEMENTARY
) {
559 sec
= (struct iso_supplementary_descriptor
*)vdp
;
560 if (sec
->escape
[0] == 0x25 && sec
->escape
[1] == 0x2f) {
561 if (opt
.joliet
== 'y') {
562 if (sec
->escape
[2] == 0x40) {
564 } else if (sec
->escape
[2] == 0x43) {
566 } else if (sec
->escape
[2] == 0x45) {
569 printk(KERN_DEBUG
"ISO 9660 Extensions: Microsoft Joliet Level %d\n",
574 /* Unknown supplementary volume descriptor */
580 if (strncmp (hdp
->id
, HS_STANDARD_ID
, sizeof hdp
->id
) == 0) {
581 if (isonum_711 (hdp
->type
) != ISO_VD_PRIMARY
)
584 s
->u
.isofs_sb
.s_high_sierra
= 1;
587 h_pri
= (struct hs_primary_descriptor
*)vdp
;
592 /* Just skip any volume descriptors we don't recognize */
598 * If we fall through, either no volume descriptor was found,
599 * or else we passed a primary descriptor looking for others.
602 goto out_unknown_format
;
610 if (joliet_level
&& opt
.rock
== 'n') {
611 /* This is the case of Joliet with the norock mount flag.
612 * A disc with both Joliet and Rock Ridge is handled later
614 pri
= (struct iso_primary_descriptor
*) sec
;
618 rootp
= (struct iso_directory_record
*) h_pri
->root_directory_record
;
619 #ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
620 if (isonum_723 (h_pri
->volume_set_size
) != 1)
622 #endif IGNORE_WRONG_MULTI_VOLUME_SPECS
623 s
->u
.isofs_sb
.s_nzones
= isonum_733 (h_pri
->volume_space_size
);
624 s
->u
.isofs_sb
.s_log_zone_size
= isonum_723 (h_pri
->logical_block_size
);
625 s
->u
.isofs_sb
.s_max_size
= isonum_733(h_pri
->volume_space_size
);
627 rootp
= (struct iso_directory_record
*) pri
->root_directory_record
;
628 #ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
629 if (isonum_723 (pri
->volume_set_size
) != 1)
631 #endif IGNORE_WRONG_MULTI_VOLUME_SPECS
632 s
->u
.isofs_sb
.s_nzones
= isonum_733 (pri
->volume_space_size
);
633 s
->u
.isofs_sb
.s_log_zone_size
= isonum_723 (pri
->logical_block_size
);
634 s
->u
.isofs_sb
.s_max_size
= isonum_733(pri
->volume_space_size
);
637 s
->u
.isofs_sb
.s_ninodes
= 0; /* No way to figure this out easily */
639 orig_zonesize
= s
-> u
.isofs_sb
.s_log_zone_size
;
641 * If the zone size is smaller than the hardware sector size,
642 * this is a fatal error. This would occur if the disc drive
643 * had sectors that were 2048 bytes, but the filesystem had
644 * blocks that were 512 bytes (which should only very rarely
647 if(blocksize
!= 0 && orig_zonesize
< blocksize
)
650 /* RDE: convert log zone size to bit shift */
651 switch (s
-> u
.isofs_sb
.s_log_zone_size
)
652 { case 512: s
-> u
.isofs_sb
.s_log_zone_size
= 9; break;
653 case 1024: s
-> u
.isofs_sb
.s_log_zone_size
= 10; break;
654 case 2048: s
-> u
.isofs_sb
.s_log_zone_size
= 11; break;
657 goto out_bad_zone_size
;
660 s
->s_magic
= ISOFS_SUPER_MAGIC
;
662 /* The CDROM is read-only, has no nodes (devices) on it, and since
663 all of the files appear to be owned by root, we really do not want
664 to allow suid. (suid or devices will not show up unless we have
665 Rock Ridge extensions) */
667 s
->s_flags
|= MS_RDONLY
/* | MS_NODEV | MS_NOSUID */;
669 /* RDE: data zone now byte offset! */
671 first_data_zone
= ((isonum_733 (rootp
->extent
) +
672 isonum_711 (rootp
->ext_attr_length
))
673 << s
-> u
.isofs_sb
.s_log_zone_size
);
674 s
->u
.isofs_sb
.s_firstdatazone
= first_data_zone
;
676 printk(KERN_DEBUG
"Max size:%ld Log zone size:%ld\n",
677 s
->u
.isofs_sb
.s_max_size
,
678 1UL << s
->u
.isofs_sb
.s_log_zone_size
);
679 printk(KERN_DEBUG
"First datazone:%ld Root inode number:%ld\n",
680 s
->u
.isofs_sb
.s_firstdatazone
>> s
-> u
.isofs_sb
.s_log_zone_size
,
681 s
->u
.isofs_sb
.s_firstdatazone
);
683 printk(KERN_DEBUG
"Disc in High Sierra format.\n");
687 * If the Joliet level is set, we _may_ decide to use the
688 * secondary descriptor, but can't be sure until after we
689 * read the root inode. But before reading the root inode
690 * we may need to change the device blocksize, and would
691 * rather release the old buffer first. So, we cache the
692 * first_data_zone value from the secondary descriptor.
695 pri
= (struct iso_primary_descriptor
*) sec
;
696 rootp
= (struct iso_directory_record
*)
697 pri
->root_directory_record
;
698 first_data_zone
= ((isonum_733 (rootp
->extent
) +
699 isonum_711 (rootp
->ext_attr_length
))
700 << s
-> u
.isofs_sb
.s_log_zone_size
);
704 * We're all done using the volume descriptor, and may need
705 * to change the device blocksize, so release the buffer now.
710 * Force the blocksize to 512 for 512 byte sectors. The file
711 * read primitives really get it wrong in a bad way if we don't
714 * Note - we should never be setting the blocksize to something
715 * less than the hardware sector size for the device. If we
716 * do, we would end up having to read larger buffers and split
717 * out portions to satisfy requests.
719 * Note2- the idea here is that we want to deal with the optimal
720 * zonesize in the filesystem. If we have it set to something less,
721 * then we have horrible problems with trying to piece together
722 * bits of adjacent blocks in order to properly read directory
723 * entries. By forcing the blocksize in this way, we ensure
724 * that we will never be required to do this.
726 if ( orig_zonesize
!= opt
.blocksize
) {
727 set_blocksize(dev
, orig_zonesize
);
730 "ISOFS: Forcing new log zone size:%d\n", orig_zonesize
);
733 s
->s_blocksize
= orig_zonesize
;
734 s
->s_blocksize_bits
= s
-> u
.isofs_sb
.s_log_zone_size
;
736 s
->u
.isofs_sb
.s_nls_iocharset
= NULL
;
739 if (joliet_level
&& opt
.utf8
== 0) {
740 char * p
= opt
.iocharset
? opt
.iocharset
: "iso8859-1";
741 s
->u
.isofs_sb
.s_nls_iocharset
= load_nls(p
);
742 if (! s
->u
.isofs_sb
.s_nls_iocharset
) {
743 /* Fail only if explicit charset specified */
746 s
->u
.isofs_sb
.s_nls_iocharset
= load_nls_default();
750 s
->s_op
= &isofs_sops
;
751 s
->u
.isofs_sb
.s_mapping
= opt
.map
;
752 s
->u
.isofs_sb
.s_rock
= (opt
.rock
== 'y' ? 2 : 0);
753 s
->u
.isofs_sb
.s_cruft
= opt
.cruft
;
754 s
->u
.isofs_sb
.s_unhide
= opt
.unhide
;
755 s
->u
.isofs_sb
.s_uid
= opt
.uid
;
756 s
->u
.isofs_sb
.s_gid
= opt
.gid
;
757 s
->u
.isofs_sb
.s_utf8
= opt
.utf8
;
759 * It would be incredibly stupid to allow people to mark every file on the disk
760 * as suid, so we merely allow them to set the default permissions.
762 s
->u
.isofs_sb
.s_mode
= opt
.mode
& 0777;
765 * Read the root inode, which _may_ result in changing
766 * the s_rock flag. Once we have the final s_rock value,
767 * we then decide whether to use the Joliet descriptor.
769 inode
= iget(s
, s
->u
.isofs_sb
.s_firstdatazone
);
772 * If this disk has both Rock Ridge and Joliet on it, then we
773 * want to use Rock Ridge by default. This can be overridden
774 * by using the norock mount option. There is still one other
775 * possibility that is not taken into account: a Rock Ridge
776 * CD with Unicode names. Until someone sees such a beast, it
777 * will not be supported.
779 if (s
->u
.isofs_sb
.s_rock
== 1) {
781 } else if (joliet_level
) {
782 s
->u
.isofs_sb
.s_rock
= 0;
783 if (s
->u
.isofs_sb
.s_firstdatazone
!= first_data_zone
) {
784 s
->u
.isofs_sb
.s_firstdatazone
= first_data_zone
;
786 "ISOFS: changing to secondary root\n");
788 inode
= iget(s
, s
->u
.isofs_sb
.s_firstdatazone
);
792 if (opt
.check
== 'u') {
793 /* Only Joliet is case insensitive by default */
794 if (joliet_level
) opt
.check
= 'r';
795 else opt
.check
= 's';
797 s
->u
.isofs_sb
.s_joliet_level
= joliet_level
;
799 /* check the root inode */
804 /* get the root dentry */
805 s
->s_root
= d_alloc_root(inode
, NULL
);
810 if (joliet_level
) table
+= 2;
811 if (opt
.check
== 'r') table
++;
812 s
->s_root
->d_op
= &isofs_dentry_ops
[table
];
818 * Display error messages and free resources.
821 printk(KERN_WARNING
"isofs_read_super: root inode not initialized\n");
824 printk(KERN_WARNING
"isofs_read_super: get root inode failed\n");
828 if (s
->u
.isofs_sb
.s_nls_iocharset
)
829 unload_nls(s
->u
.isofs_sb
.s_nls_iocharset
);
833 printk(KERN_WARNING
"isofs_read_super: "
834 "bread failed, dev=%s, iso_blknum=%d, block=%d\n",
835 kdevname(dev
), iso_blknum
, block
);
838 printk(KERN_WARNING
"Bad logical zone size %ld\n",
839 s
->u
.isofs_sb
.s_log_zone_size
);
842 printk(KERN_WARNING
"Logical zone size(%d) < hardware blocksize(%u)\n",
843 orig_zonesize
, blocksize
);
845 #ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
847 printk(KERN_WARNING
"Multi-volume disks not supported.\n");
852 printk(KERN_WARNING
"Unable to identify CD-ROM format.\n");
863 int isofs_statfs (struct super_block
*sb
, struct statfs
*buf
, int bufsiz
)
867 tmp
.f_type
= ISOFS_SUPER_MAGIC
;
868 tmp
.f_bsize
= sb
->s_blocksize
;
869 tmp
.f_blocks
= (sb
->u
.isofs_sb
.s_nzones
870 << (sb
->u
.isofs_sb
.s_log_zone_size
- sb
->s_blocksize_bits
));
873 tmp
.f_files
= sb
->u
.isofs_sb
.s_ninodes
;
875 tmp
.f_namelen
= NAME_MAX
;
876 return copy_to_user(buf
, &tmp
, bufsiz
) ? -EFAULT
: 0;
879 int isofs_bmap(struct inode
* inode
,int block
)
881 off_t b_off
, offset
, size
;
883 unsigned int firstext
;
884 unsigned long nextino
;
888 printk("_isofs_bmap: block<0");
892 b_off
= block
<< ISOFS_BUFFER_BITS(inode
);
895 * If we are beyond the end of this file, don't give out any
898 if( b_off
> inode
->i_size
)
900 off_t max_legal_read_offset
;
903 * If we are *way* beyond the end of the file, print a message.
904 * Access beyond the end of the file up to the next page boundary
905 * is normal, however because of the way the page cache works.
906 * In this case, we just return 0 so that we can properly fill
907 * the page with useless information without generating any
910 max_legal_read_offset
= (inode
->i_size
+ PAGE_SIZE
- 1)
912 if( b_off
>= max_legal_read_offset
)
915 printk("_isofs_bmap: block>= EOF(%d, %ld)\n", block
,
922 firstext
= inode
->u
.isofs_i
.i_first_extent
;
923 size
= inode
->u
.isofs_i
.i_section_size
;
924 nextino
= inode
->u
.isofs_i
.i_next_section_ino
;
926 printk("first inode: inode=%x nextino=%x firstext=%u size=%lu\n",
927 inode
->i_ino
, nextino
, firstext
, size
);
931 while(b_off
>= offset
+ size
) {
934 if(nextino
== 0) return 0;
935 ino
= iget(inode
->i_sb
, nextino
);
937 firstext
= ino
->u
.isofs_i
.i_first_extent
;
938 size
= ino
->u
.isofs_i
.i_section_size
;
940 printk("read inode: inode=%lu ino=%lu nextino=%lu firstext=%u size=%lu\n",
941 inode
->i_ino
, nextino
, ino
->u
.isofs_i
.i_next_section_ino
, firstext
, size
);
943 nextino
= ino
->u
.isofs_i
.i_next_section_ino
;
947 printk("isofs_bmap: More than 100 file sections ?!?, aborting...\n");
948 printk("isofs_bmap: ino=%lu block=%d firstext=%u size=%u nextino=%lu\n",
949 inode
->i_ino
, block
, firstext
, (unsigned)size
, nextino
);
955 printk("isofs_bmap: mapped inode:block %x:%d to block %lu\n",
956 inode
->i_ino
, block
, (b_off
- offset
+ firstext
) >> ISOFS_BUFFER_BITS(inode
));
958 return (b_off
- offset
+ firstext
) >> ISOFS_BUFFER_BITS(inode
);
962 static void test_and_set_uid(uid_t
*p
, uid_t value
)
967 printk("Resetting to %d\n", value
);
972 static int isofs_read_level3_size(struct inode
* inode
)
974 unsigned long ino
= inode
->i_ino
;
975 unsigned long bufsize
= ISOFS_BUFFER_SIZE(inode
);
976 int high_sierra
= inode
->i_sb
->u
.isofs_sb
.s_high_sierra
;
977 struct buffer_head
* bh
= NULL
;
981 struct iso_directory_record
* raw_inode
;
984 inode
->u
.isofs_i
.i_next_section_ino
= 0;
988 int offset
= (ino
& (bufsize
- 1));
991 /* Check whether to update our buffer */
992 if (block
!= ino
>> ISOFS_BUFFER_BITS(inode
)) {
993 block
= ino
>> ISOFS_BUFFER_BITS(inode
);
995 bh
= bread(inode
->i_dev
, block
, bufsize
);
999 pnt
= ((unsigned char *) bh
->b_data
+ offset
);
1000 raw_inode
= ((struct iso_directory_record
*) pnt
);
1002 * Note: this is invariant even if the record
1003 * spans buffers and must be copied ...
1007 /* N.B. this test doesn't trigger the i++ code ... */
1009 ino
= (ino
& ~(ISOFS_BLOCK_SIZE
- 1)) + ISOFS_BLOCK_SIZE
;
1013 /* Check whether the raw inode spans the buffer ... */
1014 if (offset
+ reclen
> bufsize
){
1015 int frag1
= bufsize
- offset
;
1017 cpnt
= kmalloc(reclen
, GFP_KERNEL
);
1020 memcpy(cpnt
, pnt
, frag1
);
1022 bh
= bread(inode
->i_dev
, ++block
, bufsize
);
1025 offset
+= reclen
- bufsize
;
1026 memcpy((char *)cpnt
+frag1
, bh
->b_data
, offset
);
1027 raw_inode
= ((struct iso_directory_record
*) cpnt
);
1030 inode
->i_size
+= isonum_733 (raw_inode
->size
);
1031 if(i
== 1) inode
->u
.isofs_i
.i_next_section_ino
= ino
;
1039 } while(raw_inode
->flags
[-high_sierra
] & 0x80);
1045 printk(KERN_INFO
"ISOFS: NoMem ISO inode %lu\n", inode
->i_ino
);
1049 printk(KERN_INFO
"ISOFS: unable to read i-node block %d\n", block
);
1054 printk(KERN_INFO
"isofs_read_level3_size: "
1055 "More than 100 file sections ?!?, aborting...\n"
1056 "isofs_read_level3_size: inode=%lu ino=%lu\n",
1061 void isofs_read_inode(struct inode
* inode
)
1063 struct super_block
*sb
= inode
->i_sb
;
1064 unsigned long bufsize
= ISOFS_BUFFER_SIZE(inode
);
1065 int block
= inode
->i_ino
>> ISOFS_BUFFER_BITS(inode
);
1066 int high_sierra
= sb
->u
.isofs_sb
.s_high_sierra
;
1067 struct buffer_head
* bh
;
1068 struct iso_directory_record
* raw_inode
;
1070 int volume_seq_no
, i
;
1072 bh
= bread(inode
->i_dev
, block
, bufsize
);
1074 printk(KERN_WARNING
"ISOFS: unable to read i-node block\n");
1078 pnt
= ((unsigned char *) bh
->b_data
1079 + (inode
->i_ino
& (bufsize
- 1)));
1080 raw_inode
= ((struct iso_directory_record
*) pnt
);
1082 if (raw_inode
->flags
[-high_sierra
] & 2) {
1083 inode
->i_mode
= S_IRUGO
| S_IXUGO
| S_IFDIR
;
1084 inode
->i_nlink
= 1; /* Set to 1. We know there are 2, but
1085 the find utility tries to optimize
1086 if it is 2, and it screws up. It is
1087 easier to give 1 which tells find to
1088 do it the hard way. */
1090 /* Everybody gets to read the file. */
1091 inode
->i_mode
= inode
->i_sb
->u
.isofs_sb
.s_mode
;
1093 inode
->i_mode
|= S_IFREG
;
1094 /* If there are no periods in the name,
1095 * then set the execute permission bit
1097 for(i
=0; i
< raw_inode
->name_len
[0]; i
++)
1098 if(raw_inode
->name
[i
]=='.' || raw_inode
->name
[i
]==';')
1100 if(i
== raw_inode
->name_len
[0] || raw_inode
->name
[i
] == ';')
1101 inode
->i_mode
|= S_IXUGO
; /* execute permission */
1103 inode
->i_uid
= inode
->i_sb
->u
.isofs_sb
.s_uid
;
1104 inode
->i_gid
= inode
->i_sb
->u
.isofs_sb
.s_gid
;
1105 inode
->i_blocks
= inode
->i_blksize
= 0;
1108 inode
->u
.isofs_i
.i_section_size
= isonum_733 (raw_inode
->size
);
1109 if(raw_inode
->flags
[-high_sierra
] & 0x80) {
1110 if(isofs_read_level3_size(inode
)) goto fail
;
1112 inode
->i_size
= isonum_733 (raw_inode
->size
);
1115 /* There are defective discs out there - we do this to protect
1116 ourselves. A cdrom will never contain more than 800Mb
1117 .. but a DVD may be up to 1Gig (Ulrich Habel) */
1118 if((inode
->i_size
< 0 || inode
->i_size
> 1073741824) &&
1119 inode
->i_sb
->u
.isofs_sb
.s_cruft
== 'n') {
1120 printk("Warning: defective cdrom. Enabling \"cruft\" mount option.\n");
1121 inode
->i_sb
->u
.isofs_sb
.s_cruft
= 'y';
1124 /* Some dipshit decided to store some other bit of information in the high
1125 byte of the file length. Catch this and holler. WARNING: this will make
1126 it impossible for a file to be > 16Mb on the CDROM!!!*/
1128 if(inode
->i_sb
->u
.isofs_sb
.s_cruft
== 'y' &&
1129 inode
->i_size
& 0xff000000){
1130 /* printk("Illegal format on cdrom. Pester manufacturer.\n"); */
1131 inode
->i_size
&= 0x00ffffff;
1134 if (raw_inode
->interleave
[0]) {
1135 printk("Interleaved files not (yet) supported.\n");
1139 /* I have no idea what file_unit_size is used for, so
1140 we will flag it for now */
1141 if(raw_inode
->file_unit_size
[0] != 0){
1142 printk("File unit size != 0 for ISO file (%ld).\n",inode
->i_ino
);
1145 /* I have no idea what other flag bits are used for, so
1146 we will flag it for now */
1148 if((raw_inode
->flags
[-high_sierra
] & ~2)!= 0){
1149 printk("Unusual flag settings for ISO file (%ld %x).\n",
1150 inode
->i_ino
, raw_inode
->flags
[-high_sierra
]);
1155 printk("Get inode %x: %d %d: %d\n",inode
->i_ino
, block
,
1156 ((int)pnt
) & 0x3ff, inode
->i_size
);
1159 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
=
1160 iso_date(raw_inode
->date
, high_sierra
);
1162 inode
->u
.isofs_i
.i_first_extent
= (isonum_733 (raw_inode
->extent
) +
1163 isonum_711 (raw_inode
->ext_attr_length
))
1164 << inode
-> i_sb
-> u
.isofs_sb
.s_log_zone_size
;
1166 /* Now test for possible Rock Ridge extensions which will override some of
1167 these numbers in the inode structure. */
1170 parse_rock_ridge_inode(raw_inode
, inode
);
1171 /* hmm..if we want uid or gid set, override the rock ridge setting */
1172 test_and_set_uid(&inode
->i_uid
, inode
->i_sb
->u
.isofs_sb
.s_uid
);
1176 printk("Inode: %x extent: %x\n",inode
->i_ino
, inode
->u
.isofs_i
.i_first_extent
);
1179 /* get the volume sequence number */
1180 volume_seq_no
= isonum_723 (raw_inode
->volume_sequence_number
) ;
1183 * All done with buffer ... no more references to buffer memory!
1188 * Disable checking if we see any volume number other than 0 or 1.
1189 * We could use the cruft option, but that has multiple purposes, one
1190 * of which is limiting the file size to 16Mb. Thus we silently allow
1191 * volume numbers of 0 to go through without complaining.
1193 if (inode
->i_sb
->u
.isofs_sb
.s_cruft
== 'n' &&
1194 (volume_seq_no
!= 0) && (volume_seq_no
!= 1)) {
1195 printk("Warning: defective cdrom (volume sequence number). Enabling \"cruft\" mount option.\n");
1196 inode
->i_sb
->u
.isofs_sb
.s_cruft
= 'y';
1199 /* Install the inode operations vector */
1201 #ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS
1202 if (inode
->i_sb
->u
.isofs_sb
.s_cruft
!= 'y' &&
1203 (volume_seq_no
!= 0) && (volume_seq_no
!= 1)) {
1204 printk("Multi volume CD somehow got mounted.\n");
1206 #endif IGNORE_WRONG_MULTI_VOLUME_SPECS
1208 if (S_ISREG(inode
->i_mode
))
1209 inode
->i_op
= &isofs_file_inode_operations
;
1210 else if (S_ISDIR(inode
->i_mode
))
1211 inode
->i_op
= &isofs_dir_inode_operations
;
1212 else if (S_ISLNK(inode
->i_mode
))
1213 inode
->i_op
= &isofs_symlink_inode_operations
;
1215 /* XXX - parse_rock_ridge_inode() had already set i_rdev. */
1216 init_special_inode(inode
, inode
->i_mode
, kdev_t_to_nr(inode
->i_rdev
));
1221 /* With a data error we return this information */
1222 inode
->i_mtime
= inode
->i_atime
= inode
->i_ctime
= 0;
1223 inode
->u
.isofs_i
.i_first_extent
= 0;
1225 inode
->i_blocks
= inode
->i_blksize
= 0;
1227 inode
->i_uid
= inode
->i_gid
= 0;
1228 inode
->i_mode
= S_IFREG
; /*Regular file, no one gets to read*/
1233 /* There are times when we need to know the inode number of a parent of
1234 a particular directory. When control passes through a routine that
1235 has access to the parent information, it fills it into the inode structure,
1236 but sometimes the inode gets flushed out of the queue, and someone
1237 remembers the number. When they try to open up again, we have lost
1238 the information. The '..' entry on the disc points to the data area
1239 for a particular inode, so we can follow these links back up, but since
1240 we do not know the inode number, we do not actually know how large the
1241 directory is. The disc is almost always correct, and there is
1242 enough error checking on the drive itself, but an open ended search
1243 makes me a little nervous.
1245 The BSD iso filesystem uses the extent number for an inode, and this
1246 would work really nicely for us except that the read_inode function
1247 would not have any clean way of finding the actual directory record
1248 that goes with the file. If we had such info, then it would pay
1249 to change the inode numbers and eliminate this function.
1252 int isofs_lookup_grandparent(struct inode
* parent
, int extent
)
1254 unsigned long bufsize
= ISOFS_BUFFER_SIZE(parent
);
1255 unsigned char bufbits
= ISOFS_BUFFER_BITS(parent
);
1256 unsigned int block
,offset
;
1257 int parent_dir
, inode_number
;
1260 struct buffer_head
* bh
;
1261 struct iso_directory_record
* de
;
1264 block
= extent
<< (ISOFS_ZONE_BITS(parent
) - bufbits
);
1265 if (!(bh
= bread(parent
->i_dev
, block
, bufsize
))) return -1;
1268 de
= (struct iso_directory_record
*) (bh
->b_data
+ offset
);
1269 if (*((unsigned char *) de
) == 0)
1272 printk("Directory .. not found\n");
1276 offset
+= *((unsigned char *) de
);
1278 if (offset
>= bufsize
)
1280 printk(".. Directory not in first block"
1281 " of directory.\n");
1286 if (de
->name_len
[0] == 1 && de
->name
[0] == 1)
1288 parent_dir
= find_rock_ridge_relocation(de
, parent
);
1289 directory_size
= isonum_733 (de
->size
);
1295 printk("Parent dir:%x\n",parent_dir
);
1297 /* Now we know the extent where the parent dir starts on. */
1302 block
= parent_dir
<< (ISOFS_ZONE_BITS(parent
) - bufbits
);
1303 if (!block
|| !(bh
= bread(parent
->i_dev
,block
, bufsize
)))
1310 de
= (struct iso_directory_record
*) (bh
->b_data
+ offset
);
1311 inode_number
= (block
<< bufbits
)+(offset
& (bufsize
- 1));
1313 /* If the length byte is zero, we should move on to the next
1314 CDROM sector. If we are at the end of the directory, we
1315 kick out of the while loop. */
1317 if ((*((unsigned char *) de
) == 0) || (offset
== bufsize
) )
1322 directory_size
-= bufsize
;
1323 if(directory_size
< 0) return -1;
1324 if((block
& 1) && (ISOFS_ZONE_BITS(parent
) - bufbits
) == 1)
1328 if((block
& 3) && (ISOFS_ZONE_BITS(parent
) - bufbits
) == 2)
1333 || !(bh
= bread(parent
->i_dev
,block
, bufsize
)))
1340 /* Make sure that the entire directory record is in the current
1341 bh block. If not, we malloc a buffer, and put the two
1342 halves together, so that we can cleanly read the block. */
1344 offset
+= *((unsigned char *) de
);
1346 if (offset
> bufsize
)
1348 printk("Directory overrun\n");
1352 if (find_rock_ridge_relocation(de
, parent
) == extent
){
1353 result
= inode_number
;
1359 /* We go here for any condition we cannot handle.
1360 We also drop through to here at the end of the directory. */
1365 printk("Resultant Inode %d\n",result
);
1376 void * leak_check_malloc(unsigned int size
){
1379 tmp
= kmalloc(size
, GFP_KERNEL
);
1383 void leak_check_free_s(void * obj
, int size
){
1385 return kfree_s(obj
, size
);
1388 struct buffer_head
* leak_check_bread(int dev
, int block
, int size
){
1390 return bread(dev
, block
, size
);
1393 void leak_check_brelse(struct buffer_head
* bh
){
1400 static struct file_system_type iso9660_fs_type
= {
1407 __initfunc(int init_iso9660_fs(void))
1409 return register_filesystem(&iso9660_fs_type
);
1415 int init_module(void)
1417 return init_iso9660_fs();
1420 void cleanup_module(void)
1422 unregister_filesystem(&iso9660_fs_type
);