1*25867Ssam /* devcopy.c 1.1 86/01/12 */
2*25867Ssam /* devcopy.c */
3*25867Ssam #define BSIZE 1024
4*25867Ssam char dev[50];
5*25867Ssam char disk[50];
6*25867Ssam char blocks[50] ;
7*25867Ssam int fsi;
8*25867Ssam int fso;
9*25867Ssam char buffer[BSIZE];
10*25867Ssam
main()11*25867Ssam main()
12*25867Ssam {
13*25867Ssam int j, c, i, n;
14*25867Ssam char buf[50];
15*25867Ssam int input, output;
16*25867Ssam
17*25867Ssam do {
18*25867Ssam printf("Source device : ");
19*25867Ssam gets(dev);
20*25867Ssam printf("Copy to device : ");
21*25867Ssam gets(disk);
22*25867Ssam printf("Number of blocks : ");
23*25867Ssam gets(blocks);
24*25867Ssam j = number(blocks);
25*25867Ssam input = open(dev, 0);
26*25867Ssam if (input <= 0) printf("Cannot open %s\n", dev);
27*25867Ssam output = open(disk, 1);
28*25867Ssam if (output <= 0) printf("Cannot open output\n", disk);
29*25867Ssam } while (input <= 0 || output <= 0);
30*25867Ssam
31*25867Ssam i = 0; /* Block number */
32*25867Ssam n = BSIZE;
33*25867Ssam while (n == BSIZE && i < j) {
34*25867Ssam if (i > 0 && (i%500 == 0) ) printf("%d blocks\n", i);
35*25867Ssam lseek (input, i*BSIZE, 0);
36*25867Ssam n = read (input, buffer, BSIZE);
37*25867Ssam if (n == BSIZE) {
38*25867Ssam lseek (output, i*BSIZE, 0);
39*25867Ssam n = write(output, buffer, BSIZE);
40*25867Ssam if (n != BSIZE) printf("Short write, block %d, %d bytes only\n",i,n);
41*25867Ssam i++;
42*25867Ssam }
43*25867Ssam else printf("Short read, block %d, %d bytes only\n",i,n);
44*25867Ssam }
45*25867Ssam printf ("Total of %d blocks copied\n",i);
46*25867Ssam }
47*25867Ssam
number(response)48*25867Ssam int number (response)
49*25867Ssam char *response;
50*25867Ssam {
51*25867Ssam int i, j;
52*25867Ssam
53*25867Ssam j = 0; /* Total */
54*25867Ssam while (*response == ' ' || *response == '\t') response++;
55*25867Ssam while (*response >= '0' && *response <= '9') {
56*25867Ssam j = j*10 + *response - '0';
57*25867Ssam response++;
58*25867Ssam }
59*25867Ssam return (j);
60*25867Ssam }
61