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 b = Bopen(argv[0], OREAD);
159 fprint(2, "cannot open \"%s\": %r\n", argv[0]);
163 if((plist = readsnap(b)) == nil) {
164 fprint(2, "readsnap fails\n");
168 tree = alloctree(nil, nil, DMDIR|0555, nil);
171 for(p=plist; p; p=p->link) {
172 print("process %ld %.*s\n", p->pid, 28, p->d[Pstatus] ? p->d[Pstatus]->data : "");
174 snprint(buf, sizeof buf, "%ld", p->pid);
175 fdir = ecreatefile(tree->root, buf, nil, DMDIR|0555, nil);
176 ecreatefile(fdir, "ctl", nil, 0777, nil);
178 ecreatefile(fdir, "text", nil, 0777, PDProc(p));
180 ecreatefile(fdir, "mem", nil, 0666, PDProc(p));
181 for(i=0; i<Npfile; i++) {
183 f = ecreatefile(fdir, pfile[i], nil, 0666, PDData(d));
189 postmountsrv(&fs, nil, mtpt, mflag);