Browse Source

Plan 9 from Bell Labs 2008-03-29

David du Colombier 12 years ago
parent
commit
ec74f8be29

+ 9 - 9
dist/replica/_plan9.db

@@ -16,7 +16,7 @@
 386/bin/8a - 775 sys sys 1168402260 116604
 386/bin/8c - 775 sys sys 1190520740 367214
 386/bin/8l - 775 sys sys 1148500567 115711
-386/bin/9660srv - 775 sys sys 1204948766 104897
+386/bin/9660srv - 775 sys sys 1206732240 104949
 386/bin/aan - 775 sys sys 1196742429 129831
 386/bin/acid - 775 sys sys 1200262712 405315
 386/bin/acme - 775 sys sys 1200262719 431779
@@ -492,7 +492,7 @@
 386/bin/usb/kb - 775 sys sys 1203567409 133600
 386/bin/usb/print - 775 sys sys 1203567409 314
 386/bin/usb/probe - 775 sys sys 1203567409 173
-386/bin/usb/usbaudio - 775 sys sys 1202876962 188937
+386/bin/usb/usbaudio - 775 sys sys 1206760689 189891
 386/bin/usb/usbd - 775 sys sys 1202876965 132270
 386/bin/usb/usbmouse - 775 sys sys 1204057823 129465
 386/bin/usb/usbprint - 775 sys sys 1203567409 373
@@ -7761,7 +7761,7 @@ sys/man/4/tapefs - 664 sys sys 1196638944 1861
 sys/man/4/telco - 664 sys sys 1196638944 4359
 sys/man/4/u9fs - 664 sys sys 1205964618 5225
 sys/man/4/upasfs - 664 sys sys 1196638944 6212
-sys/man/4/usb - 664 sys sys 1203552814 5677
+sys/man/4/usb - 664 sys sys 1206739773 5725
 sys/man/4/usbd - 664 sys sys 1202846392 1035
 sys/man/4/usbdisk - 664 sys sys 1205857582 3044
 sys/man/4/vacfs - 664 sys sys 1196638944 1545
@@ -8106,7 +8106,7 @@ sys/src/9/pc/devlpt.c - 664 sys sys 1184469951 4423
 sys/src/9/pc/devpccard.c - 664 sys sys 1184469910 39336
 sys/src/9/pc/devrtc.c - 664 sys sys 1015014515 7167
 sys/src/9/pc/devtv.c - 664 sys sys 1184469620 45423
-sys/src/9/pc/devusb.c - 664 sys sys 1204179902 20831
+sys/src/9/pc/devusb.c - 664 sys sys 1206740166 21073
 sys/src/9/pc/devvga.c - 664 sys sys 1181083003 9334
 sys/src/9/pc/dma.c - 664 sys sys 1142966373 5332
 sys/src/9/pc/ether2000.c - 664 sys sys 1173287379 4901
@@ -9429,7 +9429,7 @@ sys/src/cmd/8l/optab.c - 664 sys sys 1111156413 16231
 sys/src/cmd/8l/pass.c - 664 sys sys 1095107668 13675
 sys/src/cmd/8l/span.c - 664 sys sys 1107721554 23294
 sys/src/cmd/9660srv - 20000000775 sys sys 1048644372 0
-sys/src/cmd/9660srv/9660srv.c - 664 sys sys 1132451689 17151
+sys/src/cmd/9660srv/9660srv.c - 664 sys sys 1206721469 17203
 sys/src/cmd/9660srv/dat.h - 664 sys sys 1204937773 2129
 sys/src/cmd/9660srv/data.c - 664 sys sys 944960735 373
 sys/src/cmd/9660srv/fns.h - 664 sys sys 1204937773 429
@@ -14276,12 +14276,12 @@ sys/src/cmd/upas/vf/mkfile - 664 sys sys 1064393881 241
 sys/src/cmd/upas/vf/vf.c - 664 sys sys 1181681383 20307
 sys/src/cmd/usb - 20000000775 sys sys 1091205029 0
 sys/src/cmd/usb/audio - 20000000775 sys sys 1091204980 0
-sys/src/cmd/usb/audio/audiofs.c - 664 sys sys 1172903208 18518
+sys/src/cmd/usb/audio/audiofs.c - 664 sys sys 1206739707 18727
 sys/src/cmd/usb/audio/audiosub.c - 664 sys sys 1172764044 8275
 sys/src/cmd/usb/audio/mkfile - 664 sys sys 1091204980 349
-sys/src/cmd/usb/audio/usbaudio.c - 664 sys sys 1202255398 10343
-sys/src/cmd/usb/audio/usbaudio.h - 664 sys sys 1140695062 1889
-sys/src/cmd/usb/audio/usbaudioctl.c - 664 sys sys 1172764044 18825
+sys/src/cmd/usb/audio/usbaudio.c - 664 sys sys 1206739761 10505
+sys/src/cmd/usb/audio/usbaudio.h - 664 sys sys 1206739688 1907
+sys/src/cmd/usb/audio/usbaudioctl.c - 664 sys sys 1206739741 18993
 sys/src/cmd/usb/audio/usbaudioctl.h - 664 sys sys 1140695062 618
 sys/src/cmd/usb/disk - 20000000775 sys sys 1193181450 0
 sys/src/cmd/usb/disk/disk.c - 664 sys sys 1202256113 20245

+ 9 - 9
dist/replica/plan9.db

@@ -16,7 +16,7 @@
 386/bin/8a - 775 sys sys 1168402260 116604
 386/bin/8c - 775 sys sys 1190520740 367214
 386/bin/8l - 775 sys sys 1148500567 115711
-386/bin/9660srv - 775 sys sys 1204948766 104897
+386/bin/9660srv - 775 sys sys 1206732240 104949
 386/bin/aan - 775 sys sys 1196742429 129831
 386/bin/acid - 775 sys sys 1200262712 405315
 386/bin/acme - 775 sys sys 1200262719 431779
@@ -492,7 +492,7 @@
 386/bin/usb/kb - 775 sys sys 1203567409 133600
 386/bin/usb/print - 775 sys sys 1203567409 314
 386/bin/usb/probe - 775 sys sys 1203567409 173
-386/bin/usb/usbaudio - 775 sys sys 1202876962 188937
+386/bin/usb/usbaudio - 775 sys sys 1206760689 189891
 386/bin/usb/usbd - 775 sys sys 1202876965 132270
 386/bin/usb/usbmouse - 775 sys sys 1204057823 129465
 386/bin/usb/usbprint - 775 sys sys 1203567409 373
@@ -7761,7 +7761,7 @@ sys/man/4/tapefs - 664 sys sys 1196638944 1861
 sys/man/4/telco - 664 sys sys 1196638944 4359
 sys/man/4/u9fs - 664 sys sys 1205964618 5225
 sys/man/4/upasfs - 664 sys sys 1196638944 6212
-sys/man/4/usb - 664 sys sys 1203552814 5677
+sys/man/4/usb - 664 sys sys 1206739773 5725
 sys/man/4/usbd - 664 sys sys 1202846392 1035
 sys/man/4/usbdisk - 664 sys sys 1205857582 3044
 sys/man/4/vacfs - 664 sys sys 1196638944 1545
@@ -8106,7 +8106,7 @@ sys/src/9/pc/devlpt.c - 664 sys sys 1184469951 4423
 sys/src/9/pc/devpccard.c - 664 sys sys 1184469910 39336
 sys/src/9/pc/devrtc.c - 664 sys sys 1015014515 7167
 sys/src/9/pc/devtv.c - 664 sys sys 1184469620 45423
-sys/src/9/pc/devusb.c - 664 sys sys 1204179902 20831
+sys/src/9/pc/devusb.c - 664 sys sys 1206740166 21073
 sys/src/9/pc/devvga.c - 664 sys sys 1181083003 9334
 sys/src/9/pc/dma.c - 664 sys sys 1142966373 5332
 sys/src/9/pc/ether2000.c - 664 sys sys 1173287379 4901
@@ -9429,7 +9429,7 @@ sys/src/cmd/8l/optab.c - 664 sys sys 1111156413 16231
 sys/src/cmd/8l/pass.c - 664 sys sys 1095107668 13675
 sys/src/cmd/8l/span.c - 664 sys sys 1107721554 23294
 sys/src/cmd/9660srv - 20000000775 sys sys 1048644372 0
-sys/src/cmd/9660srv/9660srv.c - 664 sys sys 1132451689 17151
+sys/src/cmd/9660srv/9660srv.c - 664 sys sys 1206721469 17203
 sys/src/cmd/9660srv/dat.h - 664 sys sys 1204937773 2129
 sys/src/cmd/9660srv/data.c - 664 sys sys 944960735 373
 sys/src/cmd/9660srv/fns.h - 664 sys sys 1204937773 429
@@ -14276,12 +14276,12 @@ sys/src/cmd/upas/vf/mkfile - 664 sys sys 1064393881 241
 sys/src/cmd/upas/vf/vf.c - 664 sys sys 1181681383 20307
 sys/src/cmd/usb - 20000000775 sys sys 1091205029 0
 sys/src/cmd/usb/audio - 20000000775 sys sys 1091204980 0
-sys/src/cmd/usb/audio/audiofs.c - 664 sys sys 1172903208 18518
+sys/src/cmd/usb/audio/audiofs.c - 664 sys sys 1206739707 18727
 sys/src/cmd/usb/audio/audiosub.c - 664 sys sys 1172764044 8275
 sys/src/cmd/usb/audio/mkfile - 664 sys sys 1091204980 349
-sys/src/cmd/usb/audio/usbaudio.c - 664 sys sys 1202255398 10343
-sys/src/cmd/usb/audio/usbaudio.h - 664 sys sys 1140695062 1889
-sys/src/cmd/usb/audio/usbaudioctl.c - 664 sys sys 1172764044 18825
+sys/src/cmd/usb/audio/usbaudio.c - 664 sys sys 1206739761 10505
+sys/src/cmd/usb/audio/usbaudio.h - 664 sys sys 1206739688 1907
+sys/src/cmd/usb/audio/usbaudioctl.c - 664 sys sys 1206739741 18993
 sys/src/cmd/usb/audio/usbaudioctl.h - 664 sys sys 1140695062 618
 sys/src/cmd/usb/disk - 20000000775 sys sys 1193181450 0
 sys/src/cmd/usb/disk/disk.c - 664 sys sys 1202256113 20245

+ 9 - 0
dist/replica/plan9.log

@@ -18908,3 +18908,12 @@
 1206554404 0 c sys/src/cmd/ndb/dblookup.c - 664 sys sys 1206554141 25262
 1206559804 0 c 386/bin/cdfs - 775 sys sys 1206559723 173155
 1206648004 0 c sys/games/lib/fortunes - 664 sys sys 1206647893 268958
+1206721804 0 c sys/src/cmd/9660srv/9660srv.c - 664 sys sys 1206721469 17203
+1206732604 0 c 386/bin/9660srv - 775 sys sys 1206732240 104949
+1206739804 0 c sys/man/4/usb - 664 sys sys 1206739773 5725
+1206739804 1 c sys/src/cmd/usb/audio/audiofs.c - 664 sys sys 1206739707 18727
+1206739804 2 c sys/src/cmd/usb/audio/usbaudio.c - 664 sys sys 1206739761 10505
+1206739804 3 c sys/src/cmd/usb/audio/usbaudio.h - 664 sys sys 1206739688 1907
+1206739804 4 c sys/src/cmd/usb/audio/usbaudioctl.c - 664 sys sys 1206739741 18993
+1206741603 0 c sys/src/9/pc/devusb.c - 664 sys sys 1206740166 21073
+1206761403 0 c 386/bin/usb/usbaudio - 775 sys sys 1206760689 189891

+ 13 - 10
sys/man/4/usb

@@ -30,10 +30,7 @@ print
 .PP
 .B usb/usbaudio
 [
-.B -V
-] [
-.B -v
-.I volume
+.B -pV
 ] [
 .B -m
 .I mountpoint
@@ -41,6 +38,9 @@ print
 .B -s
 .I srvname
 ] [
+.B -v
+.I volume
+] [
 .I ctrlno
 .I n
 ]
@@ -121,11 +121,11 @@ is a script that mounts a USB printer on
 .SS Audio devices
 .I Usbaudio
 configures and manages a USB audio device.  It implements a file system,
-normally mounted in
+normally mounted on
 .BI /dev ,
 but this can be changed with the
 .B \-m
-flag, with files
+option, with files
 .BR volume ,
 .BR audioctl ,
 .BR audio ,
@@ -139,12 +139,15 @@ maintain backward compatibility with the soundblaster driver.
 .PP
 The
 .B \-V
-flag (verbose) causes usbaudio to print information about the device on startup.
-.PP
+option (verbose) causes usbaudio to print information about the device on startup.
 The
 .B \-s
-flag specifies a name for a file descriptor to be posted in
-.CW /srv .
+option specifies a name for a file descriptor to be posted in
+.BR /srv .
+The
+.B \-v
+options sets initial
+.IR volume .
 .PP
 Reading
 .B volume

+ 12 - 8
sys/src/9/pc/devusb.c

@@ -27,7 +27,11 @@ static char *devstates[] = {
 	[Configured]	"Configured",
 };
 
-static	char	Ebadusbmsg[] = "invalid parameters to USB ctl message";
+static	char	Ebadusbmsg[]	= "invalid parameters to USB ctl message";
+static	char	Eeprange[]	= "usb endpoint number out of range";
+static	char	Eiso[]		= "usb endpoint in isochronous mode";
+static	char	Enousbhost[]	= "no Usbhost";
+static	char	Ewrongmode[]	= "no usb endpoint or wrong open mode";
 
 enum
 {
@@ -153,7 +157,7 @@ usbdevice(Chan *c)
 
 	bus = CTLR(c->qid);
 	if(bus >= nelem(usbhost) || (uh = usbhost[bus]) == nil) {
-		error(Egreg);
+		error(Enousbhost);
 		return nil;		/* for compiler */
 	}
 	d = usbdeviceofslot(uh, SLOT(c->qid));
@@ -665,10 +669,10 @@ usbread(Chan *c, void *a, long n, vlong offset)
 			error(Eio);
 		e = d->ep[t];
 		if(e == nil || e->mode == OWRITE)
-			error(Egreg);
+			error(Ewrongmode);
 		if(t == 0) {
 			if(e->epmode == Isomode)
-				error(Egreg);
+				error(Eiso);
 			if(e->override)
 				e->override = 0;
 			else
@@ -737,7 +741,7 @@ usbwrite(Chan *c, void *a, long n, vlong offset)
 	char cmd[50];
 
 	if(c->qid.type == QTDIR)
-		error(Egreg);
+		error(Eisdir);
 	d = usbdevice(c);
 	uh = d->uh;
 	t = TYPE(c->qid);
@@ -1000,7 +1004,7 @@ usbwrite(Chan *c, void *a, long n, vlong offset)
 		/* should canqlock etc */
 		e = d->ep[0];
 		if(e == nil || e->epmode == Isomode)
-			error(Egreg);
+			error(Eiso);
 		if(n < 8)
 			error(Eio);
 		nw = *(uchar*)a & RD2H;
@@ -1021,10 +1025,10 @@ usbwrite(Chan *c, void *a, long n, vlong offset)
 	default:	/* sends DATA[01] */
 		t -= Qep0;
 		if(t < 0 || t >= nelem(d->ep))
-			error(Egreg);
+			error(Eeprange);
 		e = d->ep[t];
 		if(e == nil || e->mode == OREAD)
-			error(Egreg);
+			error(Ewrongmode);
 		n = uh->write(uh, e, a, n, offset, uh->tokout);
 		break;
 	}

+ 5 - 3
sys/src/cmd/9660srv/9660srv.c

@@ -831,22 +831,24 @@ gtime(uchar *p)	/* yMdhmsz */
 {
 	long t;
 	int i, y, M, d, h, m, s, tz;
+
 	y=p[0]; M=p[1]; d=p[2];
 	h=p[3]; m=p[4]; s=p[5]; tz=p[6];
 	USED(tz);
-	if (y < 70)
+	y += 1900;
+	if (y < 1970)
 		return 0;
 	if (M < 1 || M > 12)
 		return 0;
 	if (d < 1 || d > dmsize[M-1])
-		return 0;
+		if (!(M == 2 && d == 29 && dysize(y) == 366))
+			return 0;
 	if (h > 23)
 		return 0;
 	if (m > 59)
 		return 0;
 	if (s > 59)
 		return 0;
-	y += 1900;
 	t = 0;
 	for(i=1970; i<y; i++)
 		t += dysize(i);

+ 13 - 4
sys/src/cmd/usb/audio/audiofs.c

@@ -171,6 +171,7 @@ serve(void *)
 {
 	int i;
 	ulong t;
+	Dir *dir;
 
 	if(pipe(p) < 0)
 		sysfatal("pipe failed");
@@ -211,6 +212,11 @@ serve(void *)
 		sprint(audiofile, "%s/audio", mntpt);
 		if(bind(epdata, audiofile, MREPL) < 0)
 			sysfatal("bind failed");
+
+		dir = dirstat(epdata);
+		if (dir && (dir->mode & 0222) != 0222)
+			sysfatal("%s unwritable", epdata);
+		free(dir);
 	}
 	if (endpt[Record] >= 0){
 		sprint(epdata, "#U/usb%d/%d/ep%ddata", ad->ctlrno, ad->id,
@@ -559,7 +565,7 @@ flush:
 char*
 rread(Fid *f)
 {
-	int i, n, cnt, rec;
+	int i, n, cnt, rec, div;
 	vlong off;
 	char *p;
 	Audiocontrol *c;
@@ -588,27 +594,30 @@ rread(Fid *f)
 		for (rec = 0; rec < 2; rec++){
 			c = &controls[rec][Volume_control];
 			if (c->readable){
+				div = c->max - c->min;
 				i = snprint(p, n, "audio %s %ld\n",
 					rec? "in": "out", (c->min != Undef?
-					100*(c->value[0]-c->min)/(c->max-c->min):
+					100*(c->value[0]-c->min)/(div? div: 1):
 					c->value[0]));
 				p += i;
 				n -= i;
 			}
 			c = &controls[rec][Treble_control];
 			if (c->readable){
+				div = c->max - c->min;
 				i = snprint(p, n, "treb %s %ld\n",
 					rec? "in": "out", (c->min != Undef?
-					100*(c->value[0]-c->min)/(c->max-c->min):
+					100*(c->value[0]-c->min)/(div? div: 1):
 					c->value[0]));
 				p += i;
 				n -= i;
 			}
 			c = &controls[rec][Bass_control];
 			if (c->readable){
+				div = c->max - c->min;
 				i = snprint(p, n, "bass %s %ld\n",
 					rec? "in": "out", (c->min != Undef?
-					100*(c->value[0]-c->min)/(c->max-c->min):
+					100*(c->value[0]-c->min)/(div? div: 1):
 					c->value[0]));
 				p += i;
 				n -= i;

+ 48 - 39
sys/src/cmd/usb/audio/usbaudio.c

@@ -18,6 +18,7 @@ Channel *controlchan;
 
 char audstr[]		= "Enabled 0x000101";	/* audio.control.0 */
 
+int setrec = 0;
 int defaultspeed[2] = {44100, 44100};
 
 static void
@@ -159,7 +160,8 @@ controlproc(void *)
 }
 
 void
-buttonproc(void *) {
+buttonproc(void *)
+{
 	int	i, fd, b;
 	char fname[64], err[32];
 	byte buf[1];
@@ -240,7 +242,8 @@ findendpoints(void)
 void
 usage(void)
 {
-	fprint(2, "usage: usbaudio [-V] [-v volume] [-m mountpoint] [-s srvname] [ctrlno n]\n");
+	fprint(2, "usage: usbaudio [-pV] [-m mountpoint] [-s srvname] "
+		"[-v volume] [ctrlno n]\n");
 	threadexitsall("usage");
 }
 
@@ -248,14 +251,12 @@ void
 threadmain(int argc, char **argv)
 {
 	int ctlrno, id, i, sfd;
-	long value[8];
-	long volume[8];
+	long value[8], volume[8];
 	Audiocontrol *c;
 	char buf[32], *p, line[256];
 	extern int attachok;
 
-	ctlrno = -1;
-	id = -1;
+	ctlrno = id = -1;
 	volume[0] = Undef;
 	for (i = 0; i<8; i++)
 		value[i] = 0;
@@ -263,27 +264,28 @@ threadmain(int argc, char **argv)
 	quotefmtinstall();
 
 	ARGBEGIN{
-	case 'V':
-		verbose++;
-		break;
 	case 'd':
 		debug = strtol(EARGF(usage()), nil, 0);
-		if (debug == -1) debugdebug++;
+		if (debug == -1)
+			debugdebug++;
 		verbose++;
 		break;
-	case 'v':
-		volume[0] = strtol(EARGF(usage()), &p, 0);
-		for(i = 1; i < 8; i++)
-			volume[i] = volume[0];
-		break;
 	case 'm':
 		mntpt = EARGF(usage());
 		break;
+	case 'p':
+		attachok++;
+		break;
 	case 's':
 		srvpost = EARGF(usage());
 		break;
-	case 'p':
-		attachok++;
+	case 'v':
+		volume[0] = strtol(EARGF(usage()), &p, 0);
+		for(i = 1; i < 8; i++)
+			volume[i] = volume[0];
+		break;
+	case 'V':
+		verbose++;
 		break;
 	default:
 		usage();
@@ -318,7 +320,6 @@ threadmain(int argc, char **argv)
 	}
 
 	ad = opendev(ctlrno, id);
-
 	if (describedevice(ad) < 0)
 		sysfatal("describedevice");
 
@@ -345,45 +346,53 @@ threadmain(int argc, char **argv)
 		}
 		value[0] = 2;
 		if (setcontrol(Play, "channels", value) == Undef)
-			sysfatal("Can't set play channels\n");
+			sysfatal("Can't set play channels");
 		value[0] = 16;
 		if (setcontrol(Play, "resolution", value) == Undef)
-			sysfatal("Can't set play resolution\n");
+			sysfatal("Can't set play resolution");
 	}
 
 	if(endpt[Record] >= 0){
+		setrec = 1;
 		if(verbose)
-			fprint(2, "Setting default record parameters: %d Hz, %d channels at %d bits\n",
+			fprint(2, "Setting default record parameters: "
+				"%d Hz, %d channels at %d bits\n",
 				defaultspeed[Record], 2, 16);
 		i = 2;
-		while(findalt(Record, i, 16, defaultspeed[Record]) < 0){
+		while(findalt(Record, i, 16, defaultspeed[Record]) < 0)
 			if(i == 2 && controls[Record][Channel_control].max == 1){
-				fprint(2, "Warning, can't configure stereo recording, configuring mono instead\n");
+				fprint(2, "Warning, can't configure stereo "
+					"recording, configuring mono instead\n");
 				i = 1;
-				continue;
-			}
-			if(findalt(Record, i, 16, 48000) < 0)
-				sysfatal("Can't configure record for %d or %d Hz", defaultspeed[Record], 48000);
-			fprint(2, "Warning, can't configure record for %d Hz, configuring for %d Hz instead\n",
+			} else
+				break;
+		if(findalt(Record, i, 16, 48000) < 0) {
+			endpt[Record] = -1;	/* disable recording */
+			setrec = 0;
+			fprint(2, "Warning, can't configure record for %d Hz or %d Hz\n",
 				defaultspeed[Record], 48000);
-			defaultspeed[Record] = 48000;
-			break;
+		} else
+			fprint(2, "Warning, can't configure record for %d Hz, "
+				"configuring for %d Hz instead\n",
+				defaultspeed[Record], 48000);
+		defaultspeed[Record] = 48000;
+		if (setrec) {
+			value[0] = i;
+			if (setcontrol(Record, "channels", value) == Undef)
+				sysfatal("Can't set record channels");
+			value[0] = 16;
+			if (setcontrol(Record, "resolution", value) == Undef)
+				sysfatal("Can't set record resolution");
 		}
-		value[0] = i;
-		if (setcontrol(Record, "channels", value) == Undef)
-			sysfatal("Can't set record channels\n");
-		value[0] = 16;
-		if (setcontrol(Record, "resolution", value) == Undef)
-			sysfatal("Can't set record resolution\n");
 	}
 
 	getcontrols();	/* Get the initial value of all controls */
 	value[0] = defaultspeed[Play];
 	if (endpt[Play] >= 0 && setcontrol(Play, "speed", value) < 0)
-		sysfatal("Can't set play speed\n");
+		sysfatal("can't set play speed");
 	value[0] = defaultspeed[Record];
 	if (endpt[Record] >= 0 && setcontrol(Record, "speed", value) < 0)
-		fprint(2, "Can't set record speed\n");
+		fprint(2, "%s: can't set record speed\n", argv0);
 	value[0] = 0;
 	setcontrol(Play, "mute", value);
 
@@ -395,7 +404,7 @@ threadmain(int argc, char **argv)
 		if (c->settable)
 			setcontrol(Play, "volume", volume);
 		c = &controls[Record][Volume_control];
-		if (c->settable)
+		if (c->settable && setrec)
 			setcontrol(Record, "volume", volume);
 	}
 

+ 1 - 1
sys/src/cmd/usb/audio/usbaudio.h

@@ -1,4 +1,3 @@
-
 enum {
 	master_chan		= 0x00,
 	Speed_control		= 0x00,
@@ -56,6 +55,7 @@ enum {
 	maxpkt_only = 0x80,	/* packets must be padded to max size */
 };
 
+extern int setrec;
 extern int defaultspeed[2];
 extern Device *ad;
 extern Channel *controlchan;

+ 22 - 13
sys/src/cmd/usb/audio/usbaudioctl.c

@@ -140,23 +140,26 @@ setspeed(int rec, int speed)
 	char cmdbuf[32];
 	uchar buf[3];
 
+	if (rec == Record && !setrec)
+		return Undef;
 	if (curalt[rec] < 0){
 		fprint(2, "Must set channels and resolution before speed\n");
 		return Undef;
 	}
 	if (endpt[rec] < 0)
-		sysfatal("endpt[%s] not set\n", rec?"Record":"Playback");
+		sysfatal("endpt[%s] not set", rec?"Record":"Playback");
 	ep = ad->ep[endpt[rec]];
 	if (ep->iface == nil)
 		sysfatal("no interface");
 	if (curalt[rec] < 0)
-		sysfatal("curalt[%s] not set\n", rec?"Record":"Playback");
+		sysfatal("curalt[%s] not set", rec?"Record":"Playback");
 	da = ep->iface->dalt[curalt[rec]];
 	a = da->devspec;
 	if (a->caps & onefreq){
 		if (debug & Dbgcontrol)
 			fprint(2, "setspeed %d: onefreq\n", speed);
-		speed = a->freqs[0];		/* speed not settable, but packet size must still be set */
+		/* speed not settable, but packet size must still be set */
+		speed = a->freqs[0];
 	}else if (a->caps & has_contfreq){
 		if (debug & Dbgcontrol)
 			fprint(2, "setspeed %d: contfreq\n", speed);
@@ -216,7 +219,8 @@ setspeed(int rec, int speed)
 			if (buf[2] || n == 0){
 				if (debug & Dbgcontrol)
 					fprint(2, "Speed out of bounds %d (0x%x)\n", n, n);
-			}else if (n != speed && ad->vid == 0x077d && (ad->did == 0x0223 || ad->did == 0x07af)){
+			}else if (n != speed && ad->vid == 0x077d &&
+			    (ad->did == 0x0223 || ad->did == 0x07af)){
 				/* Griffin iMic responds incorrectly to sample rate inquiry */
 				if (debug & Dbgcontrol)
 					fprint(2, " reported as %d (iMic bug?);", n);
@@ -230,21 +234,23 @@ setspeed(int rec, int speed)
 		* controls[rec][Channel_control].value[0]
 		* controls[rec][Resolution_control].value[0]/8;
 	if(ps > ep->maxpkt){
-		fprint(2, "packet size %d > maximum packet size %d\n",
-			ps, ep->maxpkt);
+		fprint(2, "%s: setspeed(rec %d, speed %d): packet size %d > "
+			"maximum packet size %d\n",
+			argv0, rec, speed, ps, ep->maxpkt);
 		return Undef;
 	}
 	if (debug & Dbgcontrol)
 		fprint(2, "Configuring %s endpoint for %d Hz\n",
 				rec?"record":"playback", speed);
 	sprint(cmdbuf, "ep %d %d %c %ld %d", endpt[rec], da->interval, rec?'r':'w',
-		controls[rec][Channel_control].value[0]*controls[rec][Resolution_control].value[0]/8,
-		speed);
+		controls[rec][Channel_control].value[0] *
+		controls[rec][Resolution_control].value[0]/8, speed);
 	if (write(ad->ctl, cmdbuf, strlen(cmdbuf)) != strlen(cmdbuf)){
 		fprint(2, "writing %s to #U/usb/%d/ctl: %r\n", cmdbuf, id);
 		return Undef;
 	}
-	if (debug & Dbgcontrol) fprint(2, "sent `%s' to /dev/usb/%d/ctl\n", cmdbuf, id);
+	if (debug & Dbgcontrol)
+		fprint(2, "sent `%s' to /dev/usb/%d/ctl\n", cmdbuf, id);
 	return speed;
 }
 
@@ -262,14 +268,14 @@ getspeed(int rec, int which)
 		return Undef;
 	}
 	if (endpt[rec] < 0)
-		sysfatal("endpt[%s] not set\n", rec?"Record":"Playback");
+		sysfatal("endpt[%s] not set", rec?"Record":"Playback");
 	if(debug & Dbgcontrol)
 		fprint(2, "getspeed: endpt[%d] == %d\n", rec, endpt[rec]);
 	ep = ad->ep[endpt[rec]];
 	if (ep->iface == nil)
 		sysfatal("no interface");
 	if (curalt[rec] < 0)
-		sysfatal("curalt[%s] not set\n", rec?"Record":"Playback");
+		sysfatal("curalt[%s] not set", rec?"Record":"Playback");
 	da = ep->iface->dalt[curalt[rec]];
 	a = da->devspec;
 	if (a->caps & onefreq){
@@ -388,7 +394,7 @@ setcontrol(int rec, char *name, long *value)
 		if (debug & Dbgcontrol) fprint(2, "setcontrol: can't happen\n");
 		return -1;
 	case Speed_control:
-		if ((value[0] = setspeed(rec, value[0])) < 0)
+		if (setrec && (value[0] = setspeed(rec, value[0])) < 0)
 			return -1;
 		c->value[0] = value[0];
 		return 0;
@@ -608,7 +614,9 @@ getcontrols(void)
 	Audiocontrol *c;
 	long v[8];
 
-	for (rec = 0; rec < 2; rec++)
+	for (rec = 0; rec < 2; rec++) {
+		if (rec == Record && !setrec)
+			continue;
 		for (ctl = 0; ctl < Ncontrol; ctl++){
 			c = &controls[rec][ctl];
 			if (c->readable){
@@ -647,6 +655,7 @@ getcontrols(void)
 						rec?"Playback":"Record", controls[rec][ctl].name);
 			}
 		}
+	}
 }
 
 int