Annotation of 43BSD/contrib/np100/npdump.c, revision 1.1

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

unix.superglobalmegacorp.com

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