Annotation of coherent/d/bin/check/clri.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Clear inodes.
        !             3:  */
        !             4: #include <sys/filsys.h>
        !             5: #include <sys/ino.h>
        !             6: #include <canon.h>
        !             7: #include <stdio.h>
        !             8: 
        !             9: 
        !            10: union {
        !            11:        struct filsys   filsys_;
        !            12:        struct dinode   dinode_[INOPB];
        !            13: } buff;
        !            14: #define        fs      buff.filsys_
        !            15: #define        di      buff.dinode_
        !            16: 
        !            17: unsigned       isize;
        !            18: 
        !            19: 
        !            20: main(argc, argv)
        !            21: register char **argv;
        !            22: {
        !            23:        register fd;
        !            24: 
        !            25:        if (argc < 3)
        !            26:                fatal("usage: clri dev ino ...");
        !            27:        fd = open(*++argv, 2);
        !            28:        if (fd < 0)
        !            29:                fatal("can't open %s", *argv);
        !            30:        lseek(fd, (long)SUPERI*BSIZE, 0);
        !            31:        if (read(fd, (char *)&fs, sizeof fs) != sizeof fs)
        !            32:                fatal("superblock read error");
        !            33:        isize = fs.s_isize;
        !            34:        canint(isize);
        !            35: 
        !            36:        while (*++argv)
        !            37:                clri(fd, atoi(*argv));
        !            38: 
        !            39:        return (0);
        !            40: }
        !            41: 
        !            42: 
        !            43: clri(fd, ino)
        !            44: register fd;
        !            45: ino_t  ino;
        !            46: {
        !            47:        register bn;
        !            48: 
        !            49:        bn = iblockn(ino);
        !            50:        if (bn >= isize)
        !            51:                fatal("inode %u out of range", ino);
        !            52:        lseek(fd, (long)bn*BSIZE, 0);
        !            53:        if (read(fd, (char *)di, sizeof di) != sizeof di)
        !            54:                fatal("read error on inode %u", ino);
        !            55:        clear(&di[iblocko(ino)]);
        !            56:        lseek(fd, (long)bn*BSIZE, 0);
        !            57:        if (write(fd, (char *)di, sizeof di) != sizeof di)
        !            58:                fatal("write error on inode %u", ino);
        !            59: }
        !            60: 
        !            61: 
        !            62: clear(dp)
        !            63: struct dinode *dp;
        !            64: {
        !            65:        register char *p;
        !            66:        register i;
        !            67: 
        !            68:        p = dp;
        !            69:        i = sizeof *dp;
        !            70:        do {
        !            71:                *p++ = 0;
        !            72:        } while (--i);
        !            73: }
        !            74: 
        !            75: 
        !            76: fatal(arg0)
        !            77: char *arg0;
        !            78: {
        !            79: 
        !            80:        fprintf(stderr, "clri: %r\n", &arg0);
        !            81:        exit(1);
        !            82: }

unix.superglobalmegacorp.com

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