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