|
|
1.1 root 1: #include <libc.h>
2: #include "worm.h"
3:
4: main(argc, argv)
5: char **argv;
6: {
7: Superblock s;
8: char *e, *vol_id = 0;
9: char *dev = "/dev/worm0";
10: int c;
11: long nf = 0;
12: int vflag = 0;
13: Superblock ss;
14: extern char *optarg;
15: extern int optind;
16: extern long atol();
17:
18: while((c = getopt(argc, argv, "vF:f:")) != -1)
19: switch(c)
20: {
21: case 'f': dev = optarg; break;
22: case 'F': nf = atol(optarg); break;
23: case 'v': vflag = 1; break;
24: case '?': usage();
25: }
26: if(optind < argc){
27: vol_id = argv[optind++];
28: if(optind != argc)
29: usage();
30: }
31: dev = mapdev(dev);
32: if((s.fd = open(dev, 0)) < 0){
33: perror(dev);
34: exit(2);
35: }
36: if(read(s.fd, &ss, sizeof ss) != sizeof ss){
37: if(errno == ENXIO)
38: print("unwritten block zero\n");
39: else
40: perror("block zero");
41: } else {
42: if(ss.magic == SMAGIC){
43: print("appears to be a good superblock at zero\n");
44: exit(0);
45: } else if(ss.magic == 0){
46: print("appears to be a zero'ed block at zero.\n");
47: } else
48: print("ignoring bogus block at zero\n");
49: }
50: vlink(s.fd, 1);
51: exit(0);
52: }
53:
54: usage()
55: {
56: print("Usage: worm poke [-v] [-fdevice] [-Fnfree] [vol_id]\n");
57: exit(2);
58: }
59:
60: vlink(fd, blk)
61: {
62: Superblock s;
63: int i, n;
64:
65: while(blk < 1650000){
66: loop:
67: print("reading sb at %d\n", blk);
68: bigseek(fd, blk, 1024, 0);
69: if(read(fd, &s, sizeof s) == sizeof s){
70: if(s.magic == SMAGIC){
71: blk = s.nextsb;
72: continue;
73: }
74: print("apparent garbage at supposed superblock@%ld\n", blk);
75: } else {
76: print("bad read at blk %ld, errno=%d\n", blk, errno);
77: lseek(fd, 1024, 1);
78: blk++;
79: }
80: for(i = 0; i < 50; i++){
81: n = read(fd, &s, sizeof s);
82: if(n < 0){
83: lseek(fd, 1024, 1);
84: continue;
85: }
86: if((n == sizeof s) && (s.magic == SMAGIC)){
87: blk += i;
88: print("after error, skipped %d blocks to apparent superblock at %ld\n", i, blk);
89: goto loop;
90: }
91: }
92: print("after error, no superblock after %d tries\n", i);
93: blk += i;
94: }
95: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.