8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / dumpadm / swap.c
blob8f6ac7033ece963619e7660689a354709dddfd0e
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
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>
30 #include <string.h>
31 #include <stdlib.h>
32 #include <stdio.h>
34 #include "utils.h"
35 #include "swap.h"
37 swaptbl_t *
38 swap_list(void)
40 swaptbl_t *swt;
42 int n, i;
43 char *p;
45 if ((n = swapctl(SC_GETNSWP, NULL)) == -1) {
46 warn(gettext("failed to get swap table size"));
47 return (NULL);
50 swt = malloc(sizeof (int) + n * sizeof (swapent_t) + n * MAXPATHLEN);
52 if (swt == NULL) {
53 warn(gettext("failed to allocate swap table"));
54 return (NULL);
57 swt->swt_n = n;
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;
62 p += MAXPATHLEN;
65 if ((n = swapctl(SC_LIST, swt)) == -1) {
66 warn(gettext("failed to get swap table"));
67 free(swt);
68 return (NULL);
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[].
85 if (i > n) {
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] != '/') {
95 char buf[MAXPATHLEN];
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);
102 n++;
106 swt->swt_n = n; /* Update swt_n with number of valid entries */
107 return (swt);