Beispiel #1
0
int
disk_open(void)
{
	int di;

	di = get_diskinfo(BDEV(dev,unit));

#ifdef	DEBUG
	if(debug) {
		printf("disk_open()\n");
		printf("diskinfo %x\n", di);
		printf("HS %d %d\n", HEADS(di) ,SPT(di));
	}
#endif
	spc = (spt = SPT(di)) * HEADS(di);
	use_badsect = FALSE;
	if (dev == DEV_FLOPPY) {
		boff = 0;
		part = (spt == 15 ? 3 : 1);
		return 0;
	}
	else {
	  	/*
		 * Usually H=32 S=64 for SCSI
		 * But sometimes we also have H=33 & S=62.
		 * For IDE Apparently H<64 
		 */
		if (spt >= 64 || HEADS(di) > 32) /* scsi */
			dev = DEV_SD;
		if (read_partitions())
			return(1);
#if	DEBUG
	if(debug)
		printf("%d partitions, active is %d\n", 
		       npartitions, active_partition);
#endif
		if (part > npartitions)
			return(1);
		boff = partitions[part].p_start;
	}
	return 0;
}
Beispiel #2
0
int
devopen(void)
{
	struct dos_partition *dptr;
	struct disklabel *dl;
	char *p;
	int i, sector = 0, di, dosdev_copy;

	dosdev_copy = dosdev;
	di = get_diskinfo(dosdev_copy);
	spt = SPT(di);

	/* Hack for 2.88MB floppy drives. */
	if (!(dosdev_copy & 0x80) && spt == 36)
		spt = 18;

	spc = spt * HEADS(di);

#ifndef RAWBOOT
	{
#ifdef	EMBEDDED_DISKLABEL
		dl = &disklabel;
#else	EMBEDDED_DISKLABEL
		p = Bread(dosdev_copy, 0);
		dptr = (struct dos_partition *)(p+DOSPARTOFF);
		slice = WHOLE_DISK_SLICE;
		for (i = 0; i < NDOSPART; i++, dptr++)
			if (dptr->dp_typ == DOSPTYP_386BSD) {
				slice = BASE_SLICE + i;
				sector = dptr->dp_start;
				break;
			}
		p = Bread(dosdev_copy, sector + LABELSECTOR);
		dl=((struct disklabel *)p);
		disklabel = *dl;	/* structure copy (maybe useful later)*/
#endif	EMBEDDED_DISKLABEL
		if (dl->d_magic != DISKMAGIC) {
			printf("bad disklabel");
			return 1;
		}
		if( (maj == 4) || (maj == 0) || (maj == 1))
		{
			if (dl->d_type == DTYPE_SCSI)
			{
				maj = 4; /* use scsi as boot dev */
			}
			else
			{
				maj = 0; /* must be ESDI/IDE */
			}
		}
		/* This little trick is for OnTrack DiskManager disks */
		boff = dl->d_partitions[part].p_offset -
			dl->d_partitions[2].p_offset + sector;

		/* This is a good idea for all disks */
		bsize = dl->d_partitions[part].p_size;
#ifdef DO_BAD144
		do_bad144 = 0;
		if (dl->d_flags & D_BADSECT) {
		    /* this disk uses bad144 */
		    int i;
		    int dkbbnum;
		    struct dkbad *dkbptr;

		    /* find the first readable bad sector table */
		    /* some of this code is copied from ufs/ufs_disksubr.c */
		    /* including the bugs :-( */
		    /* read a bad sector table */

#define BAD144_PART	2	/* XXX scattered magic numbers */
#define BSD_PART	0	/* XXX should be 2 but bad144.c uses 0 */
		    if (dl->d_partitions[BSD_PART].p_offset != 0)
			    dkbbnum = dl->d_partitions[BAD144_PART].p_offset
				      + dl->d_partitions[BAD144_PART].p_size;
		    else
			    dkbbnum = dl->d_secperunit;
		    dkbbnum -= dl->d_nsectors;

		    if (dl->d_secsize > DEV_BSIZE)
		      dkbbnum *= dl->d_secsize / DEV_BSIZE;
		    else
		      dkbbnum /= DEV_BSIZE / dl->d_secsize;
		    i = 0;
		    do_bad144 = 0;
		    do {
			/* XXX: what if the "DOS sector" < 512 bytes ??? */
			p = Bread(dosdev_copy, dkbbnum + i);
			dkbptr = (struct dkbad *) p;
/* XXX why is this not in <sys/dkbad.h> ??? */
#define DKBAD_MAGIC 0x4321
			if (dkbptr->bt_mbz == 0 &&
			        dkbptr->bt_flag == DKBAD_MAGIC) {
			    dkb = *dkbptr;	/* structure copy */
			    do_bad144 = 1;
			    break;
			}
			i += 2;
		    } while (i < 10 && (unsigned)i < dl->d_nsectors);
		    if (!do_bad144)
		      printf("Bad bad sector table\n");
		    else
		      printf("Using bad sector table at %d\n", dkbbnum+i);
		}
#endif /* DO_BAD144 */
	}
#endif /* RAWBOOT */
	return 0;
}
Beispiel #3
0
int devopen(void)
{
	struct dos_partition *dptr;
	struct disklabel *dl;
	int dosdev = (int) inode.i_dev;
	int i;
	long di, sector;
	
	di = get_diskinfo(dosdev);
	spc = (spt = (int)SPT(di)) * (int)HEADS(di);
	if (dosdev == 2)
	{
		boff = 0;
		part = (spt == 15 ? 3 : 1);
	}
	else
	{
#ifdef	EMBEDDED_DISKLABEL
		dl = &disklabel;
#else	EMBEDDED_DISKLABEL
		Bread(dosdev, 0);
		dptr = (struct dos_partition *)(((char *)I_ADDR)+DOSPARTOFF);
		sector = LABELSECTOR;
		slice = WHOLE_DISK_SLICE;
		for (i = 0; i < NDOSPART; i++, dptr++)
			if (dptr->dp_typ == DOSPTYP_386BSD) {
				slice = BASE_SLICE + i;
				sector = dptr->dp_start + LABELSECTOR;
				break;
			}
		Bread(dosdev, sector++);
		dl=((struct disklabel *)I_ADDR);
		disklabel = *dl;	/* structure copy (maybe useful later)*/
#endif	EMBEDDED_DISKLABEL
		if (dl->d_magic != DISKMAGIC) {
			printf("bad disklabel");
			return 1;
		}

		if( (maj == 4) || (maj == 0) || (maj == 1)) {
			if (dl->d_type == DTYPE_SCSI)
				maj = 4; /* use scsi as boot dev */
			else
				maj = 0; /* must be ESDI/IDE */
		}

		boff = dl->d_partitions[part].p_offset;
#ifdef DO_BAD144
		bsize = dl->d_partitions[part].p_size;
		do_bad144 = 0;
		if (dl->d_flags & D_BADSECT) {
		    /* this disk uses bad144 */
		    int i;
		    long dkbbnum;
		    struct dkbad *dkbptr;

		    /* find the first readable bad sector table */
		    /* some of this code is copied from ufs/ufs_disksubr.c */
		    /* including the bugs :-( */
		    /* read a bad sector table */

#define BAD144_PART	2	/* XXX scattered magic numbers */
#define BSD_PART	0	/* XXX should be 2 but bad144.c uses 0 */
		    if (dl->d_partitions[BSD_PART].p_offset != 0)
			    dkbbnum = dl->d_partitions[BAD144_PART].p_offset
				      + dl->d_partitions[BAD144_PART].p_size;
		    else
			    dkbbnum = dl->d_secperunit;
		    dkbbnum -= dl->d_nsectors;

		    if (dl->d_secsize > DEV_BSIZE)
		      dkbbnum *= dl->d_secsize / DEV_BSIZE;
		    else
		      dkbbnum /= DEV_BSIZE / dl->d_secsize;
		    i = 0;
		    do_bad144 = 0;
		    do {
			/* XXX: what if the "DOS sector" < 512 bytes ??? */
			Bread(dosdev, dkbbnum + i);
			dkbptr = (struct dkbad *) I_ADDR;
/* XXX why is this not in <sys/dkbad.h> ??? */
#define DKBAD_MAGIC 0x4321
			if (dkbptr->bt_mbz == 0 &&
			        dkbptr->bt_flag == DKBAD_MAGIC) {
			    dkb = *dkbptr;	/* structure copy */
			    do_bad144 = 1;
			    break;
			}
			i += 2;
		    } while (i < 10 && (u_long) i < dl->d_nsectors);
		    if (!do_bad144)
		      printf("Bad badsect table\n");
		    else
		      printf("Using bad144 bad sector at %ld\n", dkbbnum+i);
		}
#endif
	}
	return 0;
}
Beispiel #4
0
int
read_partitions(void)
{
	char 		*altptr;
	struct ipart 	*iptr, *active, *extended;
	int 		i, sector;
	int 		base =0;
	int		ext_base = 0;
	struct evtoc 	*evp;
	int 		di;

	di  = get_diskinfo(BDEV(dev,unit));
	spc = (spt = SPT(di)) * HEADS(di);
	use_badsect = FALSE;

	npartitions = 0;
	active_partition = 0;
	active = (struct ipart *)0;
	extended = (struct ipart *)0;

	disk_read(0, BPS, (vm_offset_t)0);
	iptr = (struct ipart *)((struct mboot *)0)->parts;
	for (i = 0; i < FD_NUMPART; i++, iptr++) {
#if	DEBUG
	  	if (debug)
			show_part(iptr, i, 0);
#endif
		if (iptr->bootid == ACTIVE) {
			active = iptr;
			active_partition = i;
		}
		if (iptr->systid == EXT_PART)
			extended = iptr;
		partitions[i].p_start = iptr->relsect;
		partitions[i].p_size = iptr->numsect;
	}
	if (active && active->systid == UNIXOS) {
	  	sector = active->relsect + HDPDLOC;
		evp = (struct evtoc *)0;
		if (disk_read(sector++, BPS, (vm_offset_t)0) == 0 &&
		    evp->sanity == VTOC_SANE) {	/* compatibility */
			bcopy((char *)evp->part,
			      (char *)partitions, sizeof(partitions));
			npartitions = evp->nparts;
			altptr = (char *)(&alt_info);
			for (i = 0; i++ < 4; altptr += BPS, sector++) {
			    if (disk_read(sector, BPS, (vm_offset_t)altptr))
				return 1;
			}
			if (alt_info.alt_sanity != ALT_SANITY) {
				printf("Bad alt_sanity\n");
				return 1;
			}
			active_partition = 0;
			use_badsect = TRUE;
			return 0;
		} 
	}
	if (extended) {
		/* look for extended partitions */
		base = extended->relsect;
		ext_base = base;
		while (1) {
			if (disk_read(base, BPS, (vm_offset_t)0))
		        	return 1;	
			iptr = (struct ipart *)((struct mboot *)0)->parts;
#if	DEBUG
			if (debug)
				show_part(iptr, i, base);
#endif
			partitions[i].p_start = base + iptr->relsect;
			partitions[i].p_size = iptr->numsect;
			i++;
			iptr++;
#if 	DEBUG
			if (debug)
				show_part(iptr, i, base);
#endif
			if (iptr->systid == EXT_PART) {
		        	extended = iptr;
				base = extended->relsect + ext_base;
			} else
				break;
		}
	}
	npartitions = i;
	return 0;
}
Beispiel #5
0
int
devopen(void)
{
	struct dos_partition *dptr;
	struct disklabel *dl;
	char *p;
	int i, sector = 0, di, dosdev_copy;

	dosdev_copy = dosdev;
	di = get_diskinfo(dosdev_copy);
	spt = SPT(di);

	/* Hack for 2.88MB floppy drives. */
	if (!(dosdev_copy & 0x80) && spt == 36)
		spt = 18;

	spc = spt * HEADS(di);

#ifndef RAWBOOT
	{
#ifdef	EMBEDDED_DISKLABEL
		dl = &disklabel;
#else	EMBEDDED_DISKLABEL
		p = Bread(dosdev_copy, 0);
		dptr = (struct dos_partition *)(p+DOSPARTOFF);
		slice = WHOLE_DISK_SLICE;
		for (i = 0; i < NDOSPART; i++, dptr++)
			if (dptr->dp_typ == DOSPTYP_386BSD) {
				slice = BASE_SLICE + i;
				sector = dptr->dp_start;
				break;
			}
		p = Bread(dosdev_copy, sector + LABELSECTOR);
		dl=((struct disklabel *)p);
		disklabel = *dl;	/* structure copy (maybe useful later)*/
#endif	EMBEDDED_DISKLABEL
		if (dl->d_magic != DISKMAGIC) {
			printf("bad disklabel\n");
			return 1;
		}
		if( (maj == 4) || (maj == 0) || (maj == 1))
		{
			if (dl->d_type == DTYPE_SCSI)
			{
				maj = 4; /* use scsi as boot dev */
			}
			else
			{
				maj = 0; /* must be ESDI/IDE */
			}
		}
		/* This little trick is for OnTrack DiskManager disks */
		boff = dl->d_partitions[part].p_offset -
			dl->d_partitions[2].p_offset + sector;

		bsize = dl->d_partitions[part].p_size;
		if (bsize == 0) {
			printf("empty partition\n");
			return 1;
		}

	}
#endif /* RAWBOOT */
	return 0;
}