1.\" $OpenBSD: swapctl.2,v 1.14 2003/06/02 20:18:39 millert 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 June 20, 1997 33.Dt SWAPCTL 2 34.Os 35.Sh NAME 36.Nm swapctl 37.Nd modify swap configuration 38.Sh SYNOPSIS 39.Fd #include <unistd.h> 40.Fd #include <sys/swap.h> 41.Ft int 42.Fn swapctl "int cmd" "const void *arg" "int misc" 43.Sh DESCRIPTION 44The 45.Fn swapctl 46function is used to add and delete swap devices, and modify their 47configuration. 48.Pp 49The 50.Fa cmd 51parameter specifies the operation to be performed. 52The 53.Fa arg 54and 55.Fa misc 56parameters have different meanings, depending on the 57.Fa cmd 58parameter. 59.Bl -item -offset indent 60.It 61If 62.Fa cmd 63is 64.Dv SWAP_NSWAP , 65the current number of swap devices in the system is returned. 66The 67.Fa arg 68and 69.Fa misc 70parameters are ignored. 71.It 72If 73.Fa cmd 74is 75.Dv SWAP_STATS , 76the current statistics for swap devices are returned in the 77.Fa arg 78parameter. 79No more than 80.Fa misc 81swap devices are returned. 82The 83.Fa arg 84parameter should point to an array of at least 85.Fa misc 86struct swapent structures: 87.Bd -literal 88struct swapent { 89 dev_t se_dev; /* device id */ 90 int se_flags; /* entry flags */ 91 int se_nblks; /* total blocks */ 92 int se_inuse; /* blocks in use */ 93 int se_priority; /* priority */ 94 char se_path[MAXPATHLEN]; /* path to entry */ 95}; 96.Ed 97.Pp 98The flags are defined as 99.Bd -literal 100 SWF_INUSE in use: we have swapped here 101 SWF_ENABLE enabled: we can swap here 102 SWF_BUSY busy: I/O happening here 103 SWF_FAKE fake: still being built 104.Ed 105.It 106If 107.Fa cmd 108is 109.Dv SWAP_ON , 110the 111.Fa arg 112parameter is used as a pathname of a file to enable swapping to. 113The 114.Fa misc 115parameter is used to set the priority of this swap device. 116.It 117If 118.Fa cmd 119is 120.Dv SWAP_OFF , 121the 122.Fa arg 123parameter is used as the pathname of a file to disable swapping from. 124The 125.Fa misc 126parameter is ignored. 127.It 128If 129.Fa cmd 130is 131.Dv SWAP_CTL , 132the 133.Fa arg 134and 135.Fa misc 136parameters have the same function as for the 137.Dv SWAP_ON 138case, except that they change the priority of a currently enabled swap device. 139.El 140.Pp 141When swapping is enabled on a block device, the first portion of the disk is 142left unused to prevent any disklabel present from being overwritten. 143This space is allocated from the swap device when the 144.Dv SWAP_ON 145command is used. 146.Sh RETURN VALUES 147If the 148.Fa cmd 149parameter is 150.Dv SWAP_NSWAP 151or 152.Dv SWAP_STATS , 153.Fn swapctl 154returns the number of swap devices, if successful. 155The 156.Dv SWAP_NSWAP 157command is always successful. 158Otherwise it returns 0 on success and \-1 on failure, 159setting the global variable 160.Va errno 161to indicate the error. 162.Sh ERRORS 163.Fn swapctl 164succeeds unless: 165.Bl -tag -width Er 166.It Bq Er ENOTDIR 167A component of the path prefix is not a directory. 168.It Bq Er ENAMETOOLONG 169A component of a pathname exceeded 170.Dv NAME_MAX 171characters, or an entire path name exceeded 172.Dv PATH_MAX 173characters. 174.It Bq Er ENOENT 175The named device does not exist. 176For the 177.Dv SWAP_CTL 178command, the named device is not currently enabled for swapping. 179.It Bq Er EACCES 180Search permission is denied for a component of the path prefix. 181.It Bq Er ELOOP 182Too many symbolic links were encountered in translating the pathname. 183.It Bq Er EPERM 184The caller is not the superuser. 185.It Bq Er EBUSY 186The device specified by 187.Fa arg 188has already been made available for swapping. 189.It Bq Er EINVAL 190The device configured by 191.Fa arg 192has no associated size, or the 193.Fa cmd 194was unknown. 195.It Bq Er ENXIO 196The major device number of 197.Fa arg 198is out of range (this indicates no device driver exists 199for the associated hardware). 200.It Bq Er EIO 201An I/O error occurred while opening the swap device. 202.It Bq Er EFAULT 203.Fa arg 204points outside the process' allocated address space. 205.El 206.Sh SEE ALSO 207.Xr config 8 , 208.Xr swapctl 8 209.Sh HISTORY 210The 211.Fn swapctl 212function call appeared in 213.Nx 1.3 . 214The 215.Fa se_path 216member was added to 217.Li struct swapent 218in 219.Nx 1.4 , 220when the header file was also moved from 221.Aq Pa vm/vm_swap.h . 222.Sh AUTHORS 223The current swap system was designed and implemented by 224.An Matthew Green Aq mrg@eterna.com.au , 225with help from Paul Kranenburg 226.Aq pk@NetBSD.ORG 227and Leo Weppelman 228.Aq leo@NetBSD.ORG , 229and insights from Jason R. Thorpe 230.Aq thorpej@NetBSD.ORG . 231