System Calls swapctl(2)
NAME
swapctl - manage swap space
SYNOPSIS
#include
#include
int swapctl(int cmd, void *arg);
DESCRIPTION
The swapctl() function adds, deletes, or returns informa-
tion about swap resources. cmd specifies one of the follow-
ing options contained in :
SCAD /* add a resource for swapping */
SCLIST /* list the resources for swapping */
SCREMOVE /* remove a resource for swapping */
SCGETNSWP /* return number of swap resources */
When SCAD or SCREMOVE is specified, arg is a pointer to a
swapres structure containing the following members:
char *srname; /* pathname of resource */
offt srstart; /* offset to start of swap area */
offt srlength; /* length of swap area */
The srstart and srlength members are specified in 512-byte
blocks. A swap resource can only be removed by specifying
the same values for the srstart and srlength members as
were specified when it was added. Swap resources need not be
removed in the order in which they were added.
When SCLIST is specified, arg is a pointer to a swaptable
structure containing the following members:
int swtn; /* number of swapents following */
struct swapent swtent[]; /* array of swtn swapents */
A swapent structure contains the following members:
char *stepath; /* name of the swap file */
offt stestart; /* starting block for swapping */
offt stelength; /* length of swap area */
long stepages; /* number of pages for swapping */
SunOS 5.11 Last change: 25 Sep 1997 1
System Calls swapctl(2)
long stefree; /* number of stepages free */
long steflags; /* STINDEL bit set if swap file */
/* is now being deleted */
The SCLIST function causes swapctl() to return at most
swtn entries. The return value of swapctl() is the number
actually returned. The STINDEL bit is turned on in
steflags if the swap file is in the process of being
deleted.
When SCGETNSWP is specified, swapctl() returns as its value
the number of swap resources in use. arg is ignored for this
operation.
The SCAD and SCREMOVE functions will fail if calling pro-
cess does not have appropriate privileges.
RETURN VALUES
Upon successful completion, the function swapctl() returns a
value of 0 for SCAD or SCREMOVE, the number of struct
swapent entries actually returned for SCLIST, or the
number of swap resources in use for SCGETNSWP. Upon
failure, the function swapctl() returns a value of -1 and
sets errno to indicate an error.
ERORS
Under the following conditions, the function swapctl() fails
and sets errno to:
EXIST Part of the range specified by srstart and
srlength is already being used for swapping
on the specified resource (SCAD).
EFAULT Either arg, srname, or stepath points to
an illegal address.
EINVAL The specified function value is not valid,
the path specified is not a swap resource
(SCREMOVE), part of the range specified by
srstart and srlength lies outside the
resource specified (SCAD), or the speci-
fied swap area is less than one page
(SCAD).
SunOS 5.11 Last change: 25 Sep 1997 2
System Calls swapctl(2)
EISDIR The path specified for SCAD is a direc-
tory.
ELOP Too many symbolic links were encountered in
translating the pathname provided to SCAD
or SCREMOVE.
ENAMETOLONG The length of a component of the path speci-
fied for SCAD or SCREMOVE exceeds
NAMEMAX characters or the length of the
path exceeds PATHMAX characters and
POSIXNOTRUNC is in effect.
ENOENT The pathname specified for SCAD or
SCREMOVE does not exist.
ENOMEM An insufficient number of struct swapent
structures were provided to SCLIST, or
there were insufficient system storage
resources available during an SCAD or
SCREMOVE, or the system would not have
enough swap space after an SCREMOVE.
ENOSYS The pathname specified for SCAD or
SCREMOVE is not a file or block special
device.
ENOTDIR Pathname provided to SCAD or SCREMOVE
contained a component in the path prefix
that was not a directory.
EPERM The {PRIVSYSMOUNT} was not asserted in the
effective set of the calling process.
EROFS The pathname specified for SCAD is a
read-only file system.
Additionally, the swapctl() function will fail for 32-bit
interfaces if:
EOVERFLOW The amount of swap space configured on the
machine is too large to be represented by a
SunOS 5.11 Last change: 25 Sep 1997 3
System Calls swapctl(2)
32-bit quantity.
EXAMPLES
Example 1 The usage of the SCGETNSWP and SCLIST commands.
The following example demonstrates the usage of the
SCGETNSWP and SCLIST commands.
#include
#include
#include
#define MAXSTRSIZE 80
main(argc, argv)
int argc;
char *argv[];
{
swaptblt *s;
int i, n, num;
char *strtab; /* string table for path names */
again:
if ((num = swapctl(SCGETNSWP, 0)) == -1) {
perror("swapctl: GETNSWP");
exit(1);
}
if (num == 0) {
fprintf(stderr, "No Swap Devices Configured\n");
exit(2);
}
/* allocate swaptable for num]1 entries */
if ((s = (swaptblt *)
malloc(num * sizeof(swapentt) ]
sizeof(struct swaptable))) ==
(void *) 0) {
fprintf(stderr, "Malloc Failed\n");
exit(3);
}
/* allocate num]1 string holders */
if ((strtab = (char *)
malloc((num ] 1) * MAXSTRSIZE)) == (void *) 0) {
fprintf(stderr, "Malloc Failed\n");
exit(3);
}
/* initialize string pointers */
for (i = 0; i < (num ] 1); i]) {
s->swtent[i].stepath = strtab ] (i * MAXSTRSIZE);
}
SunOS 5.11 Last change: 25 Sep 1997 4
System Calls swapctl(2)
s->swtn = num ] 1;
if ((n = swapctl(SCLIST, s)) < 0) {
perror("swapctl");
exit(1);
}
if (n > num) { /* more were added */
free(s);
free(strtab);
goto again;
}
for (i = 0; i < n; i])
printf("%s %ld\n",
s->swtent[i].stepath, s->swtent[i].stepages);
}
SEE ALSO
privileges(5)
SunOS 5.11 Last change: 25 Sep 1997 5
|