Home | History | Annotate | Line # | Download | only in rawwrite
rawwrite.c revision 1.1.1.1
      1 /*	$NetBSD: rawwrite.c,v 1.1.1.1 1996/01/07 20:57:03 leo Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1995 Leo Weppelman.
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed by Leo Weppelman.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #include <osbind.h>
     34 #include <stdio.h>
     35 #include <fcntl.h>
     36 #include <string.h>
     37 
     38 #define	SECT_SIZE	512		/* Sector size			*/
     39 #define	NSECT_DD	18		/* Sectors per track 720Kb	*/
     40 #define	NSECT_HD	36		/* Sectors per track 1.44Mb	*/
     41 #define	NTRK		80		/* Number of tracks		*/
     42 
     43 static void usage();
     44 static void brwrite();
     45 
     46 char	buf[NSECT_HD * SECT_SIZE];
     47 int	vflag = 0;
     48 char	*progname;
     49 
     50 main(argc, argv)
     51 int	argc;
     52 char	*argv[];
     53 {
     54 	extern	int	optind;
     55 	extern	char	*optarg;
     56 	int		ch;
     57 	char		*infile;
     58 	int		fd;
     59 	int		i;
     60 	int		nsect;
     61 
     62 	progname = argv[0];
     63 	while ((ch = getopt(argc, argv, "v")) != EOF) {
     64 		switch(ch) {
     65 			case 'v':
     66 				vflag = 1;
     67 				break;
     68 			default :
     69 				usage();
     70 				break;
     71 		}
     72 	}
     73 	if(optind >= argc)
     74 		usage();
     75 
     76 	infile = argv[optind];
     77 	nsect  = NSECT_DD;
     78 
     79 	if((fd = open(infile, O_RDONLY)) < 0) {
     80 		fprintf(stderr, "%s: Cannot open '%s'\n", progname, infile);
     81 		exit(1);
     82 	}
     83 
     84 	for(i = 0; i < NTRK; i++) {
     85 		if(read(fd, buf, nsect * SECT_SIZE) != (nsect * SECT_SIZE)) {
     86 		    fprintf(stderr, "\nRead error on '%s'\n", progname, infile);
     87 		    exit(1);
     88 		}
     89 		if(vflag) {
     90 			if(i && !(i % 40))
     91 				printf("\n");
     92 			fprintf(stderr, ".");
     93 		}
     94 		brwrite(buf, nsect * i, nsect);
     95 	}
     96 	close(fd);
     97 	if(vflag)
     98 		printf("\n");
     99 }
    100 
    101 static void brwrite(buf, blk, cnt)
    102 char	*buf;
    103 int	blk, cnt;
    104 {
    105 	if(Rwabs(3, buf, cnt, blk, 0) != 0) {
    106 		fprintf(stderr, "\n%s: Write error on floppy\n", progname);
    107 		exit(1);
    108 	}
    109 }
    110 
    111 static void usage()
    112 {
    113 	fprintf(stderr, "usage: rawwrite [-v] <infile>\n");
    114 	exit(1);
    115 }
    116