ref: e1260aa4d6ff21ef374ca05bf13aecb16fca1f94
parent: f882472d0b67661c52bd7f0918d4d270b1bd99d9
author: aiju <[email protected]>
date: Sun Jul 24 10:51:49 EDT 2011
devshr: added unmounting
--- a/sys/src/9/port/devshr.c
+++ b/sys/src/9/port/devshr.c
@@ -103,6 +103,35 @@
return nil;
}
+static int
+shrremovemnt(Shr *sp, int id)
+{
+ Mount *m, **l;
+
+ wlock(&sp->umh.lock);
+ l = &sp->umh.mount;
+ for(m = *l; m; m = m->next){
+ if(m->mountid == id){
+ cclose(m->to);
+ *l = m->next;
+ free(m);
+ break;
+ }
+ l = &m->next;
+ }
+
+ if(m == nil){
+ wunlock(&sp->umh.lock);
+ return -1;
+ }
+ qlock(&sp->desclock);
+ free(sp->desc);
+ sp->desc = nil;
+ qunlock(&sp->desclock);
+ wunlock(&sp->umh.lock);
+ return 0;
+}
+
static Walkqid*
shrwalk(Chan *c, Chan *nc, char **name, int nname)
{
@@ -360,7 +389,7 @@
if(strcmp(sp->owner, eve) == 0 && !iseve())
error(Eperm);
- if((sp->perm&7) != 7 && strcmp(sp->owner, up->user) && !iseve())
+ if((sp->perm&7) != 7 && strcmp(sp->owner, up->user) != 0 && !iseve())
error(Eperm);
*l = sp->link;
@@ -454,7 +483,7 @@
rlock(&sp->umh.lock);
for(f = sp->umh.mount; f != nil; f = f->next)
nn += 32 + strlen((char*)(f + 1));
- s = sp->desc = smalloc(nn);
+ s = sp->desc = smalloc(nn + 1);
e = s + nn;
for(f = sp->umh.mount; f != nil; f = f->next)
s = seprint(s, e, "%lud %s %C %lud %lld\n", f->mountid, (char*)(f + 1), devtab[f->to->mchan->type]->dc, f->to->mchan->dev, f->to->qid.path);
@@ -470,7 +499,7 @@
{
Shr *sp;
char *buf, *p, *desc, *aname;
- int mode, fd;
+ int mode, fd, id;
Chan *bc, *c0;
Mount *m, *mm;
struct{
@@ -501,6 +530,22 @@
memmove(buf, va, n);
buf[n] = 0;
+ if(*buf == 'u'){
+ p = buf + 1;
+ while(*p <= ' ' && *p != '\n')
+ p++;
+ if(*p == 0 || *p == '\n')
+ error(Ebadarg);
+ id = strtol(p, 0, 10);
+ if(shrremovemnt(sp, id) < 0)
+ error(Ebadarg);
+ shrdecref(sp);
+ free(buf);
+ poperror();
+ poperror();
+ return n;
+ }
+
p = buf;
mode = 0;
for(; *p > ' '; p++)
@@ -514,9 +559,9 @@
if((mode & (MAFTER|MBEFORE)) == 0 || (mode & (MAFTER|MBEFORE)) == (MAFTER|MBEFORE))
error(Ebadarg);
- while(*p <= ' ')
+ while(*p <= ' ' && *p != '\n')
p++;
- if(*p == 0)
+ if(*p == 0 || *p == '\n')
error(Ebadarg);
fd = strtol(p, &p, 10);
while(*p <= ' ' && *p != '\n')