⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inode.c

📁 嵌入式系统设计与实验教材二源码linux内核移植与编译
💻 C
📖 第 1 页 / 共 3 页
字号:
static struct super_block *isofs_read_super(struct super_block *s, void *data,					    int silent){	kdev_t				dev = s->s_dev;	struct buffer_head	      * bh = NULL, *pri_bh = NULL;	struct hs_primary_descriptor  * h_pri = NULL;	struct iso_primary_descriptor * pri = NULL;	struct iso_supplementary_descriptor *sec = NULL;	struct iso_directory_record   * rootp;	int				joliet_level = 0;	int				high_sierra;	int				iso_blknum, block;	int				orig_zonesize;	int				table;	unsigned int			blocksize, blocksize_bits;	unsigned int			vol_desc_start;	unsigned long			first_data_zone;	struct inode		      * inode;	struct iso9660_options		opt;	if (!parse_options((char *) data, &opt))		goto out_unlock;#if 0	printk("map = %c\n", opt.map);	printk("rock = %c\n", opt.rock);	printk("joliet = %c\n", opt.joliet);	printk("check = %c\n", opt.check);	printk("cruft = %c\n", opt.cruft);	printk("unhide = %c\n", opt.unhide);	printk("blocksize = %d\n", opt.blocksize);	printk("gid = %d\n", opt.gid);	printk("uid = %d\n", opt.uid);	printk("iocharset = %s\n", opt.iocharset);#endif	/*	 * First of all, get the hardware blocksize for this device.	 * If we don't know what it is, or the hardware blocksize is	 * larger than the blocksize the user specified, then use	 * that value.	 */	blocksize = get_hardsect_size(dev);	if(blocksize > opt.blocksize) {	    /*	     * Force the blocksize we are going to use to be the	     * hardware blocksize.	     */	    opt.blocksize = blocksize;	}	blocksize_bits = 0;	{	  int i = opt.blocksize;	  while (i != 1){	    blocksize_bits++;	    i >>=1;	  }	}	set_blocksize(dev, opt.blocksize);	s->s_blocksize = opt.blocksize;	s->u.isofs_sb.s_high_sierra = high_sierra = 0; /* default is iso9660 */	vol_desc_start = (opt.sbsector != -1) ?		opt.sbsector : isofs_get_last_session(s,opt.session);  	for (iso_blknum = vol_desc_start+16;             iso_blknum < vol_desc_start+100; iso_blknum++)	{	    struct hs_volume_descriptor   * hdp;	    struct iso_volume_descriptor  * vdp;	    block = iso_blknum << (ISOFS_BLOCK_BITS-blocksize_bits);	    if (!(bh = sb_bread(s, block)))		goto out_no_read;	    vdp = (struct iso_volume_descriptor *)bh->b_data;	    hdp = (struct hs_volume_descriptor *)bh->b_data;	    	    /* Due to the overlapping physical location of the descriptors, 	     * ISO CDs can match hdp->id==HS_STANDARD_ID as well. To ensure 	     * proper identification in this case, we first check for ISO.	     */	    if (strncmp (vdp->id, ISO_STANDARD_ID, sizeof vdp->id) == 0) {		if (isonum_711 (vdp->type) == ISO_VD_END)		    break;		if (isonum_711 (vdp->type) == ISO_VD_PRIMARY) {		    if (pri == NULL) {			pri = (struct iso_primary_descriptor *)vdp;			/* Save the buffer in case we need it ... */			pri_bh = bh;			bh = NULL;		    }		}#ifdef CONFIG_JOLIET		else if (isonum_711 (vdp->type) == ISO_VD_SUPPLEMENTARY) {		    sec = (struct iso_supplementary_descriptor *)vdp;		    if (sec->escape[0] == 0x25 && sec->escape[1] == 0x2f) {			if (opt.joliet == 'y') {			    if (sec->escape[2] == 0x40) {				joliet_level = 1;			    } else if (sec->escape[2] == 0x43) {				joliet_level = 2;			    } else if (sec->escape[2] == 0x45) {				joliet_level = 3;			    }			    printk(KERN_DEBUG"ISO 9660 Extensions: Microsoft Joliet Level %d\n",				   joliet_level);			}			goto root_found;		    } else {			/* Unknown supplementary volume descriptor */			sec = NULL;		    }		}#endif	    } else {	        if (strncmp (hdp->id, HS_STANDARD_ID, sizeof hdp->id) == 0) {		    if (isonum_711 (hdp->type) != ISO_VD_PRIMARY)		        goto out_freebh;				    s->u.isofs_sb.s_high_sierra = 1;		    high_sierra = 1;		    opt.rock = 'n';		    h_pri = (struct hs_primary_descriptor *)vdp;		    goto root_found;		}	    }            /* Just skip any volume descriptors we don't recognize */	    brelse(bh);	    bh = NULL;	}	/*	 * If we fall through, either no volume descriptor was found,	 * or else we passed a primary descriptor looking for others.	 */	if (!pri)		goto out_unknown_format;	brelse(bh);	bh = pri_bh;	pri_bh = NULL;root_found:	if (joliet_level && (pri == NULL || opt.rock == 'n')) {	    /* This is the case of Joliet with the norock mount flag.	     * A disc with both Joliet and Rock Ridge is handled later	     */	    pri = (struct iso_primary_descriptor *) sec;	}	if(high_sierra){	  rootp = (struct iso_directory_record *) h_pri->root_directory_record;#ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS	  if (isonum_723 (h_pri->volume_set_size) != 1)		goto out_no_support;#endif /* IGNORE_WRONG_MULTI_VOLUME_SPECS */	  s->u.isofs_sb.s_nzones = isonum_733 (h_pri->volume_space_size);	  s->u.isofs_sb.s_log_zone_size = isonum_723 (h_pri->logical_block_size);	  s->u.isofs_sb.s_max_size = isonum_733(h_pri->volume_space_size);	} else {	  rootp = (struct iso_directory_record *) pri->root_directory_record;#ifndef IGNORE_WRONG_MULTI_VOLUME_SPECS	  if (isonum_723 (pri->volume_set_size) != 1)		goto out_no_support;#endif /* IGNORE_WRONG_MULTI_VOLUME_SPECS */	  s->u.isofs_sb.s_nzones = isonum_733 (pri->volume_space_size);	  s->u.isofs_sb.s_log_zone_size = isonum_723 (pri->logical_block_size);	  s->u.isofs_sb.s_max_size = isonum_733(pri->volume_space_size);	}	s->u.isofs_sb.s_ninodes = 0; /* No way to figure this out easily */	orig_zonesize = s -> u.isofs_sb.s_log_zone_size;	/*	 * If the zone size is smaller than the hardware sector size,	 * this is a fatal error.  This would occur if the disc drive	 * had sectors that were 2048 bytes, but the filesystem had	 * blocks that were 512 bytes (which should only very rarely	 * happen.)	 */	if(blocksize != 0 && orig_zonesize < blocksize)		goto out_bad_size;	/* RDE: convert log zone size to bit shift */	switch (s -> u.isofs_sb.s_log_zone_size)	  { case  512: s -> u.isofs_sb.s_log_zone_size =  9; break;	    case 1024: s -> u.isofs_sb.s_log_zone_size = 10; break;	    case 2048: s -> u.isofs_sb.s_log_zone_size = 11; break;	    default:		goto out_bad_zone_size;	  }	s->s_magic = ISOFS_SUPER_MAGIC;	/* The CDROM is read-only, has no nodes (devices) on it, and since	   all of the files appear to be owned by root, we really do not want	   to allow suid.  (suid or devices will not show up unless we have	   Rock Ridge extensions) */	s->s_flags |= MS_RDONLY /* | MS_NODEV | MS_NOSUID */;	/* Set this for reference. Its not currently used except on write	   which we don't have .. */	   	/* RDE: data zone now byte offset! */	first_data_zone = ((isonum_733 (rootp->extent) +			  isonum_711 (rootp->ext_attr_length))			 << s -> u.isofs_sb.s_log_zone_size);	s->u.isofs_sb.s_firstdatazone = first_data_zone;#ifndef BEQUIET	printk(KERN_DEBUG "Max size:%ld   Log zone size:%ld\n",	       s->u.isofs_sb.s_max_size,	       1UL << s->u.isofs_sb.s_log_zone_size);	printk(KERN_DEBUG "First datazone:%ld   Root inode number:%ld\n",	       s->u.isofs_sb.s_firstdatazone >> s -> u.isofs_sb.s_log_zone_size,	       s->u.isofs_sb.s_firstdatazone);	if(high_sierra)		printk(KERN_DEBUG "Disc in High Sierra format.\n");#endif	/*	 * If the Joliet level is set, we _may_ decide to use the	 * secondary descriptor, but can't be sure until after we	 * read the root inode. But before reading the root inode	 * we may need to change the device blocksize, and would	 * rather release the old buffer first. So, we cache the	 * first_data_zone value from the secondary descriptor.	 */	if (joliet_level) {		pri = (struct iso_primary_descriptor *) sec;		rootp = (struct iso_directory_record *)			pri->root_directory_record;		first_data_zone = ((isonum_733 (rootp->extent) +			  	isonum_711 (rootp->ext_attr_length))				 << s -> u.isofs_sb.s_log_zone_size);	}	/*	 * We're all done using the volume descriptor, and may need	 * to change the device blocksize, so release the buffer now.	 */	brelse(pri_bh);	brelse(bh);	/*	 * Force the blocksize to 512 for 512 byte sectors.  The file	 * read primitives really get it wrong in a bad way if we don't	 * do this.	 *	 * Note - we should never be setting the blocksize to something	 * less than the hardware sector size for the device.  If we	 * do, we would end up having to read larger buffers and split	 * out portions to satisfy requests.	 *	 * Note2- the idea here is that we want to deal with the optimal	 * zonesize in the filesystem.  If we have it set to something less,	 * then we have horrible problems with trying to piece together	 * bits of adjacent blocks in order to properly read directory	 * entries.  By forcing the blocksize in this way, we ensure	 * that we will never be required to do this.	 */	if ( orig_zonesize != opt.blocksize ) {		set_blocksize(dev, orig_zonesize);#ifndef BEQUIET		printk(KERN_DEBUG 			"ISOFS: Forcing new log zone size:%d\n", orig_zonesize);#endif	}	s->s_blocksize = orig_zonesize;	s->s_blocksize_bits = s -> u.isofs_sb.s_log_zone_size;	s->u.isofs_sb.s_nls_iocharset = NULL;#ifdef CONFIG_JOLIET	if (joliet_level && opt.utf8 == 0) {		char * p = opt.iocharset ? opt.iocharset : "iso8859-1";		s->u.isofs_sb.s_nls_iocharset = load_nls(p);		if (! s->u.isofs_sb.s_nls_iocharset) {			/* Fail only if explicit charset specified */			if (opt.iocharset)				goto out_unlock;			s->u.isofs_sb.s_nls_iocharset = load_nls_default();		}	}#endif	s->s_op = &isofs_sops;	s->u.isofs_sb.s_mapping = opt.map;	s->u.isofs_sb.s_rock = (opt.rock == 'y' ? 2 : 0);	s->u.isofs_sb.s_rock_offset = -1; /* initial offset, will guess until SP is found*/	s->u.isofs_sb.s_cruft = opt.cruft;	s->u.isofs_sb.s_unhide = opt.unhide;	s->u.isofs_sb.s_uid = opt.uid;	s->u.isofs_sb.s_gid = opt.gid;	s->u.isofs_sb.s_utf8 = opt.utf8;	s->u.isofs_sb.s_nocompress = opt.nocompress;	/*	 * It would be incredibly stupid to allow people to mark every file	 * on the disk as suid, so we merely allow them to set the default	 * permissions.	 */	s->u.isofs_sb.s_mode = opt.mode & 0777;	/*	 * Read the root inode, which _may_ result in changing	 * the s_rock flag. Once we have the final s_rock value,	 * we then decide whether to use the Joliet descriptor.	 */	inode = iget(s, s->u.isofs_sb.s_firstdatazone);	/*	 * If this disk has both Rock Ridge and Joliet on it, then we	 * want to use Rock Ridge by default.  This can be overridden	 * by using the norock mount option.  There is still one other	 * possibility that is not taken into account: a Rock Ridge	 * CD with Unicode names.  Until someone sees such a beast, it	 * will not be supported.	 */	if (s->u.isofs_sb.s_rock == 1) {		joliet_level = 0;	} else if (joliet_level) {		s->u.isofs_sb.s_rock = 0;		if (s->u.isofs_sb.s_firstdatazone != first_data_zone) {			s->u.isofs_sb.s_firstdatazone = first_data_zone;			printk(KERN_DEBUG 				"ISOFS: changing to secondary root\n");			iput(inode);			inode = iget(s, s->u.isofs_sb.s_firstdatazone);		}	}	if (opt.check == 'u') {		/* Only Joliet is case insensitive by default */		if (joliet_level) opt.check = 'r';		else opt.check = 's';	}	s->u.isofs_sb.s_joliet_level = joliet_level;	/* check the root inode */	if (!inode)		goto out_no_root;	if (!inode->i_op)		goto out_bad_root;	/* get the root dentry */	s->s_root = d_alloc_root(inode);	if (!(s->s_root))		goto out_no_root;	table = 0;	if (joliet_level) table += 2;	if (opt.check == 'r') table++;	s->s_root->d_op = &isofs_dentry_ops[table];	return s;	/*	 * Display error messages and free resources.	 */out_bad_root:	printk(KERN_WARNING "isofs_read_super: root inode not initialized\n");	goto out_iput;out_no_root:	printk(KERN_WARNING "isofs_read_super: get root inode failed\n");out_iput:	iput(inode);#ifdef CONFIG_JOLIET	if (s->u.isofs_sb.s_nls_iocharset)		unload_nls(s->u.isofs_sb.s_nls_iocharset);#endif	goto out_unlock;out_no_read:	printk(KERN_WARNING "isofs_read_super: "		"bread failed, dev=%s, iso_blknum=%d, block=%d\n",		kdevname(dev), iso_blknum, block);	goto out_unlock;out_bad_zone_size:	printk(KERN_WARNING "Bad logical zone size %ld\n",		s->u.isofs_sb.s_log_zone_size);	goto out_freebh;out_bad_size:	printk(KERN_WARNING "Logical zone size(%d) < hardware blocksize(%u)\n",		orig_zonesize, blocksize);	goto out_freebh;#ifndef IGNORE_WRONG_MULTI_VOLUME_SPECSout_no_support:	printk(KERN_WARNING "Multi-volume disks not supported.\n");	goto out_freebh;#endifout_unknown_format:	if (!silent)		printk(KERN_WARNING "Unable to identify CD-ROM format.\n");out_freebh:	brelse(bh);out_unlock:	return NULL;}static int isofs_statfs (struct super_block *sb, struct statfs *buf){	buf->f_type = ISOFS_SUPER_MAGIC;	buf->f_bsize = sb->s_blocksize;	buf->f_blocks = (sb->u.isofs_sb.s_nzones                  << (sb->u.isofs_sb.s_log_zone_size - sb->s_blocksize_bits));	buf->f_bfree = 0;	buf->f_bavail = 0;	buf->f_files = sb->u.isofs_sb.s_ninodes;	buf->f_ffree = 0;	buf->f_namelen = NAME_MAX;	return 0;}/* * Get a set of blocks; filling in buffer_heads if already allocated * or getblk() if they are not.  Returns the number of blocks inserted * (0 == error.) */int isofs_get_blocks(struct inode *inode, long iblock,		     struct buffer_head **bh_result, unsigned long nblocks){	unsigned long b_off;	unsigned offset, sect_size;	unsigned int firstext;	unsigned long nextino;	int section, rv;	lock_kernel();	rv = 0;	if (iblock < 0) {		printk("isofs_get_blocks: block < 0\n");		goto abort;	}	b_off = iblock;		offset    = 0;	firstext  = inode->u.isofs_i.i_first_extent;	sect_size = inode->u.isofs_i.i_section_size >> ISOFS_BUFFER_BITS(inode);	nextino   = inode->u.isofs_i.i_next_section_ino;	section   = 0;	while ( nblocks ) {		/* If we are *way* beyond the end of the file, print a message.		 * Access beyond the end of the file up to the next page boundary		 * is normal, however because of the way the page cache works.		 * In this case, we just return 0 so that we can properly fill		 * the page with useless information without generating any		 * I/O errors.		 */		if (b_off > ((inode->i_size + PAGE_CACHE_SIZE - 1) >> ISOFS_BUFFER_BITS(inode))) {			printk("isofs_get_blocks: block >= EOF (%ld, %ld)\n",			       iblock, (unsigned long) inode->i_size);			goto abort;		}				if (nextino) {			while (b_off >= (offset + sect_size)) {				struct inode *ninode;								offset += sect_size;				if (nextino == 0)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -