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

📄 msdos.c

📁 《嵌入式系统设计与实例开发实验教材二源码》Linux内核移植与编译实验
💻 C
📖 第 1 页 / 共 2 页
字号:
		return;	if (le32_to_cpu(l->d_magic) != BSD_DISKMAGIC) {		put_dev_sector(sect);		return;	}	printk(" %s: <%s:", partition_name(hd, minor, buf), name);	if (le16_to_cpu(l->d_npartitions) < max_partitions)		max_partitions = le16_to_cpu(l->d_npartitions);	for (p = l->d_partitions; p - l->d_partitions <  max_partitions; p++) {		if ((*current_minor & mask) == 0)			break;		if (p->p_fstype == BSD_FS_UNUSED) 			continue;		check_and_add_bsd_partition(hd, p, baseminor, current_minor);	}	put_dev_sector(sect);	printk(" >\n");}#endifstatic void bsd_partition(struct gendisk *hd, struct block_device *bdev,	int minor, int *current_minor){#ifdef CONFIG_BSD_DISKLABEL	do_bsd_partition(hd, bdev, minor, current_minor, "bsd",		BSD_MAXPARTITIONS);#endif}static void netbsd_partition(struct gendisk *hd, struct block_device *bdev,		int minor, int *current_minor){#ifdef CONFIG_BSD_DISKLABEL	do_bsd_partition(hd, bdev, minor, current_minor, "netbsd",			BSD_MAXPARTITIONS);#endif}static void openbsd_partition(struct gendisk *hd, struct block_device *bdev,		int minor, int *current_minor){#ifdef CONFIG_BSD_DISKLABEL	do_bsd_partition(hd, bdev, minor, current_minor,			"openbsd", OPENBSD_MAXPARTITIONS);#endif}/* * Create devices for Unixware partitions listed in a disklabel, under a * dos-like partition. See extended_partition() for more information. */static void unixware_partition(struct gendisk *hd, struct block_device *bdev,		int minor, int *current_minor){#ifdef CONFIG_UNIXWARE_DISKLABEL	long offset = hd->part[minor].start_sect;	Sector sect;	struct unixware_disklabel *l;	struct unixware_slice *p;	int mask = (1 << hd->minor_shift) - 1;	char buf[40];	l = (struct unixware_disklabel *)read_dev_sector(bdev, offset+29, &sect);	if (!l)		return;	if (le32_to_cpu(l->d_magic) != UNIXWARE_DISKMAGIC ||	    le32_to_cpu(l->vtoc.v_magic) != UNIXWARE_DISKMAGIC2) {		put_dev_sector(sect);		return;	}	printk(" %s: <unixware:", partition_name(hd, minor, buf));	p = &l->vtoc.v_slice[1];	/* I omit the 0th slice as it is the same as whole disk. */	while (p - &l->vtoc.v_slice[0] < UNIXWARE_NUMSLICE) {		if ((*current_minor & mask) == 0)			break;		if (p->s_label != UNIXWARE_FS_UNUSED) {			add_gd_partition(hd, *current_minor, START_SECT(p),					 NR_SECTS(p));			(*current_minor)++;		}		p++;	}	put_dev_sector(sect);	printk(" >\n");#endif}/* * Minix 2.0.0/2.0.2 subpartition support. * Anand Krishnamurthy <anandk@wiproge.med.ge.com> * Rajeev V. Pillai    <rajeevvp@yahoo.com> */static void minix_partition(struct gendisk *hd, struct block_device *bdev,		int minor, int *current_minor){#ifdef CONFIG_MINIX_SUBPARTITION	long offset = hd->part[minor].start_sect;	Sector sect;	unsigned char *data;	struct partition *p;	int mask = (1 << hd->minor_shift) - 1;	int i;	char buf[40];	data = read_dev_sector(bdev, offset, &sect);	if (!data)		return;	p = (struct partition *)(data + 0x1be);	/* The first sector of a Minix partition can have either	 * a secondary MBR describing its subpartitions, or	 * the normal boot sector. */	if (msdos_magic_present (data + 510) &&	    SYS_IND(p) == MINIX_PARTITION) { /* subpartition table present */		printk(" %s: <minix:", partition_name(hd, minor, buf));		for (i = 0; i < MINIX_NR_SUBPARTITIONS; i++, p++) {			if ((*current_minor & mask) == 0)				break;			/* add each partition in use */			if (SYS_IND(p) == MINIX_PARTITION) {				add_gd_partition(hd, *current_minor,					      START_SECT(p), NR_SECTS(p));				(*current_minor)++;			}		}		printk(" >\n");	}	put_dev_sector(sect);#endif /* CONFIG_MINIX_SUBPARTITION */}static struct {	unsigned char id;	void (*parse)(struct gendisk *, struct block_device *, int, int *);} subtypes[] = {	{BSD_PARTITION, bsd_partition},	{NETBSD_PARTITION, netbsd_partition},	{OPENBSD_PARTITION, openbsd_partition},	{MINIX_PARTITION, minix_partition},	{UNIXWARE_PARTITION, unixware_partition},	{SOLARIS_X86_PARTITION, solaris_x86_partition},	{0, NULL},};/* * Look for various forms of IDE disk geometry translation */static int handle_ide_mess(struct block_device *bdev){#ifdef CONFIG_BLK_DEV_IDE	Sector sect;	unsigned char *data;	kdev_t dev = to_kdev_t(bdev->bd_dev);	unsigned int sig;	int heads = 0;	struct partition *p;	int i;	/*	 * The i386 partition handling programs very often	 * make partitions end on cylinder boundaries.	 * There is no need to do so, and Linux fdisk doesnt always	 * do this, and Windows NT on Alpha doesnt do this either,	 * but still, this helps to guess #heads.	 */	data = read_dev_sector(bdev, 0, &sect);	if (!data)		return -1;	if (!msdos_magic_present(data + 510)) {		put_dev_sector(sect);		return 0;	}	sig = le16_to_cpu(*(unsigned short *)(data + 2));	p = (struct partition *) (data + 0x1be);	for (i = 0; i < 4; i++) {		struct partition *q = &p[i];		if (NR_SECTS(q)) {			if ((q->sector & 63) == 1 &&			    (q->end_sector & 63) == 63)				heads = q->end_head + 1;			break;		}	}	if (SYS_IND(p) == EZD_PARTITION) {		/*		 * Accesses to sector 0 must go to sector 1 instead.		 */		if (ide_xlate_1024(dev, -1, heads, " [EZD]"))			goto reread;	} else if (SYS_IND(p) == DM6_PARTITION) {		/*		 * Everything on the disk is offset by 63 sectors,		 * including a "new" MBR with its own partition table.		 */		if (ide_xlate_1024(dev, 1, heads, " [DM6:DDO]"))			goto reread;	} else if (sig <= 0x1ae &&		   data[sig] == 0xAA && data[sig+1] == 0x55 &&		   (data[sig+2] & 1)) {		/* DM6 signature in MBR, courtesy of OnTrack */		(void) ide_xlate_1024 (dev, 0, heads, " [DM6:MBR]");	} else if (SYS_IND(p) == DM6_AUX1PARTITION ||		   SYS_IND(p) == DM6_AUX3PARTITION) {		/*		 * DM6 on other than the first (boot) drive		 */		(void) ide_xlate_1024(dev, 0, heads, " [DM6:AUX]");	} else {		(void) ide_xlate_1024(dev, 2, heads, " [PTBL]");	}	put_dev_sector(sect);	return 1;reread:	put_dev_sector(sect);	/* Flush the cache */	invalidate_bdev(bdev, 1);	truncate_inode_pages(bdev->bd_inode->i_mapping, 0);#endif /* CONFIG_BLK_DEV_IDE */	return 1;} int msdos_partition(struct gendisk *hd, struct block_device *bdev,		    unsigned long first_sector, int first_part_minor){	int i, minor = first_part_minor;	Sector sect;	struct partition *p;	unsigned char *data;	int mask = (1 << hd->minor_shift) - 1;	int sector_size = get_hardsect_size(to_kdev_t(bdev->bd_dev)) / 512;	int current_minor = first_part_minor;	int err;	err = handle_ide_mess(bdev);	if (err <= 0)		return err;	data = read_dev_sector(bdev, 0, &sect);	if (!data)		return -1;	if (!msdos_magic_present(data + 510)) {		put_dev_sector(sect);		return 0;	}	p = (struct partition *) (data + 0x1be);	/*	 * Look for partitions in two passes:	 * First find the primary and DOS-type extended partitions.	 * On the second pass look inside *BSD, Unixware and Solaris partitions.	 */	current_minor += 4;	for (i=1 ; i<=4 ; minor++,i++,p++) {		if (!NR_SECTS(p))			continue;		add_gd_partition(hd, minor,				first_sector+START_SECT(p)*sector_size,				NR_SECTS(p)*sector_size);#if CONFIG_BLK_DEV_MD		if (SYS_IND(p) == LINUX_RAID_PARTITION) {			md_autodetect_dev(MKDEV(hd->major,minor));		}#endif		if (is_extended_partition(p)) {			unsigned long size = hd->part[minor].nr_sects;			printk(" <");			/* prevent someone doing mkfs or mkswap on an			   extended partition, but leave room for LILO */			if (size > 2)				hd->part[minor].nr_sects = 2;			extended_partition(hd, bdev, minor, size, &current_minor);			printk(" >");		}	}	/*	 *  Check for old-style Disk Manager partition table	 */	if (msdos_magic_present(data + 0xfc)) {		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_gd_partition(hd, current_minor, START_SECT(p), NR_SECTS(p));		}	}	printk("\n");	/* second pass - output for each on a separate line */	minor -= 4;	p = (struct partition *) (0x1be + data);	for (i=1 ; i<=4 ; minor++,i++,p++) {		unsigned char id = SYS_IND(p);		int n;		if (!NR_SECTS(p))			continue;		for (n = 0; subtypes[n].parse && id != subtypes[n].id; n++)			;		if (subtypes[n].parse)			subtypes[n].parse(hd, bdev, minor, &current_minor);	}	put_dev_sector(sect);	return 1;}

⌨️ 快捷键说明

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