xref: /titanic_41/usr/src/lib/lvm/libmeta/common/meta_mount.c (revision 989f28072d20c73ae0955d6a1e3e2fc74831cb39)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * return mount association with meta device
30  */
31 
32 #include <meta.h>
33 
34 #include <sys/mnttab.h>
35 
36 #include "meta_lib_prv.h"
37 
38 /*
39  * return associated mount point with this mdname_t
40  */
41 char *
42 meta_get_mountp(
43 	mdsetname_t	*sp,
44 	mdname_t	*np,
45 	md_error_t	*ep
46 )
47 {
48 	FILE		*mfp;
49 	struct mnttab	 m;
50 	char		*mountp	= NULL;
51 	char		mnt_mountp[MNT_LINE_MAX];
52 	char		mnt_special[MNT_LINE_MAX];
53 
54 	/* should have a set */
55 	assert(sp != NULL);
56 
57 	/* look in mnttab */
58 	if ((mfp = open_mnttab()) == NULL) {
59 		(void) mdsyserror(ep, errno, MNTTAB);
60 		return (NULL);
61 	}
62 
63 	while ((!mountp) && (getmntent(mfp, &m) == 0)) {
64 		mdname_t	*mnp;
65 
66 		if ((m.mnt_special == NULL) || (m.mnt_mountp == NULL))
67 			continue;
68 
69 		if (m.mnt_mountp[0] != '/')
70 			continue;
71 
72 		if ((strcmp(m.mnt_fstype, "nfs") == 0) ||
73 		    (strcmp(m.mnt_fstype, "autofs") == 0) ||
74 		    (strcmp(m.mnt_fstype, "proc") == 0) ||
75 		    (strcmp(m.mnt_fstype, "tmpfs") == 0) ||
76 		    (strcmp(m.mnt_fstype, "cachefs") == 0) ||
77 		    (strcmp(m.mnt_fstype, "lofs") == 0) ||
78 		    (strcmp(m.mnt_fstype, "rfs") == 0) ||
79 		    (strcmp(m.mnt_fstype, "fd") == 0))
80 			continue;
81 
82 		(void) strcpy(mnt_mountp, m.mnt_mountp);
83 		(void) strcpy(mnt_special, m.mnt_special);
84 		if ((mnp = metaname(&sp, mnt_special, UNKNOWN, ep)) == NULL) {
85 			mdclrerror(ep);
86 			continue;
87 		}
88 
89 		if (np->dev == mnp->dev) {
90 			mountp = mnt_mountp;
91 		}
92 	}
93 
94 	/* return success, if found */
95 	return (mountp? Strdup(mountp): NULL);
96 }
97