138494Sobrien/* 2310490Scy * Copyright (c) 1997-2014 Erez Zadok 338494Sobrien * Copyright (c) 1989 Jan-Simon Pendry 438494Sobrien * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 538494Sobrien * Copyright (c) 1989 The Regents of the University of California. 638494Sobrien * All rights reserved. 738494Sobrien * 838494Sobrien * This code is derived from software contributed to Berkeley by 938494Sobrien * Jan-Simon Pendry at Imperial College, London. 1038494Sobrien * 1138494Sobrien * Redistribution and use in source and binary forms, with or without 1238494Sobrien * modification, are permitted provided that the following conditions 1338494Sobrien * are met: 1438494Sobrien * 1. Redistributions of source code must retain the above copyright 1538494Sobrien * notice, this list of conditions and the following disclaimer. 1638494Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1738494Sobrien * notice, this list of conditions and the following disclaimer in the 1838494Sobrien * documentation and/or other materials provided with the distribution. 19310490Scy * 3. Neither the name of the University nor the names of its contributors 2038494Sobrien * may be used to endorse or promote products derived from this software 2138494Sobrien * without specific prior written permission. 2238494Sobrien * 2338494Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2438494Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2538494Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2638494Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2738494Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2838494Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2938494Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3038494Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3138494Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3238494Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3338494Sobrien * SUCH DAMAGE. 3438494Sobrien * 3538494Sobrien * 36174294Sobrien * File: am-utils/amd/am_ops.c 3738494Sobrien * 3838494Sobrien */ 3938494Sobrien 4038494Sobrien#ifdef HAVE_CONFIG_H 4138494Sobrien# include <config.h> 4238494Sobrien#endif /* HAVE_CONFIG_H */ 4338494Sobrien#include <am_defs.h> 4438494Sobrien#include <amd.h> 4538494Sobrien 4638494Sobrien 4738494Sobrien/* 4838494Sobrien * The order of these entries matters, since lookups in this table are done 4938494Sobrien * on a first-match basis. The entries below are a mixture of native 5038494Sobrien * filesystems supported by the OS (HAVE_FS_FOO), and some meta-filesystems 5182794Sobrien * supported by amd (HAVE_AMU_FS_FOO). The order is set here in expected 5238494Sobrien * match-hit such that more popular filesystems are listed first (nfs is the 5338494Sobrien * most popular, followed by a symlink F/S) 5438494Sobrien */ 5538494Sobrienstatic am_ops *vops[] = 5638494Sobrien{ 5738494Sobrien#ifdef HAVE_FS_NFS 5838494Sobrien &nfs_ops, /* network F/S (version 2) */ 5938494Sobrien#endif /* HAVE_FS_NFS */ 6082794Sobrien#ifdef HAVE_AMU_FS_LINK 6138494Sobrien &amfs_link_ops, /* symlink F/S */ 6282794Sobrien#endif /* HAVE_AMU_FS_LINK */ 6338494Sobrien 6438494Sobrien /* 6538494Sobrien * Other amd-supported meta-filesystems. 6638494Sobrien */ 6782794Sobrien#ifdef HAVE_AMU_FS_NFSX 6838494Sobrien &amfs_nfsx_ops, /* multiple-nfs F/S */ 6982794Sobrien#endif /* HAVE_AMU_FS_NFSX */ 7082794Sobrien#ifdef HAVE_AMU_FS_NFSL 7138494Sobrien &amfs_nfsl_ops, /* NFS with local link existence check */ 7282794Sobrien#endif /* HAVE_AMU_FS_NFSL */ 7382794Sobrien#ifdef HAVE_AMU_FS_HOST 7438494Sobrien &amfs_host_ops, /* multiple exported nfs F/S */ 7582794Sobrien#endif /* HAVE_AMU_FS_HOST */ 7682794Sobrien#ifdef HAVE_AMU_FS_LINKX 7738494Sobrien &amfs_linkx_ops, /* symlink F/S with link target verify */ 7882794Sobrien#endif /* HAVE_AMU_FS_LINKX */ 7982794Sobrien#ifdef HAVE_AMU_FS_PROGRAM 8038494Sobrien &amfs_program_ops, /* program F/S */ 8182794Sobrien#endif /* HAVE_AMU_FS_PROGRAM */ 8282794Sobrien#ifdef HAVE_AMU_FS_UNION 8338494Sobrien &amfs_union_ops, /* union F/S */ 8482794Sobrien#endif /* HAVE_AMU_FS_UNION */ 8538494Sobrien 8638494Sobrien /* 8738494Sobrien * A few more native filesystems. 8838494Sobrien */ 8938494Sobrien#ifdef HAVE_FS_UFS 9038494Sobrien &ufs_ops, /* Unix F/S */ 9138494Sobrien#endif /* HAVE_FS_UFS */ 9238494Sobrien#ifdef HAVE_FS_XFS 9338494Sobrien &xfs_ops, /* Unix (irix) F/S */ 9438494Sobrien#endif /* HAVE_FS_XFS */ 95310490Scy#ifdef HAVE_FS_EXT 96310490Scy &ext2_ops, /* Unix (linux) F/S */ 97310490Scy &ext3_ops, /* Unix (linux) F/S */ 98310490Scy &ext4_ops, /* Unix (linux) F/S */ 99310490Scy#endif /* HAVE_FS_EXT */ 10038494Sobrien#ifdef HAVE_FS_EFS 10138494Sobrien &efs_ops, /* Unix (irix) F/S */ 10238494Sobrien#endif /* HAVE_FS_EFS */ 10338494Sobrien#ifdef HAVE_FS_LOFS 10438494Sobrien &lofs_ops, /* loopback F/S */ 10538494Sobrien#endif /* HAVE_FS_LOFS */ 10638494Sobrien#ifdef HAVE_FS_CDFS 10738494Sobrien &cdfs_ops, /* CDROM/HSFS/ISO9960 F/S */ 10838494Sobrien#endif /* HAVE_FS_CDFS */ 10938494Sobrien#ifdef HAVE_FS_PCFS 11038494Sobrien &pcfs_ops, /* Floppy/MSDOS F/S */ 11138494Sobrien#endif /* HAVE_FS_PCFS */ 11238494Sobrien#ifdef HAVE_FS_CACHEFS 11338494Sobrien &cachefs_ops, /* caching F/S */ 11438494Sobrien#endif /* HAVE_FS_CACHEFS */ 115310490Scy#ifdef HAVE_FS_TMPFS 116310490Scy &tmpfs_ops, /* /tmp (in memory) F/S */ 117310490Scy#endif /* HAVE_FS_TMPFS */ 11838494Sobrien#ifdef HAVE_FS_NULLFS 11938494Sobrien/* FILL IN */ /* null (loopback) F/S */ 12038494Sobrien#endif /* HAVE_FS_NULLFS */ 12138494Sobrien#ifdef HAVE_FS_UNIONFS 12238494Sobrien/* FILL IN */ /* union (bsd44) F/S */ 12338494Sobrien#endif /* HAVE_FS_UNIONFS */ 12438494Sobrien#ifdef HAVE_FS_UMAPFS 12538494Sobrien/* FILL IN */ /* uid/gid mapping F/S */ 12638494Sobrien#endif /* HAVE_FS_UMAPFS */ 127310490Scy#ifdef HAVE_FS_UDF 128310490Scy &udf_ops, /* UDF F/S */ 129310490Scy#endif /* HAVE_FS_UDF */ 130310490Scy#ifdef HAVE_FS_LUSTRE 131310490Scy &lustre_ops, /* Lustre */ 132310490Scy#endif /* HAVE_FS_LUSTRE */ 13338494Sobrien 13438494Sobrien /* 135174294Sobrien * These 4 should be last, in the order: 13638494Sobrien * (1) amfs_auto 13738494Sobrien * (2) amfs_direct 13838494Sobrien * (3) amfs_toplvl 139119679Smbr * (4) amfs_error 14038494Sobrien */ 14182794Sobrien#ifdef HAVE_AMU_FS_AUTO 14238494Sobrien &amfs_auto_ops, /* Automounter F/S */ 14382794Sobrien#endif /* HAVE_AMU_FS_AUTO */ 14482794Sobrien#ifdef HAVE_AMU_FS_DIRECT 14538494Sobrien &amfs_direct_ops, /* direct-mount F/S */ 14682794Sobrien#endif /* HAVE_AMU_FS_DIRECT */ 14782794Sobrien#ifdef HAVE_AMU_FS_TOPLVL 14838494Sobrien &amfs_toplvl_ops, /* top-level mount F/S */ 14982794Sobrien#endif /* HAVE_AMU_FS_TOPLVL */ 15082794Sobrien#ifdef HAVE_AMU_FS_ERROR 15138494Sobrien &amfs_error_ops, /* error F/S */ 15282794Sobrien#endif /* HAVE_AMU_FS_ERROR */ 15338494Sobrien 0 15438494Sobrien}; 15538494Sobrien 15638494Sobrien 15738494Sobrienvoid 158174294Sobrienops_showamfstypes(char *buf, size_t l) 15938494Sobrien{ 16038494Sobrien struct am_ops **ap; 161174294Sobrien int linesize = 0; 16238494Sobrien 16338494Sobrien buf[0] = '\0'; 16438494Sobrien for (ap = vops; *ap; ap++) { 165174294Sobrien xstrlcat(buf, (*ap)->fs_type, l); 16638494Sobrien if (ap[1]) 167174294Sobrien xstrlcat(buf, ", ", l); 168174294Sobrien linesize += strlen((*ap)->fs_type) + 2; 169174294Sobrien if (linesize > 62) { 170174294Sobrien linesize = 0; 171174294Sobrien xstrlcat(buf, "\n ", l); 17238494Sobrien } 17338494Sobrien } 17438494Sobrien} 17538494Sobrien 17638494Sobrien 17738494Sobrienstatic void 178174294Sobrienops_show1(char *buf, size_t l, int *linesizep, const char *name) 17938494Sobrien{ 180174294Sobrien xstrlcat(buf, name, l); 181174294Sobrien xstrlcat(buf, ", ", l); 182174294Sobrien *linesizep += strlen(name) + 2; 183174294Sobrien if (*linesizep > 60) { 184174294Sobrien xstrlcat(buf, "\t\n", l); 185174294Sobrien *linesizep = 0; 18638494Sobrien } 18738494Sobrien} 18838494Sobrien 18938494Sobrien 19038494Sobrienvoid 191174294Sobrienops_showfstypes(char *buf, size_t l) 19238494Sobrien{ 193174294Sobrien int linesize = 0; 19438494Sobrien 19538494Sobrien buf[0] = '\0'; 19638494Sobrien 197174294Sobrien#ifdef MNTTAB_TYPE_AUTOFS 198174294Sobrien ops_show1(buf, l, &linesize, MNTTAB_TYPE_AUTOFS); 199174294Sobrien#endif /* MNTTAB_TYPE_AUTOFS */ 200174294Sobrien 20138494Sobrien#ifdef MNTTAB_TYPE_CACHEFS 202174294Sobrien ops_show1(buf, l, &linesize, MNTTAB_TYPE_CACHEFS); 20338494Sobrien#endif /* MNTTAB_TYPE_CACHEFS */ 20438494Sobrien 20538494Sobrien#ifdef MNTTAB_TYPE_CDFS 206174294Sobrien ops_show1(buf, l, &linesize, MNTTAB_TYPE_CDFS); 20738494Sobrien#endif /* MNTTAB_TYPE_CDFS */ 20838494Sobrien 20938494Sobrien#ifdef MNTTAB_TYPE_CFS 210174294Sobrien ops_show1(buf, l, &linesize, MNTTAB_TYPE_CFS); 21138494Sobrien#endif /* MNTTAB_TYPE_CFS */ 21238494Sobrien 21338494Sobrien#ifdef MNTTAB_TYPE_LOFS 214174294Sobrien ops_show1(buf, l, &linesize, MNTTAB_TYPE_LOFS); 21538494Sobrien#endif /* MNTTAB_TYPE_LOFS */ 21638494Sobrien 21738494Sobrien#ifdef MNTTAB_TYPE_EFS 218174294Sobrien ops_show1(buf, l, &linesize, MNTTAB_TYPE_EFS); 21938494Sobrien#endif /* MNTTAB_TYPE_EFS */ 22038494Sobrien 22138494Sobrien#ifdef MNTTAB_TYPE_MFS 222174294Sobrien ops_show1(buf, l, &linesize, MNTTAB_TYPE_MFS); 22338494Sobrien#endif /* MNTTAB_TYPE_MFS */ 22438494Sobrien 22538494Sobrien#ifdef MNTTAB_TYPE_NFS 226174294Sobrien ops_show1(buf, l, &linesize, MNTTAB_TYPE_NFS); 22738494Sobrien#endif /* MNTTAB_TYPE_NFS */ 22838494Sobrien 22938494Sobrien#ifdef MNTTAB_TYPE_NFS3 230174294Sobrien ops_show1(buf, l, &linesize, "nfs3"); /* always hard-code as nfs3 */ 23138494Sobrien#endif /* MNTTAB_TYPE_NFS3 */ 23238494Sobrien 23338494Sobrien#ifdef MNTTAB_TYPE_NULLFS 234174294Sobrien ops_show1(buf, l, &linesize, MNTTAB_TYPE_NULLFS); 23538494Sobrien#endif /* MNTTAB_TYPE_NULLFS */ 23638494Sobrien 23738494Sobrien#ifdef MNTTAB_TYPE_PCFS 238174294Sobrien ops_show1(buf, l, &linesize, MNTTAB_TYPE_PCFS); 23938494Sobrien#endif /* MNTTAB_TYPE_PCFS */ 24038494Sobrien 24138494Sobrien#ifdef MNTTAB_TYPE_TFS 242174294Sobrien ops_show1(buf, l, &linesize, MNTTAB_TYPE_TFS); 24338494Sobrien#endif /* MNTTAB_TYPE_TFS */ 24438494Sobrien 24538494Sobrien#ifdef MNTTAB_TYPE_TMPFS 246174294Sobrien ops_show1(buf, l, &linesize, MNTTAB_TYPE_TMPFS); 24738494Sobrien#endif /* MNTTAB_TYPE_TMPFS */ 24838494Sobrien 24938494Sobrien#ifdef MNTTAB_TYPE_UFS 250174294Sobrien ops_show1(buf, l, &linesize, MNTTAB_TYPE_UFS); 25138494Sobrien#endif /* MNTTAB_TYPE_UFS */ 25238494Sobrien 25338494Sobrien#ifdef MNTTAB_TYPE_UMAPFS 254174294Sobrien ops_show1(buf, l, &linesize, MNTTAB_TYPE_UMAPFS); 25538494Sobrien#endif /* MNTTAB_TYPE_UMAPFS */ 25638494Sobrien 25738494Sobrien#ifdef MNTTAB_TYPE_UNIONFS 258174294Sobrien ops_show1(buf, l, &linesize, MNTTAB_TYPE_UNIONFS); 25938494Sobrien#endif /* MNTTAB_TYPE_UNIONFS */ 26038494Sobrien 26138494Sobrien#ifdef MNTTAB_TYPE_XFS 262174294Sobrien ops_show1(buf, l, &linesize, MNTTAB_TYPE_XFS); 26338494Sobrien#endif /* MNTTAB_TYPE_XFS */ 26438494Sobrien 26538494Sobrien /* terminate with a period, newline, and NULL */ 26638494Sobrien if (buf[strlen(buf)-1] == '\n') 26738494Sobrien buf[strlen(buf) - 4] = '\0'; 26838494Sobrien else 26938494Sobrien buf[strlen(buf) - 2] = '\0'; 270174294Sobrien xstrlcat(buf, ".\n", l); 27138494Sobrien} 27238494Sobrien 27338494Sobrien 27438494Sobrien/* 27538494Sobrien * return string option which is the reverse of opt. 27638494Sobrien * nosuid -> suid 27738494Sobrien * quota -> noquota 27838494Sobrien * ro -> rw 27938494Sobrien * etc. 28038494Sobrien * may return pointer to static buffer or subpointer within opt. 28138494Sobrien */ 28238494Sobrienstatic char * 28338494Sobrienreverse_option(const char *opt) 28438494Sobrien{ 28538494Sobrien static char buf[80]; 28638494Sobrien 28738494Sobrien /* sanity check */ 28838494Sobrien if (!opt) 28938494Sobrien return NULL; 29038494Sobrien 29138494Sobrien /* check special cases */ 29238494Sobrien /* XXX: if this gets too long, rewrite the code more flexibly */ 29338494Sobrien if (STREQ(opt, "ro")) return "rw"; 29438494Sobrien if (STREQ(opt, "rw")) return "ro"; 29538494Sobrien if (STREQ(opt, "bg")) return "fg"; 29638494Sobrien if (STREQ(opt, "fg")) return "bg"; 29738494Sobrien if (STREQ(opt, "soft")) return "hard"; 29838494Sobrien if (STREQ(opt, "hard")) return "soft"; 29938494Sobrien 30038494Sobrien /* check if string starts with 'no' and chop it */ 30138494Sobrien if (NSTREQ(opt, "no", 2)) { 302174294Sobrien xstrlcpy(buf, &opt[2], sizeof(buf)); 30338494Sobrien } else { 30438494Sobrien /* finally return a string prepended with 'no' */ 305174294Sobrien xstrlcpy(buf, "no", sizeof(buf)); 306174294Sobrien xstrlcat(buf, opt, sizeof(buf)); 30738494Sobrien } 30838494Sobrien return buf; 30938494Sobrien} 31038494Sobrien 31138494Sobrien 31238494Sobrien/* 31338494Sobrien * start with an empty string. for each opts1 option that is not 31438494Sobrien * in opts2, add it to the string (make sure the reverse of it 31538494Sobrien * isn't in either). finally add opts2. return new string. 31638494Sobrien * Both opts1 and opts2 must not be null! 31738494Sobrien * Caller must eventually free the string being returned. 31838494Sobrien */ 31938494Sobrienstatic char * 32042629Sobrienmerge_opts(const char *opts1, const char *opts2) 32138494Sobrien{ 32238494Sobrien mntent_t mnt2; /* place holder for opts2 */ 32338494Sobrien char *newstr; /* new string to return (malloc'ed) */ 32438494Sobrien char *tmpstr; /* temp */ 32582794Sobrien char *eq; /* pointer to whatever follows '=' within temp */ 32638494Sobrien char oneopt[80]; /* one option w/o value if any */ 32738494Sobrien char *revoneopt; /* reverse of oneopt */ 328174294Sobrien size_t len = strlen(opts1) + strlen(opts2) + 2; /* space for "," and NULL */ 329310490Scy char *s1 = xstrdup(opts1); /* copy of opts1 to munge */ 33038494Sobrien 33138494Sobrien /* initialization */ 33242629Sobrien mnt2.mnt_opts = (char *) opts2; 33338494Sobrien newstr = xmalloc(len); 33438494Sobrien newstr[0] = '\0'; 33538494Sobrien 33638494Sobrien for (tmpstr = strtok(s1, ","); 33738494Sobrien tmpstr; 33838494Sobrien tmpstr = strtok(NULL, ",")) { 33938494Sobrien /* copy option to temp buffer */ 340310490Scy xstrlcpy(oneopt, tmpstr, sizeof(oneopt)); 34138494Sobrien /* if option has a value such as rsize=1024, chop the value part */ 342310490Scy if ((eq = strchr(oneopt, '='))) 34382794Sobrien *eq = '\0'; 34438494Sobrien /* find reverse option of oneopt */ 34538494Sobrien revoneopt = reverse_option(oneopt); 346310490Scy /* if option or its reverse exist in opts2, ignore it */ 347174294Sobrien if (amu_hasmntopt(&mnt2, oneopt) || amu_hasmntopt(&mnt2, revoneopt)) 34838494Sobrien continue; 34938494Sobrien /* add option to returned string */ 350174294Sobrien if (newstr[0]) { 351174294Sobrien xstrlcat(newstr, ",", len); 352174294Sobrien xstrlcat(newstr, tmpstr, len); 35338494Sobrien } else { 354174294Sobrien xstrlcpy(newstr, tmpstr, len); 35538494Sobrien } 35638494Sobrien } 35738494Sobrien 35838494Sobrien /* finally, append opts2 itself */ 359174294Sobrien if (newstr[0]) { 360174294Sobrien xstrlcat(newstr, ",", len); 361174294Sobrien xstrlcat(newstr, opts2, len); 36238494Sobrien } else { 363174294Sobrien xstrlcpy(newstr, opts2, len); 36438494Sobrien } 36538494Sobrien 36638494Sobrien XFREE(s1); 36738494Sobrien return newstr; 36838494Sobrien} 36938494Sobrien 37038494Sobrien 37138494Sobrienam_ops * 372174294Sobrienops_search(char *type) 37338494Sobrien{ 37438494Sobrien am_ops **vp; 375310490Scy am_ops *rop = NULL; 376174294Sobrien for (vp = vops; (rop = *vp); vp++) 377174294Sobrien if (STREQ(rop->fs_type, type)) 378174294Sobrien break; 379174294Sobrien return rop; 380174294Sobrien} 38138494Sobrien 382174294Sobrien 383174294Sobrienam_ops * 384174294Sobrienops_match(am_opts *fo, char *key, char *g_key, char *path, char *keym, char *map) 385174294Sobrien{ 386310490Scy am_ops *rop = NULL; 387174294Sobrien char *link_dir; 388174294Sobrien 38938494Sobrien /* 39038494Sobrien * First crack the global opts and the local opts 39138494Sobrien */ 39238494Sobrien if (!eval_fs_opts(fo, key, g_key, path, keym, map)) { 39338494Sobrien rop = &amfs_error_ops; 39438494Sobrien } else if (fo->opt_type == 0) { 39538494Sobrien plog(XLOG_USER, "No fs type specified (key = \"%s\", map = \"%s\")", keym, map); 39638494Sobrien rop = &amfs_error_ops; 39738494Sobrien } else { 39838494Sobrien /* 39938494Sobrien * Next find the correct filesystem type 40038494Sobrien */ 401174294Sobrien rop = ops_search(fo->opt_type); 40238494Sobrien if (!rop) { 40338494Sobrien plog(XLOG_USER, "fs type \"%s\" not recognized", fo->opt_type); 40438494Sobrien rop = &amfs_error_ops; 40538494Sobrien } 40638494Sobrien } 40738494Sobrien 40838494Sobrien /* 40938494Sobrien * Make sure we have a default mount option. 41038494Sobrien * Otherwise skip past any leading '-'. 41138494Sobrien */ 41238494Sobrien if (fo->opt_opts == 0) 413310490Scy fo->opt_opts = xstrdup("rw,defaults"); 41438494Sobrien else if (*fo->opt_opts == '-') { 41538494Sobrien /* 41638494Sobrien * We cannot simply do fo->opt_opts++ here since the opts 41738494Sobrien * module will try to free the pointer fo->opt_opts later. 41838494Sobrien * So just reallocate the thing -- stolcke 11/11/94 41938494Sobrien */ 42038494Sobrien char *old = fo->opt_opts; 421310490Scy fo->opt_opts = xstrdup(old + 1); 42238494Sobrien XFREE(old); 42338494Sobrien } 42438494Sobrien 42538494Sobrien /* 42638494Sobrien * If addopts option was used, then append it to the 42751292Sobrien * current options and remote mount options. 42838494Sobrien */ 42938494Sobrien if (fo->opt_addopts) { 43051292Sobrien if (STREQ(fo->opt_opts, fo->opt_remopts)) { 43151292Sobrien /* optimize things for the common case where opts==remopts */ 43251292Sobrien char *mergedstr; 43351292Sobrien mergedstr = merge_opts(fo->opt_opts, fo->opt_addopts); 43482794Sobrien plog(XLOG_INFO, "merge rem/opts \"%s\" add \"%s\" => \"%s\"", 43551292Sobrien fo->opt_opts, fo->opt_addopts, mergedstr); 43651292Sobrien XFREE(fo->opt_opts); 43751292Sobrien XFREE(fo->opt_remopts); 43851292Sobrien fo->opt_opts = mergedstr; 439310490Scy fo->opt_remopts = xstrdup(mergedstr); 44051292Sobrien } else { 44151292Sobrien char *mergedstr, *remmergedstr; 44251292Sobrien mergedstr = merge_opts(fo->opt_opts, fo->opt_addopts); 44382794Sobrien plog(XLOG_INFO, "merge opts \"%s\" add \"%s\" => \"%s\"", 44451292Sobrien fo->opt_opts, fo->opt_addopts, mergedstr); 44551292Sobrien XFREE(fo->opt_opts); 44651292Sobrien fo->opt_opts = mergedstr; 44751292Sobrien remmergedstr = merge_opts(fo->opt_remopts, fo->opt_addopts); 44882794Sobrien plog(XLOG_INFO, "merge remopts \"%s\" add \"%s\" => \"%s\"", 44951292Sobrien fo->opt_remopts, fo->opt_addopts, remmergedstr); 45051292Sobrien XFREE(fo->opt_remopts); 45151292Sobrien fo->opt_remopts = remmergedstr; 45251292Sobrien } 45338494Sobrien } 45438494Sobrien 45538494Sobrien /* 456174294Sobrien * Initialize opt_mount_type to "nfs", if it's not initialized already 457174294Sobrien */ 458174294Sobrien if (!fo->opt_mount_type) 459174294Sobrien fo->opt_mount_type = "nfs"; 460174294Sobrien 461174294Sobrien /* Normalize the sublink and make it absolute */ 462174294Sobrien link_dir = fo->opt_sublink; 463174294Sobrien if (link_dir && link_dir[0] && link_dir[0] != '/') { 464310490Scy link_dir = str3cat((char *) NULL, fo->opt_fs, "/", link_dir); 465174294Sobrien normalize_slash(link_dir); 466174294Sobrien XFREE(fo->opt_sublink); 467174294Sobrien fo->opt_sublink = link_dir; 468174294Sobrien } 469174294Sobrien 470174294Sobrien /* 47138494Sobrien * Check the filesystem is happy 47238494Sobrien */ 473310490Scy XFREE(fo->fs_mtab); 47438494Sobrien 475174294Sobrien fo->fs_mtab = rop->fs_match(fo); 476174294Sobrien if (fo->fs_mtab) 47738494Sobrien return rop; 47838494Sobrien 47938494Sobrien /* 48038494Sobrien * Return error file system 48138494Sobrien */ 482174294Sobrien fo->fs_mtab = amfs_error_ops.fs_match(fo); 48338494Sobrien return &amfs_error_ops; 48438494Sobrien} 485