Annotation of src/usr.bin/fdeject/fdeject.c, Revision 1.1
1.1 ! deraadt 1: /* $NetBSD: fdeject.c,v 1.1 1995/10/09 12:01:06 pk Exp $ */
! 2:
! 3: /*
! 4: * Copyright (c) 1995 Paul Kranenburg
! 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 Paul Kranenburg.
! 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 <sys/types.h>
! 34: #include <sys/ioctl.h>
! 35: #include <sys/disklabel.h>
! 36: #include <err.h>
! 37: #include <fcntl.h>
! 38: #include <stdio.h>
! 39: #include <stdlib.h>
! 40:
! 41: static void
! 42: usage()
! 43: {
! 44: fprintf(stderr, "usage: fdeject\n");
! 45: exit(1);
! 46: }
! 47:
! 48: static char *dlist[] = {
! 49: "/dev/rfd0c",
! 50: "/dev/rfd0a",
! 51: NULL
! 52: };
! 53:
! 54: int
! 55: main(argc, argv)
! 56: int argc;
! 57: char *argv[];
! 58: {
! 59: int c, fd;
! 60: char **dev;
! 61:
! 62: while ((c = getopt(argc, argv, "")) != EOF) {
! 63: switch (c) {
! 64: default:
! 65: usage();
! 66: }
! 67: }
! 68:
! 69: if (argc > optind) {
! 70: fd = open(argv[optind], O_RDONLY, 0);
! 71: if (fd < 0)
! 72: err(1, "open(%s)", argv[optind]);
! 73: } else {
! 74: /* Search a list of default floppy devices */
! 75: for (dev = dlist; *dev; dev++) {
! 76: fd = open(*dev, O_RDONLY, 0);
! 77: if (fd > 0)
! 78: break;
! 79: }
! 80: if (fd < 0)
! 81: errx(1, "No floppy found");
! 82: }
! 83:
! 84: if (ioctl(fd, DIOCEJECT, 0) < 0)
! 85: err(1, "ioctl(DIOCEJECT)");
! 86:
! 87: if (close(fd) < 0)
! 88: err(1, "close");
! 89:
! 90: return 0;
! 91: }