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