Annotation of 40BSD/cmd/clri.c, revision 1.1.1.1

1.1       root        1: static char *sccsid = "@(#)clri.c      4.1 (Berkeley) 10/1/80";
                      2: /*
                      3:  * clri filsys inumber ...
                      4:  */
                      5: 
                      6: #include <sys/param.h>
                      7: #include <sys/ino.h>
                      8: 
                      9: #define ISIZE  (sizeof(struct dinode))
                     10: #define        NI      (BSIZE/ISIZE)
                     11: struct ino
                     12: {
                     13:        char    junk[ISIZE];
                     14: };
                     15: struct ino     buf[NI];
                     16: int    status;
                     17: 
                     18: main(argc, argv)
                     19: char *argv[];
                     20: {
                     21:        register i, f;
                     22:        unsigned n;
                     23:        int j, k;
                     24:        long off;
                     25: 
                     26:        if(argc < 3) {
                     27:                printf("usage: clri filsys inumber ...\n");
                     28:                exit(4);
                     29:        }
                     30:        f = open(argv[1], 2);
                     31:        if(f < 0) {
                     32:                printf("cannot open %s\n", argv[1]);
                     33:                exit(4);
                     34:        }
                     35:        for(i=2; i<argc; i++) {
                     36:                if(!isnumber(argv[i])) {
                     37:                        printf("%s: is not a number\n", argv[i]);
                     38:                        status = 1;
                     39:                        continue;
                     40:                }
                     41:                n = atoi(argv[i]);
                     42:                if(n == 0) {
                     43:                        printf("%s: is zero\n", argv[i]);
                     44:                        status = 1;
                     45:                        continue;
                     46:                }
                     47:                off = itod(n) * BSIZE;
                     48:                lseek(f, off, 0);
                     49:                if(read(f, (char *)buf, BSIZE) != BSIZE) {
                     50:                        printf("%s: read error\n", argv[i]);
                     51:                        status = 1;
                     52:                }
                     53:        }
                     54:        if(status)
                     55:                exit(status);
                     56:        for(i=2; i<argc; i++) {
                     57:                n = atoi(argv[i]);
                     58:                printf("clearing %u\n", n);
                     59:                off = itod(n) * BSIZE;
                     60:                lseek(f, off, 0);
                     61:                read(f, (char *)buf, BSIZE);
                     62:                j = itoo(n);
                     63:                for(k=0; k<ISIZE; k++)
                     64:                        buf[j].junk[k] = 0;
                     65:                lseek(f, off, 0);
                     66:                write(f, (char *)buf, BSIZE);
                     67:        }
                     68:        exit(status);
                     69: }
                     70: 
                     71: isnumber(s)
                     72: char *s;
                     73: {
                     74:        register c;
                     75: 
                     76:        while(c = *s++)
                     77:                if(c < '0' || c > '9')
                     78:                        return(0);
                     79:        return(1);
                     80: }

unix.superglobalmegacorp.com

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