dumpon.c revision 96381
18478Swollman/*
28478Swollman * Copyright (c) 1980, 1993
38478Swollman *	The Regents of the University of California.  All rights reserved.
48478Swollman *
58478Swollman * Redistribution and use in source and binary forms, with or without
68478Swollman * modification, are permitted provided that the following conditions
78478Swollman * are met:
88478Swollman * 1. Redistributions of source code must retain the above copyright
98478Swollman *    notice, this list of conditions and the following disclaimer.
108478Swollman * 2. Redistributions in binary form must reproduce the above copyright
118478Swollman *    notice, this list of conditions and the following disclaimer in the
128478Swollman *    documentation and/or other materials provided with the distribution.
138478Swollman * 3. All advertising materials mentioning features or use of this software
148478Swollman *    must display the following acknowledgement:
158478Swollman *	This product includes software developed by the University of
168478Swollman *	California, Berkeley and its contributors.
178478Swollman * 4. Neither the name of the University nor the names of its contributors
188478Swollman *    may be used to endorse or promote products derived from this software
198478Swollman *    without specific prior written permission.
208478Swollman *
218478Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
228478Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
238478Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
248478Swollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
258478Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
268478Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
278478Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
288478Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
298478Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
308478Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
318478Swollman * SUCH DAMAGE.
328478Swollman */
338478Swollman
348478Swollman#ifndef lint
3536999Scharnierstatic const char copyright[] =
368478Swollman"@(#) Copyright (c) 1980, 1993\n\
378478Swollman	The Regents of the University of California.  All rights reserved.\n";
388478Swollman#endif /* not lint */
398478Swollman
408478Swollman#ifndef lint
4136999Scharnier#if 0
4236999Scharnierstatic char sccsid[] = "From: @(#)swapon.c	8.1 (Berkeley) 6/5/93";
4336999Scharnier#endif
448478Swollmanstatic const char rcsid[] =
4550476Speter  "$FreeBSD: head/sbin/dumpon/dumpon.c 96381 2002-05-11 03:07:38Z alfred $";
468478Swollman#endif /* not lint */
478478Swollman
4836999Scharnier#include <err.h>
498478Swollman#include <stdio.h>
5078732Sdd#include <stdlib.h>
5193491Sphk#include <fcntl.h>
5293491Sphk#include <paths.h>
5396381Salfred#include <string.h>
548478Swollman#include <unistd.h>
558478Swollman#include <sys/param.h>
5694182Sphk#include <sys/disk.h>
578478Swollman#include <sysexits.h>
588478Swollman
5992542Simpvoid	usage(void) __dead2;
608478Swollman
618478Swollmanint
6292542Simpmain(int argc, char *argv[])
638478Swollman{
648478Swollman	int ch, verbose, rv;
6593491Sphk	int i, fd;
6693491Sphk	u_int u;
678478Swollman
688478Swollman	verbose = rv = 0;
6924359Simp	while ((ch = getopt(argc, argv, "v")) != -1)
708478Swollman		switch((char)ch) {
718478Swollman		case 'v':
728478Swollman			verbose = 1;
738478Swollman			break;
748478Swollman		case '?':
758478Swollman		default:
768478Swollman			usage();
778478Swollman		}
788478Swollman	argv += optind;
798478Swollman
808478Swollman	if (!argv[0] || argv[1])
818478Swollman		usage();
828478Swollman
838478Swollman	if (strcmp(argv[0], "off")) {
8493491Sphk		fd = open(argv[0], O_RDONLY);
8593491Sphk		if (fd < 0)
868478Swollman			err(EX_OSFILE, "%s", argv[0]);
8793491Sphk		u = 0;
8894272Sphk		i = ioctl(fd, DIOCSKERNELDUMP, &u);
8993491Sphk		u = 1;
9094272Sphk		i = ioctl(fd, DIOCSKERNELDUMP, &u);
9193491Sphk		if (i == 0 && verbose)
9293491Sphk			printf("kernel dumps on %s\n", argv[0]);
9393491Sphk
948478Swollman	} else {
9593491Sphk		fd = open(_PATH_DEVNULL, O_RDONLY);
9693491Sphk		if (fd < 0)
9793491Sphk			err(EX_OSFILE, "%s", _PATH_DEVNULL);
9893491Sphk		u = 0;
9994272Sphk		i = ioctl(fd, DIOCSKERNELDUMP, &u);
10093491Sphk		if (i == 0 && verbose)
10193491Sphk			printf("kernel dumps disabled\n");
1028478Swollman	}
10393491Sphk	if (i < 0)
10494272Sphk		err(EX_OSERR, "ioctl(DIOCSKERNELDUMP)");
1058478Swollman
10693491Sphk	exit (0);
1078478Swollman}
1088478Swollman
1098478Swollmanvoid
11092542Simpusage(void)
1118478Swollman{
1128478Swollman	fprintf(stderr,
11336999Scharnier		"usage: dumpon [-v] special_file\n"
11436999Scharnier		"       dumpon [-v] off\n");
1158478Swollman	exit(EX_USAGE);
1168478Swollman}
117