Sat Aug 27 18:57:50 2011 UTC ()
static + __dead


(joerg)
diff -r1.35 -r1.36 src/sbin/swapctl/swapctl.c

cvs diff -r1.35 -r1.36 src/sbin/swapctl/swapctl.c (expand / switch to unified diff)

--- src/sbin/swapctl/swapctl.c 2009/09/24 16:15:20 1.35
+++ src/sbin/swapctl/swapctl.c 2011/08/27 18:57:50 1.36
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: swapctl.c,v 1.35 2009/09/24 16:15:20 apb Exp $ */ 1/* $NetBSD: swapctl.c,v 1.36 2011/08/27 18:57:50 joerg Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, 1997, 1999 Matthew R. Green 4 * Copyright (c) 1996, 1997, 1999 Matthew R. Green
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -54,51 +54,51 @@ @@ -54,51 +54,51 @@
54 * -p <pri> use this priority 54 * -p <pri> use this priority
55 * -c change priority 55 * -c change priority
56 * 56 *
57 * or, if invoked as "swapon" (compatibility mode): 57 * or, if invoked as "swapon" (compatibility mode):
58 * 58 *
59 * -a all devices listed as `sw' in /etc/fstab 59 * -a all devices listed as `sw' in /etc/fstab
60 * -t same as -t above (feature not present in old 60 * -t same as -t above (feature not present in old
61 * swapon(8) command) 61 * swapon(8) command)
62 * <dev> add this device 62 * <dev> add this device
63 */ 63 */
64#include <sys/cdefs.h> 64#include <sys/cdefs.h>
65 65
66#ifndef lint 66#ifndef lint
67__RCSID("$NetBSD: swapctl.c,v 1.35 2009/09/24 16:15:20 apb Exp $"); 67__RCSID("$NetBSD: swapctl.c,v 1.36 2011/08/27 18:57:50 joerg Exp $");
68#endif 68#endif
69 69
70 70
71#include <sys/param.h> 71#include <sys/param.h>
72#include <sys/stat.h> 72#include <sys/stat.h>
73#include <sys/swap.h> 73#include <sys/swap.h>
74#include <sys/sysctl.h> 74#include <sys/sysctl.h>
75#include <sys/disk.h> 75#include <sys/disk.h>
76#include <sys/disklabel.h> 76#include <sys/disklabel.h>
77 77
78#include <unistd.h> 78#include <unistd.h>
79#include <err.h> 79#include <err.h>
80#include <errno.h> 80#include <errno.h>
81#include <stdio.h> 81#include <stdio.h>
82#include <stdlib.h> 82#include <stdlib.h>
83#include <string.h> 83#include <string.h>
84#include <fstab.h> 84#include <fstab.h>
85#include <fcntl.h> 85#include <fcntl.h>
86#include <util.h> 86#include <util.h>
87#include <paths.h> 87#include <paths.h>
88 88
89#include "swapctl.h" 89#include "swapctl.h"
90 90
91int command; 91static int command;
92 92
93/* 93/*
94 * Commands for swapctl(8). These are mutually exclusive. 94 * Commands for swapctl(8). These are mutually exclusive.
95 */ 95 */
96#define CMD_A 0x01 /* process /etc/fstab for adding */ 96#define CMD_A 0x01 /* process /etc/fstab for adding */
97#define CMD_D 0x02 /* set dumpdev */ 97#define CMD_D 0x02 /* set dumpdev */
98#define CMD_U 0x04 /* process /etc/fstab for removing */ 98#define CMD_U 0x04 /* process /etc/fstab for removing */
99#define CMD_a 0x08 /* add a swap file/device */ 99#define CMD_a 0x08 /* add a swap file/device */
100#define CMD_c 0x10 /* change priority of a swap file/device */ 100#define CMD_c 0x10 /* change priority of a swap file/device */
101#define CMD_d 0x20 /* delete a swap file/device */ 101#define CMD_d 0x20 /* delete a swap file/device */
102#define CMD_l 0x40 /* list swap files/devices */ 102#define CMD_l 0x40 /* list swap files/devices */
103#define CMD_s 0x80 /* summary of swap files/devices */ 103#define CMD_s 0x80 /* summary of swap files/devices */
104#define CMD_z 0x100 /* show dump device */ 104#define CMD_z 0x100 /* show dump device */
@@ -111,65 +111,65 @@ do { \ @@ -111,65 +111,65 @@ do { \
111 command = (cmd); \ 111 command = (cmd); \
112} while (0) 112} while (0)
113 113
114/* 114/*
115 * Commands that require a "path" argument at the end of the command 115 * Commands that require a "path" argument at the end of the command
116 * line, and the ones which require that none exist. 116 * line, and the ones which require that none exist.
117 */ 117 */
118#define REQUIRE_PATH (CMD_D | CMD_a | CMD_c | CMD_d) 118#define REQUIRE_PATH (CMD_D | CMD_a | CMD_c | CMD_d)
119#define REQUIRE_NOPATH (CMD_A | CMD_U | CMD_l | CMD_s | CMD_z | CMD_q) 119#define REQUIRE_NOPATH (CMD_A | CMD_U | CMD_l | CMD_s | CMD_z | CMD_q)
120 120
121/* 121/*
122 * Option flags, and the commands with which they are valid. 122 * Option flags, and the commands with which they are valid.
123 */ 123 */
124int kflag; /* display in 1K^x blocks */ 124static int kflag; /* display in 1K^x blocks */
125#define KFLAG_CMDS (CMD_l | CMD_s) 125#define KFLAG_CMDS (CMD_l | CMD_s)
126#define MFLAG_CMDS (CMD_l | CMD_s) 126#define MFLAG_CMDS (CMD_l | CMD_s)
127#define GFLAG_CMDS (CMD_l | CMD_s) 127#define GFLAG_CMDS (CMD_l | CMD_s)
128 128
129int hflag; /* display with humanize_number */ 129static int hflag; /* display with humanize_number */
130#define HFLAG_CMDS (CMD_l | CMD_s) 130#define HFLAG_CMDS (CMD_l | CMD_s)
131 131
132int pflag; /* priority was specified */ 132static int pflag; /* priority was specified */
133#define PFLAG_CMDS (CMD_A | CMD_a | CMD_c) 133#define PFLAG_CMDS (CMD_A | CMD_a | CMD_c)
134 134
135char *tflag; /* swap device type (blk, noblk, auto) */ 135static char *tflag; /* swap device type (blk, noblk, auto) */
136int autoflag; /* 1, if tflag is "auto" */ 136static int autoflag; /* 1, if tflag is "auto" */
137#define TFLAG_CMDS (CMD_A | CMD_U) 137#define TFLAG_CMDS (CMD_A | CMD_U)
138 138
139int fflag; /* first swap becomes dump */ 139static int fflag; /* first swap becomes dump */
140#define FFLAG_CMDS (CMD_A) 140#define FFLAG_CMDS (CMD_A)
141 141
142int oflag; /* only autoset dump device */ 142static int oflag; /* only autoset dump device */
143#define OFLAG_CMDS (CMD_A) 143#define OFLAG_CMDS (CMD_A)
144 144
145int nflag; /* no execute, just print actions */ 145static int nflag; /* no execute, just print actions */
146#define NFLAG_CMDS (CMD_A | CMD_U) 146#define NFLAG_CMDS (CMD_A | CMD_U)
147 147
148int pri; /* uses 0 as default pri */ 148static int pri; /* uses 0 as default pri */
149 149
150static void change_priority(char *); 150static void change_priority(char *);
151static int add_swap(char *, int); 151static int add_swap(char *, int);
152static int delete_swap(char *); 152static int delete_swap(char *);
153static void set_dumpdev(char *); 153static void set_dumpdev(char *);
154static int get_dumpdev(void); 154static int get_dumpdev(void);
155static void do_fstab(int); 155__dead static void do_fstab(int);
156static int check_fstab(void); 156static int check_fstab(void);
157static void do_localdevs(int); 157static void do_localdevs(int);
158static void do_localdisk(const char *, int); 158static void do_localdisk(const char *, int);
159static int do_wedgesofdisk(int fd, int); 159static int do_wedgesofdisk(int fd, int);
160static int do_partitionsofdisk(const char *, int fd, int); 160static int do_partitionsofdisk(const char *, int fd, int);
161static void usage(void); 161__dead static void usage(void);
162static void swapon_command(int, char **); 162__dead static void swapon_command(int, char **);
163#if 0 163#if 0
164static void swapoff_command(int, char **); 164static void swapoff_command(int, char **);
165#endif 165#endif
166 166
167int 167int
168main(int argc, char *argv[]) 168main(int argc, char *argv[])
169{ 169{
170 int c; 170 int c;
171 171
172 if (strcmp(getprogname(), "swapon") == 0) { 172 if (strcmp(getprogname(), "swapon") == 0) {
173 swapon_command(argc, argv); 173 swapon_command(argc, argv);
174 /* NOTREACHED */ 174 /* NOTREACHED */
175 } 175 }