ref: dafdfcb12496bfc27cdc863996172a7409dffd11
parent: f09a60d8cd60d2ec193b0315bfe0d7fd74b23406
author: aap <[email protected]>
date: Mon Jan 30 09:17:03 EST 2023
write text; file permissions
--- a/TODO
+++ b/TODO
@@ -1,8 +1,8 @@
rethink resizing and repainting
rethink hiding/unhiding
-file permissions
+snarfversion
+check for bad rects
border resize/move
-write text
top/bottom/current seems to work a bit different in rio
release keys and buttons when unfocused
...
--- a/fs.c
+++ b/fs.c
@@ -31,32 +31,33 @@
int path;
int type;
char *name;
+ uint mode;
};
Dirent dirents[] = {
- Qroot, QTDIR, ".",
- Qwsys, QTDIR, "wsys",
- Qwinid, QTFILE, "winid",
- Qwinname, QTFILE, "winname",
- Qwdir, QTFILE, "wdir",
- Qlabel, QTFILE, "label",
- Qsnarf, QTFILE, "snarf",
- Qtext, QTFILE, "text",
- Qcons, QTFILE, "cons",
- Qconsctl, QTFILE, "consctl",
- Qkbd, QTFILE, "kbd",
- Qmouse, QTFILE, "mouse",
- Qcursor, QTFILE, "cursor",
- Qscreen, QTFILE, "screen",
- Qwindow, QTFILE, "window",
- Qwctl, QTFILE, "wctl",
- Qtap, QTFILE, "kbdtap",
+ { Qroot, QTDIR, ".", 0500|DMDIR },
+ { Qwsys, QTDIR, "wsys", 0500|DMDIR },
+ { Qwinid, QTFILE, "winid", 0400 },
+ { Qwinname, QTFILE, "winname", 0400 },
+ { Qwdir, QTFILE, "wdir", 0600 },
+ { Qlabel, QTFILE, "label", 0600 },
+ { Qsnarf, QTFILE, "snarf", 0600 },
+ { Qtext, QTFILE, "text", 0600 },
+ { Qcons, QTFILE, "cons", 0600 },
+ { Qconsctl, QTFILE, "consctl", 0200 },
+ { Qkbd, QTFILE, "kbd", 0600 },
+ { Qmouse, QTFILE, "mouse", 0600 },
+ { Qcursor, QTFILE, "cursor", 0600 },
+ { Qscreen, QTFILE, "screen", 0400 },
+ { Qwindow, QTFILE, "window", 0400 },
+ { Qwctl, QTFILE, "wctl", 0600 },
+ { Qtap, QTFILE, "kbdtap", 0660 }
};
char Eperm[] = "permission denied";
-char Eexist[] = "file does not exist";
-char Enotdir[] = "not a directory";
-char Ebadfcall[] = "bad fcall type";
+char Eexist[] = "file does not exist"; // XXX
+char Enotdir[] = "not a directory"; // XXX
+char Ebadfcall[] = "bad fcall type"; // XXX
char Eoffset[] = "illegal offset";
char Enomem[] = "out of memory";
@@ -67,11 +68,15 @@
char Eshort[] = "short i/o request";
char Elong[] = "snarf buffer too long";
char Eunkid[] = "unknown id in attach";
-char Ebadrect[] = "bad rectangle in attach";
+char Ebadrect[] = "bad rectangle in attach"; // XXX
char Ewindow[] = "cannot make window";
-char Enowindow[] = "window has no image";
+char Enowindow[] = "window has no image"; // XXX
char Ebadmouse[] = "bad format on /dev/mouse";
+int fsysfd;
+char srvpipe[64];
+char *user;
+
/* Extension of a Req, req->aux. also has a thread. */
typedef struct Xreq Xreq;
struct Xreq
@@ -173,6 +178,11 @@
int id;
Wctlcmd cmd;
+ if(strcmp(r->ifcall.uname, user) != 0){
+ respond(r, Eperm);
+ return;
+ }
+
if(strncmp(r->ifcall.aname, "new", 3) == 0){
cmd = parsewctl(r->ifcall.aname, ZR);
if(cmd.error){
@@ -181,7 +191,7 @@
}
w = wcreate(cmd.r, cmd.hidden, cmd.scrolling);
if(w == nil){
- respond(r, "window creation failed");
+ respond(r, Ewindow);
return;
}
wincmd(w, cmd.pid, cmd.dir, nil);
@@ -192,11 +202,11 @@
}else if(id = strtol(r->ifcall.aname, &end, 10), *end == '\0'){
w = wfind(id);
if(w == nil){
- respond(r, "bad attach name");
+ respond(r, Eunkid);
return;
}
}else{
- respond(r, "bad attach name");
+ respond(r, Eunkid);
return;
}
@@ -222,7 +232,6 @@
!servekbd && strcmp(name, "kbd") == 0;
}
-
static char*
fswalk1(Fid *fid, char *name, Qid *qid)
{
@@ -293,13 +302,11 @@
d->atime = time(nil);
d->mtime = d->atime;
- d->uid = estrdup9p(getuser());
+ d->uid = estrdup9p(user);
d->gid = estrdup9p(d->uid);
d->muid = estrdup9p(d->uid);
d->qid = (Qid){QID(ID(w),dirents[i].path), 0, dirents[i].type};
- d->mode = 0664;
- if(dirents[i].type & QTDIR)
- d->mode |= 0111;
+ d->mode = dirents[i].mode;
d->name = estrdup9p(dirents[i].name);
d->length = 0;
return 0;
@@ -308,28 +315,21 @@
static int
genwsysdir(int n, Dir *d, void*)
{
- d->atime = time(nil);
- d->mtime = d->atime;
- d->uid = estrdup9p(getuser());
- d->gid = estrdup9p(d->uid);
- d->muid = estrdup9p(d->uid);
+ Window *w;
if(n == -1){
- d->qid = (Qid){Qwsys, 0, QTDIR};
- d->mode = 0775;
+ genrootdir(0, d, nil);
+ free(d->name);
d->name = estrdup9p("wsys");
- d->length = 0;
return 0;
}
if(n < nwindows){
- int id = windows[n]->id;
- d->qid = (Qid){QID(id,Qroot), 0, QTDIR};
- d->mode = 0775;
- d->name = smprint("%d", id);
- d->length = 0;
+ w = windows[n];
+ genrootdir(-1, d, w);
+ free(d->name);
+ d->name = smprint("%d", w->id);
return 0;
}
-
return -1;
}
@@ -355,6 +355,11 @@
r->ifcall.mode &= (OREAD|OWRITE|ORDWR);
switch(QFILE(r->fid->qid.path)){
+ case Qtext:
+ if(r->ifcall.mode & OTRUNC)
+ xdelete(&w->text, 0, w->text.nr);
+ break;
+
case Qsnarf:
if(r->ifcall.mode==ORDWR || r->ifcall.mode==OWRITE)
ntsnarf = 0;
@@ -381,7 +386,6 @@
respond(r, Einuse);
return;
}
-// TODO: copy comment from rio
w->resized = FALSE;
w->mouseopen = TRUE;
break;
@@ -679,6 +683,7 @@
}
int f = QFILE(r->fid->qid.path);
switch(f){
+ case Qtext:
case Qcons:
alts[Adata] = ALT(w->conswrite, &kbd, CHANRCV);
alts[Agone] = ALT(w->gone, nil, CHANRCV);
@@ -966,9 +971,6 @@
return 0;
}
-int fsysfd;
-char srvpipe[64];
-
void
fs(void)
{
@@ -977,7 +979,8 @@
if(cexecpipe(&fsysfd, &fsys.infd) < 0)
panic("pipe");
fsys.outfd = fsys.infd;
- snprint(srvpipe, sizeof(srvpipe), "lola.%s.%lud", getuser(), (ulong)getpid());
+ user = getuser();
+ snprint(srvpipe, sizeof(srvpipe), "lola.%s.%lud", user, (ulong)getpid());
post(srvpipe, fsysfd);
// chatty9p++;
srv(&fsys);