From e2a008c047b156c6441bb99e760560f0303f688a Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 11 Jun 1992 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1992-06-11 --- boot/boot.c | 29 ++++++++------- boot/boot.h | 6 +++ boot/settime.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++-- gnot/devhifi.c | 5 --- gnot/devincon.c | 1 + gnot/main.c | 1 + port/devconc.c | 1 + port/devcons.c | 1 - port/devproc.c | 1 - port/portfns.h | 3 +- port/stsplice.c | 82 +++++++++++++++++++++++++++++++++++++++++ 11 files changed, 202 insertions(+), 25 deletions(-) create mode 100644 port/stsplice.c diff --git a/boot/boot.c b/boot/boot.c index ae27dd472ecf27f1a51166b226b1f4d9a29c5258..e1a1ac8f251fe98a8d52613c8ca100e04bd43724 100644 --- a/boot/boot.c +++ b/boot/boot.c @@ -112,21 +112,22 @@ boot(int argc, char *argv[]) newkernel(); /* - * if a local file server exists and it's not the - * root file server, start it and mount it onto /n/kfs + * if a local file server exists and it's not + * running, start it and mount it onto /n/kfs */ - if(!islocal){ - for(mp = method; mp->name; mp++) - if(strcmp(mp->name, "local")==0){ - (*mp->config)(mp); - fd = (*mp->connect)(); - if(fd < 0) - break; - if(mount(fd, "/n/kfs", MAFTER|MCREATE, "", "") < 0) - print("failed to mount kfs\n"); - close(fd); - break; - } + for(mp = method; mp->name; mp++){ + if(strcmp(mp->name, "local") != 0) + continue; + if(access("#s/kfs", ORDWR) >= 0) + break; + (*mp->config)(mp); + fd = (*mp->connect)(); + if(fd < 0) + break; + if(mount(fd, "/n/kfs", MAFTER|MCREATE, "", "") < 0) + print("failed to mount kfs\n"); + close(fd); + break; } settime(islocal); diff --git a/boot/boot.h b/boot/boot.h index 07a4fa7d1a984b24b1c2347a0db2ea45e8781bd6..4943597e68581bee15210404de698c33173acb30 100644 --- a/boot/boot.h +++ b/boot/boot.h @@ -60,6 +60,9 @@ extern int connecths(void); extern void configincon(Method*); extern int authincon(void); extern int connectincon(void); +extern void configcincon(Method*); +extern int authcincon(void); +extern int connectcincon(void); extern void configil(Method*); extern int authil(void); extern int connectil(void); @@ -72,3 +75,6 @@ extern int connectcyc(void); extern void configlocal(Method*); extern int authlocal(void); extern int connectlocal(void); +extern void configbri(Method*); +extern int authbri(void); +extern int connectbri(void); diff --git a/boot/settime.c b/boot/settime.c index 13546ff73fa87c5d632a5efec66bf473327eebdc..dce47b90843fbfe718ec5f7353f5c18447ed425f 100644 --- a/boot/settime.c +++ b/boot/settime.c @@ -3,6 +3,8 @@ #include #include "../boot/boot.h" +static long lusertime(char*); + void settime(int islocal) { @@ -25,7 +27,10 @@ settime(int islocal) timeset = 1; } close(f); - } + }else do{ + strcpy(dirbuf, "yymmddhhmm[ss]"); + outin("\ndate/time ", dirbuf, sizeof(dirbuf)); + }while((timeset=lusertime(dirbuf)) <= 0); } if(timeset == 0){ /* @@ -52,10 +57,96 @@ settime(int islocal) write(f, dirbuf, strlen(dirbuf)); close(f); } - close(f); } f = open("#c/time", OWRITE); - write(f, dirbuf, strlen(dirbuf)); + if(write(f, dirbuf, strlen(dirbuf)) < 0) + warning("can't set #c/time"); close(f); } + +#define SEC2MIN 60L +#define SEC2HOUR (60L*SEC2MIN) +#define SEC2DAY (24L*SEC2HOUR) + +int +g2(char **pp) +{ + int v; + + v = 10*((*pp)[0]-'0') + (*pp)[1]-'0'; + *pp += 2; + return v; +} + +/* + * days per month plus days/year + */ +static int dmsize[] = +{ + 365, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 +}; +static int ldmsize[] = +{ + 366, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 +}; + +/* + * return the days/month for the given year + */ +static int * +yrsize(int yr) +{ + if((yr % 4) == 0) + return ldmsize; + else + return dmsize; +} + +/* + * compute seconds since Jan 1 1970 + */ +static long +lusertime(char *argbuf) +{ + char *buf; + ulong secs; + int i, y, m; + int *d2m; + + buf = argbuf; + i = strlen(buf); + if(i != 10 && i != 12) + return -1; + secs = 0; + y = g2(&buf); + m = g2(&buf); + if(y < 70) + y += 2000; + else + y += 1900; + + /* + * seconds per year + */ + for(i = 1970; i < y; i++){ + d2m = yrsize(i); + secs += d2m[0] * SEC2DAY; + } + + /* + * seconds per month + */ + d2m = yrsize(y); + for(i = 1; i < m; i++) + secs += d2m[i] * SEC2DAY; + + secs += (g2(&buf)-1) * SEC2DAY; + secs += g2(&buf) * SEC2HOUR; + secs += g2(&buf) * SEC2MIN; + if(*buf) + secs += g2(&buf); + + sprint(argbuf, "%ld", secs); + return secs; +} diff --git a/gnot/devhifi.c b/gnot/devhifi.c index 04aba9aa33f1f38579bdd3990b2024db37ba277d..b97ecabed51a8bd219961dce274fcfe369cec0f5 100644 --- a/gnot/devhifi.c +++ b/gnot/devhifi.c @@ -155,8 +155,6 @@ hifistat(Chan *c, char *dp) Chan* hifiopen(Chan *c, int omode) { - Hifichan *hp = &hifichan[c->dev]; - if(c->qid.path == CHDIR){ if(omode != OREAD) error(Eperm); @@ -183,8 +181,6 @@ hificreate(Chan *c, char *name, int omode, ulong perm) void hificlose(Chan *c) { - Hifichan *hp = &hifichan[c->dev]; - if(c->qid.path != CHDIR) streamclose(c); } @@ -235,7 +231,6 @@ long hifiwrite(Chan *c, void *buf, long n, ulong offset) { Hifichan *hp = &hifichan[c->dev]; - Hifi *hifi = hp->hdev; char nbuf[32], *p; if(n < 0) diff --git a/gnot/devincon.c b/gnot/devincon.c index ed3d990ee72ac51adc9af9319a75cac2c17d3809..7252d37ed92cd7a05a682c60207029b593dfb064 100644 --- a/gnot/devincon.c +++ b/gnot/devincon.c @@ -875,6 +875,7 @@ rdpackets(Incon *ip) * how to use more than one incon, this routine only * is for incon[0]. */ +void inconintr(Ureg *ur) { uchar status; diff --git a/gnot/main.c b/gnot/main.c index 70631d263dc9725b5f02615796cf4a06a57a4727..41674033ef5dc4b9a7341c2b2eadea121cfd8982 100644 --- a/gnot/main.c +++ b/gnot/main.c @@ -350,6 +350,7 @@ confinit(void) conf.portispaged = 0; conf.cntrlp = 0; conf.dkif = 2; + confinit1(mul); } /* diff --git a/port/devconc.c b/port/devconc.c index a328f485241d41a1abb1ac28b213b0b9b69e0ccd..2ab9fe4e2d4da5fba015faadf2d4ecfb42b8c681 100644 --- a/port/devconc.c +++ b/port/devconc.c @@ -466,6 +466,7 @@ concread(Chan *c, void *a, long n, ulong offset) if(c->qid.path & CHDIR) return devdirread(c, a, n, 0, 0, concgen); error(Eio); + return -1; /* does not return */ } long diff --git a/port/devcons.c b/port/devcons.c index b6f82bf4f5e9bbb2b007249635f2b4c1613a7c09..06d6ddede2bf366b2a9a601a7089dcac1bf2a422 100644 --- a/port/devcons.c +++ b/port/devcons.c @@ -176,7 +176,6 @@ panic(char *fmt, ...) else for(;;); } - int pprint(char *fmt, ...) { diff --git a/port/devproc.c b/port/devproc.c index eb3840fd8a0b2d2ee9dbdff25a58a8f2a241f14e..0bd30078edbdacd1822ab2bd4aaec54d565b4e32 100644 --- a/port/devproc.c +++ b/port/devproc.c @@ -184,7 +184,6 @@ procopen(Chan *c, int omode) c->qid.vers = p->pid; return devopen(c, omode, 0, 0, procgen); -; } void diff --git a/port/portfns.h b/port/portfns.h index 8f9cb8e2871858f4596b7557e8160cdfcc91e72f..4c979ccb285f057392542b203fd5c2dc47bd0136 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -26,7 +26,7 @@ void closemount(Mount*); void closepgrp(Pgrp*); long clrfpintr(void); void confinit(void); -void confinit1(int mul); +void confinit1(int); int consactive(void); void consdebug(void); Block *copyb(Block*, int); @@ -104,6 +104,7 @@ void kbdrepeat(int); void kickpager(void); int kprint(char*, ...); void kproc(char*, void(*)(void*), void*); +void kproftimer(ulong); void ksetenv(char*, char*); void ksetterm(char*); long latin1(uchar*); diff --git a/port/stsplice.c b/port/stsplice.c new file mode 100644 index 0000000000000000000000000000000000000000..100aea15e1a4986d1beefb02630dc5010670f8c2 --- /dev/null +++ b/port/stsplice.c @@ -0,0 +1,82 @@ +#include "u.h" +#include "../port/lib.h" +#include "mem.h" +#include "dat.h" +#include "fns.h" +#include "io.h" +#include "../port/error.h" + +#define splicedebug 1 + +#define DPRINT if(splicedebug)kprint + +/* + * Splice line discipline. + */ + +static void spliceopen(Queue*, Stream*); +static void spliceclose(Queue*); +static void spliceoput(Queue*, Block*); +static void spliceiput(Queue*, Block*); +Qinfo spliceinfo = +{ + spliceiput, + spliceoput, + spliceopen, + spliceclose, + "splice" +}; + +static void +spliceopen(Queue *q, Stream *s) +{ + DPRINT("spliceopen q=0x%ux s=0x%ux\n", q, s); + + WR(q)->ptr = s; /* pointer to ourselves */ + RD(q)->ptr = 0; /* pointer to other side */ +} + +static void +spliceclose(Queue *q) +{ + DPRINT("spliceclose q=0x%ux us=0x%ux them=0x%ux\n", + q, WR(q)->ptr, RD(q)->ptr); + + RD(q)->ptr = 0; + WR(q)->ptr = 0; +} + +static void +spliceoput(Queue *q, Block *bp) +{ + int fd; + Chan *c; + Stream *s; + + if(bp->type != M_CTL){ + PUTNEXT(q, bp); + return; + } + fd = strtol((char *)bp->rptr, 0, 0); + freeb(bp); + if(RD(q)->ptr) + error("stream already spliced"); + c = fdtochan(fd, ORDWR, 0); + s = c->stream; + if(s == 0) + error("splice attempt on non-stream"); + pushq(s, &spliceinfo); + RD(q)->ptr = s; + RD(s->procq->next)->ptr = WR(q)->ptr; +} + +static void +spliceiput(Queue *q, Block *bp) +{ + Stream *s; + + if(bp->type == M_HANGUP) + PUTNEXT(q, bp); + else + FLOWCTL(((Stream *)q->ptr)->procq, bp); +}