xref: /original-bsd/usr.sbin/amd/amd/am_ops.c (revision 56c13d2e)
1 /*
2  * $Id: am_ops.c,v 5.2.1.3 91/03/03 20:37:39 jsp Alpha $
3  *
4  * Copyright (c) 1989 Jan-Simon Pendry
5  * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
6  * Copyright (c) 1989 The Regents of the University of California.
7  * All rights reserved.
8  *
9  * This code is derived from software contributed to Berkeley by
10  * Jan-Simon Pendry at Imperial College, London.
11  *
12  * %sccs.include.redist.c%
13  *
14  *	@(#)am_ops.c	5.2 (Berkeley) 03/17/91
15  */
16 
17 #include "am.h"
18 
19 static am_ops *vops[] = {
20 #ifdef HAS_UFS
21 	&ufs_ops,
22 #endif
23 #ifdef HAS_NFS
24 	&nfs_ops,
25 #endif
26 #ifdef HAS_NFSX
27 	&nfsx_ops,
28 #endif
29 #ifdef HAS_HOST
30 	&host_ops,
31 #endif
32 #ifdef HAS_SFS
33 	&sfs_ops,
34 #endif
35 #ifdef HAS_LOFS
36 	&lofs_ops,
37 #endif
38 #ifdef HAS_PFS
39 	&pfs_ops,
40 #endif
41 #ifdef HAS_UNION_FS
42 	&union_ops,
43 #endif
44 	&afs_ops,	/* These four should be last ... */
45 	&dfs_ops,	/* ... */
46 	&toplvl_ops,	/* ... */
47 	&efs_ops,	/* ... in the order afs; dfs; toplvl; efs */
48 	0
49 };
50 
51 void ops_showfstypes P((FILE *fp));
52 void ops_showfstypes(fp)
53 FILE *fp;
54 {
55 	struct am_ops **ap;
56 	char *sep = "";
57 
58 	for (ap = vops; *ap; ap++) {
59 		fprintf(fp, "%s%s", sep, (*ap)->fs_type);
60 		sep = ", ";
61 	}
62 }
63 
64 #ifdef SUNOS4_COMPAT
65 /*
66  * Crack a SunOS4-style host:fs:sub-link line
67  * Construct an amd-style line and call the
68  * normal amd matcher.
69  */
70 am_ops *sunos4_match(fo, key, g_key, path, keym, map)
71 am_opts *fo;
72 char *key;
73 char *g_key;
74 char *path;
75 char *keym;
76 char *map;
77 {
78 	char *host = key;
79 	char *fs = strchr(host, ':');
80 	char *sublink = fs ? strchr(fs+1, ':') : 0;
81 	char keybuf[MAXPATHLEN];
82 
83 	sprintf(keybuf, "type:=nfs;rhost:=%s;rfs:=%s;sublink:=%s;opts:=%s", host,
84 		fs ? fs+1 : "",
85 		sublink ? sublink+1  : "",
86 		g_key);
87 	return ops_match(fo, keybuf, "", path, keym, map);
88 }
89 #endif /* SUNOS4_COMPAT */
90 
91 am_ops *ops_match(fo, key, g_key, path, keym, map)
92 am_opts *fo;
93 char *key;
94 char *g_key;
95 char *path;
96 char *keym;
97 char *map;
98 {
99 	am_ops **vp;
100 	am_ops *rop = 0;
101 
102 	/*
103 	 * First crack the global opts and the local opts
104 	 */
105 	if (!eval_fs_opts(fo, key, g_key, path, keym, map)) {
106 		rop = &efs_ops;
107 	} else if (fo->opt_type == 0) {
108 		plog(XLOG_USER, "No fs type specified (key = \"%s\", map = \"%s\")", keym, map);
109 		rop = &efs_ops;
110 	} else {
111 		/*
112 		 * Next find the correct filesystem type
113 		 */
114 		for (vp = vops; rop = *vp; vp++)
115 			if (strcmp(rop->fs_type, fo->opt_type) == 0)
116 				break;
117 
118 		if (!rop) {
119 			plog(XLOG_USER, "fs type \"%s\" not recognised", fo->opt_type);
120 			rop = &efs_ops;
121 		}
122 	}
123 
124 	/*
125 	 * Make sure we have a default mount option.
126 	 * Otherwise skip past any leading '-'.
127 	 */
128 	if (fo->opt_opts == 0)
129 		fo->opt_opts = "rw,defaults";
130 	else if (*fo->opt_opts == '-')
131 		fo->opt_opts++;
132 
133 	/*
134 	 * Check the filesystem is happy
135 	 */
136 	if (fo->fs_mtab)
137 		free((voidp) fo->fs_mtab);
138 
139 	if (fo->fs_mtab = (*rop->fs_match)(fo))
140 		return rop;
141 
142 	/*
143 	 * Return error file system
144 	 */
145 	fo->fs_mtab = (*efs_ops.fs_match)(fo);
146 	return &efs_ops;
147 }
148