xref: /titanic_41/usr/src/cmd/fs.d/deffs.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 /* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990, 1991, 1997 SMI	*/
23 /* All Rights Reserved							*/
24 
25 #ident	"%Z%%M%	%I%	%E% SMI"
26 
27 #include	<stdio.h>
28 #include        <deflt.h>
29 #include        <string.h>
30 
31 #define	LOCAL		"/etc/default/fs"
32 #define	REMOTE		"/etc/dfs/fstypes"
33 
34 /*
35  * This is used to figure out the default file system type if "-F FStype"
36  * is not specified with the file system command and no entry in the
37  * /etc/vfstab matches the specified special.
38  * If the first character of the "special" is a "/" (eg, "/dev/dsk/c0d1s2"),
39  * returns the default local filesystem type.
40  * Otherwise (eg, "server:/path/name" or "resource"), returns the default
41  * remote filesystem type.
42  */
43 char	*
default_fstype(char * special)44 default_fstype(char *special)
45 {
46 	char	*deffs;
47 	static	char	buf[BUFSIZ];
48 	FILE	*fp;
49 
50 	if (*special == '/') {
51 		if (defopen(LOCAL) != 0)
52 			return ("ufs");
53 		else {
54 			if ((deffs = defread("LOCAL=")) == NULL) {
55 				defopen(NULL);	/* close default file */
56 				return ("ufs");
57 			} else {
58 				defopen(NULL);	/* close default file */
59 				return (deffs);
60 			}
61 		}
62 	} else {
63 		if ((fp = fopen(REMOTE, "r")) == NULL)
64 			return ("nfs");
65 		else {
66 			if (fgets(buf, sizeof (buf), fp) == NULL) {
67 				fclose(fp);
68 				return ("nfs");
69 			} else {
70 				deffs = strtok(buf, " \t\n");
71 				fclose(fp);
72 				return (deffs);
73 			}
74 		}
75 	}
76 }
77