Annotation of researchv10no/cmd/worm/poot.c, revision 1.1

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 buf[1024];
        !            10:        char *e;
        !            11:        Inode *i;
        !            12:        int c;
        !            13:        char *com = 0;
        !            14:        char *dev = "/dev/worm0";
        !            15:        extern char *optarg;
        !            16:        extern int optind;
        !            17: 
        !            18:        while((c = getopt(argc, argv, "f:c:")) != -1)
        !            19:                switch(c)
        !            20:                {
        !            21:                case 'c':       com = optarg; break;
        !            22:                case 'f':       dev = optarg; break;
        !            23:                case '?':       usage();
        !            24:                }
        !            25:        if(optind+2 != argc)
        !            26:                usage();
        !            27:        dev = mapdev(dev);
        !            28:        if((s.fd = open(dev, 2)) < 0){
        !            29:                perror(dev);
        !            30:                exit(1);
        !            31:        }
        !            32:        if(e = openinode(&s, SPIN_DOWN)){
        !            33:                fprint(2, "%s: %s\n", dev, e);
        !            34:                exit(1);
        !            35:        }
        !            36:        if(strcmp(s.vol_id, argv[optind])){
        !            37:                fprint(2, "vol_id mismatch: wanted %s, got %s\n", argv[optind], s.vol_id);
        !            38:                exit(1);
        !            39:        }
        !            40:        if(s.version != VBTREE){
        !            41:                fprint(2, "poot: %s must be a btree disk\n", s.vol_id);
        !            42:                exit(1);
        !            43:        }
        !            44:        memset(buf, sizeof buf, 0);
        !            45:        memset(s.vol_id, sizeof s.vol_id, 0);
        !            46:        strcpy(s.vol_id, argv[++optind]);
        !            47:        if(com){
        !            48:                memset(s.comment, sizeof s.comment, 0);
        !            49:                strcpy(s.comment, com);
        !            50:        }
        !            51:        memcpy(buf, &s, 1024);
        !            52:        lseek(s.fd, 0, 0);
        !            53:        if(write(s.fd, buf, 1024) != 1024){
        !            54:                perror("write of new superblock");
        !            55:                exit(1);
        !            56:        }
        !            57:        exit(0);
        !            58: }
        !            59: 
        !            60: usage()
        !            61: {
        !            62:        fprint(2, "Usage: poot [-fdevice] [-ccnewcomment] vol_id new_vol_id\n");
        !            63:        exit(1);
        !            64: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.