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)
136 fs.tree = alloctree(nil, nil, DMDIR|0777, fsdestroyfile);
137 q = fs.tree->root->qid;
144 addr = EARGF(usage());
147 srvname = EARGF(usage());
150 mtpt = EARGF(usage());
160 fprint(2, "srvname %s mtpt %s\n", srvname, mtpt);
161 if(addr == nil && srvname == nil && mtpt == nil)
162 sysfatal("must specify -a, -s, or -m option");
164 listensrv(&fs, addr);
167 postmountsrv(&fs, srvname, mtpt, MREPL|MCREATE);