Annotation of researchv10no/cmd/clri.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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