swap.c (7c478bd95313f5f23a4c958a745db2134aa03244) | swap.c (3e1bd7a2aaeb6188caef90679b98088cfef1edc6) |
---|---|
1/* 2 * CDDL HEADER START 3 * 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. 8 * --- 6 unchanged lines hidden (view full) --- 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] 19 * 20 * CDDL HEADER END 21 */ 22/* | 1/* 2 * CDDL HEADER START 3 * 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. 8 * --- 6 unchanged lines hidden (view full) --- 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] 19 * 20 * CDDL HEADER END 21 */ 22/* |
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. | 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. |
24 * Use is subject to license terms. 25 */ 26 27/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28/* All Rights Reserved */ 29 30/* 31 * University Copyright- Copyright (c) 1982, 1986, 1988 --- 26 unchanged lines hidden (view full) --- 58#include <sys/mkdev.h> 59#include <sys/stat.h> 60#include <sys/statvfs.h> 61#include <sys/uadmin.h> 62#include <vm/anon.h> 63#include <fcntl.h> 64#include <locale.h> 65#include <libintl.h> | 24 * Use is subject to license terms. 25 */ 26 27/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28/* All Rights Reserved */ 29 30/* 31 * University Copyright- Copyright (c) 1982, 1986, 1988 --- 26 unchanged lines hidden (view full) --- 58#include <sys/mkdev.h> 59#include <sys/stat.h> 60#include <sys/statvfs.h> 61#include <sys/uadmin.h> 62#include <vm/anon.h> 63#include <fcntl.h> 64#include <locale.h> 65#include <libintl.h> |
66#include <libdiskmgt.h> |
|
66 67#define LFLAG 0x01 /* swap -l (list swap devices) */ 68#define DFLAG 0x02 /* swap -d (delete swap device) */ 69#define AFLAG 0x04 /* swap -a (add swap device) */ 70#define SFLAG 0x08 /* swap -s (swap info summary) */ 71#define P1FLAG 0x10 /* swap -1 (swapadd pass1; do not modify dump device) */ 72#define P2FLAG 0x20 /* swap -2 (swapadd pass2; do not modify dump device) */ 73 --- 6 unchanged lines hidden (view full) --- 80static int valid(char *, off_t, off_t); 81static int list(void); 82 83int 84main(int argc, char **argv) 85{ 86 int c, flag = 0; 87 int ret; | 67 68#define LFLAG 0x01 /* swap -l (list swap devices) */ 69#define DFLAG 0x02 /* swap -d (delete swap device) */ 70#define AFLAG 0x04 /* swap -a (add swap device) */ 71#define SFLAG 0x08 /* swap -s (swap info summary) */ 72#define P1FLAG 0x10 /* swap -1 (swapadd pass1; do not modify dump device) */ 73#define P2FLAG 0x20 /* swap -2 (swapadd pass2; do not modify dump device) */ 74 --- 6 unchanged lines hidden (view full) --- 81static int valid(char *, off_t, off_t); 82static int list(void); 83 84int 85main(int argc, char **argv) 86{ 87 int c, flag = 0; 88 int ret; |
89 int error = 0; |
|
88 off_t s_offset = 0; 89 off_t length = 0; 90 char *pathname; | 90 off_t s_offset = 0; 91 off_t length = 0; 92 char *pathname; |
93 char *msg; |
|
91 92 (void) setlocale(LC_ALL, ""); 93 94#if !defined(TEXT_DOMAIN) 95#define TEXT_DOMAIN "SYS_TEST" 96#endif 97 (void) textdomain(TEXT_DOMAIN); 98 --- 81 unchanged lines hidden (view full) --- 180 errno = 0; 181 length = strtol(argv[optind++], &char_p, 10); 182 if (errno != 0 || *char_p != '\0') { 183 (void) fprintf(stderr, 184 gettext("error in [nbr of blocks]\n")); 185 exit(1); 186 } 187 } | 94 95 (void) setlocale(LC_ALL, ""); 96 97#if !defined(TEXT_DOMAIN) 98#define TEXT_DOMAIN "SYS_TEST" 99#endif 100 (void) textdomain(TEXT_DOMAIN); 101 --- 81 unchanged lines hidden (view full) --- 183 errno = 0; 184 length = strtol(argv[optind++], &char_p, 10); 185 if (errno != 0 || *char_p != '\0') { 186 (void) fprintf(stderr, 187 gettext("error in [nbr of blocks]\n")); 188 exit(1); 189 } 190 } |
188 if ((ret = valid(pathname, 189 s_offset * 512, length * 512)) == 0) 190 ret = add(pathname, s_offset, length, flag); | |
191 break; 192 193 case '1': 194 flag |= P1FLAG; 195 break; 196 197 case '2': 198 flag |= P2FLAG; 199 break; 200 201 case '?': 202 usage(); 203 exit(1); 204 } 205 } | 191 break; 192 193 case '1': 194 flag |= P1FLAG; 195 break; 196 197 case '2': 198 flag |= P2FLAG; 199 break; 200 201 case '?': 202 usage(); 203 exit(1); 204 } 205 } |
206 /* 207 * do the add here. Check for in use prior to add. 208 * The values for length and offset are set above. 209 */ 210 if (flag & AFLAG) { 211 /* 212 * If device is in use for a swap device, print message 213 * and exit. 214 */ 215 if (dm_inuse(pathname, &msg, DM_WHO_SWAP, &error) || 216 error) { 217 if (error != 0) { 218 (void) fprintf(stderr, gettext("Error occurred" 219 " with device in use checking: %s\n"), 220 strerror(error)); 221 } else { 222 (void) fprintf(stderr, "%s", msg); 223 free(msg); 224 exit(1); 225 } 226 } 227 if ((ret = valid(pathname, 228 s_offset * 512, length * 512)) == 0) { 229 ret = add(pathname, s_offset, length, flag); 230 } 231 } |
|
206 if (!flag) { 207 usage(); 208 exit(1); 209 } 210 return (ret); 211} 212 213 --- 393 unchanged lines hidden --- | 232 if (!flag) { 233 usage(); 234 exit(1); 235 } 236 return (ret); 237} 238 239 --- 393 unchanged lines hidden --- |