rio: implement writable and truncatable /dev/text

This commit is contained in:
cinap_lenrek 2017-05-07 19:05:12 +02:00
parent 7327bd43c0
commit bff4fad52a
4 changed files with 15 additions and 4 deletions

View file

@ -68,6 +68,7 @@ enum /* control messages */
Rawoff,
Holdon,
Holdoff,
Truncate,
Deleted,
Exited,
};

View file

@ -32,7 +32,7 @@ Dirtab dirtab[]=
{ "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 @@ filsysopen(Filsys *fs, Xfid *x, Fid *f)
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:

View file

@ -1198,6 +1198,9 @@ wctlmesg(Window *w, int m, Rectangle r, void *p)
wrepaint(w);
flushimage(display, 1);
break;
case Truncate:
wdelete(w, 0, w->nr);
break;
case Deleted:
wclunk(w);
if(w->notefd >= 0)

View file

@ -250,6 +250,10 @@ xfidopen(Xfid *x)
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 @@ xfidwrite(Xfid *x)
x->data[cnt] = 0;
switch(qid){
case Qcons:
case Qtext:
alts[CWdata].c = w->conswrite;
alts[CWdata].v = &cwm;
alts[CWdata].op = CHANRCV;