126179Ssklower /*
2*26270Ssklower * Copyright (c) 1986 MICOM-Interlan, Inc., Boxborough Mass.
3*26270Ssklower * All rights reserved. The Berkeley software License Agreement
4*26270Ssklower * specifies the terms and conditions for redistribution.
526179Ssklower *
626179Ssklower */
726179Ssklower #ifndef lint
826179Ssklower char copyright[] =
9*26270Ssklower "@(#) Copyright (c) 1986 MICOM-Interlan, Inc., Boxborough Mass.\n\
1026179Ssklower All rights reserved.\n";
1126179Ssklower #endif not lint
1226179Ssklower
1326179Ssklower #ifndef lint
14*26270Ssklower static char sccsid[] = "@(#)npdump.c 6.2 (Berkeley) 02/20/86";
1526179Ssklower #endif not lint
1626179Ssklower
1726179Ssklower #include <stdio.h>
1826179Ssklower #include <sys/file.h>
1926179Ssklower #include "npcmd.h"
2026179Ssklower #include <sys/ioctl.h>
2126179Ssklower
2226179Ssklower extern int errno;
2326179Ssklower
2426179Ssklower #define IMAGESIZE (1024 * 256)
2526179Ssklower
main(argc,argv)2626179Ssklower main(argc,argv)
2726179Ssklower int argc;
2826179Ssklower char **argv;
2926179Ssklower {
3026179Ssklower
3126179Ssklower int totalread; /* Total byte count of device reads */
3226179Ssklower int ed; /* Device's file descriptor */
3326179Ssklower int fd; /* Dumpfile device descriptor */
3426179Ssklower int nread; /* Value returned from read() call */
3526179Ssklower int nwritten; /* Value returned from write() call */
3626179Ssklower char *fname;
3726179Ssklower char ibuf[1024];
3826179Ssklower char *devname = "/dev/np00";
3926179Ssklower
4026179Ssklower
4126179Ssklower switch (argc) {
4226179Ssklower case 3:
4326179Ssklower /* Pathname for device to be dumped */
4426179Ssklower devname = argv[2];
4526179Ssklower case 2:
4626179Ssklower /* Name of the dump file */
4726179Ssklower fname = argv[1];
4826179Ssklower break;
4926179Ssklower default:
5026179Ssklower printf("usage: npdump dumpfile [device]\n");
5126179Ssklower exit(1);
5226179Ssklower }
5326179Ssklower
5426179Ssklower /* Open the device to be dumped */
5526179Ssklower
5626179Ssklower if ((ed = open(devname, O_RDWR)) == -1) {
5726179Ssklower char fullpath[50];
5826179Ssklower (void) sprintf(fullpath, "/dev/%s", devname);
5926179Ssklower if ((ed = open(devname,O_RDWR)) == -1) {
6026179Ssklower fprintf(stderr,
6126179Ssklower "%s unable to open device %s errno = %d\n",
6226179Ssklower argv[0], devname, errno);
6326179Ssklower exit(2);
6426179Ssklower }
6526179Ssklower }
6626179Ssklower
6726179Ssklower /* Open/create the dump file */
6826179Ssklower
6926179Ssklower if ((fd = open(fname, O_RDWR | O_CREAT)) == -1) {
7026179Ssklower fprintf(stderr,"%s: unable to open file %s errno = %d\n",
7126179Ssklower argv[0], fname, errno);
7226179Ssklower exit(2);
7326179Ssklower }
7426179Ssklower
7526179Ssklower
7626179Ssklower /* Read from the device and write to the dump file */
7726179Ssklower
7826179Ssklower totalread = 0;
7926179Ssklower
8026179Ssklower while (totalread < IMAGESIZE) {
8126179Ssklower
8226179Ssklower if ((nread = read(ed,ibuf,1024)) > 0) {
8326179Ssklower
8426179Ssklower totalread += nread;
8526179Ssklower
8626179Ssklower nwritten = write(fd,ibuf,nread);
8726179Ssklower
8826179Ssklower if (nwritten != nread) {
8926179Ssklower fprintf(stderr,"Bad write to %s errno = %d\n",
9026179Ssklower argv[2],errno);
9126179Ssklower exit(7);
9226179Ssklower }
9326179Ssklower }
9426179Ssklower
9526179Ssklower else {
9626179Ssklower fprintf(stderr,"Bad read from %s errno = %d\n", argv[0],errno);
9726179Ssklower exit(7);
9826179Ssklower
9926179Ssklower }
10026179Ssklower }
10126179Ssklower
10226179Ssklower close(fd);
10326179Ssklower close(ed);
10426179Ssklower
10526179Ssklower exit(0);
10626179Ssklower }
107