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.4 (Berkeley) 02/09/92 13 * 14 * $Id: am_ops.c,v 5.2.2.1 1992/02/09 15:08:17 jsp beta $ 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_SFSX 37 &sfsx_ops, 38 #endif 39 #ifdef HAS_LOFS 40 &lofs_ops, 41 #endif 42 #ifdef HAS_PFS 43 &pfs_ops, 44 #endif 45 #ifdef HAS_UNION_FS 46 &union_ops, 47 #endif 48 &afs_ops, /* These four should be last ... */ 49 &dfs_ops, /* ... */ 50 &toplvl_ops, /* ... */ 51 &efs_ops, /* ... in the order afs; dfs; toplvl; efs */ 52 0 53 }; 54 55 void ops_showfstypes P((FILE *fp)); 56 void ops_showfstypes(fp) 57 FILE *fp; 58 { 59 struct am_ops **ap; 60 int l = 0; 61 62 for (ap = vops; *ap; ap++) { 63 fputs((*ap)->fs_type, fp); 64 if (ap[1]) fputs(", ", fp); 65 l += strlen((*ap)->fs_type) + 2; 66 if (l > 60) { l = 0; fputs("\n ", fp); } 67 } 68 } 69 70 #ifdef SUNOS4_COMPAT 71 #ifdef nomore 72 /* 73 * Crack a SunOS4-style host:fs:sub-link line 74 * Construct an amd-style line and call the 75 * normal amd matcher. 76 */ 77 am_ops *sunos4_match(fo, key, g_key, path, keym, map) 78 am_opts *fo; 79 char *key; 80 char *g_key; 81 char *path; 82 char *keym; 83 char *map; 84 { 85 char *host = key; 86 char *fs = strchr(host, ':'); 87 char *sublink = fs ? strchr(fs+1, ':') : 0; 88 char keybuf[MAXPATHLEN]; 89 90 sprintf(keybuf, "type:=nfs;rhost:=%s;rfs:=%s;sublink:=%s;opts:=%s", host, 91 fs ? fs+1 : "", 92 sublink ? sublink+1 : "", 93 g_key); 94 return ops_match(fo, keybuf, "", path, keym, map); 95 } 96 #endif 97 #endif /* SUNOS4_COMPAT */ 98 99 am_ops *ops_match(fo, key, g_key, path, keym, map) 100 am_opts *fo; 101 char *key; 102 char *g_key; 103 char *path; 104 char *keym; 105 char *map; 106 { 107 am_ops **vp; 108 am_ops *rop = 0; 109 110 /* 111 * First crack the global opts and the local opts 112 */ 113 if (!eval_fs_opts(fo, key, g_key, path, keym, map)) { 114 rop = &efs_ops; 115 } else if (fo->opt_type == 0) { 116 plog(XLOG_USER, "No fs type specified (key = \"%s\", map = \"%s\")", keym, map); 117 rop = &efs_ops; 118 } else { 119 /* 120 * Next find the correct filesystem type 121 */ 122 for (vp = vops; rop = *vp; vp++) 123 if (strcmp(rop->fs_type, fo->opt_type) == 0) 124 break; 125 126 if (!rop) { 127 plog(XLOG_USER, "fs type \"%s\" not recognised", fo->opt_type); 128 rop = &efs_ops; 129 } 130 } 131 132 /* 133 * Make sure we have a default mount option. 134 * Otherwise skip past any leading '-'. 135 */ 136 if (fo->opt_opts == 0) 137 fo->opt_opts = "rw,defaults"; 138 else if (*fo->opt_opts == '-') 139 fo->opt_opts++; 140 141 /* 142 * Check the filesystem is happy 143 */ 144 if (fo->fs_mtab) 145 free((voidp) fo->fs_mtab); 146 147 if (fo->fs_mtab = (*rop->fs_match)(fo)) 148 return rop; 149 150 /* 151 * Return error file system 152 */ 153 fo->fs_mtab = (*efs_ops.fs_match)(fo); 154 return &efs_ops; 155 } 156