Annotation of researchv10no/cmd/hideblock.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * hideblock filesystem(not raw) file b1 b2 ...
        !             3:  *  -- puts blocks in named file in file system.
        !             4:  */
        !             5: 
        !             6: #include <stdio.h>
        !             7: #include <sys/param.h>
        !             8: #include <sys/ino.h>
        !             9: #include <sys/stat.h>
        !            10: 
        !            11: #ifdef BITFS
        !            12: #define        Bsize   BSIZE(dev)
        !            13: #define        Inopb   INOPB(dev)
        !            14: #else
        !            15: #define        Bsize   BSIZE
        !            16: #define        Inopb   INOPB
        !            17: #endif
        !            18: 
        !            19: int    fd;
        !            20: struct dinode di;
        !            21: ino_t  inode;
        !            22: char   cntflag;
        !            23: long   count;
        !            24: long   size;
        !            25: dev_t  dev;
        !            26: int    writing;
        !            27: 
        !            28: main(argc,argv)
        !            29: char **argv;
        !            30: {
        !            31:        long pos;
        !            32:        int i,j;
        !            33:        long addr[13];
        !            34:        char *file;
        !            35:        struct stat s;
        !            36: 
        !            37:        if(argc<3) {
        !            38:                printf("usage: %s non-raw-fs file b1 b2 ... (512)\n", argv[0]);
        !            39:                exit(1);
        !            40:        }
        !            41:        writing = argc>3;
        !            42:        if ((fd=open(argv[1], writing?2:0)) < 0) {
        !            43:                perror(argv[1]);
        !            44:                printf("%s couldn't open %s\n", argv[0], argv[1]);
        !            45:                exit(1);
        !            46:        }
        !            47:        if (stat(argv[2], &s) < 0) {
        !            48:                printf("%s: %s must exist\n", argv[0], argv[2]);
        !            49:                exit(1);
        !            50:        }
        !            51:        if (s.st_size != 0 && argc>3) {
        !            52:                printf("%s: %s must be 0 length\n", argv[0], argv[2]);
        !            53:                exit(1);
        !            54:        }
        !            55:        inode = s.st_ino;
        !            56:        dev = s.st_dev;
        !            57:        pos = ((long)inode-1)/Inopb*Bsize+((inode-1)%Inopb)*sizeof(struct dinode);
        !            58:        pos += 2*Bsize;
        !            59:        lseek(fd, pos, 0);
        !            60:        bread(fd, &di, sizeof(di));
        !            61:        l3tol(addr, di.di_addr, 13);
        !            62:        for (i = 0; i < 10; i++) {
        !            63:                if (addr[i])
        !            64:                        printf(" %ld", addr[i]*(Bsize/512));
        !            65:                else
        !            66:                        break;
        !            67:        }
        !            68:        argc -= 2;
        !            69:        argv += 2;
        !            70:        while (argc > 1) {
        !            71:                if (i >= 10) {
        !            72:                        printf("\nhideblock: at most 10 blocks\n");
        !            73:                        break;
        !            74:                }
        !            75:                addr[i] = atol(argv[1])/(Bsize/512);
        !            76:                printf(" %ld", addr[i]*(Bsize/512));
        !            77:                i++;
        !            78:                argc--;
        !            79:                argv++;
        !            80:        }
        !            81:        printf("\n");
        !            82:        if (writing) {
        !            83:                ltol3(di.di_addr, addr, 13);
        !            84:                lseek(fd, pos, 0);
        !            85:                bwrite(fd, &di, sizeof(di));
        !            86:        }
        !            87:        return(0);
        !            88: }
        !            89: 
        !            90: bread(f, b, c)
        !            91: char *b;
        !            92: {
        !            93:        register n;
        !            94: 
        !            95:        n = read(f, b, c);
        !            96:        if (n!=c)
        !            97:                printf("bad read on %d: %d\n", f, n);
        !            98: }
        !            99: 
        !           100: bwrite(f, b, c)
        !           101: char *b;
        !           102: {
        !           103:        register n;
        !           104: 
        !           105:        n = write(f, b, c);
        !           106:        if (n!=c)
        !           107:                printf("bad write on %d: %d\n", f, n);
        !           108: }

unix.superglobalmegacorp.com

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