summaryrefslogtreecommitdiff
path: root/usr/src/cmd/swap
diff options
context:
space:
mode:
authorsjelinek <none@none>2005-10-27 09:01:18 -0700
committersjelinek <none@none>2005-10-27 09:01:18 -0700
commit3e1bd7a2aaeb6188caef90679b98088cfef1edc6 (patch)
treef96d6ce4a25ea39514dd8b1fd2a23978cabc5055 /usr/src/cmd/swap
parent108322fb1c3ed341aba9c80c9774df0ed9e35768 (diff)
downloadillumos-joyent-3e1bd7a2aaeb6188caef90679b98088cfef1edc6.tar.gz
PSARC 2004/776 device checking for fs utilities
PSARC 2005/461 Device in use checking environment variables 5084421 libdiskmgt needs to detect in use ZFS data 5085739 remove workaround for bug 4725434 6194015 Device in use checking for Solaris utilities-PSARC/2004/776 6261853 libdiskmgt does not work correctly in all cases on amd64 6268374 libdiskmgt allocates incorrect size for readdir_r() dirent argument 6291309 PSARC/2005/461 - libdiskmgt should enable bypassing of inuse checking 6301815 PSARC/2005/461-Need Sun private libdiskmgt flag for use during install to disable sysevent starting --HG-- rename : usr/src/cmd/format/checkmount.c => usr/src/cmd/format/checkdev.c rename : usr/src/cmd/format/checkmount.h => usr/src/cmd/format/checkdev.h
Diffstat (limited to 'usr/src/cmd/swap')
-rw-r--r--usr/src/cmd/swap/Makefile.com3
-rw-r--r--usr/src/cmd/swap/swap.c34
2 files changed, 32 insertions, 5 deletions
diff --git a/usr/src/cmd/swap/Makefile.com b/usr/src/cmd/swap/Makefile.com
index a2e5cf53a4..c5d4e75ef6 100644
--- a/usr/src/cmd/swap/Makefile.com
+++ b/usr/src/cmd/swap/Makefile.com
@@ -20,7 +20,7 @@
# CDDL HEADER END
#
#
-# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "%Z%%M% %I% %E% SMI"
@@ -46,6 +46,7 @@ CLEANFILES += $(OBJS)
all: $(PROG)
+LDLIBS += -ldiskmgt
$(PROG): $(OBJS)
$(LINK.c) $(OBJS) -o $@ $(LDLIBS)
$(POST_PROCESS)
diff --git a/usr/src/cmd/swap/swap.c b/usr/src/cmd/swap/swap.c
index 4e9883f58a..3587df15db 100644
--- a/usr/src/cmd/swap/swap.c
+++ b/usr/src/cmd/swap/swap.c
@@ -20,7 +20,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -63,6 +63,7 @@
#include <fcntl.h>
#include <locale.h>
#include <libintl.h>
+#include <libdiskmgt.h>
#define LFLAG 0x01 /* swap -l (list swap devices) */
#define DFLAG 0x02 /* swap -d (delete swap device) */
@@ -85,9 +86,11 @@ main(int argc, char **argv)
{
int c, flag = 0;
int ret;
+ int error = 0;
off_t s_offset = 0;
off_t length = 0;
char *pathname;
+ char *msg;
(void) setlocale(LC_ALL, "");
@@ -185,9 +188,6 @@ main(int argc, char **argv)
exit(1);
}
}
- if ((ret = valid(pathname,
- s_offset * 512, length * 512)) == 0)
- ret = add(pathname, s_offset, length, flag);
break;
case '1':
@@ -203,6 +203,32 @@ main(int argc, char **argv)
exit(1);
}
}
+ /*
+ * do the add here. Check for in use prior to add.
+ * The values for length and offset are set above.
+ */
+ if (flag & AFLAG) {
+ /*
+ * If device is in use for a swap device, print message
+ * and exit.
+ */
+ if (dm_inuse(pathname, &msg, DM_WHO_SWAP, &error) ||
+ error) {
+ if (error != 0) {
+ (void) fprintf(stderr, gettext("Error occurred"
+ " with device in use checking: %s\n"),
+ strerror(error));
+ } else {
+ (void) fprintf(stderr, "%s", msg);
+ free(msg);
+ exit(1);
+ }
+ }
+ if ((ret = valid(pathname,
+ s_offset * 512, length * 512)) == 0) {
+ ret = add(pathname, s_offset, length, flag);
+ }
+ }
if (!flag) {
usage();
exit(1);