ref: 19f9f65cede04b19db1c5bc861119a613f8b91b8
parent: c78114eb74f78c4756cee7938217fdd33122f45b
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Nov 16 09:13:18 EST 2025
kernel: sync devno() and namec() changes from 9front Get rid of user argument for devno(). Handle Aunmount in namec() such that it returns the same chan as in Abind for directories.
--- a/kern/chan.c
+++ b/kern/chan.c
@@ -1182,7 +1182,6 @@
case '#':
nomount = 1;
- up->genbuf[0] = '\0';
n = 0;
while(*name != '\0' && (*name != '/' || n < 2)){if(n >= sizeof(up->genbuf)-1)
@@ -1205,7 +1204,7 @@
n = chartorune(&r, up->genbuf+1)+1;
if(up->pgrp->noattach && utfrune("|decp", r)==nil)error(Enoattach);
- t = devno(r, 1);
+ t = devno(r);
if(t == -1)
error(Ebadsharp);
c = devtab[t]->attach(up->genbuf+n);
@@ -1278,6 +1277,14 @@
error("cannot exec directory"); switch(amode){+ case Aunmount:
+ /*
+ * When unmounting, the channel must be opend when not a directory
+ * in order to get the real chan from something like /srv/cs or /fd/0.
+ */
+ if((c->qid.type&QTDIR) == 0)
+ goto Open;
+ /* wet floor */
case Abind:
/* no need to maintain path - cannot dotdot an Abind */
m = nil;
@@ -1330,6 +1337,7 @@
case Aopen:
case Acreate:
+ case Aunmount:
/* only save the mount head if it's a multiple element union */
if(m != nil) {rlock(&m->lock);
--- a/kern/dat.h
+++ b/kern/dat.h
@@ -98,6 +98,7 @@
Amount, /* to be mounted or mounted upon */
Acreate, /* is to be created */
Aremove, /* will be removed by caller */
+ Aunmount, /* unmount arg */
COPEN = 0x0001, /* for i/o */
CMSG = 0x0002, /* the message channel for a mount */
--- a/kern/dev.c
+++ b/kern/dev.c
@@ -15,7 +15,7 @@
}
int
-devno(int c, int user)
+devno(int c)
{int i;
@@ -23,9 +23,6 @@
if(devtab[i]->dc == c)
return i;
}
- if(user == 0)
- panic("devno %C %#ux", c, c);-
return -1;
}
@@ -130,7 +127,7 @@
c = newchan();
mkqid(&c->qid, 0, 0, QTDIR);
- c->type = devno(tc, 0);
+ c->type = devno(tc);
if(spec == nil)
spec = "";
n = 1+UTFmax+strlen(spec)+1;
--- a/kern/devlfd-posix.c
+++ b/kern/devlfd-posix.c
@@ -14,7 +14,7 @@
Chan *c;
c = newchan();
- c->type = devno('L', 0);+ c->type = devno('L');c->aux = fd;
c->path = newpath("fd");c->mode = ORDWR;
--- a/kern/devlfd-win32.c
+++ b/kern/devlfd-win32.c
@@ -11,7 +11,7 @@
Chan *c;
c = newchan();
- c->type = devno('L', 0);+ c->type = devno('L');c->aux = fd;
c->path = newpath("fd");c->mode = ORDWR;
--- a/kern/fns.h
+++ b/kern/fns.h
@@ -40,7 +40,7 @@
long devdirread(Chan*, char*, long, Dirtab*, int, Devgen*);
Devgen devgen;
void devinit(void);
-int devno(int, int);
+int devno(int);
Chan* devopen(Chan*, int, Dirtab*, int, Devgen*);
void devpermcheck(char*, ulong, int);
void devpower(int);
--- a/kern/sysfile.c
+++ b/kern/sysfile.c
@@ -202,18 +202,16 @@
_syspipe(int fd[2])
{Chan *c[2];
- Dev *d;
static char *datastr[] = {"data", "data1"};- d = devtab[devno('|', 0)]; c[0] = namec("#|", Atodir, 0, 0);- c[1] = 0;
+ c[1] = nil;
fd[0] = -1;
fd[1] = -1;
if(waserror()){cclose(c[0]);
- if(c[1])
+ if(c[1] != nil)
cclose(c[1]);
nexterror();
}
@@ -222,8 +220,8 @@
error(Egreg);
if(walk(&c[1], datastr+1, 1, 1, nil) < 0)
error(Egreg);
- c[0] = d->open(c[0], ORDWR);
- c[1] = d->open(c[1], ORDWR);
+ c[0] = devtab[c[0]->type]->open(c[0], ORDWR);
+ c[1] = devtab[c[1]->type]->open(c[1], ORDWR);
if(newfd2(fd, c) < 0)
error(Enofd);
poperror();
@@ -719,7 +717,7 @@
{Chan *cmount, *cmounted;
- cmounted = 0;
+ cmounted = nil;
cmount = namec(new, Amount, 0, 0);
@@ -729,13 +727,7 @@
nexterror();
}
validaddr(old, 1, 0);
- /*
- * This has to be namec(..., Aopen, ...) because
- * if arg[0] is something like /srv/cs or /fd/0,
- * opening it is the only way to get at the real
- * Chan underneath.
- */
- cmounted = namec(old, Aopen, OREAD, 0);
+ cmounted = namec(old, Aunmount, OREAD, 0);
poperror();
}
--
⑨