|
|
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: #include <signal.h>
9:
10: int lflag = 0;
11: int bflag = 0;
12:
13: main(argc, argv)
14: char **argv;
15: {
16: Superblock s;
17: register Inode *i;
18: Inode newi;
19: char *e;
20: char *dev = "/dev/worm0";
21: int c;
22: extern char *optarg;
23: extern int optind;
24: void pr();
25:
26: while((c = getopt(argc, argv, "lbf:")) != -1)
27: switch(c)
28: {
29: case 'f': dev = optarg; break;
30: case 'l': lflag = 1; break;
31: case 'b': bflag = 1; break;
32: case '?': usage();
33: }
34: dev = mapdev(dev);
35: if((s.fd = open(dev, 2)) < 0){
36: perror(dev);
37: exit(1);
38: }
39: if(e = openinode(&s, DO_INODE|SPIN_DOWN)){
40: fprint(2, "%s: %s\n", dev, e);
41: exit(1);
42: }
43: if(optind != argc-3)
44: usage();
45: if(strcmp(s.vol_id, argv[optind])){
46: fprint(2, "worm mv: vol_id mismatch: wanted %s, got %s\n", argv[optind], s.vol_id);
47: exit(1);
48: }
49: optind++;
50: if((i = inodeof(argv[optind])) == 0){
51: Fprint(2, "%s not found\n", argv[optind]);
52: exit(1);
53: }
54: optind++;
55: if(strlen(argv[optind]) < 1){
56: Fprint(2, "worm mv: destination name is null\n");
57: exit(1);
58: }
59: for(c = 1; c <= NSIG; c++)
60: signal(c, SIG_IGN);
61: ininit();
62: newi = *i;
63: i->block = -1;
64: inadd(&s, i);
65: newi.name.n = argv[optind];
66: inadd(&s, &newi);
67: if(inwrite(&s))
68: exit(1);
69: exit(0);
70: }
71:
72: usage()
73: {
74: fprint(2, "Usage: worm mv [-fdevice] vol_id from to\n");
75: exit(2);
76: }
77:
78: static Inode *inodes;
79: static long ip;
80: static long ninodes = 0;
81: static char *nameb;
82: static long np;
83: static long nnameb = 0;
84: static long nblocks;
85: #define IINC 1024
86: #define NINC (64*IINC)
87:
88: ininit()
89: {
90: if(nnameb == 0){
91: nameb = malloc((unsigned)(nnameb = NINC));
92: if(nameb == 0){
93: fprint(2, "wmv: malloc fail, %d bytes\n", nnameb);
94: exit(1);
95: }
96: }
97: np = 0;
98: if(ninodes == 0){
99: inodes = (Inode *)malloc(sizeof(Inode)*(unsigned)(ninodes = IINC));
100: if(inodes == 0){
101: fprint(2, "wmv: malloc fail, %d inodes %d bytes\n", ninodes, ninodes*sizeof(Inode));
102: exit(1);
103: }
104: }
105: ip = 0;
106: }
107:
108: inadd(s, i)
109: Superblock *s;
110: register Inode *i;
111: {
112: register long len;
113:
114: len = strlen(i->name.n)+1;
115: if(np+len > nnameb){
116: while(np+len > nnameb)
117: nnameb += NINC;
118: nameb = realloc(nameb, (unsigned)nnameb);
119: if(nameb == 0){
120: fprint(2, "wmv: realloc fail, %d bytes\n", nnameb);
121: exit(1);
122: }
123: }
124: strcpy(nameb+np, i->name.n);
125: i->name.o = np;
126: np += len;
127: if(ip == ninodes){
128: ninodes += IINC;
129: inodes = (Inode *)realloc((char *)inodes, (unsigned)ninodes*sizeof(Inode));
130: if(inodes == 0){
131: fprint(2, "wmv: realloc fail, %d inodes %d bytes\n", ninodes, ninodes*sizeof(Inode));
132: exit(1);
133: }
134: }
135: inodes[ip++] = *i;
136: }
137:
138: inwrite(s)
139: Superblock *s;
140: {
141: char *e;
142:
143: if(e = lkwri(s, inodes, ip, nameb, np, 0L)){
144: fprint(2, "%s\n", e);
145: return(1);
146: }
147: return(0);
148: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.