File:  [Power 6/32 Unix Tahoe 4.2BSD] / cci / sys / stand / devcopy.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Sun Jul 28 12:24:19 2019 UTC (6 years, 11 months ago) by root
Branches: bsd, MAIN
CVS tags: v12b, v121, HEAD
Power 6/32 Unix version 1.2b

/*	devcopy.c */
#define	BSIZE	1024
char dev[50];
char disk[50];
char blocks[50] ;
int	fsi;
int	fso;
char	buffer[BSIZE];

main()
{
	int j, c, i, n;
	char buf[50];
	int input, output;

	do {
		printf("Source device : ");
		gets(dev);
		printf("Copy to device : ");
		gets(disk);
		printf("Number of blocks : ");
		gets(blocks);
		j = number(blocks);
		input = open(dev, 0);
		if (input <= 0) printf("Cannot open %s\n", dev);
		output = open(disk, 1);
		if (output <= 0) printf("Cannot open output\n", disk);
	} while (input <= 0 || output <= 0);

	i = 0;	/* Block number */
	n = BSIZE;
	while (n == BSIZE && i < j) {
		if (i > 0 && (i%500 == 0) ) printf("%d blocks\n", i);
		lseek (input, i*BSIZE, 0);
		n = read (input, buffer, BSIZE);
		if (n == BSIZE) {
			lseek (output, i*BSIZE, 0);
			n = write(output, buffer, BSIZE);
			if (n != BSIZE) printf("Short write, block %d, %d bytes only\n",i,n);
			i++;
		}
		else printf("Short read, block %d, %d bytes only\n",i,n);
	}
	printf ("Total of %d blocks copied\n",i);
}

int number (response)
char *response;
{
	int	i, j;
	
	j = 0;	/* Total */
	while (*response == ' ' || *response == '\t') response++;
	while (*response >= '0' && *response <= '9') {
		j = j*10 + *response - '0';
		response++;
	}
	return (j);
}

unix.superglobalmegacorp.com

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