Annotation of cci/sys/stand/fastcopy.c, revision 1.1

1.1     ! root        1: /*     fastcopy.c */
        !             2: 
        !             3: #define        BSIZE   1024
        !             4: #define FACTOR 32      /* 32k bytes in one i/o */
        !             5: 
        !             6: char   buffer[BSIZE * FACTOR];
        !             7: 
        !             8: main()
        !             9: {
        !            10:        char            in_dev[50];
        !            11:        char            out_dev[50];
        !            12:        char            blocks[50];
        !            13:        register int    input;
        !            14:        register int    output;
        !            15:        register int    count;
        !            16:        register int    firstread = 1;
        !            17:        register int    blk_siz = BSIZE * FACTOR;
        !            18:        register int    blk_num = 0;
        !            19:        register int    read_count = 0;
        !            20:        register int    write_count = 0;
        !            21:        register int    transfers = 0;
        !            22: 
        !            23:        in_dev[0] = 0;
        !            24:        out_dev[0] = 0;
        !            25:        blocks[0] = 0;
        !            26:        for(;;) {
        !            27:                /* get input and output devices */
        !            28:                printf("Source device : ");
        !            29:                gets(in_dev);
        !            30:                if((input = open(in_dev, 0)) > 0)
        !            31:                        break;
        !            32:                printf("Cannot open input file '%s'\n", in_dev);
        !            33:        }
        !            34: 
        !            35:        for(;;) {
        !            36:                printf("Copy to device : ");
        !            37:                gets(out_dev);
        !            38:                if((output = open(out_dev, 1)) > 0)
        !            39:                        break;
        !            40:                printf("Cannot open output file '%s'\n", out_dev);
        !            41:        }
        !            42: 
        !            43:        for(;;) {
        !            44:                printf("Number of blocks : ");
        !            45:                gets(blocks);
        !            46:                count = number(blocks);
        !            47:                if(count > 0)
        !            48:                        break;
        !            49:        }
        !            50:        printf("\nCopy %d blocks from %s to %s\n", count, in_dev, out_dev);
        !            51:        do {    
        !            52:                if ((transfers > 0) && !(transfers % 25))
        !            53:                        printf("%d blocks\n", blk_num);
        !            54:                transfers++;
        !            55:                read_count = read(input, buffer,
        !            56:                    ((count*BSIZE) > blk_siz) ? blk_siz : count*BSIZE);
        !            57:                if (firstread) {
        !            58:                        if (read_count != blk_siz) {
        !            59:                                blk_siz = read_count;
        !            60:                        }
        !            61:                        firstread = 0;
        !            62:                        printf("Block size from input = %d bytes\n", blk_siz);
        !            63:                }
        !            64:                if (read_count > 0) {
        !            65:                        if (read_count != blk_siz)
        !            66:                                printf("Short read!  Block %d: %d read, %d bytes requested\n", blk_num, read_count, blk_siz);
        !            67:                        write_count = write(output, buffer, read_count);
        !            68:                        if (write_count != read_count)
        !            69:                                printf("Short write!  Block %d: %d bytes written of %d bytes possible\n", blk_num, write_count, read_count);
        !            70:                        count -= read_count / BSIZE;
        !            71:                        blk_num += read_count / BSIZE;
        !            72:                }
        !            73:        } while((read_count > 0) && (write_count > 0) && (count > 0));
        !            74:        printf ("Total of %d blocks copied\n", blk_num);
        !            75:        close(input);
        !            76:        close(output);
        !            77: }
        !            78: 
        !            79: int number (response)
        !            80: char *response;
        !            81: {
        !            82:        int     total;
        !            83:        
        !            84:        total = 0;
        !            85:        while (*response == ' ' || *response == '\t') response++;
        !            86:        while (*response >= '0' && *response <= '9') {
        !            87:                total = total * 10 + (*response - '0');
        !            88:                response++;
        !            89:        }
        !            90:        return (total);
        !            91: }

unix.superglobalmegacorp.com

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