|
|
1.1 root 1: #include <libc.h>
2: #include "sym.h"
3: #include "worm.h"
4:
5: main(argc, argv)
6: char **argv;
7: {
8: Superblock s;
9: char *e;
10: Inode *i;
11: int c;
12: char *dev = "/dev/worm0";
13: extern char *optarg;
14: extern int optind;
15:
16: while((c = getopt(argc, argv, "f:")) != -1)
17: switch(c)
18: {
19: case 'f': dev = optarg; break;
20: case '?': usage();
21: }
22: if(optind+2 != argc)
23: usage();
24: dev = mapdev(dev);
25: if((s.fd = open(dev, 0)) < 0){
26: perror(dev);
27: exit(1);
28: }
29: if(e = openinode(&s, DO_INODE|SPIN_DOWN)){
30: fprint(2, "%s: %s\n", dev, e);
31: exit(1);
32: }
33: if(strcmp(s.vol_id, argv[optind])){
34: fprint(2, "vol_id mismatch: wanted %s, got %s\n", argv[optind], s.vol_id);
35: exit(1);
36: }
37: if(i = inodeof(argv[++optind]))
38: c = pr(&s, i);
39: else {
40: fprint(2, "wcat: can't find %s\n", argv[optind]);
41: c = 1;
42: }
43: exit(c);
44: }
45:
46: usage()
47: {
48: fprint(2, "Usage: worm cat [-fdevice] vol_id file\n");
49: exit(1);
50: }
51:
52: pr(s, i)
53: Superblock *s;
54: register Inode *i;
55: {
56: char b[BIGBLOCK];
57: register long len, n;
58: long nb;
59: int fd;
60:
61: fd = 1;
62: nb = sizeof b / s->blocksize;
63: Seek(s, i->block);
64: for(n = i->nbytes, len = nb*s->blocksize; n > 0;){
65: if(len > n){
66: len = n;
67: nb = (len+s->blocksize-1)/s->blocksize;
68: }
69: Read(s, b, nb);
70: if(write(fd, b, (int)len) != len){
71: perror("write");
72: return(1);
73: }
74: n -= len;
75: }
76: close(fd);
77: return(0);
78: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.