24 pd = emalloc(sizeof(*pd));
35 pd = emalloc(sizeof(*pd));
44 fprint(2, "usage: snapfs [-a] [-m mtpt] file\n");
49 memread(Proc *p, File *f, void *buf, long *count, vlong offset)
55 if(!(pg = findpage(p, p->pid, f->name[0], offset-po)))
56 return "address not mapped";
58 if(*count > Pagesize-po)
61 memmove(buf, pg->data+po, *count);
66 dataread(Data *d, void *buf, long *count, vlong offset)
70 if(offset >= d->len) {
75 if(offset+*count >= d->len)
76 *count = d->len - offset;
78 memmove(buf, d->data+offset, *count);
93 data = r->ofcall.data;
94 offset = r->ifcall.offset;
95 count = r->ifcall.count;
99 e = memread(pd->p, fid->file, data, &count, offset);
101 e = dataread(pd->d, data, &count, offset);
104 r->ofcall.count = count;
113 ecreatefile(File *a, char *b, char *c, ulong d, void *e)
117 f = createfile(a, b, c, d, e);
119 sysfatal("error creating snap tree: %r");
124 main(int argc, char **argv)
157 if((b = Bopen(argv[0], OREAD)) == nil)
158 sysfatal("cannot open \"%s\": %r", argv[0]);
160 if((plist = readsnap(b)) == nil)
161 sysfatal("readsnap fails");
163 tree = alloctree(nil, nil, DMDIR|0555, nil);
166 for(p=plist; p; p=p->link) {
167 print("process %ld %.*s\n", p->pid, 28, p->d[Pstatus] ? p->d[Pstatus]->data : "");
169 snprint(buf, sizeof buf, "%ld", p->pid);
170 fdir = ecreatefile(tree->root, buf, nil, DMDIR|0555, nil);
171 ecreatefile(fdir, "ctl", nil, 0777, nil);
173 ecreatefile(fdir, "text", nil, 0777, PDProc(p));
175 ecreatefile(fdir, "mem", nil, 0666, PDProc(p));
176 for(i=0; i<Npfile; i++) {
178 f = ecreatefile(fdir, pfile[i], nil, 0666, PDData(d));
184 postmountsrv(&fs, nil, mtpt, mflag);