xref: /original-bsd/usr.sbin/amd/amd/am_ops.c (revision 9bffe400)
1 /*
2  * $Id: am_ops.c,v 5.2 90/06/23 22:19:19 jsp Rel $
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.1 (Berkeley) 06/29/90
15  */
16 
17 #include "am.h"
18 
19 static am_ops *vops[] = {
20 #ifdef HAS_UFS
21 	&ufs_ops,
22 #endif /* HAS_UFS */
23 #ifdef HAS_NFS
24 	&nfs_ops,
25 #endif /* HAS_NFS */
26 #ifdef HAS_HOST
27 	&host_ops,
28 #endif /* HAS_HOST */
29 #ifdef HAS_SFS
30 	&sfs_ops,
31 #endif /* HAS_SFS */
32 #ifdef HAS_LOFS
33 	&lofs_ops,
34 #endif /* HAS_LOFS */
35 #ifdef HAS_PFS
36 	&pfs_ops,
37 #endif /* HAS_PFS */
38 	&afs_ops,	/* These three should be last ... */
39 	&dfs_ops,	/* ... */
40 	&efs_ops,	/* ... in the order afs; dfs; efs */
41 	0
42 };
43 
44 #ifdef SUNOS4_COMPAT
45 /*
46  * Crack a SunOS4-style host:fs:sub-link line
47  * Construct an amd-style line and call the
48  * normal amd matcher.
49  */
50 am_ops *sunos4_match(fo, key, g_key, path, keym, map)
51 am_opts *fo;
52 char *key;
53 char *g_key;
54 char *path;
55 char *keym;
56 char *map;
57 {
58 	char *host = key;
59 	char *fs = strchr(host, ':');
60 	char *sublink = fs ? strchr(fs+1, ':') : 0;
61 	char keybuf[MAXPATHLEN];
62 
63 	sprintf(keybuf, "type:=nfs;rhost:=%s;rfs:=%s;sublink:=%s;opts:=%s", host,
64 		fs ? fs+1 : "",
65 		sublink ? sublink+1  : "",
66 		g_key);
67 	return ops_match(fo, keybuf, "", path, keym, map);
68 }
69 #endif /* SUNOS4_COMPAT */
70 
71 am_ops *ops_match(fo, key, g_key, path, keym, map)
72 am_opts *fo;
73 char *key;
74 char *g_key;
75 char *path;
76 char *keym;
77 char *map;
78 {
79 	am_ops **vp;
80 	am_ops *rop = 0;
81 
82 	/*
83 	 * First crack the global opts and the local opts
84 	 */
85 	if (!eval_fs_opts(fo, key, g_key, path, keym, map)) {
86 		rop = &efs_ops;
87 	} else if (fo->opt_type == 0) {
88 		plog(XLOG_USER, "No fs type specified (somewhere!)");
89 		rop = &efs_ops;
90 	} else {
91 		/*
92 		 * Next find the correct filesystem type
93 		 */
94 		for (vp = vops; rop = *vp; vp++)
95 			if (strcmp(rop->fs_type, fo->opt_type) == 0)
96 				break;
97 
98 		if (!rop) {
99 			plog(XLOG_USER, "fs type \"%s\" not recognised", fo->opt_type);
100 			rop = &efs_ops;
101 		}
102 	}
103 
104 	/*
105 	 * Make sure we have a default mount option.
106 	 * Otherwise skip past any leading '-'.
107 	 */
108 	if (fo->opt_opts == 0)
109 		fo->opt_opts = "rw,defaults";
110 	else if (*fo->opt_opts == '-')
111 		fo->opt_opts++;
112 
113 	/*
114 	 * Check the filesystem is happy
115 	 */
116 	if ((*rop->fs_match)(fo))
117 		return rop;
118 
119 	/*
120 	 * Return error file system
121 	 */
122 	(void) (*efs_ops.fs_match)(fo);
123 	return &efs_ops;
124 }
125