|
|
1.1 root 1: #include <libc.h>
2: #include "worm.h"
3: #include "sym.h"
4: #include <sys/types.h>
5: #include <sys/stat.h>
6:
7: char *dumpdir();
8: int verbose = 0;
9:
10: main(argc, argv)
11: char **argv;
12: {
13: Superblock s, news;
14: char *e;
15: char *dev = "/dev/worm0";
16: int update = 0;
17: int c;
18: char buf[1024];
19: extern char *optarg;
20: extern int optind;
21: void blkfn();
22:
23: while((c = getopt(argc, argv, "f:vu")) != -1)
24: switch(c)
25: {
26: case 'f': dev = optarg; break;
27: case 'u': update = 1; break;
28: case 'v': verbose = 1; break;
29: case '?': usage();
30: }
31: dev = mapdev(dev);
32: if(optind != argc-1)
33: usage();
34: if((s.fd = open(dev, 2)) < 0){
35: perror(dev);
36: exit(1);
37: }
38: if(e = openinode(&s, SPIN_DOWN)){
39: fprint(2, "%s: %s\n", dev, e);
40: exit(2);
41: }
42: if(s.version != VBTREE){
43: fprint(2, "%s is not a btree!\n", s.vol_id);
44: exit(2);
45: }
46: if(strcmp(argv[optind], s.vol_id)){
47: fprint(2, "wanted volid '%s'; got '%s'\n", argv[optind], s.vol_id);
48: exit(1);
49: }
50: if(e = dumpdir(&s, update)){
51: fprint(2, "%s: %s\n", dev, e);
52: exit(2);
53: }
54: sprint(buf, "/usr/worm/tmp/%s", s.vol_id);
55: unlink(buf);
56: exit(0);
57: }
58:
59: usage()
60: {
61: fprint(2, "Usage: dir [-fdevice] -v] [-u] vol_id\n");
62: exit(2);
63: }
64:
65: char *
66: dumpdir(s, update)
67: register Superblock *s;
68: {
69: char *b;
70: static char buf[64];
71: char name[256], buf1[256];
72:
73: if((b = malloc(s->blocksize)) == 0){
74: sprint(buf, "couldn't malloc buffer (%d bytes)", s->blocksize);
75: return(buf);
76: }
77: numinodes = s->ninodes;
78: sprint(name, "/usr/worm/dirs/%s", s->vol_id);
79: Seek(s, s->binodes);
80: sprint(buf1, "%s.F", name);
81: copyout(s, buf1, s->nF, update, verbose);
82: sprint(buf1, "%s.T", name);
83: copyout(s, buf1, s->nT, update, verbose);
84: sprint(buf1, "%s.I", name);
85: copyout(s, buf1, s->ninochars, update, verbose);
86: free(b);
87: return((char *)0);
88: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.