|
|
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: extern char *optarg;
14: extern int optind;
15: extern long atol();
16:
17: while((c = getopt(argc, argv, "vF:f:")) != -1)
18: switch(c)
19: {
20: case 'f': dev = optarg; break;
21: case 'F': nf = atol(optarg); break;
22: case 'v': vflag = 1; break;
23: case '?': usage();
24: }
25: if(optind < argc){
26: vol_id = argv[optind++];
27: if(optind != argc)
28: usage();
29: }
30: dev = mapdev(dev);
31: if((s.fd = open(dev, 0)) < 0){
32: if(!vol_id && !nf)
33: perror(dev);
34: exit(2);
35: }
36: if(e = openinode(&s, SPIN_DOWN)){
37: if(!vol_id && !nf)
38: fprint(2, "%s: %s\n", dev, e);
39: exit(2);
40: }
41: if(nf){
42: if(vol_id)
43: if(strcmp(vol_id, s.vol_id) != 0)
44: exit(1);
45: exit(s.nfree >= nf? 0:3);
46: }
47: if(vol_id)
48: exit(strcmp(vol_id, s.vol_id) != 0);
49: if(vflag){
50: Fprint(1, "%s: %s, %s\t%ldx%uhd blocks, %ld (=%.1fMB) free, zero=%ld this_sb@%ld next_sb@%ld\n",
51: s.vol_id, s.comment, ctime(&s.ctime), s.nblocks, s.blocksize,
52: s.nfree, s.nfree*(double)s.blocksize*1e-6, s.zero, s.myblock, s.nextsb);
53: } else
54: Fprint(1, "%s: %.0f%% used (%.1fMB free)\n", s.vol_id,
55: s.nextffree*100.0/s.nblocks, s.nfree*(double)s.blocksize*1e-6);
56: exit(0);
57: }
58:
59: usage()
60: {
61: print("Usage: worm stat [-v] [-fdevice] [-Fnfree] [vol_id]\n");
62: exit(2);
63: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.