From bdadd563467b7b7d05dc175dfb8a27fea030c845 Mon Sep 17 00:00:00 2001 From: mrg Date: Tue, 23 Feb 1999 17:00:53 +0000 Subject: [PATCH] add a new fstab type "dp" for the user-specified dump device. change swapctl -A to see this and add it via swapctl(2). also add a new swapctl -D to change the dump device on the fly. --- include/fstab.h | 3 +- lib/libc/gen/fstab.c | 6 ++-- sbin/swapctl/swapctl.8 | 26 +++++++++++++-- sbin/swapctl/swapctl.c | 72 ++++++++++++++++++++++++++++++++---------- share/man/man5/fstab.5 | 56 ++++++++++++++++++++++++-------- 5 files changed, 126 insertions(+), 37 deletions(-) diff --git a/include/fstab.h b/include/fstab.h index 03f8e55b4949..5d52cf35db30 100644 --- a/include/fstab.h +++ b/include/fstab.h @@ -1,4 +1,4 @@ -/* $NetBSD: fstab.h,v 1.8 1998/07/27 11:14:34 mycroft Exp $ */ +/* $NetBSD: fstab.h,v 1.9 1999/02/23 17:00:53 mrg Exp $ */ /* * Copyright (c) 1980, 1993 @@ -58,6 +58,7 @@ #define FSTAB_RQ "rq" /* read/write with quotas */ #define FSTAB_RO "ro" /* read-only device */ #define FSTAB_SW "sw" /* swap device */ +#define FSTAB_DP "dp" /* dump device */ #define FSTAB_XX "xx" /* ignore totally */ struct fstab { diff --git a/lib/libc/gen/fstab.c b/lib/libc/gen/fstab.c index eaa820159702..5afe65c73dab 100644 --- a/lib/libc/gen/fstab.c +++ b/lib/libc/gen/fstab.c @@ -1,4 +1,4 @@ -/* $NetBSD: fstab.c,v 1.18 1999/01/26 02:23:34 thorpej Exp $ */ +/* $NetBSD: fstab.c,v 1.19 1999/02/23 17:00:53 mrg Exp $ */ /* * Copyright (c) 1980, 1988, 1993 @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)fstab.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: fstab.c,v 1.18 1999/01/26 02:23:34 thorpej Exp $"); +__RCSID("$NetBSD: fstab.c,v 1.19 1999/02/23 17:00:53 mrg Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -92,7 +92,7 @@ fstabscan() static const char sep[] = ":\n"; static const char ws[] = " \t\n"; static char *fstab_type[] = { - FSTAB_RW, FSTAB_RQ, FSTAB_RO, FSTAB_SW, FSTAB_XX, NULL + FSTAB_RW, FSTAB_RQ, FSTAB_RO, FSTAB_SW, FSTAB_DP, FSTAB_XX, NULL }; for (;;) { diff --git a/sbin/swapctl/swapctl.8 b/sbin/swapctl/swapctl.8 index af8e75617898..e32b102f95b2 100644 --- a/sbin/swapctl/swapctl.8 +++ b/sbin/swapctl/swapctl.8 @@ -1,4 +1,4 @@ -.\" $NetBSD: swapctl.8,v 1.14 1998/05/22 18:27:52 msaitoh Exp $ +.\" $NetBSD: swapctl.8,v 1.15 1999/02/23 17:00:53 mrg Exp $ .\" .\" Copyright (c) 1997 Matthew R. Green .\" All rights reserved. @@ -36,6 +36,7 @@ .Sh SYNOPSIS .Nm .Fl A +.Op Fl D Ar dumpdev .Op Fl p Ar priority .Op Fl t Ar blk|noblk .Nm "" @@ -86,10 +87,29 @@ This option causes .Nm to read the .Pa /etc/fstab -file for devices and files with a ``sw'' type, and adds all these entries -as swap devices. If no swap devices are configured, +file for devices and files with a +.Dq sw +and +.Dq dp +type, and adds all these entries +as swap devices, or for a dump device in the case of a +.Dq dp +type. If no swap devices are configured, .Nm will exit with an error code. +.It Fl D +The +.Fl D +option requires that a +.Ar dumpdev +also be in the argument list. The kernel dump device is set to +.Ar dumpdev . +This changed is made via the +.Xr swapctl 2 +system call. The dump device is used when the system crashes +to write a current snapshot of real memory, to be saved later with +.Xr savecore 8 +at system reboot, and analyzed to determine the problem. .It Fl a The .Fl a diff --git a/sbin/swapctl/swapctl.c b/sbin/swapctl/swapctl.c index ce048a279acb..f23d4d5bdc58 100644 --- a/sbin/swapctl/swapctl.c +++ b/sbin/swapctl/swapctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: swapctl.c,v 1.9 1998/07/26 20:23:15 mycroft Exp $ */ +/* $NetBSD: swapctl.c,v 1.10 1999/02/23 17:00:53 mrg Exp $ */ /* * Copyright (c) 1996, 1997 Matthew R. Green @@ -30,7 +30,9 @@ /* * swapctl command: - * -A add all devices listed as `sw' in /etc/fstab + * -A add all devices listed as `sw' in /etc/fstab (also + * (sets the the dump device, if listed in fstab) + * -D set dumpdev to * -t [blk|noblk] if -A, add either all block device or all non-block * devices * -a add this device @@ -70,11 +72,12 @@ int command; * Commands for swapctl(8). These are mutually exclusive. */ #define CMD_A 0x01 /* process /etc/fstab */ -#define CMD_a 0x02 /* add a swap file/device */ -#define CMD_c 0x04 /* change priority of a swap file/device */ -#define CMD_d 0x08 /* delete a swap file/device */ -#define CMD_l 0x10 /* list swap files/devices */ -#define CMD_s 0x20 /* summary of swap files/devices */ +#define CMD_D 0x02 /* set dumpdev */ +#define CMD_a 0x04 /* add a swap file/device */ +#define CMD_c 0x08 /* change priority of a swap file/device */ +#define CMD_d 0x10 /* delete a swap file/device */ +#define CMD_l 0x20 /* list swap files/devices */ +#define CMD_s 0x40 /* summary of swap files/devices */ #define SET_COMMAND(cmd) \ do { \ @@ -87,7 +90,7 @@ do { \ * Commands that require a "path" argument at the end of the command * line, and the ones which require that none exist. */ -#define REQUIRE_PATH (CMD_a | CMD_c | CMD_d) +#define REQUIRE_PATH (CMD_D | CMD_a | CMD_c | CMD_d) #define REQUIRE_NOPATH (CMD_A | CMD_l | CMD_s) /* @@ -104,9 +107,10 @@ char *tflag; /* swap device type (blk or noblk) */ int pri; /* uses 0 as default pri */ -static void change_priority __P((char *)); -static void add_swap __P((char *)); -static void del_swap __P((char *)); +static void change_priority __P((const char *)); +static void add_swap __P((const char *)); +static void del_swap __P((const char *)); +static void set_dumpdev __P((const char *)); int main __P((int, char *[])); static void do_fstab __P((void)); static void usage __P((void)); @@ -136,12 +140,16 @@ main(argc, argv) } #endif - while ((c = getopt(argc, argv, "Aacdlkp:st:")) != -1) { + while ((c = getopt(argc, argv, "ADacdlkp:st:")) != -1) { switch (c) { case 'A': SET_COMMAND(CMD_A); break; + case 'D': + SET_COMMAND(CMD_D); + break; + case 'a': SET_COMMAND(CMD_a); break; @@ -244,6 +252,10 @@ main(argc, argv) case CMD_A: do_fstab(); break; + + case CMD_D: + set_dumpdev(argv[0]); + break; } exit(0); @@ -309,7 +321,7 @@ swapon_command(argc, argv) */ void change_priority(path) - char *path; + const char *path; { if (swapctl(SWAP_CTL, path, pri) < 0) @@ -321,10 +333,20 @@ change_priority(path) */ void add_swap(path) - char *path; + const char *path; { + struct stat sb; + + if (stat(path, &sb) < 0) + goto oops; + + if (sb.st_mode & S_IROTH) + warnx("%s is readable by the world", path); + if (sb.st_mode & S_IWOTH) + warnx("%s is writable by the world", path); if (swapctl(SWAP_ON, path, pri) < 0) +oops: err(1, "%s", path); } @@ -333,13 +355,24 @@ add_swap(path) */ void del_swap(path) - char *path; + const char *path; { if (swapctl(SWAP_OFF, path, pri) < 0) err(1, "%s", path); } +void +set_dumpdev(path) + const char *path; +{ + + if (swapctl(SWAP_DUMPDEV, path, NULL) == -1) + warn("could not set dump device to %s", path); + else + printf("%s: setting dump device to %s\n", __progname, path); +} + void do_fstab() { @@ -356,10 +389,15 @@ do_fstab() while ((fp = getfsent()) != NULL) { const char *spec; + spec = fp->fs_spec; + + if (strcmp(fp->fs_type, "dp") == 0) { + set_dumpdev(spec); + continue; + } + if (strcmp(fp->fs_type, "sw") != 0) continue; - - spec = fp->fs_spec; isblk = 0; if ((s = strstr(fp->fs_mntops, PRIORITYEQ)) != NULL) { diff --git a/share/man/man5/fstab.5 b/share/man/man5/fstab.5 index 1a38802d67e6..3bbad3b220b6 100644 --- a/share/man/man5/fstab.5 +++ b/share/man/man5/fstab.5 @@ -1,4 +1,4 @@ -.\" $NetBSD: fstab.5,v 1.14 1999/01/01 19:05:23 msaitoh Exp $ +.\" $NetBSD: fstab.5,v 1.15 1999/02/23 17:00:53 mrg Exp $ .\" .\" Copyright (c) 1980, 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -51,7 +51,9 @@ it is the duty of the system administrator to properly create and maintain this file. Each filesystem is described on a separate line; fields on each line are separated by tabs or spaces. Lines beginning -with ``#'' are comments. +with +.Dq # +are comments. The order of records in .Nm is important because @@ -72,13 +74,18 @@ For filesystems of type the special file name is the block special file name, and not the character special file name. If a program needs the character special file name, -the program must create it by appending a ``r'' after the -last ``/'' in the special file name. +the program must create it by appending a +.Dq r +after the +last +.Dq / +in the special file name. .Pp The second field, .Pq Fa fs_file , describes the mount point for the filesystem. -For swap partitions, this field should be specified as ``none''. +For swap and dump partitions, this field should be specified as +.Dq none . .Pp The third field, .Pq Fa fs_vfstype , @@ -115,7 +122,8 @@ an .Tn MS-DOS .Dq FAT filesystem .It Em nfs -a Sun Microsystems compatible ``Network File System'' +a Sun Microsystems compatible +.Dq Network File System .It Em nullfs a loop-back filesystem, allowing parts of the system to be viewed elsewhere. @@ -140,11 +148,21 @@ It contains at least the type of mount (see below) plus any additional options appropriate to the filesystem type. .Pp -The option ``auto'' can be used in the ``noauto'' form to cause -a file system not to be mounted automatically (with ``mount -a'', +The option +.Dq auto +can be used in the +.Dq noauto +form to cause +a file system not to be mounted automatically (with +.Dq mount -a +, or system boot time). .Pp -If the options ``userquota'' and/or ``groupquota'' are specified, +If the options +.Dq userquota +and/or +.Dq groupquota +are specified, the filesystem is automatically processed by the .Xr quotacheck 8 command, and user and/or group disk quotas are enabled with @@ -175,19 +193,28 @@ field (it is not deleted from the field). If .Fa fs_type -is ``rw'' or ``ro'' then the filesystem whose name is given in the +is +.Dq rw +or +.Dq ro +then the filesystem whose name is given in the .Fa fs_file field is normally mounted read-write or read-only on the specified special file. If .Fa fs_type -is ``sw'' then the special file is made available as a piece of swap +is +.Dq sw +or +.Dq dp +then the special file is made available as a piece of swap +or dump space by the .Xr swapctl 8 command towards the beginning of the system reboot procedure. See .Xr swapctl 8 -for more information on configuring swap devices. +for more information on configuring swap and dump devices. The fields other than .Fa fs_spec and @@ -195,7 +222,9 @@ and are unused. If .Fa fs_type -is specified as ``xx'' the entry is ignored. +is specified as +.Dq xx +the entry is ignored. This is useful to show disk partitions which are currently unused. .Pp The fifth field, @@ -229,6 +258,7 @@ will assume that the filesystem does not need to be checked. #define FSTAB_RW "rw" /* read-write device */ #define FSTAB_RO "ro" /* read-only device */ #define FSTAB_SW "sw" /* swap device */ +#define FSTAB_DP "dp" /* dump device */ #define FSTAB_XX "xx" /* ignore totally */ struct fstab {