sexp sexp_postmountsrv (sexp ctx, sexp self, sexp_sint_t n, sexp ls, sexp name, sexp mtpt, sexp flags) { Srv s; struct sexp_plan9_srv p9s; if (! sexp_listp(ctx, ls)) return sexp_type_exception(ctx, self, SEXP_PAIR, ls); if (! sexp_stringp(name)) return sexp_type_exception(ctx, self, SEXP_STRING, name); if (! sexp_stringp(mtpt)) return sexp_type_exception(ctx, self, SEXP_STRING, mtpt); if (! sexp_integerp(flags)) return sexp_type_exception(ctx, self, SEXP_FIXNUM, flags); sexp_build_srv(ctx, &p9s, ls); s.aux = &p9s; s.auth = &sexp_9p_auth; s.attach = &sexp_9p_attach; s.walk = &sexp_9p_walk; s.walk1 = &sexp_9p_walk1; s.clone = &sexp_9p_clone; s.open = &sexp_9p_open; s.create = &sexp_9p_create; s.remove = &sexp_9p_remove; s.read = &sexp_9p_read; s.write = &sexp_9p_write; s.stat = &sexp_9p_stat; s.wstat = &sexp_9p_wstat; s.flush = &sexp_9p_flush; s.destroyfid = &sexp_9p_destroyfid; s.destroyreq = &sexp_9p_destroyreq; s.end = &sexp_9p_end; postmountsrv(&s, sexp_string_data(name), sexp_string_data(mtpt), sexp_unbox_fixnum(flags)); return SEXP_UNDEF; }
void main(int argc, char **argv) { int stdio; stdio = 0; ARGBEGIN{ case 'D': ++chatty9p; break; case 'v': ++chatty; break; case 'f': deffile = ARGF(); break; case 'g': gidfile(ARGF()); break; case 'p': uidfile(ARGF()); break; case 's': stdio = 1; break; case 'r': rdonly = 1; break; default: usage(); }ARGEND if(argc == 0) srvfile = "ext2"; else if(argc == 1) srvfile = argv[0]; else usage(); iobuf_init(); /*notify(handler);*/ if(!chatty){ close(2); open("#c/cons", OWRITE); } if(stdio){ srv(&ext2srv); }else{ chat("%s %d: serving %s\n", argv0, getpid(), srvfile); postmountsrv(&ext2srv, srvfile, 0, 0); } exits(0); }
void main(int argc, char **argv) { char *file; file = nil; quotefmtinstall(); time0 = time(0); if(NPTR != BLKSZ/sizeof(void*)) sysfatal("unexpected pointer size"); ARGBEGIN{ case 'D': chatty9p++; break; case 'f': file = EARGF(usage()); break; case 'r': rdonly = 1; break; case 's': srvname = EARGF(usage()); break; case 'm': mtpt = EARGF(usage()); break; default: usage(); }ARGEND if(argc > 1) usage(); if(argc == 1) sdname = argv[0]; if(file){ if((fd = open(file, rdonly ? OREAD : ORDWR)) < 0) sysfatal("open %s: %r", file); } inquiry = estrdup9p(inquiry); tab[0].name = estrdup9p("data"); tab[0].inuse = 1; tab[0].mode = 0666; postmountsrv(&fs, srvname, mtpt, MBEFORE); exits(nil); }
void main(int argc, char **argv) { char *addr = nil; char *srvname = nil; char *mtpt = nil; Qid q; fs.tree = alloctree(nil, nil, DMDIR|0777, fsdestroyfile); q = fs.tree->root->qid; ARGBEGIN{ case 'D': chatty9p++; break; case 'a': addr = EARGF(usage()); break; case 's': srvname = EARGF(usage()); break; case 'm': mtpt = EARGF(usage()); break; default: usage(); }ARGEND; if(argc) usage(); if(chatty9p) fprint(2, "ramsrv.nopipe %d srvname %s mtpt %s\n", fs.nopipe, srvname, mtpt); if(addr == nil && srvname == nil && mtpt == nil) sysfatal("must specify -a, -s, or -m option"); if(addr) listensrv(&fs, addr); if(srvname || mtpt) postmountsrv(&fs, srvname, mtpt, MREPL|MCREATE); exits(0); }
void main(int argc, char **argv) { char *mtpt; Ofile *f; Odir d; mtpt = "/mnt/doc"; ARGBEGIN{ case 'm': mtpt = ARGF(); break; default: goto Usage; }ARGEND if(argc != 1) { Usage: fprint(2, "usage: olefs file\n"); exits("usage"); } f = oleopen(argv[0]); if(f == nil) { print("error opening %s: %r\n", argv[0]); exits("open"); } // dumpdir(f, 0); if(oreaddir(f, 0, &d) != 1) { fprint(2, "oreaddir error: %r\n"); exits("oreaddir"); } olesrv.tree = alloctree(nil, nil, DMDIR|0777, nil); filldir(olesrv.tree->root, f, d.dir, 0); postmountsrv(&olesrv, nil, mtpt, MREPL); exits(0); }
void main(int argc, char *argv[]) { char *srv, *mtpt; char buf[MAXPATH]; inflateinit(); fmtinstall('H', Hfmt); srv = nil; mtpt = "/mnt/hg"; ARGBEGIN { case 'D': chatty9p++; break; case 'm': mtpt = EARGF(usage()); break; case 's': srv = EARGF(usage()); break; default: usage(); } ARGEND; if(getworkdir(workdir, *argv) < 0) sysfatal("can't find workdir: %r"); snprint(buf, sizeof(buf), "%s/.hg/store/00changelog", workdir); if(revlogopen(&changelog, buf, OREAD) < 0) sysfatal("can't open changelog: %r\n"); snprint(buf, sizeof(buf), "%s/.hg/store/00manifest", workdir); if(revlogopen(&manifest, buf, OREAD) < 0) sysfatal("can't open menifest: %r\n"); postmountsrv(&fs, srv, mtpt, MREPL); exits(0); }
void main(int argc, char **argv) { int i; ARGBEGIN{ case 'D': dbg++; break; case 'c': chatty9p++; break; default: fprint(2, "Usage: grepfs /path/to/files/*\n"); exits("usage"); break; }ARGEND if(argc < 1){ fprint(2, "Usage: grepfs /path/to/files/*\n"); exits("usage"); } grepargs = emalloc9p(sizeof(*grepargs) * (argc + 4)); *grepargs = "grep"; for(i = 0; i < argc; i++) grepargs[i+3] = argv[i]; grepargs[i+3] = nil; grepflags = estrdup9p("-n"); starttime = grepatime = grepmtime = time(nil); if(dbg){ logfd = create("/tmp/grepfs.log", OWRITE, 0644); postmountsrv(&fs, "grepfs", nil, 0); }else{ fs.infd = 0; fs.outfd = 1; srv(&fs); } exits(0); }
void main(int argc, char **argv) { char *service; time0 = time(0); service = nil; ARGBEGIN{ case 'D': chatty9p++; break; case 's': service = EARGF(usage()); break; default: usage(); }ARGEND if(argc > 1) usage(); postmountsrv(&fs, service, argc ? argv[0] : "/n", MAFTER); exits(nil); }
void main(int argc, char **argv) { int auth, x; char *mtpt, *service, *where, *user; Netbuf n; UserPasswd *up; mtpt = "/mnt/news"; service = nil; memset(&n, 0, sizeof n); user = nil; auth = 0; ARGBEGIN{ case 'D': chatty9p++; break; case 'N': netdebug = 1; break; case 'a': auth = 1; break; case 'u': user = EARGF(usage()); break; case 's': service = EARGF(usage()); break; case 'm': mtpt = EARGF(usage()); break; default: usage(); }ARGEND if(argc > 1) usage(); if(argc==0) where = "$nntp"; else where = argv[0]; now = time(0); net = &n; if(auth) { n.auth = 1; if(user) up = auth_getuserpasswd(auth_getkey, "proto=pass service=nntp server=%q user=%q", where, user); else up = auth_getuserpasswd(auth_getkey, "proto=pass service=nntp server=%q", where); if(up == nil) sysfatal("no password: %r"); n.user = up->user; n.pass = up->passwd; } n.addr = netmkaddr(where, "tcp", "nntp"); root = emalloc(sizeof *root); root->name = estrdup(""); root->parent = root; n.fd = -1; if(nntpconnect(&n) < 0) sysfatal("nntpconnect: %s", n.response); x=netdebug; netdebug=0; nntprefreshall(&n); netdebug=x; // dumpgroups(root, 0); postmountsrv(&nntpsrv, service, mtpt, MREPL); exits(nil); }
void main(int argc, char **argv) { int isdir; char *file, *cname; Dir *dir; quotefmtinstall(); time0 = time(0); ARGBEGIN{ case 'D': chatty9p++; break; case 'd': sdname = EARGF(usage()); break; case 'm': mtpt = EARGF(usage()); break; case 'r': rdonly = 1; break; case 's': srvname = EARGF(usage()); break; default: usage(); }ARGEND if(argc != 1) usage(); file = argv[0]; dir = dirstat(file); if(!dir) sysfatal("%s: %r", file); isdir = (dir->mode & DMDIR) != 0; free(dir); if (isdir) { cname = smprint("%s/ctl", file); if ((ctlfd = open(cname, ORDWR)) < 0) sysfatal("open %s: %r", cname); file = smprint("%s/data", file); } if((fd = open(file, rdonly? OREAD: ORDWR)) < 0) sysfatal("open %s: %r", file); sectsize = 512; /* conventional */ dir = dirfstat(fd); if (dir) nsect = dir->length / sectsize; free(dir); inquiry = estrdup9p(inquiry); tab[0].inuse = 1; tab[0].name = estrdup9p("data"); tab[0].mode = 0666; tab[0].length = nsect; postmountsrv(&fs, srvname, mtpt, MBEFORE); exits(nil); }
void main(int argc, char **argv) { Biobuf *b; Data *d; File *fdir, *f; Proc *p, *plist; Tree *tree; char *mtpt, buf[32]; int i, mflag; mtpt = "/proc"; mflag = MBEFORE; ARGBEGIN{ case 'D': chatty9p++; break; case 'd': debug = 1; break; case 'a': mflag = MAFTER; break; case 'm': mtpt = ARGF(); break; default: usage(); }ARGEND if(argc != 1) usage(); b = Bopen(argv[0], OREAD); if(b == nil) { fprint(2, "cannot open \"%s\": %r\n", argv[0]); exits("Bopen"); } if((plist = readsnap(b)) == nil) { fprint(2, "readsnap fails\n"); exits("readsnap"); } tree = alloctree(nil, nil, DMDIR|0555, nil); fs.tree = tree; for(p=plist; p; p=p->link) { print("process %ld %.*s\n", p->pid, 28, p->d[Pstatus] ? p->d[Pstatus]->data : ""); snprint(buf, sizeof buf, "%ld", p->pid); fdir = ecreatefile(tree->root, buf, nil, DMDIR|0555, nil); ecreatefile(fdir, "ctl", nil, 0777, nil); if(p->text) ecreatefile(fdir, "text", nil, 0777, PDProc(p)); ecreatefile(fdir, "mem", nil, 0666, PDProc(p)); for(i=0; i<Npfile; i++) { if((d = p->d[i])) { f = ecreatefile(fdir, pfile[i], nil, 0666, PDData(d)); f->Dir.length = d->len; } } } postmountsrv(&fs, nil, mtpt, mflag); exits(0); }
void main(int argc, char **argv) { int i, trysecstore; char err[ERRMAX], *s; Dir d; Proto *p; char *secstorepw; trysecstore = 1; secstorepw = nil; ARGBEGIN{ case 'D': chatty9p++; break; case 'S': /* server: read nvram, no prompting for keys */ askforkeys = 0; trysecstore = 0; sflag = 1; break; case 'a': authaddr = EARGF(usage()); break; case 'd': debug = 1; doprivate = 0; break; case 'g': /* get: prompt for key for name and domain */ gflag = 1; break; case 'k': /* reinitialize nvram */ kflag = 1; break; case 'm': /* set default mount point */ mtpt = EARGF(usage()); break; case 'n': trysecstore = 0; break; case 'p': doprivate = 0; break; case 's': /* set service name */ service = EARGF(usage()); break; case 'u': /* user: set hostowner */ uflag = 1; break; default: usage(); }ARGEND if(argc != 0 && !gflag) usage(); if(doprivate) private(); initcap(); quotefmtinstall(); fmtinstall('A', _attrfmt); fmtinstall('N', attrnamefmt); fmtinstall('H', encodefmt); ring = emalloc(sizeof(*ring)); notify(notifyf); if(gflag){ if(argc != 1) usage(); askuser(argv[0]); exits(nil); } for(i=0; prototab[i]; i++){ p = prototab[i]; if(p->name == nil) sysfatal("protocol %d has no name", i); if(p->init == nil) sysfatal("protocol %s has no init", p->name); if(p->write == nil) sysfatal("protocol %s has no write", p->name); if(p->read == nil) sysfatal("protocol %s has no read", p->name); if(p->close == nil) sysfatal("protocol %s has no close", p->name); if(p->keyprompt == nil) p->keyprompt = ""; } if(sflag){ s = getnvramkey(kflag ? NVwrite : NVwriteonerr, &secstorepw); if(s == nil) fprint(2, "factotum warning: cannot read nvram: %r\n"); else if(ctlwrite(s, 0) < 0) fprint(2, "factotum warning: cannot add nvram key: %r\n"); if(secstorepw != nil) trysecstore = 1; if (s != nil) { memset(s, 0, strlen(s)); free(s); } } else if(uflag) promptforhostowner(); owner = getuser(); if(trysecstore){ if(havesecstore() == 1){ while(secstorefetch(secstorepw) < 0){ rerrstr(err, sizeof err); if(strcmp(err, "cancel") == 0) break; fprint(2, "factotum: secstorefetch: %r\n"); fprint(2, "Enter an empty password to quit.\n"); free(secstorepw); secstorepw = nil; /* just try nvram pw once */ } }else{ /* rerrstr(err, sizeof err); if(*err) fprint(2, "factotum: havesecstore: %r\n"); */ } } postmountsrv(&fs, service, mtpt, MBEFORE); if(service){ nulldir(&d); d.mode = 0666; s = emalloc(10+strlen(service)); strcpy(s, "/srv/"); strcat(s, service); if(dirwstat(s, &d) < 0) fprint(2, "factotum warning: cannot chmod 666 %s: %r\n", s); free(s); } exits(nil); }