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