xref: /csrg-svn/old/np100/npdump.c (revision 26179)
1*26179Ssklower /*
2*26179Ssklower  * Copyright (c) 1986 MICOM-Interlan, Inc., Foxborough Mass.
3*26179Ssklower  *
4*26179Ssklower  * This software is furnished under a license and may only be used
5*26179Ssklower  * or copied in accordance with the terms of that license.
6*26179Ssklower  *
7*26179Ssklower  */
8*26179Ssklower #ifndef lint
9*26179Ssklower char copyright[] =
10*26179Ssklower "@(#) Copyright (c) 1986 MICOM-Interlan, Inc., Foxborough Mass.\n\
11*26179Ssklower  All rights reserved.\n";
12*26179Ssklower #endif not lint
13*26179Ssklower 
14*26179Ssklower #ifndef lint
15*26179Ssklower static char sccsid[] = "@(#)npdump.c	6.1 (Berkeley) 02/14/86";
16*26179Ssklower #endif not lint
17*26179Ssklower 
18*26179Ssklower #include <stdio.h>
19*26179Ssklower #include <sys/file.h>
20*26179Ssklower #include "npcmd.h"
21*26179Ssklower #include <sys/ioctl.h>
22*26179Ssklower 
23*26179Ssklower extern int errno;
24*26179Ssklower 
25*26179Ssklower #define IMAGESIZE (1024 * 256)
26*26179Ssklower 
27*26179Ssklower main(argc,argv)
28*26179Ssklower int argc;
29*26179Ssklower char **argv;
30*26179Ssklower {
31*26179Ssklower 
32*26179Ssklower 	int	totalread;		/* Total byte count of device reads */
33*26179Ssklower 	int	ed;			/* Device's file descriptor */
34*26179Ssklower 	int	fd;			/* Dumpfile device descriptor */
35*26179Ssklower 	int	nread;			/* Value returned from read() call */
36*26179Ssklower 	int 	nwritten;		/* Value returned from write() call */
37*26179Ssklower 	char	*fname;
38*26179Ssklower 	char	ibuf[1024];
39*26179Ssklower 	char	*devname = "/dev/np00";
40*26179Ssklower 
41*26179Ssklower 
42*26179Ssklower 	switch (argc) {
43*26179Ssklower 	case 3:
44*26179Ssklower 		/* Pathname for device to be dumped */
45*26179Ssklower 		devname = argv[2];
46*26179Ssklower 	case 2:
47*26179Ssklower 		/* Name of the dump file */
48*26179Ssklower 		fname = argv[1];
49*26179Ssklower 		break;
50*26179Ssklower 	default:
51*26179Ssklower 		printf("usage: npdump dumpfile [device]\n");
52*26179Ssklower 		exit(1);
53*26179Ssklower 	}
54*26179Ssklower 
55*26179Ssklower 	/* Open the device to be dumped */
56*26179Ssklower 
57*26179Ssklower 	if ((ed = open(devname, O_RDWR)) == -1) {
58*26179Ssklower 		char fullpath[50];
59*26179Ssklower 		(void) sprintf(fullpath, "/dev/%s", devname);
60*26179Ssklower 		if ((ed = open(devname,O_RDWR)) == -1) {
61*26179Ssklower 			fprintf(stderr,
62*26179Ssklower 				"%s unable to open device %s errno = %d\n",
63*26179Ssklower 				argv[0], devname, errno);
64*26179Ssklower 			exit(2);
65*26179Ssklower 		}
66*26179Ssklower 	}
67*26179Ssklower 
68*26179Ssklower 	/* Open/create the dump file */
69*26179Ssklower 
70*26179Ssklower 	if ((fd = open(fname, O_RDWR | O_CREAT)) == -1) {
71*26179Ssklower 		fprintf(stderr,"%s: unable to open file %s errno = %d\n",
72*26179Ssklower 		    argv[0], fname, errno);
73*26179Ssklower 		exit(2);
74*26179Ssklower 	}
75*26179Ssklower 
76*26179Ssklower 
77*26179Ssklower 	/* Read from the device and write to the dump file */
78*26179Ssklower 
79*26179Ssklower 	totalread = 0;
80*26179Ssklower 
81*26179Ssklower 	while (totalread < IMAGESIZE) {
82*26179Ssklower 
83*26179Ssklower 		if ((nread = read(ed,ibuf,1024)) > 0) {
84*26179Ssklower 
85*26179Ssklower 			totalread += nread;
86*26179Ssklower 
87*26179Ssklower 			nwritten = write(fd,ibuf,nread);
88*26179Ssklower 
89*26179Ssklower 			if (nwritten != nread) {
90*26179Ssklower 				fprintf(stderr,"Bad write to %s errno = %d\n",
91*26179Ssklower 			    	argv[2],errno);
92*26179Ssklower 				exit(7);
93*26179Ssklower 			}
94*26179Ssklower 		}
95*26179Ssklower 
96*26179Ssklower 		else {
97*26179Ssklower 			fprintf(stderr,"Bad read from %s errno = %d\n", argv[0],errno);
98*26179Ssklower 			exit(7);
99*26179Ssklower 
100*26179Ssklower 		}
101*26179Ssklower 	}
102*26179Ssklower 
103*26179Ssklower 	close(fd);
104*26179Ssklower 	close(ed);
105*26179Ssklower 
106*26179Ssklower 	exit(0);
107*26179Ssklower }
108