dumpon.c revision 36999
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[] = 4536999Scharnier "$Id$"; 468478Swollman#endif /* not lint */ 478478Swollman 4836999Scharnier#include <err.h> 498478Swollman#include <stdio.h> 508478Swollman#include <unistd.h> 518478Swollman#include <sys/param.h> 528478Swollman#include <sys/types.h> 538478Swollman#include <sys/sysctl.h> 548478Swollman#include <sys/stat.h> 558478Swollman#include <sysexits.h> 568478Swollman 578478Swollmanvoid usage __P((void)) __dead2; 588478Swollman 598478Swollmanint 608478Swollmanmain(int argc, char **argv) 618478Swollman{ 628478Swollman int ch, verbose, rv; 638478Swollman struct stat stab; 648478Swollman int mib[2]; 658478Swollman 668478Swollman verbose = rv = 0; 6724359Simp while ((ch = getopt(argc, argv, "v")) != -1) 688478Swollman switch((char)ch) { 698478Swollman case 'v': 708478Swollman verbose = 1; 718478Swollman break; 728478Swollman case '?': 738478Swollman default: 748478Swollman usage(); 758478Swollman } 768478Swollman argv += optind; 778478Swollman 788478Swollman if (!argv[0] || argv[1]) 798478Swollman usage(); 808478Swollman 818478Swollman if (strcmp(argv[0], "off")) { 828478Swollman rv = stat(argv[0], &stab); 838478Swollman if (rv) { 848478Swollman err(EX_OSFILE, "%s", argv[0]); 858478Swollman } 868478Swollman 878478Swollman if (!S_ISBLK(stab.st_mode)) { 888478Swollman errx(EX_USAGE, "%s: must specify a block device", 898478Swollman argv[0]); 908478Swollman } 918478Swollman } else { 928478Swollman stab.st_rdev = NODEV; 938478Swollman } 948478Swollman 958478Swollman mib[0] = CTL_KERN; 968478Swollman mib[1] = KERN_DUMPDEV; 978478Swollman 988871Srgrimes rv = sysctl(mib, 2, (void *)0, (size_t *)0, &stab.st_rdev, 998478Swollman sizeof stab.st_rdev); 1008478Swollman if (rv) { 1018478Swollman err(EX_OSERR, "sysctl: kern.dumpdev"); 1028478Swollman } 1038478Swollman 1048478Swollman if (verbose) { 1058478Swollman if (stab.st_rdev == NODEV) { 10636999Scharnier printf("dumpon: crash dumps disabled\n"); 1078478Swollman } else { 10836999Scharnier printf("dumpon: crash dumps to %s (%lu, %lu)\n", 10936999Scharnier argv[0], 1108478Swollman (unsigned long)major(stab.st_rdev), 1118478Swollman (unsigned long)minor(stab.st_rdev)); 1128478Swollman } 1138478Swollman } 1148478Swollman 1158478Swollman return 0; 1168478Swollman} 1178478Swollman 1188478Swollmanvoid 1198478Swollmanusage() 1208478Swollman{ 1218478Swollman fprintf(stderr, 12236999Scharnier "usage: dumpon [-v] special_file\n" 12336999Scharnier " dumpon [-v] off\n"); 1248478Swollman exit(EX_USAGE); 1258478Swollman} 126