plan 9 kernel history: overview | file list | diff list

1995/0405/port/devsd.c (diff list | history)

1995/0404/sys/src/9/port/devsd.c:100,1071995/0405/sys/src/9/port/devsd.c:100,106 (short | long | prev | next)
1994/0913    
sdinit(void) 
{ 
	Disk *d; 
	ulong s, b; 
1995/0329    
	uchar inq[255]; 
1995/0405    
	uchar scratch[0xFF], type; 
1995/0329    
	int dev, i, nbytes; 
1994/0913    
 
	dev = 0; 
1995/0404/sys/src/9/port/devsd.c:111,1261995/0405/sys/src/9/port/devsd.c:110,120
1994/0913    
		if(dev < 0) 
			break; 
 
1995/0404    
		if(scsitest(d->t, 0) < 0) 
			scsireqsense(d->t, 0, 0); 
		if(scsistart(d->t, 0, 1) < 0) 
			scsireqsense(d->t, 0, 0); 
print("sd1|"); 
1994/0913    
                 
		/* Search for other lun's */ 
1995/0405    
		/* 
		 * Search for all the lun's. 
		 */ 
1994/0913    
		for(i = 0; i < Nlun; i++) { 
			d->lun = i; 
1995/0404    
print("sd2|"); 
1995/0329    
 
			/* 
			 * A SCSI target does not support a lun if the 
1995/0404/sys/src/9/port/devsd.c:127,1541995/0405/sys/src/9/port/devsd.c:121,158
1995/0329    
			 * the peripheral device type and qualifier fields 
			 * in the response to an inquiry command are 0x7F. 
			 */ 
			memset(inq, 0, sizeof(inq)); 
			nbytes = sizeof(inq); 
			if(scsiinquiry(d->t, d->lun, inq, &nbytes) != STok || inq[0] == 0x7F) 
1995/0405    
			nbytes = sizeof(scratch); 
			memset(scratch, 0, nbytes); 
			if(scsiinquiry(d->t, d->lun, scratch, &nbytes) != STok) 
1995/0329    
				continue; 
1995/0404    
print("sd3|"); 
1994/0913    
                 
			s = 0; 
			b = 0; 
			if(scsicap(d->t, d->lun, &s, &b) != STok) { 
1995/0404    
				scsireqsense(d->t, 0, 0); 
1995/0405    
			if(scratch[0] == 0x7F) 
1994/0913    
				continue; 
1995/0405    
			type = scratch[0] & 0x1F; 
 
			/* 
			 * Read-capacity is mandatory for TypeDA, TypeMO and TypeCD. 
			 * It may return 'not ready' if TypeDA is not spun up, 
			 * TypeMO or TypeCD are not loaded or just plain slow getting 
			 * their act together after a reset. 
			 * If 'not ready' comes back, try starting a TypeDA and punt 
			 * the get capacity until the drive is attached. 
			 * It might be possible to be smarter here, and look at the 
			 * response from a test-unit-ready which would show if the 
			 * target was in the process of becoming ready. 
			 */ 
			if(scsicap(d->t, d->lun, &d->size, &d->bsize) != STok) { 
				nbytes = sizeof(scratch); 
				memset(scratch, 0, nbytes); 
				scsireqsense(d->t, 0, scratch, &nbytes, 1); 
				if((scratch[2] & 0x0F) != 0x02) 
					continue; 
				if(type == TypeDA) 
					scsistart(d->t, d->lun, 0); 
				d->size = d->bsize = 0; 
1994/0913    
			} 
1995/0404    
print("sd4/%d/%d|", s, b); 
1994/0913    
 
			if(s == 0 || b == 0) 
				continue; 
1995/0404    
print("sd5/0x%2.2ux|", d->inquire[0]); 
1995/0405    
			switch(type){ 
1994/0913    
 
			d->size = s; 
			d->bsize = b; 
1995/0403    
			switch(d->inquire[0] & 0x1F){ 
1994/0913    
                 
1995/0403    
			case TypeDA: 
			case TypeMO: 
				sprint(d->vol, "sd%d", ndisk); 
1995/0404/sys/src/9/port/devsd.c:161,1671995/0405/sys/src/9/port/devsd.c:165,170
1995/0403    
			default: 
				continue; 
			} 
1995/0404    
print("sd6|"); 
1995/0403    
 
1994/0913    
			if(++ndisk >= Ndisk) 
				break; 
1995/0404/sys/src/9/port/devsd.c:281,2901995/0405/sys/src/9/port/devsd.c:284,306
1994/0913    
	char *b, *line[Npart+2], *field[3]; 
	static char MAGIC[] = "plan9 partitions"; 
 
1995/0405    
	/* 
	 * If the drive wasn't ready when we tried to do a 
	 * read-capacity earlier (in sdinit()), try again. 
	 * It might be possible to be smarter here, and look at the 
	 * response from a test-unit-ready which would show if the 
	 * target was in the process of becoming ready. 
	 */ 
	if(d->size == 0 || d->bsize == 0){ 
		if(scsicap(d->t, d->lun, &d->size, &d->bsize) != STok){ 
			d->size = d->bsize = 0; 
			error(Eio); 
		} 
	} 
 
1994/0913    
	b = scsialloc(d->bsize); 
	if(b == 0) 
		error(Enomem); 
                 
	qlock(d); 
	 
	p = d->table; 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)