8 static char Ebad[] = "something bad happened";
9 static char Enomem[] = "no memory";
11 typedef struct Ramfile Ramfile;
24 rf = r->fid->file->aux;
25 offset = r->ifcall.offset;
26 count = r->ifcall.count;
28 //print("read %ld %lld\n", *count, offset);
29 if(offset >= rf->ndata){
35 if(offset+count >= rf->ndata)
36 count = rf->ndata - offset;
38 memmove(r->ofcall.data, rf->data+offset, count);
39 r->ofcall.count = count;
51 rf = r->fid->file->aux;
52 offset = r->ifcall.offset;
53 count = r->ifcall.count;
55 if(offset+count >= rf->ndata){
56 v = realloc(rf->data, offset+count);
62 rf->ndata = offset+count;
63 r->fid->file->length = rf->ndata;
65 memmove(rf->data+offset, r->ifcall.data, count);
66 r->ofcall.count = count;
76 if(f = createfile(r->fid->file, r->ifcall.name, r->fid->uid, r->ifcall.perm, nil)){
77 rf = emalloc9p(sizeof *rf);
80 r->ofcall.qid = f->qid;
92 rf = r->fid->file->aux;
94 if(rf && (r->ifcall.mode&OTRUNC)){
96 r->fid->file->length = 0;
103 fsdestroyfile(File *f)
107 //fprint(2, "clunk\n");
125 fprint(2, "usage: ramfs [-D] [-s srvname] [-m mtpt]\n");
130 main(int argc, char **argv)
137 fs.tree = alloctree(nil, nil, DMDIR|0777, fsdestroyfile);
138 q = fs.tree->root->qid;
145 addr = EARGF(usage());
148 srvname = EARGF(usage());
151 mtpt = EARGF(usage());
161 fprint(2, "ramsrv.nopipe %d srvname %s mtpt %s\n", fs.nopipe, srvname, mtpt);
162 if(addr == nil && srvname == nil && mtpt == nil)
163 sysfatal("must specify -a, -s, or -m option");
165 listensrv(&fs, addr);
168 postmountsrv(&fs, srvname, mtpt, MREPL|MCREATE);