shithub: riscv

Download patch

ref: bff4fad52a4c3387db54195c9fc20fb69247c43c
parent: 7327bd43c039d0ce2f4052afac04204718d9e69c
author: cinap_lenrek <[email protected]>
date: Sun May 7 15:05:12 EDT 2017

rio: implement writable and truncatable /dev/text

--- a/sys/src/cmd/rio/dat.h
+++ b/sys/src/cmd/rio/dat.h
@@ -68,6 +68,7 @@
 	Rawoff,
 	Holdon,
 	Holdoff,
+	Truncate,
 	Deleted,
 	Exited,
 };
--- a/sys/src/cmd/rio/fsys.c
+++ b/sys/src/cmd/rio/fsys.c
@@ -32,7 +32,7 @@
 	{ "mouse",	QTFILE,	Qmouse,		0600 },
 	{ "screen",		QTFILE,	Qscreen,		0400 },
 	{ "snarf",		QTFILE,	Qsnarf,		0600 },
-	{ "text",		QTFILE,	Qtext,		0400 },
+	{ "text",		QTFILE,	Qtext,		0600 },
 	{ "wdir",		QTFILE,	Qwdir,		0600 },
 	{ "wctl",		QTFILE,	Qwctl,		0600 },
 	{ "window",	QTFILE,	Qwindow,		0400 },
@@ -494,12 +494,14 @@
 	Fcall t;
 	int m;
 
-	/* can't truncate anything, so just disregard */
-	x->mode &= ~(OTRUNC|OCEXEC);
+	/* can't truncate anything but Qtext, so just disregard */
+	if(FILE(f->qid) != Qtext)
+		x->mode &= ~OTRUNC;
+	x->mode &= ~OCEXEC;
 	/* can't execute or remove anything */
 	if(x->mode==OEXEC || (x->mode&ORCLOSE))
 		goto Deny;
-	switch(x->mode){
+	switch(x->mode & ~OTRUNC){
 	default:
 		goto Deny;
 	case OREAD:
--- a/sys/src/cmd/rio/wind.c
+++ b/sys/src/cmd/rio/wind.c
@@ -1198,6 +1198,9 @@
 		wrepaint(w);
 		flushimage(display, 1);
 		break;
+	case Truncate:
+		wdelete(w, 0, w->nr);
+		break;
 	case Deleted:
 		wclunk(w);
 		if(w->notefd >= 0)
--- a/sys/src/cmd/rio/xfid.c
+++ b/sys/src/cmd/rio/xfid.c
@@ -250,6 +250,10 @@
 		return;
 	}
 	switch(FILE(x->f->qid)){
+	case Qtext:
+		if(x->mode&OTRUNC)
+			wsendctlmesg(w, Truncate, ZR, nil);
+		break;
 	case Qconsctl:
 		if(w->ctlopen){
 			filsysrespond(x->fs, x, &t, Einuse);
@@ -386,6 +390,7 @@
 	x->data[cnt] = 0;
 	switch(qid){
 	case Qcons:
+	case Qtext:
 		alts[CWdata].c = w->conswrite;
 		alts[CWdata].v = &cwm;
 		alts[CWdata].op = CHANRCV;