4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1998 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/param.h>
45 if ((n
= swapctl(SC_GETNSWP
, NULL
)) == -1) {
46 warn(gettext("failed to get swap table size"));
50 swt
= malloc(sizeof (int) + n
* sizeof (swapent_t
) + n
* MAXPATHLEN
);
53 warn(gettext("failed to allocate swap table"));
58 p
= (char *)swt
+ (sizeof (int) + n
* sizeof (swapent_t
));
60 for (i
= 0; i
< n
; i
++) {
61 swt
->swt_ent
[i
].ste_path
= p
;
65 if ((n
= swapctl(SC_LIST
, swt
)) == -1) {
66 warn(gettext("failed to get swap table"));
71 swt
->swt_n
= n
; /* Number of entries filled in */
72 n
= 0; /* Number of valid entries */
75 * Shrink the array of swapent_t structures by stripping out
76 * all those which are ST_INDEL or ST_DOINGDEL.
78 for (i
= 0; i
< swt
->swt_n
; i
++) {
79 if (!(swt
->swt_ent
[i
].ste_flags
& (ST_INDEL
| ST_DOINGDEL
))) {
81 * If i is ahead of the valid count (n), copy the
82 * ith entry back to the nth entry so valid entries
83 * fill the initial part of swt_ent[].
86 (void) memcpy(&swt
->swt_ent
[n
],
87 &swt
->swt_ent
[i
], sizeof (swapent_t
));
91 * If the pathname isn't absolute, assume it begins
92 * with /dev as swap(1m) does.
94 if (swt
->swt_ent
[n
].ste_path
[0] != '/') {
97 (void) snprintf(buf
, sizeof (buf
), "/dev/%s",
98 swt
->swt_ent
[n
].ste_path
);
99 (void) strcpy(swt
->swt_ent
[n
].ste_path
, buf
);
106 swt
->swt_n
= n
; /* Update swt_n with number of valid entries */