OpenBSD manual page server

Manual Page Search Parameters

SWAPCTL(2) System Calls Manual SWAPCTL(2)

swapctlmodify swap configuration

#include <sys/types.h>
#include <sys/swap.h>
#include <unistd.h>

int
swapctl(int cmd, const void *arg, int misc);

The () function is used to add and delete swap devices, modify their configuration or query their statistics.

The cmd parameter specifies the operation to be performed. The arg and misc parameters have different meanings, depending on the cmd parameter.

When swapping is enabled on a block device, the first portion of the disk is left unused to prevent any disklabel present from being overwritten. This space is allocated from the swap device when the SWAP_ON command is used.

If the cmd parameter is SWAP_NSWAP or SWAP_STATS, swapctl() returns the number of swap devices, if successful. The SWAP_NSWAP command is always successful. Otherwise it returns 0 on success and -1 on failure, setting the global variable errno to indicate the error.

swapctl() succeeds unless:

[]
A component of the path prefix is not a directory.
[]
A component of a pathname exceeded NAME_MAX characters, or an entire pathname (including the terminating NUL) exceeded PATH_MAX bytes.
[]
The named device does not exist. For the SWAP_CTL command, the named device is not currently enabled for swapping.
[]
Search permission is denied for a component of the path prefix.
[]
Too many symbolic links were encountered in translating the pathname.
[]
The caller is not the superuser.
[]
The device specified by arg has already been made available for swapping.
[]
The device configured by arg has no associated size, or the cmd was unknown.
[]
The major device number of arg is out of range (this indicates no device driver exists for the associated hardware).
[]
An I/O error occurred while opening the swap device.
[]
arg points outside the process' allocated address space.
[]
The device specified by arg cannot be used for swapping.

config(8), swapctl(8)

The swapctl() function call appeared in NetBSD 1.3. The se_path member was added to struct swapent in NetBSD 1.4, when the header file was also moved from <vm/vm_swap.h>.

The current swap system was designed and implemented by Matthew Green <mrg@eterna.com.au>, with help from Paul Kranenburg <pk@NetBSD.ORG> and Leo Weppelman <leo@NetBSD.ORG>, and insights from Jason R. Thorpe <thorpej@NetBSD.ORG>.

April 2, 2019 OpenBSD-6.8