2 .\" Copyright 1989 AT&T Copyright (c) 1997, Sun Microsystems, Inc. All Rights Reserved
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH SWAPCTL 2 "Sep 25, 1997"
8 swapctl \- manage swap space
15 \fBint\fR \fBswapctl\fR(\fBint\fR \fIcmd\fR, \fBvoid *\fR\fIarg\fR);
21 The \fBswapctl()\fR function adds, deletes, or returns information about swap
22 resources. \fIcmd\fR specifies one of the following options contained in
27 SC_ADD /* add a resource for swapping */
28 SC_LIST /* list the resources for swapping */
29 SC_REMOVE /* remove a resource for swapping */
30 SC_GETNSWP /* return number of swap resources */
36 When \fBSC_ADD\fR or \fBSC_REMOVE\fR is specified, \fIarg\fR is a pointer to a
37 \fBswapres\fR structure containing the following members:
41 char *sr_name; /* pathname of resource */
42 off_t sr_start; /* offset to start of swap area */
43 off_t sr_length; /* length of swap area */
49 The \fBsr_start\fR and \fBsr_length\fR members are specified in 512-byte
50 blocks. A swap resource can only be removed by specifying the same values for
51 the \fBsr_start\fR and \fBsr_length\fR members as were specified when it was
52 added. Swap resources need not be removed in the order in which they were
56 When \fBSC_LIST\fR is specified, \fIarg\fR is a pointer to a \fBswaptable\fR
57 structure containing the following members:
61 int swt_n; /* number of swapents following */
62 struct swapent swt_ent[]; /* array of swt_n swapents */
68 A \fBswapent\fR structure contains the following members:
72 char *ste_path; /* name of the swap file */
73 off_t ste_start; /* starting block for swapping */
74 off_t ste_length; /* length of swap area */
75 long ste_pages; /* number of pages for swapping */
76 long ste_free; /* number of ste_pages free */
77 long ste_flags; /* ST_INDEL bit set if swap file */
78 /* is now being deleted */
84 The \fBSC_LIST\fR function causes \fBswapctl()\fR to return at most \fBswt_n\fR
85 entries. The return value of \fBswapctl()\fR is the number actually returned.
86 The \fBST_INDEL\fR bit is turned on in \fBste_flags\fR if the swap file is in
87 the process of being deleted.
90 When \fBSC_GETNSWP\fR is specified, \fBswapctl()\fR returns as its value the
91 number of swap resources in use. \fIarg\fR is ignored for this operation.
94 The \fBSC_ADD\fR and \fBSC_REMOVE\fR functions will fail if calling process
95 does not have appropriate privileges.
99 Upon successful completion, the function \fBswapctl()\fR returns a value of
100 \fB0\fR for \fBSC_ADD\fR or \fBSC_REMOVE\fR, the number of \fBstruct\fR
101 \fBswapent\fR entries actually returned for \fBSC_LIST\fR, or the number of
102 swap resources in use for \fBSC_GETNSWP\fR. Upon failure, the function
103 \fBswapctl()\fR returns a value of \fB\(mi1\fR and sets \fBerrno\fR to
108 Under the following conditions, the function \fBswapctl()\fR fails and sets
116 Part of the range specified by \fBsr_start\fR and \fBsr_length\fR is already
117 being used for swapping on the specified resource (\fBSC_ADD\fR).
126 Either \fIarg\fR, \fBsr_name\fR, or \fBste_path\fR points to an illegal
136 The specified function value is not valid, the path specified is not a swap
137 resource (\fBSC_REMOVE\fR), part of the range specified by \fBsr_start\fR and
138 \fBsr_length\fR lies outside the resource specified (\fBSC_ADD\fR), or the
139 specified swap area is less than one page (\fBSC_ADD\fR).
148 The path specified for \fBSC_ADD\fR is a directory.
157 Too many symbolic links were encountered in translating the pathname provided
158 to \fBSC_ADD\fR or \fBSC_REMOVE\fR.
164 \fB\fBENAMETOOLONG\fR\fR
167 The length of a component of the path specified for \fBSC_ADD\fR or
168 \fBSC_REMOVE\fR exceeds \fBNAME_MAX\fR characters or the length of the path
169 exceeds \fBPATH_MAX\fR characters and \fB_POSIX_NO_TRUNC\fR is in effect.
178 The pathname specified for \fBSC_ADD\fR or \fBSC_REMOVE\fR does not exist.
187 An insufficient number of \fBstruct\fR \fBswapent\fR structures were provided
188 to \fBSC_LIST\fR, or there were insufficient system storage resources available
189 during an \fBSC_ADD\fR or \fBSC_REMOVE\fR, or the system would not have enough
190 swap space after an \fBSC_REMOVE\fR.
199 The pathname specified for \fBSC_ADD\fR or \fBSC_REMOVE\fR is not a file or
200 block special device.
209 Pathname provided to \fBSC_ADD\fR or \fBSC_REMOVE\fR contained a component in
210 the path prefix that was not a directory.
219 The {\fBPRIV_SYS_MOUNT\fR} was not asserted in the effective set of the calling
229 The pathname specified for \fBSC_ADD\fR is a read-only file system.
234 Additionally, the \fBswapctl()\fR function will fail for 32-bit interfaces if:
238 \fB\fBEOVERFLOW\fR\fR
241 The amount of swap space configured on the machine is too large to be
242 represented by a 32-bit quantity.
247 \fBExample 1 \fRThe usage of the \fBSC_GETNSWP\fR and \fBSC_LIST\fR commands.
250 The following example demonstrates the usage of the \fBSC_GETNSWP\fR and
251 \fBSC_LIST\fR commands.
256 #include <sys/stat.h>
257 #include <sys/swap.h>
260 #define MAXSTRSIZE 80
268 char *strtab; /* string table for path names */
271 if ((num = swapctl(SC_GETNSWP, 0)) == -1) {
272 perror("swapctl: GETNSWP");
276 fprintf(stderr, "No Swap Devices Configured\en");
279 /* allocate swaptable for num+1 entries */
280 if ((s = malloc(num * sizeof(swapent_t) +
281 sizeof(struct swaptable))) == NULL) {
282 fprintf(stderr, "Malloc Failed\en");
285 /* allocate num+1 string holders */
286 if ((strtab = malloc((num + 1) * MAXSTRSIZE)) == NULL) {
287 fprintf(stderr, "Malloc Failed\en");
290 /* initialize string pointers */
291 for (i = 0; i < (num + 1); i++) {
292 s->swt_ent[i].ste_path = strtab + (i * MAXSTRSIZE);
296 if ((n = swapctl(SC_LIST, s)) < 0) {
300 if (n > num) { /* more were added */
305 for (i = 0; i < n; i++)
307 s->swt_ent[i].ste_path, s->swt_ent[i].ste_pages);