|
|
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: #include <pwd.h> ! 7: #include <grp.h> ! 8: ! 9: Inode *inodebase, *inext; ! 10: char *namebase, *cnext; ! 11: ! 12: main(argc, argv) ! 13: char **argv; ! 14: { ! 15: Superblock s; ! 16: char *e; ! 17: char *dev = "/dev/worm0"; ! 18: register c, j; ! 19: register Inode *from, *to; ! 20: extern char *optarg; ! 21: extern int optind; ! 22: char *vlk(); ! 23: int cmp(); ! 24: int fd; ! 25: int verbose = 0; ! 26: char buf[512]; ! 27: long ni, nc; ! 28: ! 29: while((c = getopt(argc, argv, "vf:")) != -1) ! 30: switch(c) ! 31: { ! 32: case 'v': verbose = 1; break; ! 33: case 'f': dev = optarg; break; ! 34: case '?': usage(); ! 35: } ! 36: dev = mapdev(dev); ! 37: if((s.fd = open(dev, 0)) < 0){ ! 38: perror(dev); ! 39: exit(1); ! 40: } ! 41: if(e = openinode(&s, SPIN_DOWN)){ ! 42: fprint(2, "%s: %s\n", dev, e); ! 43: exit(1); ! 44: } ! 45: if(s.version != VLINK){ ! 46: fprint(2, "%s: not a vlink disk, no action taken.\n", s.vol_id); ! 47: exit(1); ! 48: } ! 49: if(optind != argc-1) ! 50: usage(); ! 51: if(strcmp(argv[optind], s.vol_id)){ ! 52: fprint(2, "wanted volid '%s'; got '%s'\n", argv[optind], s.vol_id); ! 53: exit(1); ! 54: } ! 55: if(verbose) ! 56: print("%d inodes\n", numinodes); ! 57: if((inodebase = (Inode *)malloc(s.blocksize+(int)numinodes*sizeof(Inode))) == 0){ ! 58: fprint(2, "malloc of %ld inodes failed\n", numinodes); ! 59: exit(2); ! 60: } ! 61: if((namebase = malloc(s.blocksize+(int)numnamechars+(int)numinodes)) == 0){ ! 62: fprint(2, "malloc of %ld chars failed\n", numnamechars); ! 63: exit(2); ! 64: } ! 65: inext = inodebase; ! 66: cnext = namebase; ! 67: s.ninodes = 0; ! 68: s.nextsb = 2; ! 69: if(e = vlk(&s)){ ! 70: fprint(2, "%s: %s\n", dev, e); ! 71: exit(1); ! 72: } ! 73: j = inext-inodebase; ! 74: if(verbose) ! 75: print("%d in base\n", j); ! 76: qsort((char *)inodebase, j, sizeof(*inodebase), cmp); ! 77: for(to = inodebase, from = inodebase+1; from < inext; from++) ! 78: if(strcmp(from->name.o+namebase, from[-1].name.o+namebase)) ! 79: *to++ = from[-1]; ! 80: else { ! 81: while((++from < inext) && (strcmp(from->name.o+namebase, from[-1].name.o+namebase) == 0)) ! 82: ; ! 83: } ! 84: if(from == inext) ! 85: *to++ = from[-1]; ! 86: inext = to; ! 87: j = inext-inodebase; ! 88: sprint(buf, "/usr/worm/tmp/%s", s.vol_id); ! 89: if((fd = creat(buf, 0666)) < 0){ ! 90: perror(buf); ! 91: exit(1); ! 92: } ! 93: /**/ ! 94: for(from = inodebase; from < inext; from++){ ! 95: register char *p = from->name.o+namebase; ! 96: if(strcmp(p, "v10927") >= 0) goto big; ! 97: if(strcmp(p, "v10926") < 0) goto small; ! 98: if(strcmp(p, "v10926") == 0) goto big; ! 99: while(*p++ != '/'); ! 100: if(atoi(p) > 90){ ! 101: big: ! 102: from->block += 54695; ! 103: } else { ! 104: small: ! 105: from->block++; ! 106: } ! 107: } ! 108: /**/ ! 109: ni = j; ! 110: nc = cnext-namebase; ! 111: write(fd, (char *)&s.ctime, 4); ! 112: write(fd, (char *)&ni, 4); ! 113: write(fd, (char *)inodebase, (int)ni*sizeof(Inode)); ! 114: write(fd, (char *)&nc, 4); ! 115: write(fd, namebase, (int)nc); ! 116: exit(0); ! 117: } ! 118: ! 119: usage() ! 120: { ! 121: fprint(2, "Usage: worm tmpdir [-fdevice] vol_id\n"); ! 122: exit(2); ! 123: } ! 124: ! 125: cmp(a, b) ! 126: Inode *a, *b; ! 127: { ! 128: return(strcmp(namebase+a->name.o, namebase+b->name.o)); ! 129: } ! 130: ! 131: char * ! 132: vlk(s) ! 133: register Superblock *s; ! 134: { ! 135: register Inode *i; ! 136: short fd = s->fd; ! 137: register long j; ! 138: long blk = -1; /* shouldn't be accessed first time through */ ! 139: char *b; ! 140: long nb; ! 141: Inode *iend; ! 142: static char buf[64]; ! 143: ! 144: if((b = malloc(s->blocksize)) == 0){ ! 145: sprint(buf, "couldn't malloc buffer (%d bytes)", s->blocksize); ! 146: return(buf); ! 147: } ! 148: for(;;){ ! 149: if(s->magic != SMAGIC){ ! 150: fprint(2, "bad Superblock at %ld\n", blk); ! 151: exit(1); ! 152: } ! 153: if(s->ninodes){ ! 154: nb = (s->ninodes+IPERB-1)/IPERB; ! 155: Seek(s, s->binodes); ! 156: if(Read(s, (char *)inext, nb)) ! 157: goto skip; ! 158: j = cnext-namebase; ! 159: for(i = inext, iend = i+s->ninodes; i < iend; i++) ! 160: i->name.o += j; ! 161: inext += s->ninodes; ! 162: nb = (s->ninochars+s->blocksize-1)/s->blocksize; ! 163: if(Read(s, cnext, nb)) ! 164: goto skip; ! 165: cnext += (s->ninochars+1)&~1; ! 166: } ! 167: skip: ! 168: blk = s->nextsb; ! 169: Seek(s, blk); ! 170: if(Read(s, b, 1L)) ! 171: break; ! 172: *s = *((Superblock *)b); ! 173: s->fd = fd; ! 174: if(s->myblock == 0) ! 175: s->myblock = blk; ! 176: } ! 177: free(b); ! 178: return((char *)0); ! 179: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.