Rename various 9ns symbols to O_FOO (XCC)
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 10 Sep 2015 18:44:56 +0000 (14:44 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 28 Sep 2015 19:14:00 +0000 (15:14 -0400)
There are two sources of confusion here.  One minor one is that Plan 9
had open flags like OREAD, while we have O_READ.  Instead of #defining
them, we just use the same name.  We already were using the same value.
The other issue was the chan flags, such as CAPPEND.  Originally, these
values were not the same as their O_ counterparts, but they have been
for a little while.  There's no reason to use their old names, and doing
so was just a source of confusion.

This change was made with spatch (plan9-defines.cocci), with manual
edits of the two header files and the struct in devip.c.

This changes a kernel header, but it shouldn't affect anyone.

17 files changed:
kern/drivers/dev/alarm.c
kern/drivers/dev/kprof.c
kern/drivers/dev/mnt.c
kern/drivers/dev/nix.c
kern/drivers/dev/pipe.c
kern/drivers/dev/proc.c
kern/drivers/dev/regress.c
kern/include/ns.h
kern/include/ros/fs.h
kern/src/net/devip.c
kern/src/net/dial.c
kern/src/net/ethermedium.c
kern/src/net/netif.c
kern/src/ns/chan.c
kern/src/ns/sysfile.c
scripts/plan9user/FIX
scripts/spatch/plan9-defines.cocci [new file with mode: 0644]

index 2a2ab15..11d7564 100644 (file)
@@ -237,7 +237,7 @@ static struct chan *alarmopen(struct chan *c, int omode)
        switch (TYPE(c->qid)) {
                case Qtopdir:
                case Qalarmdir:
-                       if (omode & ORCLOSE)
+                       if (omode & O_REMCLO)
                                error(Eperm);
                        if (omode & O_WRITE)
                                error(Eisdir);
index 697c765..742db27 100644 (file)
@@ -231,7 +231,7 @@ static struct chan*
 kprofopen(struct chan *c, int omode)
 {
        if(c->qid.type & QTDIR){
-               if(openmode(omode) != OREAD)
+               if(openmode(omode) != O_READ)
                        error(Eperm);
        }
        c->mode = openmode(omode);
index af219d9..0ee76c0 100644 (file)
@@ -302,7 +302,7 @@ struct chan *mntauth(struct chan *c, char *spec)
        c->mchan = m->c;
        chan_incref(m->c);
        c->mqid = c->qid;
-       c->mode = ORDWR;
+       c->mode = O_RDWR;
 
        poperror();     /* r */
        mntfree(r);
index 765c305..5987f52 100644 (file)
@@ -319,7 +319,7 @@ static struct chan *nixopen(struct chan *c, int omode)
        switch (TYPE(c->qid)) {
        case Qtopdir:
        case Qnixdir:
-               if (omode & ORCLOSE)
+               if (omode & O_REMCLO)
                        error(Eperm);
                if (omode & O_WRITE)
                        error(Eisdir);
index 09795e2..e6913ec 100644 (file)
@@ -213,7 +213,7 @@ static struct chan *pipeopen(struct chan *c, int omode)
 
        if (c->qid.type & QTDIR) {
                if (omode & O_WRITE)
-                       error("Can only open directories OREAD, mode is %o oct", omode);
+                       error("Can only open directories O_READ, mode is %o oct", omode);
                c->mode = openmode(omode);
                c->flag |= COPEN;
                c->offset = 0;
index 3711ccc..98b2795 100644 (file)
@@ -488,7 +488,7 @@ static struct chan *procopen(struct chan *c, int omode)
                case Qsegment:
                case Qprofile:
                case Qfd:
-                       if (omode != OREAD)
+                       if (omode != O_READ)
                                error(Eperm);
                        break;
 
@@ -515,7 +515,7 @@ static struct chan *procopen(struct chan *c, int omode)
                        break;
 
                case Qns:
-                       if (omode != OREAD)
+                       if (omode != O_READ)
                                error(Eperm);
                        c->aux = kzmalloc(sizeof(struct mntwalk), KMALLOC_WAIT);
                        break;
index 30ce706..060974a 100644 (file)
@@ -87,7 +87,7 @@ static struct chan*
 regressopen(struct chan *c, int omode)
 {
        if(c->qid.type & QTDIR){
-               if(openmode(omode) != OREAD)
+               if(openmode(omode) != O_READ)
                        error(Eperm);
        }
        c->mode = openmode(omode);
index d63a7e3..13ecb1f 100644 (file)
@@ -314,11 +314,12 @@ enum {
        /* chan/file flags, getable via fcntl/getfl and setably via open and
         * sometimes fcntl/setfl.  those that can't be set cause an error() in
         * fd_setfl. */
-       CCEXEC =                O_CLOEXEC,      /* (prob should be on the FD, 9ns has it here) */
-       CRCLOSE =               O_REMCLO,       /* remove on close (also, maybe should be on FD) */
-       CAPPEND =               O_APPEND,       /* append on write */
-       CNONBLOCK =     O_NONBLOCK,     /* don't block, can't be set via setfl */
-       CEXTERNAL_FLAGS = (CCEXEC | CRCLOSE | CAPPEND | CNONBLOCK),
+       CEXTERNAL_FLAGS = (
+           O_CLOEXEC      | /* (prob should be on the FD, 9ns has it here) */
+           O_REMCLO       | /* remove on close (also, maybe should be on FD) */
+           O_APPEND       | /* append on write */
+           O_NONBLOCK     | /* don't block, can't be set via setfl */
+           0),
 };
 
 #define NS_IPCK_SHIFT  2
index 8b1f462..e32f39c 100644 (file)
@@ -63,16 +63,6 @@ struct kstat {
 #define O_CLOEXEC              02000000        /* Set close_on_exec. */
 #define O_REMCLO               04000000        /* Remove on close (unsupported). */
 
-/* Plan9 names for these flags */
-#define OREAD                  O_RDONLY
-#define OWRITE                 O_WRONLY
-#define ORDWR                  O_RDWR
-#define OEXEC                  O_EXEC
-#define OTRUNC                 O_TRUNC
-#define OCEXEC                 O_CLOEXEC
-#define OEXCL                  O_EXCL
-#define ORCLOSE                        O_REMCLO
-
 #define F_DUPFD                0       /* Duplicate file descriptor */
 #define F_GETFD                1       /* Get file descriptor flags */
 #define F_SETFD                2       /* Set file descriptor flags */
index 095a7ff..7befb77 100644 (file)
@@ -363,9 +363,9 @@ static int should_wake(void *arg)
 }
 
 static int m2p[] = {
-       [OREAD] 4,
-       [OWRITE] 2,
-       [ORDWR] 6
+       [O_READ] 4,
+       [O_WRITE] 2,
+       [O_RDWR] 6
 };
 
 static struct chan *ipopen(struct chan *c, int omode)
@@ -384,9 +384,9 @@ static struct chan *ipopen(struct chan *c, int omode)
                default:
                        break;
                case Qndb:
-                       if (omode & (OWRITE | OTRUNC) && !iseve())
+                       if (omode & (O_WRITE | O_TRUNC) && !iseve())
                                error(Eperm);
-                       if ((omode & (OWRITE | OTRUNC)) == (OWRITE | OTRUNC))
+                       if ((omode & (O_WRITE | O_TRUNC)) == (O_WRITE | O_TRUNC))
                                f->ndb[0] = 0;
                        break;
                case Qlog:
@@ -433,7 +433,7 @@ static struct chan *ipopen(struct chan *c, int omode)
                                break;
                        }
                        /* we only honor nonblock on a clone */
-                       if (c->flag & CNONBLOCK)
+                       if (c->flag & O_NONBLOCK)
                                Fsconvnonblock(cv, TRUE);
                        mkqid(&c->qid, QID(p->x, cv->x, Qctl), 0, QTFILE);
                        break;
@@ -517,7 +517,7 @@ static struct chan *ipopen(struct chan *c, int omode)
                                        kstrdup(&cv->owner, ATTACHER(c));
                                        /* O_NONBLOCK/CNONBLOCK when opening listen means the *new*
                                         * conv is already non-blocking, like accept4() in Linux */
-                                       if (c->flag & CNONBLOCK)
+                                       if (c->flag & O_NONBLOCK)
                                                Fsconvnonblock(nc, TRUE);
                                }
                                qunlock(&cv->qlock);
index eb0c722..6c80ab4 100644 (file)
@@ -104,7 +104,7 @@ static int csdial(DS * ds)
         *  open connection server
         */
        snprintf(buf, Maxstring, "%s/cs", ds->netdir);
-       fd = sysopen(buf, ORDWR);
+       fd = sysopen(buf, O_RDWR);
        if (fd < 0) {
                /* no connection server, don't translate */
                snprintf(clone, Maxpath, "%s/%s/clone", ds->netdir, ds->proto);
@@ -167,7 +167,7 @@ static int call(char *clone, char *dest, DS * ds)
        data = kmalloc(Maxpath, KMALLOC_WAIT);
        err = kmalloc(ERRMAX, KMALLOC_WAIT);
 
-       cfd = sysopen(clone, ORDWR);
+       cfd = sysopen(clone, O_RDWR);
        if (cfd < 0) {
                kerrstr(err, ERRMAX);
                set_errstr("%s (%s)", err, clone);
@@ -208,7 +208,7 @@ static int call(char *clone, char *dest, DS * ds)
        }
 
        /* open data connection */
-       fd = sysopen(data, ORDWR);
+       fd = sysopen(data, O_RDWR);
        if (fd < 0) {
                err[0] = 0;
                kerrstr(err, ERRMAX);
@@ -281,7 +281,7 @@ int kannounce(char *addr, char *dir)
        /*
         * get a control channel
         */
-       ctl = sysopen(netdir, ORDWR);
+       ctl = sysopen(netdir, O_RDWR);
        if (ctl < 0)
                return -1;
        cp = strrchr(netdir, '/');
@@ -328,7 +328,7 @@ int klisten(char *dir, char *newdir)
         *  open listen, wait for a call
         */
        snprintf(buf, sizeof buf, "%s/listen", dir);
-       ctl = sysopen(buf, ORDWR);
+       ctl = sysopen(buf, O_RDWR);
        if (ctl < 0)
                return -1;
 
@@ -415,7 +415,7 @@ static int nettrans(char *addr, char *naddr, int na, char *file, int nf)
         *  ask the connection server
         */
        snprintf(buf, sizeof(buf), "%s/cs", netdir);
-       fd = sysopen(buf, ORDWR);
+       fd = sysopen(buf, O_RDWR);
        if (fd < 0)
                return identtrans(netdir, addr, naddr, na, file, nf);
        if (syswrite(fd, addr, strlen(addr)) < 0) {
index 88d6ffe..8cda86c 100644 (file)
@@ -187,8 +187,8 @@ static void etherbind(struct Ipifc *ifc, int argc, char **argv)
        fd = kdial(addr, NULL, dir, &cfd);
        if (fd < 0)
                error("dial 0x800 failed: %s", get_cur_errbuf());
-       mchan4 = commonfdtochan(fd, ORDWR, 0, 1);
-       cchan4 = commonfdtochan(cfd, ORDWR, 0, 1);
+       mchan4 = commonfdtochan(fd, O_RDWR, 0, 1);
+       cchan4 = commonfdtochan(cfd, O_RDWR, 0, 1);
        sysclose(fd);
        sysclose(cfd);
 
@@ -201,7 +201,7 @@ static void etherbind(struct Ipifc *ifc, int argc, char **argv)
         *  get mac address and speed
         */
        snprintf(addr, Maxpath, "%s/stats", dir);
-       fd = sysopen(addr, OREAD);
+       fd = sysopen(addr, O_READ);
        if (fd < 0)
                error("can't open ether stats: %s", get_cur_errbuf());
 
@@ -240,7 +240,7 @@ static void etherbind(struct Ipifc *ifc, int argc, char **argv)
        fd = kdial(addr, NULL, NULL, NULL);
        if (fd < 0)
                error("dial 0x806 failed: %s", get_cur_errbuf());
-       achan = commonfdtochan(fd, ORDWR, 0, 1);
+       achan = commonfdtochan(fd, O_RDWR, 0, 1);
        sysclose(fd);
 
        /*
@@ -253,8 +253,8 @@ static void etherbind(struct Ipifc *ifc, int argc, char **argv)
        fd = kdial(addr, NULL, dir, &cfd);
        if (fd < 0)
                error("dial 0x86DD failed: %s", get_cur_errbuf());
-       mchan6 = commonfdtochan(fd, ORDWR, 0, 1);
-       cchan6 = commonfdtochan(cfd, ORDWR, 0, 1);
+       mchan6 = commonfdtochan(fd, O_RDWR, 0, 1);
+       cchan6 = commonfdtochan(cfd, O_RDWR, 0, 1);
        sysclose(fd);
        sysclose(cfd);
 
index 8310834..79fbf1f 100644 (file)
@@ -430,7 +430,7 @@ int netifwstat(struct ether *nif, struct chan *c, uint8_t * db, int n)
                error(Enonexist);
        }
 
-       if (netown(f, current->user, OWRITE) < 0)
+       if (netown(f, current->user, O_WRITE) < 0)
                error(Eperm);
 
        dir = kzmalloc(sizeof(struct dir) + n, 0);
index ffc1930..5531e66 100644 (file)
@@ -1163,18 +1163,18 @@ Open:
                                                c->umh = m;
                                        else
                                                putmhead(m);
-
-                                       if (omode == OEXEC)
+                                       if (omode == O_EXEC)
                                                c->flag &= ~CCACHE;
                                        /* here is where convert omode/vfs flags to c->flags.
                                         * careful, O_CLOEXEC and O_REMCLO are in there.  might need
                                         * to change that. */
                                        c->flag |= omode & CEXTERNAL_FLAGS;
-                                       c = devtab[c->type].open(c, omode & ~OCEXEC);
+                                       c = devtab[c->type].open(c,
+                                                                omode & ~O_CLOEXEC);
                                        /* if you get this from a dev, in the dev's open, you are
                                         * probably saving mode directly, without passing it through
                                         * openmode. */
-                                       if (c->mode & OTRUNC)
+                                       if (c->mode & O_TRUNC)
                                                error("Device '%c' %s open failed to clear OTRUNC",
                                                      devtab[c->type].dc, devtab[c->type].name);
                                        break;
@@ -1213,9 +1213,9 @@ Open:
                         */
                        e.ARRAY_SIZEs++;
                        if (walk(&c, e.elems + e.ARRAY_SIZEs - 1, 1, nomount, NULL) == 0) {
-                               if (omode & OEXCL)
+                               if (omode & O_EXCL)
                                        error(Eexist);
-                               omode |= OTRUNC;
+                               omode |= O_TRUNC;
                                goto Open;
                        }
 
@@ -1282,14 +1282,15 @@ Open:
                                kref_get(&cnew->name->ref, 1);
 
                                devtab[cnew->type].create(cnew, e.elems[e.ARRAY_SIZEs - 1],
-                                                                                 omode & ~(OEXCL | OCEXEC), perm);
+                                                                                 omode & ~(O_EXCL | O_CLOEXEC),
+                                                         perm);
                                poperror();
                                if (omode & O_APPEND)
-                                       cnew->flag |= CAPPEND;
-                               if (omode & OCEXEC)
-                                       cnew->flag |= CCEXEC;
-                               if (omode & ORCLOSE)
-                                       cnew->flag |= CRCLOSE;
+                                       cnew->flag |= O_APPEND;
+                               if (omode & O_CLOEXEC)
+                                       cnew->flag |= O_CLOEXEC;
+                               if (omode & O_REMCLO)
+                                       cnew->flag |= O_REMCLO;
                                if (m)
                                        putmhead(m);
                                cclose(c);
@@ -1302,7 +1303,7 @@ Open:
                        cclose(cnew);
                        if (m)
                                putmhead(m);
-                       if (omode & OEXCL)
+                       if (omode & O_EXCL)
                                nexterror();    /* safe since we're in a waserror() */
                        poperror();     /* matching the if(!waserror) */
 
@@ -1315,7 +1316,7 @@ Open:
                                error(tmperrbuf);       /* report the error we had originally */
                        }
                        strncpy(current_errstr(), tmperrbuf, MAX_ERRSTR_LEN);
-                       omode |= OTRUNC;
+                       omode |= O_TRUNC;
                        goto Open;
 
                default:
index 0daf255..511fefc 100644 (file)
@@ -168,7 +168,7 @@ int syscreate(char *path, int mode, uint32_t perm)
                return -1;
        }
 
-       openmode(mode & ~OEXCL);        /* error check only; OEXCL okay here */
+       openmode(mode & ~O_EXCL);       /* error check only; OEXCL okay here */
        c = namec(path, Acreate, mode, perm);
        if (waserror()) {
                cclose(c);
@@ -271,7 +271,7 @@ int sysfauth(int fd, char *aname)
        }
 
        validname(aname, 0);
-       c = fdtochan(&current->open_files, fd, ORDWR, 0, 1);
+       c = fdtochan(&current->open_files, fd, O_RDWR, 0, 1);
        if (waserror()) {
                cclose(c);
                nexterror();
@@ -313,7 +313,7 @@ int sysfversion(int fd, unsigned int msize, char *vers, unsigned int arglen)
        if (arglen == 0 || memchr(vers, 0, arglen) == 0)
                error(Ebadarg);
 
-       c = fdtochan(&current->open_files, fd, ORDWR, 0, 1);
+       c = fdtochan(&current->open_files, fd, O_RDWR, 0, 1);
        if (waserror()) {
                cclose(c);
                nexterror();
@@ -361,8 +361,8 @@ int syspipe(int fd[2])
                error(Egreg);
        if (walk(&c[1], &names[1], 1, 1, NULL) < 0)
                error(Egreg);
-       c[0] = d->open(c[0], ORDWR);
-       c[1] = d->open(c[1], ORDWR);
+       c[0] = d->open(c[0], O_RDWR);
+       c[1] = d->open(c[1], O_RDWR);
        fd[0] = newfd(c[0], 0);
        if (fd[0] < 0)
                error(Enofd);
@@ -467,9 +467,9 @@ int sysmount(int fd, int afd, char *old, int flags, char *spec)
                poperror();
                return -1;
        }
-       bc.c = fdtochan(&current->open_files, fd, ORDWR, 0, 1);
+       bc.c = fdtochan(&current->open_files, fd, O_RDWR, 0, 1);
        if (afd >= 0)
-               ac.c = fdtochan(&current->open_files, afd, ORDWR, 0, 1);
+               ac.c = fdtochan(&current->open_files, afd, O_RDWR, 0, 1);
        mntparam.chan = bc.c;
        mntparam.authchan = ac.c;
        mntparam.spec = spec;
@@ -512,7 +512,7 @@ int sysunmount(char *src_path, char *onto_path)
                 * opening it is the only way to get at the real
                 * Chan underneath.
                 */
-               cmounted.c = namec(src_path, Aopen, OREAD, 0);
+               cmounted.c = namec(src_path, Aopen, O_READ, 0);
        }
 
        cunmount(cmount.c, cmounted.c);
@@ -580,7 +580,8 @@ long unionread(struct chan *c, void *va, long n)
                        } else {
                                if (c->umc == NULL) {
                                        c->umc = cclone(mount->to);
-                                       c->umc = devtab[c->umc->type].open(c->umc, OREAD);
+                                       c->umc = devtab[c->umc->type].open(c->umc,
+                                                                          O_READ);
                                }
 
                                nr = devtab[c->umc->type].read(c->umc, va, n, c->umc->offset);
@@ -632,7 +633,7 @@ static long rread(int fd, void *va, long n, int64_t * offp)
                return -1;
        }
 
-       c = fdtochan(&current->open_files, fd, OREAD, 1, 1);
+       c = fdtochan(&current->open_files, fd, O_READ, 1, 1);
        if (waserror()) {
                cclose(c);
                nexterror();
@@ -979,7 +980,7 @@ static long rwrite(int fd, void *va, long n, int64_t * offp)
                poperror();
                return -1;
        }
-       c = fdtochan(&current->open_files, fd, OWRITE, 1, 1);
+       c = fdtochan(&current->open_files, fd, O_WRITE, 1, 1);
        if (waserror()) {
                cclose(c);
                nexterror();
@@ -993,7 +994,7 @@ static long rwrite(int fd, void *va, long n, int64_t * offp)
        if (offp == NULL) {
                /* append changes the offset to the end, and even if we fail later, this
                 * change will persist */
-               if (c->flag & CAPPEND) {
+               if (c->flag & O_APPEND) {
                        dir = chandirstat(c);
                        if (!dir)
                                error("internal error: stat error in append write");
index 2a26be8..348d803 100644 (file)
@@ -3,6 +3,4 @@ spatch --in-place --sp-file ~/projects/akaros/scripts/plan9user/typedef.cocci $1
 spatch --in-place --sp-file ~/projects/akaros/scripts/plan9user/plan9.cocci $1
 sh ~/akaros/scripts/plan9user/fixincludes $1
 sed -i 's/= nil/= NULL/' $1
-sed -i 's/ OREAD/ O_RDONLY/' $1
-sed -i 's/ ORDWR/ O_RDWR/' $1
 sed -i 's/return nil/return NULL/' $1
diff --git a/scripts/spatch/plan9-defines.cocci b/scripts/spatch/plan9-defines.cocci
new file mode 100644 (file)
index 0000000..a5085ef
--- /dev/null
@@ -0,0 +1,59 @@
+@@
+@@
+-OREAD
++O_READ
+
+@@
+@@
+-OWRITE
++O_WRITE
+
+@@
+@@
+-ORDWR
++O_RDWR
+
+@@
+@@
+-OEXEC
++O_EXEC
+
+@@
+@@
+-OTRUNC
++O_TRUNC
+
+@@
+@@
+-OCEXEC
++O_CLOEXEC
+
+@@
+@@
+-OEXCL
++O_EXCL
+
+@@
+@@
+-ORCLOSE
++O_REMCLO
+
+@@
+@@
+-CCEXEC
++O_CLOEXEC
+
+@@
+@@
+-CRCLOSE
++O_REMCLO
+
+@@
+@@
+-CAPPEND
++O_APPEND
+
+@@
+@@
+-CNONBLOCK
++O_NONBLOCK