xref: /openbsd-src/lib/libc/sys/swapctl.2 (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1.\"	$OpenBSD: swapctl.2,v 1.17 2009/03/28 08:33:00 espie Exp $
2.\"	$NetBSD: swapctl.2,v 1.10 1998/08/29 17:11:09 mrg Exp $
3.\"
4.\" Copyright (c) 1997 Matthew R. Green
5.\" Copyright (c) 1980, 1991, 1993
6.\"	The Regents of the University of California.  All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.Dd $Mdocdate: March 28 2009 $
33.Dt SWAPCTL 2
34.Os
35.Sh NAME
36.Nm swapctl
37.Nd modify swap configuration
38.Sh SYNOPSIS
39.Fd #include <sys/param.h>
40.Fd #include <sys/swap.h>
41.Fd #include <unistd.h>
42.Ft int
43.Fn swapctl "int cmd" "const void *arg" "int misc"
44.Sh DESCRIPTION
45The
46.Fn swapctl
47function is used to add and delete swap devices, and modify their
48configuration.
49.Pp
50The
51.Fa cmd
52parameter specifies the operation to be performed.
53The
54.Fa arg
55and
56.Fa misc
57parameters have different meanings, depending on the
58.Fa cmd
59parameter.
60.Bl -item -offset indent
61.It
62If
63.Fa cmd
64is
65.Dv SWAP_NSWAP ,
66the current number of swap devices in the system is returned.
67The
68.Fa arg
69and
70.Fa misc
71parameters are ignored.
72.It
73If
74.Fa cmd
75is
76.Dv SWAP_STATS ,
77the current statistics for swap devices are returned in the
78.Fa arg
79parameter.
80No more than
81.Fa misc
82swap devices are returned.
83The
84.Fa arg
85parameter should point to an array of at least
86.Fa misc
87struct swapent structures:
88.Bd -literal
89struct swapent {
90	dev_t	se_dev;			/* device id */
91	int	se_flags;		/* entry flags */
92	int	se_nblks;		/* total blocks */
93	int	se_inuse;		/* blocks in use */
94	int	se_priority;		/* priority */
95	char	se_path[MAXPATHLEN];	/* path to entry */
96};
97.Ed
98.Pp
99The flags are defined as
100.Bd -literal
101	SWF_INUSE       in use: we have swapped here
102	SWF_ENABLE      enabled: we can swap here
103	SWF_BUSY        busy: I/O happening here
104	SWF_FAKE        fake: still being built
105.Ed
106.Pp
107All but
108.Dv SWAP_NSWAP
109and
110.Dv SWAP_STATS
111require superuser privileges.
112.It
113If
114.Fa cmd
115is
116.Dv SWAP_ON ,
117the
118.Fa arg
119parameter is used as a pathname of a file to enable swapping to.
120The
121.Fa misc
122parameter is used to set the priority of this swap device.
123.It
124If
125.Fa cmd
126is
127.Dv SWAP_OFF ,
128the
129.Fa arg
130parameter is used as the pathname of a file to disable swapping from.
131The
132.Fa misc
133parameter is ignored.
134.It
135If
136.Fa cmd
137is
138.Dv SWAP_CTL ,
139the
140.Fa arg
141and
142.Fa misc
143parameters have the same function as for the
144.Dv SWAP_ON
145case, except that they change the priority of a currently enabled swap device.
146.El
147.Pp
148When swapping is enabled on a block device, the first portion of the disk is
149left unused to prevent any disklabel present from being overwritten.
150This space is allocated from the swap device when the
151.Dv SWAP_ON
152command is used.
153.Sh RETURN VALUES
154If the
155.Fa cmd
156parameter is
157.Dv SWAP_NSWAP
158or
159.Dv SWAP_STATS ,
160.Fn swapctl
161returns the number of swap devices, if successful.
162The
163.Dv SWAP_NSWAP
164command is always successful.
165Otherwise it returns 0 on success and \-1 on failure,
166setting the global variable
167.Va errno
168to indicate the error.
169.Sh ERRORS
170.Fn swapctl
171succeeds unless:
172.Bl -tag -width Er
173.It Bq Er ENOTDIR
174A component of the path prefix is not a directory.
175.It Bq Er ENAMETOOLONG
176A component of a pathname exceeded
177.Dv NAME_MAX
178characters, or an entire path name exceeded
179.Dv PATH_MAX
180characters.
181.It Bq Er ENOENT
182The named device does not exist.
183For the
184.Dv SWAP_CTL
185command, the named device is not currently enabled for swapping.
186.It Bq Er EACCES
187Search permission is denied for a component of the path prefix.
188.It Bq Er ELOOP
189Too many symbolic links were encountered in translating the pathname.
190.It Bq Er EPERM
191The caller is not the superuser.
192.It Bq Er EBUSY
193The device specified by
194.Fa arg
195has already been made available for swapping.
196.It Bq Er EINVAL
197The device configured by
198.Fa arg
199has no associated size, or the
200.Fa cmd
201was unknown.
202.It Bq Er ENXIO
203The major device number of
204.Fa arg
205is out of range (this indicates no device driver exists
206for the associated hardware).
207.It Bq Er EIO
208An I/O error occurred while opening the swap device.
209.It Bq Er EFAULT
210.Fa arg
211points outside the process' allocated address space.
212.El
213.Sh SEE ALSO
214.Xr config 8 ,
215.Xr swapctl 8
216.Sh HISTORY
217The
218.Fn swapctl
219function call appeared in
220.Nx 1.3 .
221The
222.Fa se_path
223member was added to
224.Li struct swapent
225in
226.Nx 1.4 ,
227when the header file was also moved from
228.Aq Pa vm/vm_swap.h .
229.Sh AUTHORS
230The current swap system was designed and implemented by
231.An Matthew Green Aq mrg@eterna.com.au ,
232with help from Paul Kranenburg
233.Aq pk@NetBSD.ORG
234and Leo Weppelman
235.Aq leo@NetBSD.ORG ,
236and insights from Jason R. Thorpe
237.Aq thorpej@NetBSD.ORG .
238