Browse Source

Plan 9 from Bell Labs 2012-10-10

David du Colombier 11 years ago
parent
commit
8842fc4524
5 changed files with 63 additions and 15 deletions
  1. 1 1
      sys/man/1/mk
  2. 8 1
      sys/src/cmd/cdfs/dat.h
  3. 7 4
      sys/src/cmd/cdfs/main.c
  4. 46 8
      sys/src/cmd/ecp.c
  5. 1 1
      sys/src/cmd/yacc.c

+ 1 - 1
sys/man/1/mk

@@ -174,7 +174,7 @@ might be:
 .EX
 %:    %.c
         8c $stem.c
-        8l -o $stem $stem.2
+        8l -o $stem $stem.8
 .EE
 .PP
 Meta-rules may contain an ampersand

+ 8 - 1
sys/src/cmd/cdfs/dat.h

@@ -6,6 +6,8 @@ enum {
 	BScdxa		= 2336,
 	BSmax		= 2352,
 
+	Maxfeatures	= 512,
+
 	/* scsi peripheral device types, SPC-3 §6.4.2 */
 	TypeDA		= 0,		/* Direct Access (SBC) */
 	TypeSA		= 1,		/* Sequential Access (SSC) */
@@ -99,7 +101,7 @@ enum {
 	Wtraw,
 	Wtlayerjump,
 
-	/* track modes (TODO: also track types?) */
+	/* track modes (determine: are these also track types?) */
 	Tmcdda	= 0,		/* audio cdda */
 	Tm2audio,		/* 2 audio channels */
 	Tmunintr = 4,		/* data, recorded uninterrupted */
@@ -132,6 +134,7 @@ enum {
 	CDNblock = 12,		/* chosen for CD */
 	DVDNblock = 16,		/* DVD ECC block is 16 sectors */
 	BDNblock = 32,		/* BD ECC block (`cluster') is 32 sectors */
+				/* BD-R are write-once in increments of 64KB */
 	/*
 	 * make a single transfer fit in a 9P rpc.  if we don't do this,
 	 * remote access (e.g., via /mnt/term/dev/sd*) fails mysteriously.
@@ -213,6 +216,7 @@ struct Drive
 	/* disc characteristics */
 	int	mmctype;		/* cd, dvd, or bd */
 	char	*dvdtype;		/* name of dvd flavour */
+	char	*laysfx;		/* layer suffix (e.g., -dl) */
 	int	firsttrack;
 	int	invistrack;
 	int	ntrack;
@@ -228,6 +232,7 @@ struct Drive
 	Tristate erasable;		/* writable after erasing? */
 
 	Track	track[Ntrack];
+	ulong	end;			/* # of blks on current disc */
 	ulong	cap;			/* drive capabilities */
 	uchar	blkbuf[BScdda];
 
@@ -237,6 +242,8 @@ struct Drive
 	int	writespeed;
 	Dev;
 
+	uchar	features[Maxfeatures/8];
+
 	void *aux;		/* kept by driver */
 };
 

+ 7 - 4
sys/src/cmd/cdfs/main.c

@@ -207,8 +207,9 @@ fsremove(Req *r)
 char *
 disctype(Drive *drive)
 {
-	char *type, *rw;
+	char *type, *rw, *laysfx;
 
+	rw = laysfx = "";
 	switch (drive->mmctype) {
 	case Mmccd:
 		type = "cd-";
@@ -219,6 +220,8 @@ disctype(Drive *drive)
 		break;
 	case Mmcbd:
 		type = "bd-";
+		if (drive->laysfx)
+			laysfx = drive->laysfx;
 		break;
 	case Mmcnone:
 		type = "no-disc";
@@ -227,7 +230,6 @@ disctype(Drive *drive)
 		type = "**GOK**";		/* traditional */
 		break;
 	}
-	rw = "";
 	if (drive->mmctype != Mmcnone && drive->dvdtype == nil)
 		if (drive->erasable == Yes)
 			rw = drive->mmctype == Mmcbd? "re": "rw";
@@ -235,7 +237,7 @@ disctype(Drive *drive)
 			rw = "r";
 		else
 			rw = "rom";
-	return smprint("%s%s", type, rw);
+	return smprint("%s%s%s", type, rw, laysfx);
 }
 
 int
@@ -715,7 +717,8 @@ main(int argc, char **argv)
 				close(fd);
 			vflag++;
 			scsiverbose = 2; /* verbose but no Readtoc errs */
-		}
+		} else
+			fprint(2, "%s: can't open /tmp/cdfs.log: %r\n", argv0);
 		break;
 	default:
 		usage();

+ 46 - 8
sys/src/cmd/ecp.c

@@ -168,6 +168,47 @@ rewind(File *fp)
 	repos(fp, 0);
 }
 
+static char magic[] = "\235any old ☺ rubbish\173";
+static char uniq[sizeof magic + 2*sizeof(ulong)];
+
+static char *
+putbe(char *p, ulong ul)
+{
+	*p++ = ul>>24;
+	*p++ = ul>>16;
+	*p++ = ul>>8;
+	*p++ = ul;
+	return p;
+}
+
+/*
+ * generate magic + unique string, add to start & end of buff.
+ * return tail pointer.
+ */
+static char *
+addmagic(char *buff, int bytes)
+{
+	char *p, *tail;
+	static ulong seq;
+
+	strcpy(uniq, magic);
+	p = putbe(uniq + sizeof magic - 1, time(0));
+	putbe(p, ++seq);
+
+	memcpy(buff, uniq, sizeof uniq);
+	tail = buff + bytes - sizeof uniq;
+	memcpy(tail, uniq, sizeof uniq);
+	return tail;
+}
+
+/* verify magic + unique strings in buff */
+static int
+ismagicok(char *buff, char *tail)
+{
+	return  memcmp(buff, uniq, sizeof uniq) == 0 ||
+		memcmp(tail, uniq, sizeof uniq) == 0;
+}
+
 /*
  * transfer (many) sectors.  reblock input as needed.
  * returns Enone if no failures, others on failure with errstr set.
@@ -179,7 +220,6 @@ bio(File *fp, Rdwrfn *rdwr, char *buff, Daddr stsect, int sects, int mustseek)
 	char *tail;
 	ulong toread, bytes = sects * sectsz;
 	static int reblocked = 0;
-	static char magic[] = "\235any old ☺ rubbish\173";
 
 	if (mustseek) {
 		if (!fp->seekable)
@@ -191,23 +231,20 @@ bio(File *fp, Rdwrfn *rdwr, char *buff, Daddr stsect, int sects, int mustseek)
 		sysfatal("i/o count too big: %lud", bytes);
 
 	SET(tail);
-	if (rdwr == read) {
-		strcpy(buff, magic);
-		tail = buff + bytes - sizeof magic;
-		strcpy(tail, magic);
-	}
+	if (rdwr == read)
+		tail = addmagic(buff, bytes);
 	werrstr("");
 	xfered = (*rdwr)(fp->fd, buff, bytes);
 	if (xfered == bytes) {
 		/* don't trust the hardware; it may lie */
-		if (rdwr == read &&
-		    (strcmp(buff, magic) == 0 || strcmp(tail, magic) == 0))
+		if (rdwr == read && ismagicok(buff, tail))
 			fprint(2, "%s: `good' read didn't change buffer\n",
 				argv0);
 		return Enone;			/* did as we asked */
 	}
 	if (xfered < 0)
 		return Eio;			/* out-and-out i/o error */
+
 	/*
 	 * Kernel transferred less than asked.  Shouldn't happen;
 	 * probably indicates disk driver error or trying to
@@ -215,6 +252,7 @@ bio(File *fp, Rdwrfn *rdwr, char *buff, Daddr stsect, int sects, int mustseek)
 	 * I/O error that reads zeros past the point of error,
 	 * unless reblocking input and this is a read.
 	 */
+
 	if (rdwr == write)
 		return Eio;
 	if (!reblock) {

+ 1 - 1
sys/src/cmd/yacc.c

@@ -2062,7 +2062,7 @@ swt:
 		if(c != '*')
 			goto swt;
 
-		/* it really is a comment */
+		/* it really is a comment; copy it */
 		Bputrune(faction, c);
 		c = Bgetrune(finput);
 		while(c >= 0) {