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