| @@ -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 | |
91 | int command; | | 91 | static 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 | */ |
124 | int kflag; /* display in 1K^x blocks */ | | 124 | static 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 | |
129 | int hflag; /* display with humanize_number */ | | 129 | static int hflag; /* display with humanize_number */ |
130 | #define HFLAG_CMDS (CMD_l | CMD_s) | | 130 | #define HFLAG_CMDS (CMD_l | CMD_s) |
131 | | | 131 | |
132 | int pflag; /* priority was specified */ | | 132 | static 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 | |
135 | char *tflag; /* swap device type (blk, noblk, auto) */ | | 135 | static char *tflag; /* swap device type (blk, noblk, auto) */ |
136 | int autoflag; /* 1, if tflag is "auto" */ | | 136 | static 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 | |
139 | int fflag; /* first swap becomes dump */ | | 139 | static int fflag; /* first swap becomes dump */ |
140 | #define FFLAG_CMDS (CMD_A) | | 140 | #define FFLAG_CMDS (CMD_A) |
141 | | | 141 | |
142 | int oflag; /* only autoset dump device */ | | 142 | static int oflag; /* only autoset dump device */ |
143 | #define OFLAG_CMDS (CMD_A) | | 143 | #define OFLAG_CMDS (CMD_A) |
144 | | | 144 | |
145 | int nflag; /* no execute, just print actions */ | | 145 | static 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 | |
148 | int pri; /* uses 0 as default pri */ | | 148 | static int pri; /* uses 0 as default pri */ |
149 | | | 149 | |
150 | static void change_priority(char *); | | 150 | static void change_priority(char *); |
151 | static int add_swap(char *, int); | | 151 | static int add_swap(char *, int); |
152 | static int delete_swap(char *); | | 152 | static int delete_swap(char *); |
153 | static void set_dumpdev(char *); | | 153 | static void set_dumpdev(char *); |
154 | static int get_dumpdev(void); | | 154 | static int get_dumpdev(void); |
155 | static void do_fstab(int); | | 155 | __dead static void do_fstab(int); |
156 | static int check_fstab(void); | | 156 | static int check_fstab(void); |
157 | static void do_localdevs(int); | | 157 | static void do_localdevs(int); |
158 | static void do_localdisk(const char *, int); | | 158 | static void do_localdisk(const char *, int); |
159 | static int do_wedgesofdisk(int fd, int); | | 159 | static int do_wedgesofdisk(int fd, int); |
160 | static int do_partitionsofdisk(const char *, int fd, int); | | 160 | static int do_partitionsofdisk(const char *, int fd, int); |
161 | static void usage(void); | | 161 | __dead static void usage(void); |
162 | static void swapon_command(int, char **); | | 162 | __dead static void swapon_command(int, char **); |
163 | #if 0 | | 163 | #if 0 |
164 | static void swapoff_command(int, char **); | | 164 | static void swapoff_command(int, char **); |
165 | #endif | | 165 | #endif |
166 | | | 166 | |
167 | int | | 167 | int |
168 | main(int argc, char *argv[]) | | 168 | main(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 | } |