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

1.1     ! root        1: #include "stdio.h"
        !             2: extern int errno;
        !             3: 
        !             4: char buf[512];
        !             5: 
        !             6: main(argc, argv)
        !             7: char **argv;
        !             8: {      int fd, n, i, j;
        !             9:        short *p = (short *) buf;
        !            10:        if(argc != 3) {
        !            11:                fprintf(stderr, "%s raw-disk sn\n", argv[0]);
        !            12:                exit(0);
        !            13:        }
        !            14:        fd = open(argv[1], 2);
        !            15:        n = atoi(argv[2]);
        !            16:        if(fd < 0 || lseek(fd, n*512, 0) < 0) {
        !            17:                perror("begin");
        !            18:                exit(1);
        !            19:        }
        !            20: foo:
        !            21:        lseek(fd, n*512, 0);
        !            22:        if (read(fd, buf, sizeof(buf)) != sizeof(buf))
        !            23:                perror("read");
        !            24:        for(i = 0; i < 16; i++) {
        !            25:                for(j = 0; j < 16; j++)
        !            26:                        printf("%o ", p[16 * i + j] & 0xffff);
        !            27:                putchar('\n');
        !            28:        }
        !            29:        printf("write?\n");
        !            30:        if((i = getchar()) == 'y') {
        !            31: wr:
        !            32:                lseek(fd, n*512, 0);
        !            33:                if (write(fd, buf, sizeof(buf)) != sizeof(buf))
        !            34:                        perror("write");
        !            35:                (void) getchar();
        !            36:                goto foo;
        !            37:        }
        !            38:        else if(i == 'c') {
        !            39:                for(j = 0; j < 512; j++)
        !            40:                        buf[j] = 0;
        !            41:                goto wr;
        !            42:        }
        !            43: }

unix.superglobalmegacorp.com

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