Xfid * setuser(Xfile *xp, char *user) { Xfid *xf, *xpf; Session *s; xf = xfid(user, xp, 1); if(xf->urfid) return xf; if(xp->parent==xp || !(xpf = setuser(xp->parent, user))) /* assign = */ return xfid(user, xp, -1); s = xp->s; xf->urfid = newfid(s); xf->urfid->owner = &xf->urfid; setfid(s, xpf->urfid); s->f.newfid = xf->urfid - s->fids; s->f.nwname = 1; s->f.wname[0] = xp->name; if(xmesg(s, Twalk) || s->f.nwqid != 1) return xfid(user, xp, -1); return xf; }
void xgamc(int index, int *nerr) { /*===================================================================== * PURPOSE: To execute a MOD command given its index number. *===================================================================== * INPUT ARGUMENTS: * INDEX: The index number of the command. *===================================================================== * OUTPUT ARGUMENTS: * NERR: Error flag. Set to 0 if no error occurred. * Potential error numbers: 0901. *===================================================================== * MODULE/LEVEL: GAM/1 *===================================================================== * GLOBAL INPUT: * MACH: *===================================================================== * GLOBAL OUTPUT: * GAM: LRTWXL, KRTWXL, ORTWXL *===================================================================== * SUBROUTINES CALLED: * SACLIB: GTOUTM, XP, XP1, XP2, XPPK, XPC, XFID, XPICKS, XPLOTPM *===================================================================== * MODIFICATION HISTORY: * 970204: Added FILENUMBER to allow or disallow file number * display. maf * 890421: Added PLOTXY command. * 870728: Moved XLIM and YLIM commands from GEM. * 870420: Added SETDEVICE command. * 861203: Added PLOTPM command. * 830105: Deleted PUSER command. * 821228: Added FILEID and PICKS commands. Deleted DISPLAY command. * 821005: Added PLOTC command. * 820825: Original version. *===================================================================== */ /* PROCEDURE: */ *nerr = 0; /* - Jump to correct command based upon its index number. */ switch( index ){ case 1: goto L_100; case 2: goto L_200; case 3: goto L_300; case 4: goto L_400; case 5: goto L_500; case 6: goto L_600; case 7: goto L_700; case 8: goto L_800; case 9: goto L_900; case 10: goto L_1000; case 11: goto L_1100; case 12: goto L_1200; case 13: goto L_1300; case 14: goto L_1400; case 15: goto L_1500; case 16: goto L_1600; /* added for FILENUMBER. maf 970204 */ case 17: goto L_1700; /* added for PRINT. maf 990422 */ case 18: goto L_1800; } /* - Error return if bad index value. */ *nerr = 901; setmsg( "ERROR", *nerr ); apcmsg( "in XGAMC",9 ); goto L_8888; L_100: /* - Command 01: PLOT */ xp( nerr ); goto L_8888; L_200: /* - Command 02: PLOT1 */ xp1( nerr ); goto L_8888; L_300: /* - Command 03: PLOT2 */ xp2( nerr ); goto L_8888; L_400: /* - Command 04: PLOTPK */ xppk( nerr ); goto L_8888; L_500: /* - Command 05: PLOTC */ xpc( nerr ); goto L_8888; L_600: /* - Command 06: FILEID */ xfid( nerr ); goto L_8888; L_700: /* - Command 07: PICKS */ xpicks( nerr ); goto L_8888; L_800: /* - Command 08: PLOTPM */ xplotpm( nerr ); goto L_8888; L_900: /* - Command 09: SETDEVICE */ xsetdevice( nerr ); goto L_8888; L_1000: /* - Command 10: XLIM */ xcrtw( &cmgam.lrtwxl, (char*)kmgam.krtwxl,9, cmgam.ortwxl, nerr ); goto L_8888; L_1100: /* - Command 11: YLIM */ xylim( nerr ); goto L_8888; L_1200: /* - Command 12: PLOTXY */ xplotxy( nerr ); goto L_8888; L_1300: /* - Command 13: FITXY */ xfitxy( nerr ); goto L_8888; L_1400: /* - Command 14: PLOTDY */ xplotdy( nerr ); goto L_8888; L_1500: /* - Command 15: PLOTALPHA */ xplotalpha( nerr ); goto L_8888; L_1600: /* - Command 16: FILENUMBER */ xfilenumber ( nerr ) ; goto L_8888 ; L_1700: /* - Command 17: PRINT */ xprint ( nerr ) ; goto L_8888 ; L_1800: xsave( ); goto L_8888; L_8888: return; } /* end of function */
void srvinit(int fd, char *file, char *addr) { char fdservice[16], *naddr; Session *s; Xfile *xp; Xfid *xf; Fid *f; s = calloc(1, sizeof(Session)); s->spec = ""; s->fd = -1; if(fd >= 0){ s->fd = fd; sprint(fdservice, "/fd/%d", s->fd); s->service = strstore(fdservice); chat("fd = %d\n", s->fd); }else if(file){ chat("file = \"%s\"\n", file); s->service = file; s->fd = open(file, ORDWR); if(s->fd < 0){ clog("can't open %s: %r\n", file); goto error; } }else if(addr){ chat("addr = \"%s\"\n", addr); naddr = netmkaddr(addr, 0, "9fs"); s->service = addr; s->fd = dial(naddr, 0, 0, 0); if(s->fd < 0){ clog("can't dial %s: %r\n", naddr); goto error; } } chat("version..."); s->tag = NOTAG-1; s->f.msize = Maxfdata+IOHDRSZ; s->f.version = "9P2000"; xmesg(s, Tversion); messagesize = IOHDRSZ+s->f.msize; chat("version spec %s size %d\n", s->f.version, s->f.msize); s->tag = 0; chat("authenticate..."); if(authhostowner(s) < 0){ clog("auth failed %r\n"); goto error; } chat("attach as none..."); f = newfid(s); s->f.fid = f - s->fids; s->f.afid = ~0x0UL; s->f.uname = "none"; s->f.aname = s->spec; if(xmesg(s, Tattach)){ clog("attach failed\n"); goto error; } xp = xfile(&s->f.qid, s, 1); s->root = xp; xp->parent = xp; xp->name = "/"; xf = xfid("none", xp, 1); xf->urfid = f; clog("service=%s uid=%s fid=%ld\n", s->service, xf->uid, xf->urfid - s->fids); if(tail) tail->next = s; else head = s; tail = s; return; error: if(s->fd >= 0) close(s->fd); free(s); }