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  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include "cmdgen_include.h"
30 #include "nfs_keys.h"
31 #include "util.h"
32 #include <errno.h>
33 
34 /*
35  * Private variables and constants.
36  */
37 #define	UMOUNT_CMD	"umount"
38 #define	SPACE		" "
39 
40 /*
41  * Private method declaration
42  */
43 
44 /*
45  * Public methods
46  */
47 /*
48  * Method: cmdgen_umount
49  *
50  * Description: Forms the umount command with the given options.
51  *
52  * Parameters:
53  *	- CCIMInstance *inst - Not used.
54  *	- CCIMObjectPath *objPath - The object path containing the options to
55  *	be used when forming the command.
56  *	- int *errp - The error indicator.  Upon error, this will be set to a
57  *	value != 0.
58  *
59  * Returns:
60  *	- char * - The formed umount command.
61  *	- NULL if an error occurred.
62  */
63 /* ARGSUSED */
64 char *
cmdgen_umount(CCIMInstance * inst,CCIMObjectPath * objPath,int * errp)65 cmdgen_umount(CCIMInstance *inst, CCIMObjectPath *objPath, int *errp) {
66 	int err;
67 	char *mount_point;
68 	char *cmd;
69 	CCIMObjectPath *depOP;
70 
71 	if (objPath == NULL) {
72 		*errp = EINVAL;
73 		return (NULL);
74 	}
75 
76 	/*
77 	 * Create the umount command with properties from the Solaris_NFSMount
78 	 * CCIMObjectPath passed in.
79 	 */
80 	/*
81 	 * We need to get the mount point from the Antecedent Key of the
82 	 * Solaris_NFSMount CCIMObjectPath.
83 	 */
84 	depOP = util_getKeyValue(objPath->mKeyProperties, reference, ANTECEDENT,
85 		&err);
86 
87 	mount_point = util_getKeyValue(depOP->mKeyProperties, string, NAME,
88 		&err);
89 
90 	cmd = (char *)calloc((size_t)(strlen(mount_point) + strlen(UMOUNT_CMD)
91 		+ 2), (size_t)sizeof (char));
92 	if (cmd == NULL) {
93 		*errp = ENOMEM;
94 		return (NULL);
95 	}
96 
97 	(void) snprintf(cmd, (size_t)(strlen(mount_point) + strlen(UMOUNT_CMD)
98 	    + 2), "%s%s%s", UMOUNT_CMD, SPACE, mount_point);
99 
100 	*errp = 0;
101 	return (cmd);
102 } /* cmdgen_umount */
103