#include <u.h>
#include <libc.h>
#include <bio.h>
#include <ctype.h>
#include <fcall.h>
#include <mp.h>
#include <libsec.h>
#include <thread.h>
#include <pool.h>
#include <ip.h>
#include <9p.h>
#include "nbcache.h"
int Debug;
int Passive;
void
fsopen(Req *r)
{
r->fid->file->aux = snapshot();
respond(r, nil);
}
static void
fsread(Req *r)
{
readstr(r, r->fid->file->aux);
respond(r, nil);
}
void
fsdestroyfile(File *f)
{
free(f->aux);
}
Srv fs = {
.open = fsopen,
.read = fsread,
};
static void
usage(void)
{
fprint(2, "usage: %s [-p] [-m mntpt] [-s srvname] [-x /net]\n", argv0);
exits("usage");
}
static void
ding(void *u, char *msg)
{
USED(u);
if(strstr(msg, "alarm"))
noted(NCONT);
noted(NDFLT);
}
void
main(int argc, char *argv[])
{
File *f;
char *mtpt, *svs;
svs = nil;
Netdir = "/net";
mtpt = "/lib/ndb";
ARGBEGIN{
case 'd':
Debug++;
break;
case 'p':
Passive = 1;
break;
case 'D':
chatty9p++;
break;
case 'm':
mtpt = EARGF(usage());
break;
case 's':
svs = EARGF(usage());
break;
case 'x':
Netdir = EARGF(usage());
break;
case '?':
usage();
break;
default:
fprint(2, "unrecognized option\n");
usage();
}ARGEND
if (argc != 0)
usage();
notify(ding);
quotefmtinstall();
fmtinstall('I', eipfmt);
fmtinstall('V', eipfmt);
fmtinstall('E', eipfmt);
fmtinstall('M', eipfmt);
switch(rfork(RFPROC|RFNOWAIT|RFMEM|RFNOTEG)){
case -1:
sysfatal("fork() failed %r\n");
case 0:
listener();
break;
default:
break;
}
fs.tree = alloctree(nil, nil, DMDIR|0755, fsdestroyfile);
postmountsrv(&fs, svs, mtpt, MBEFORE);
if((f = createfile(fs.tree->root, "gleaned", nil, 0444, nil)) == nil)
sysfatal("cannot create file %r");
closefile(f);
exits(0);
}
|