7 static char Ebad[] = "something bad happened";
8 static char Enomem[] = "no memory";
10 typedef struct Ramfile Ramfile;
23 rf = r->fid->file->aux;
24 offset = r->ifcall.offset;
25 count = r->ifcall.count;
27 /*print("read %ld %lld\n", *count, offset); */
28 if(offset >= rf->ndata){
34 if(offset+count >= rf->ndata)
35 count = rf->ndata - offset;
37 memmove(r->ofcall.data, rf->data+offset, count);
38 r->ofcall.count = count;
50 rf = r->fid->file->aux;
51 offset = r->ifcall.offset;
52 count = r->ifcall.count;
54 if(offset+count >= rf->ndata){
55 v = realloc(rf->data, offset+count);
61 rf->ndata = offset+count;
62 r->fid->file->length = rf->ndata;
64 memmove(rf->data+offset, r->ifcall.data, count);
65 r->ofcall.count = count;
75 if(f = createfile(r->fid->file, r->ifcall.name, r->fid->uid, r->ifcall.perm, nil)){
76 rf = emalloc9p(sizeof *rf);
79 r->ofcall.qid = f->qid;
91 rf = r->fid->file->aux;
93 if(rf && (r->ifcall.mode&OTRUNC)){
95 r->fid->file->length = 0;
102 fsdestroyfile(File *f)
106 /*fprint(2, "clunk\n"); */
124 fprint(2, "usage: ramfs [-D] [-s srvname] [-m mtpt]\n");
129 main(int argc, char **argv)
135 fs.tree = alloctree(nil, nil, DMDIR|0777, fsdestroyfile);
136 q = fs.tree->root->qid;
143 srvname = EARGF(usage());
146 mtpt = EARGF(usage());
156 fprint(2, "ramsrv.nopipe %d srvname %s mtpt %s\n", fs.nopipe, srvname, mtpt);
157 if(srvname == nil && mtpt == nil)
158 sysfatal("you should at least specify a -s or -m option");
160 postmountsrv(&fs, srvname, mtpt, MREPL|MCREATE);