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

📄 genhd.c

📁 GNU Mach 微内核源代码, 基于美国卡内基美隆大学的 Mach 研究项目
💻 C
📖 第 1 页 / 共 2 页
字号:
			bsd_disklabel_partition(hd, MKDEV(hd->major, minor));			printk(" >");		}#endif	}	/*	 *  Check for old-style Disk Manager partition table	 */	if (*(unsigned short *) (data+0xfc) == 0x55AA) {		p = (struct partition *) (0x1be + data);		for (i = 4 ; i < 16 ; i++, current_minor++) {			p--;			if ((current_minor & mask) == 0)				break;			if (!(START_SECT(p) && NR_SECTS(p)))				continue;			add_partition(hd, current_minor, START_SECT(p), NR_SECTS(p));		}	}	printk("\n");	brelse(bh);	return 1;}#endif /* CONFIG_MSDOS_PARTITION */#ifdef CONFIG_OSF_PARTITIONstatic int osf_partition(struct gendisk *hd, unsigned int dev, unsigned long first_sector){	int i;	int mask = (1 << hd->minor_shift) - 1;	struct buffer_head *bh;	struct disklabel {		u32 d_magic;		u16 d_type,d_subtype;		u8 d_typename[16];		u8 d_packname[16];		u32 d_secsize;		u32 d_nsectors;		u32 d_ntracks;		u32 d_ncylinders;		u32 d_secpercyl;		u32 d_secprtunit;		u16 d_sparespertrack;		u16 d_sparespercyl;		u32 d_acylinders;		u16 d_rpm, d_interleave, d_trackskew, d_cylskew;		u32 d_headswitch, d_trkseek, d_flags;		u32 d_drivedata[5];		u32 d_spare[5];		u32 d_magic2;		u16 d_checksum;		u16 d_npartitions;		u32 d_bbsize, d_sbsize;		struct d_partition {			u32 p_size;			u32 p_offset;			u32 p_fsize;			u8  p_fstype;			u8  p_frag;			u16 p_cpg;		} d_partitions[8];	} * label;	struct d_partition * partition;#define DISKLABELMAGIC (0x82564557UL)	if (!(bh = bread(dev,0,1024))) {		printk("unable to read partition table\n");		return -1;	}	label = (struct disklabel *) (bh->b_data+64);	partition = label->d_partitions;	if (label->d_magic != DISKLABELMAGIC) {		printk("magic: %08x\n", label->d_magic);		brelse(bh);		return 0;	}	if (label->d_magic2 != DISKLABELMAGIC) {		printk("magic2: %08x\n", label->d_magic2);		brelse(bh);		return 0;	}	for (i = 0 ; i < label->d_npartitions; i++, partition++) {		if ((current_minor & mask) == 0)		        break;		if (partition->p_size)			add_partition(hd, current_minor,				first_sector+partition->p_offset,				partition->p_size);		current_minor++;	}	printk("\n");	brelse(bh);	return 1;}#endif /* CONFIG_OSF_PARTITION */#ifdef CONFIG_SUN_PARTITIONstatic int sun_partition(struct gendisk *hd, kdev_t dev, unsigned long first_sector){	int i, csum;	unsigned short *ush;	struct buffer_head *bh;	struct sun_disklabel {		unsigned char info[128];   /* Informative text string */		unsigned char spare[292];  /* Boot information etc. */		unsigned short rspeed;     /* Disk rotational speed */		unsigned short pcylcount;  /* Physical cylinder count */		unsigned short sparecyl;   /* extra sects per cylinder */		unsigned char spare2[4];   /* More magic... */		unsigned short ilfact;     /* Interleave factor */		unsigned short ncyl;       /* Data cylinder count */		unsigned short nacyl;      /* Alt. cylinder count */		unsigned short ntrks;      /* Tracks per cylinder */		unsigned short nsect;      /* Sectors per track */		unsigned char spare3[4];   /* Even more magic... */		struct sun_partition {			__u32 start_cylinder;			__u32 num_sectors;		} partitions[8];		unsigned short magic;      /* Magic number */		unsigned short csum;       /* Label xor'd checksum */	} * label;	struct sun_partition *p;	int other_endian;	unsigned long spc;#define SUN_LABEL_MAGIC          0xDABE#define SUN_LABEL_MAGIC_SWAPPED  0xBEDA/* No need to optimize these macros since they are called only when reading * the partition table. This occurs only at each disk change. */#define SWAP16(x)  (other_endian ? (((__u16)(x) & 0xFF) << 8) \				 | (((__u16)(x) & 0xFF00) >> 8) \				 : (__u16)(x))#define SWAP32(x)  (other_endian ? (((__u32)(x) & 0xFF) << 24) \				 | (((__u32)(x) & 0xFF00) << 8) \				 | (((__u32)(x) & 0xFF0000) >> 8) \				 | (((__u32)(x) & 0xFF000000) >> 24) \				 : (__u32)(x))	if(!(bh = bread(dev, 0, 1024))) {		printk("Dev %s: unable to read partition table\n",		       kdevname(dev));		return -1;	}	label = (struct sun_disklabel *) bh->b_data;	p = label->partitions;	if (label->magic != SUN_LABEL_MAGIC && label->magic != SUN_LABEL_MAGIC_SWAPPED) {		printk("Dev %s Sun disklabel: bad magic %04x\n",		       kdevname(dev), label->magic);		brelse(bh);		return 0;	}	other_endian = (label->magic == SUN_LABEL_MAGIC_SWAPPED);	/* Look at the checksum */	ush = ((unsigned short *) (label+1)) - 1;	for(csum = 0; ush >= ((unsigned short *) label);)		csum ^= *ush--;	if(csum) {		printk("Dev %s Sun disklabel: Csum bad, label corrupted\n",		       kdevname(dev));		brelse(bh);		return 0;	}	/* All Sun disks have 8 partition entries */	spc = SWAP16(label->ntrks) * SWAP16(label->nsect);	for(i=0; i < 8; i++, p++) {		unsigned long st_sector;		/* We register all partitions, even if zero size, so that		 * the minor numbers end up ok as per SunOS interpretation.		 */		st_sector = first_sector + SWAP32(p->start_cylinder) * spc;		add_partition(hd, current_minor, st_sector, SWAP32(p->num_sectors));		current_minor++;	}	printk("\n");	brelse(bh);	return 1;#undef SWAP16#undef SWAP32}#endif /* CONFIG_SUN_PARTITION */#ifdef CONFIG_AMIGA_PARTITION#include <asm/byteorder.h>#include <linux/affs_hardblocks.h>static __inline__ __u32checksum_block(__u32 *m, int size){	__u32 sum = 0;	while (size--)		sum += htonl(*m++);	return sum;}static intamiga_partition(struct gendisk *hd, unsigned int dev, unsigned long first_sector){	struct buffer_head	*bh;	struct RigidDiskBlock	*rdb;	struct PartitionBlock	*pb;	int			 start_sect;	int			 nr_sects;	int			 blk;	int			 part, res;	set_blocksize(dev,512);	res = 0;	for (blk = 0; blk < RDB_ALLOCATION_LIMIT; blk++) {		if(!(bh = bread(dev,blk,512))) {			printk("Dev %d: unable to read RDB block %d\n",dev,blk);			goto rdb_done;		}		if (*(__u32 *)bh->b_data == htonl(IDNAME_RIGIDDISK)) {			rdb = (struct RigidDiskBlock *)bh->b_data;			if (checksum_block((__u32 *)bh->b_data,htonl(rdb->rdb_SummedLongs) & 0x7F)) {				printk("Dev %d: RDB in block %d has bad checksum\n",dev,blk);				brelse(bh);				continue;			}			printk(" RDSK");			blk = htonl(rdb->rdb_PartitionList);			brelse(bh);			for (part = 1; blk > 0 && part <= 16; part++) {				if (!(bh = bread(dev,blk,512))) {					printk("Dev %d: unable to read partition block %d\n",						       dev,blk);					goto rdb_done;				}				pb  = (struct PartitionBlock *)bh->b_data;				blk = htonl(pb->pb_Next);				if (pb->pb_ID == htonl(IDNAME_PARTITION) && checksum_block(				    (__u32 *)pb,htonl(pb->pb_SummedLongs) & 0x7F) == 0 ) {					/* Tell Kernel about it */					if (!(nr_sects = (htonl(pb->pb_Environment[10]) + 1 -							  htonl(pb->pb_Environment[9])) *							 htonl(pb->pb_Environment[3]) *							 htonl(pb->pb_Environment[5]))) {						continue;					}					start_sect = htonl(pb->pb_Environment[9]) *						     htonl(pb->pb_Environment[3]) *						     htonl(pb->pb_Environment[5]);					add_partition(hd,current_minor,start_sect,nr_sects);					current_minor++;					res = 1;				}				brelse(bh);			}			printk("\n");			break;		}	}rdb_done:	set_blocksize(dev,BLOCK_SIZE);	return res;}#endif /* CONFIG_AMIGA_PARTITION */static void check_partition(struct gendisk *hd, kdev_t dev){	static int first_time = 1;	unsigned long first_sector;	char buf[8];	if (first_time)		printk("Partition check (DOS partitions):\n");	first_time = 0;	first_sector = hd->part[MINOR(dev)].start_sect;	/*	 * This is a kludge to allow the partition check to be	 * skipped for specific drives (e.g. IDE cd-rom drives)	 */	if ((int)first_sector == -1) {		hd->part[MINOR(dev)].start_sect = 0;		return;	}	printk(" %s:", disk_name(hd, MINOR(dev), buf));#ifdef CONFIG_MSDOS_PARTITION	if (msdos_partition(hd, dev, first_sector))		return;#endif#ifdef CONFIG_OSF_PARTITION	if (osf_partition(hd, dev, first_sector))		return;#endif#ifdef CONFIG_SUN_PARTITION	if(sun_partition(hd, dev, first_sector))		return;#endif#ifdef CONFIG_AMIGA_PARTITION	if(amiga_partition(hd, dev, first_sector))		return;#endif	printk(" unknown partition table\n");}/* This function is used to re-read partition tables for removable disks.   Much of the cleanup from the old partition tables should have already been   done *//* This function will re-read the partition tables for a given device,and set things back up again.  There are some important caveats,however.  You must ensure that no one is using the device, and no onecan start using the device while this function is being executed. */void resetup_one_dev(struct gendisk *dev, int drive){	int i;	int first_minor	= drive << dev->minor_shift;	int end_minor	= first_minor + dev->max_p;	blk_size[dev->major] = NULL;	current_minor = 1 + first_minor;	check_partition(dev, MKDEV(dev->major, first_minor)); 	/* 	 * We need to set the sizes array before we will be able to access 	 * any of the partitions on this device. 	 */	if (dev->sizes != NULL) {	/* optional safeguard in ll_rw_blk.c */		for (i = first_minor; i < end_minor; i++)			dev->sizes[i] = dev->part[i].nr_sects >> (BLOCK_SIZE_BITS - 9);		blk_size[dev->major] = dev->sizes;	}}static void setup_dev(struct gendisk *dev){	int i, drive;	int end_minor	= dev->max_nr * dev->max_p;	blk_size[dev->major] = NULL;	for (i = 0 ; i < end_minor; i++) {		dev->part[i].start_sect = 0;		dev->part[i].nr_sects = 0;	}	dev->init(dev);	for (drive = 0 ; drive < dev->nr_real ; drive++) {		int first_minor	= drive << dev->minor_shift;		current_minor = 1 + first_minor;		check_partition(dev, MKDEV(dev->major, first_minor));	}	if (dev->sizes != NULL) {	/* optional safeguard in ll_rw_blk.c */		for (i = 0; i < end_minor; i++)			dev->sizes[i] = dev->part[i].nr_sects >> (BLOCK_SIZE_BITS - 9);		blk_size[dev->major] = dev->sizes;	}}void device_setup(void){	extern void console_map_init(void);	struct gendisk *p;	int nr=0;#ifdef MACH	extern int linux_intr_pri;	linux_intr_pri = SPL5;#endif#ifndef MACH	chr_dev_init();#endif	blk_dev_init();	sti();#ifdef CONFIG_SCSI	scsi_dev_init();#endif#ifdef CONFIG_INET#ifdef MACH	linux_intr_pri = SPL6;#endif	net_dev_init();#endif#ifndef MACH	console_map_init();#endif	for (p = gendisk_head ; p ; p=p->next) {		setup_dev(p);		nr += p->nr_real;	}#ifdef CONFIG_BLK_DEV_RAM#ifdef CONFIG_BLK_DEV_INITRD	if (initrd_start && mount_initrd) initrd_load();	else#endif	rd_load();#endif}

⌨️ 快捷键说明

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