Browse Source

Plan 9 from Bell Labs 2012-07-14

David du Colombier 12 years ago
parent
commit
1289071c66
7 changed files with 53 additions and 30 deletions
  1. 3 1
      sys/include/disk.h
  2. 11 11
      sys/man/3/sd
  3. 9 4
      sys/src/9/pc/sdata.c
  4. 12 11
      sys/src/9/port/devsd.c
  5. 13 0
      sys/src/9/port/sd.h
  6. 2 2
      sys/src/9/port/sdscsi.c
  7. 3 1
      sys/src/libdisk/scsi.c

+ 3 - 1
sys/include/disk.h

@@ -78,10 +78,12 @@ enum {					/* SCSI command codes */
 	ScmdStart	= 0x1B,		/* start/stop unit */
 	ScmdRcapacity	= 0x25,		/* read capacity */
 	ScmdRcapacity16	= 0x9e,		/* long read capacity */
+	ScmdRformatcap	= 0x23,		/* read format capacity */
 	ScmdExtread	= 0x28,		/* extended read (10 bytes) */
 	ScmdRead16	= 0x88,		/* long read (16 bytes) */
-	ScmdWrite16	= 0x8A,		/* long write (16 bytes) */
 	ScmdExtwrite	= 0x2A,		/* extended write (10 bytes) */
+	ScmdExtwritever = 0x2E,		/* extended write and verify (10) */
+	ScmdWrite16	= 0x8A,		/* long write (16 bytes) */
 	ScmdExtseek	= 0x2B,		/* extended seek */
 
 	ScmdSynccache	= 0x35,		/* flush cache */

+ 11 - 11
sys/man/3/sd

@@ -4,7 +4,7 @@ sd \- storage device interface
 .SH SYNOPSIS
 .nf
 .B bind #S /dev
-
+.sp 0.4v
 .B /dev/sdctl
 .BI /dev/sd Cu /ctl
 .BI /dev/sd Cu /raw
@@ -64,7 +64,7 @@ By default,
 the partition
 .I data
 will exist for such media.
-.PP
+.SS "\fIctl\fP and partitions
 Partitions are added and deleted by writing to the
 .I ctl
 file
@@ -94,17 +94,17 @@ and Plan 9 partitions according to their function
 .BR /dev/sdC0/swap ).
 The example in
 .IR prep (8)
-shows how this is done.
+shows how.
 .PP
 Reading the
 .I ctl
 file returns at least one line of textual information about
 the unit.
 The first line will always be prefixed by
-.B inquiry
+.L inquiry
 and will give a manufacturer and model number if possible.
 A line prefixed by
-.B config
+.L config
 will be returned for appropriate media,
 e.g. for ATA(PI) units the remainder of the line contains
 configuration information from the device's
@@ -113,7 +113,7 @@ command (config and capabilities)
 and also the available I/O transfer options;
 this is a diagnostic aid.
 A line prefixed by
-.B geometry
+.L geometry
 will be returned for appropriate media;
 at least two numbers will follow,
 the first being the number of sectors contained in the unit
@@ -126,7 +126,7 @@ cylinder and sector counts for ATA discs.
 If any partitions are defined for the media,
 their name, start-sector and end-sector will be returned,
 prefixed by
-.BR part .
+.LR part .
 .IP
 .EX
 % cat /dev/sdD0/ctl
@@ -167,9 +167,9 @@ is the standby timer period in seconds.
 .I T
 must be between 30 and 1200,
 or can be 0 to disable the timer.
-.PP
+.SS \fIraw\fP
 The
-.B raw
+.I raw
 file is used to execute an arbitrary command on the unit at
 a low level.
 This is used by programs such as
@@ -188,12 +188,12 @@ Read the
 .I raw
 file to retrieve the status of the command,
 returned as a text integer.
-.LP
+.SS sdctl
 Reading
 .B /dev/sdctl
 yields information about each controller,
 one line per controller.
-Writing `\fLconfig \fImessage\fR' to
+Writing `\fLconfig\fI message\fR' to
 .B /dev/sdctl
 passes
 .I message

+ 9 - 4
sys/src/9/pc/sdata.c

@@ -756,6 +756,10 @@ ataprobe(int cmdport, int ctlport, int irq)
 	int dev, error, rhi, rlo;
 	static int nonlegacy = 'C';
 	
+	if(cmdport == 0) {
+		print("ataprobe: cmdport is 0\n");
+		return nil;
+	}
 	if(ioalloc(cmdport, 8, 0, "atacmd") < 0) {
 		print("ataprobe: Cannot allocate %X\n", cmdport);
 		return nil;
@@ -1589,10 +1593,11 @@ atagenio(Drive* drive, uchar* cmd, int clen)
 		drive->data += 12;
 		return SDok;
 
-	case 0x28:			/* read */
-	case 0x88:
-	case 0x2a:			/* write */
-	case 0x8a:
+	case 0x28:			/* read (10) */
+	case 0x88:			/* long read (16) */
+	case 0x2a:			/* write (10) */
+	case 0x8a:			/* long write (16) */
+	case 0x2e:			/* write and verify (10) */
 		break;
 
 	case 0x5A:

+ 12 - 11
sys/src/9/port/devsd.c

@@ -185,13 +185,14 @@ sdinitpart(SDunit* unit)
 		sdincvers(unit);
 	}
 
-	if(unit->inquiry[0] & 0xC0)
+	/* device must be connected or not; other values are trouble */
+	if(unit->inquiry[0] & 0xC0)	/* see SDinq0periphqual */
 		return 0;
-	switch(unit->inquiry[0] & 0x1F){
-	case 0x00:			/* DA */
-	case 0x04:			/* WORM */
-	case 0x05:			/* CD-ROM */
-	case 0x07:			/* MO */
+	switch(unit->inquiry[0] & SDinq0periphtype){
+	case SDperdisk:
+	case SDperworm:
+	case SDpercd:
+	case SDpermo:
 		break;
 	default:
 		return 0;
@@ -422,7 +423,7 @@ sd2gen(Chan* c, int i, Dir* dp)
 		perm = &unit->ctlperm;
 		if(emptystr(perm->user)){
 			kstrdup(&perm->user, eve);
-			perm->perm = 0640;
+			perm->perm = 0644;	/* nothing secret in ctl */
 		}
 		devdir(c, q, "ctl", 0, perm->user, perm->perm, dp);
 		rv = 1;
@@ -464,7 +465,7 @@ sd1gen(Chan* c, int i, Dir* dp)
 	switch(i){
 	case Qtopctl:
 		mkqid(&q, QID(0, 0, 0, Qtopctl), 0, QTFILE);
-		devdir(c, q, "sdctl", 0, eve, 0640, dp);
+		devdir(c, q, "sdctl", 0, eve, 0644, dp);	/* no secrets */
 		return 1;
 	}
 	return -1;
@@ -792,7 +793,7 @@ sdbio(Chan* c, int write, char* a, long len, uvlong off)
 		poperror();
 		return 0;
 	}
-	if(!(unit->inquiry[1] & 0x80)){
+	if(!(unit->inquiry[1] & SDinq1removable)){
 		qunlock(&unit->ctl);
 		poperror();
 	}
@@ -802,7 +803,7 @@ sdbio(Chan* c, int write, char* a, long len, uvlong off)
 		error(Enomem);
 	if(waserror()){
 		sdfree(b);
-		if(!(unit->inquiry[1] & 0x80))
+		if(!(unit->inquiry[1] & SDinq1removable))
 			decref(&sdev->r);		/* gadverdamme! */
 		nexterror();
 	}
@@ -844,7 +845,7 @@ sdbio(Chan* c, int write, char* a, long len, uvlong off)
 	sdfree(b);
 	poperror();
 
-	if(unit->inquiry[1] & 0x80){
+	if(unit->inquiry[1] & SDinq1removable){
 		qunlock(&unit->ctl);
 		poperror();
 	}

+ 13 - 0
sys/src/9/port/sd.h

@@ -103,6 +103,19 @@ struct SDreq {
 enum {
 	SDnosense	= 0x00000001,
 	SDvalidsense	= 0x00010000,
+
+	SDinq0periphqual= 0xe0,
+	SDinq0periphtype= 0x1f,
+	SDinq1removable	= 0x80,
+
+	/* periphtype values */
+	SDperdisk	= 0,	/* Direct access (disk) */
+	SDpertape	= 1,	/* Sequential eg, tape */
+	SDperpr		= 2,	/* Printer */
+	SDperworm	= 4,	/* Worm */
+	SDpercd		= 5,	/* CD-ROM */
+	SDpermo		= 7,	/* rewriteable MO */
+	SDperjuke	= 8,	/* medium-changer */
 };
 
 enum {

+ 2 - 2
sys/src/9/port/sdscsi.c

@@ -93,7 +93,7 @@ scsiverify(SDunit* unit)
 		 * Try to ensure a direct-access device is spinning.
 		 * Don't wait for completion, ignore the result.
 		 */
-		if((unit->inquiry[0] & 0x1F) == 0){
+		if((unit->inquiry[0] & SDinq0periphtype) == SDperdisk){
 			memset(r->cmd, 0, sizeof(r->cmd));
 			r->write = 0;
 			r->cmd[0] = 0x1B;
@@ -403,7 +403,7 @@ again:
 			 */
 			if(r->sense[12] != 0x28 || r->sense[13] != 0)
 				break;
-			if(unit->inquiry[1] & 0x80)
+			if(unit->inquiry[1] & SDinq1removable)
 				unit->sectors = 0;
 			break;
 		case 0x02:		/* not ready */

+ 3 - 1
sys/src/libdisk/scsi.c

@@ -18,6 +18,7 @@ enum {
 	Testrdy		= 0x00,
 	Reqsense	= 0x03,
 	Write10		= 0x2a,
+	Writever10	= 0x2e,
 	Readtoc		= 0x43,
 
 	/* sense[2] (key) sense codes */
@@ -273,7 +274,8 @@ scsi(Scsi *s, uchar *cmd, int ccount, void *v, int dcount, int io)
 			/* read toc and media changed */
 			s->nchange++;
 			s->changetime = time(0);
-		} else if(cmd[0] == Write10 && key == Sensenotrdy &&
+		} else if((cmd[0] == Write10 || cmd[0] == Writever10) &&
+		    key == Sensenotrdy &&
 		    code == Lunnotrdy && sense[13] == 0x08) {
 			/* long write in progress, per mmc-6 */
 			tries = 0;