amfs_auto.c revision 174294
1114402Sru/* 2151497Sru * Copyright (c) 1997-2006 Erez Zadok 3151497Sru * Copyright (c) 1990 Jan-Simon Pendry 4114402Sru * Copyright (c) 1990 Imperial College of Science, Technology & Medicine 5114402Sru * Copyright (c) 1990 The Regents of the University of California. 6114402Sru * All rights reserved. 7114402Sru * 8114402Sru * This code is derived from software contributed to Berkeley by 9114402Sru * Jan-Simon Pendry at Imperial College, London. 10114402Sru * 11114402Sru * Redistribution and use in source and binary forms, with or without 12114402Sru * modification, are permitted provided that the following conditions 13114402Sru * are met: 14114402Sru * 1. Redistributions of source code must retain the above copyright 15114402Sru * notice, this list of conditions and the following disclaimer. 16114402Sru * 2. Redistributions in binary form must reproduce the above copyright 17114402Sru * notice, this list of conditions and the following disclaimer in the 18114402Sru * documentation and/or other materials provided with the distribution. 19114402Sru * 3. All advertising materials mentioning features or use of this software 20151497Sru * must display the following acknowledgment: 21114402Sru * This product includes software developed by the University of 22114402Sru * California, Berkeley and its contributors. 23114402Sru * 4. Neither the name of the University nor the names of its contributors 24114402Sru * may be used to endorse or promote products derived from this software 25114402Sru * without specific prior written permission. 26114402Sru * 27114402Sru * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28114402Sru * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29114402Sru * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30114402Sru * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31114402Sru * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32114402Sru * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33114402Sru * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34114402Sru * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35114402Sru * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36114402Sru * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37114402Sru * SUCH DAMAGE. 38114402Sru * 39114402Sru * 40114402Sru * File: am-utils/amd/amfs_auto.c 41114402Sru * 42114402Sru */ 43114402Sru 44114402Sru/* 45114402Sru * Automount file system 46114402Sru */ 47114402Sru 48114402Sru#ifdef HAVE_CONFIG_H 49114402Sru# include <config.h> 50114402Sru#endif /* HAVE_CONFIG_H */ 51114402Sru#include <am_defs.h> 52114402Sru#include <amd.h> 53114402Sru 54114402Sru/**************************************************************************** 55114402Sru *** MACROS *** 56114402Sru ****************************************************************************/ 57114402Sru 58114402Sru 59114402Sru/**************************************************************************** 60114402Sru *** STRUCTURES *** 61114402Sru ****************************************************************************/ 62114402Sru 63114402Sru 64114402Sru/**************************************************************************** 65114402Sru *** FORWARD DEFINITIONS *** 66114402Sru ****************************************************************************/ 67114402Srustatic int amfs_auto_mount(am_node *mp, mntfs *mf); 68114402Sru 69114402Sru 70114402Sru/**************************************************************************** 71114402Sru *** OPS STRUCTURES *** 72114402Sru ****************************************************************************/ 73114402Sruam_ops amfs_auto_ops = 74114402Sru{ 75114402Sru "auto", 76114402Sru amfs_generic_match, 77114402Sru 0, /* amfs_auto_init */ 78114402Sru amfs_auto_mount, 79114402Sru amfs_generic_umount, 80114402Sru amfs_generic_lookup_child, 81114402Sru amfs_generic_mount_child, 82114402Sru amfs_generic_readdir, 83114402Sru 0, /* amfs_auto_readlink */ 84114402Sru amfs_generic_mounted, 85114402Sru 0, /* amfs_auto_umounted */ 86114402Sru amfs_generic_find_srvr, 87114402Sru 0, /* amfs_auto_get_wchan */ 88114402Sru FS_AMQINFO | FS_DIRECTORY, 89114402Sru#ifdef HAVE_FS_AUTOFS 90114402Sru AUTOFS_AUTO_FS_FLAGS, 91114402Sru#endif /* HAVE_FS_AUTOFS */ 92114402Sru}; 93114402Sru 94114402Sru 95114402Sru/**************************************************************************** 96114402Sru *** FUNCTIONS *** 97114402Sru ****************************************************************************/ 98114402Sru/* 99114402Sru * Mount a sub-mount 100114402Sru */ 101114402Srustatic int 102114402Sruamfs_auto_mount(am_node *mp, mntfs *mf) 103114402Sru{ 104114402Sru /* 105114402Sru * Pseudo-directories are used to provide some structure 106114402Sru * to the automounted directories instead 107114402Sru * of putting them all in the top-level automount directory. 108114402Sru * 109114402Sru * Here, just increment the parent's link count. 110114402Sru */ 111114402Sru mp->am_parent->am_fattr.na_nlink++; 112114402Sru 113114402Sru /* 114114402Sru * Info field of . means use parent's info field. 115114402Sru * Historical - not documented. 116114402Sru */ 117114402Sru if (mf->mf_info[0] == '.' && mf->mf_info[1] == '\0') 118114402Sru mf->mf_info = strealloc(mf->mf_info, mp->am_parent->am_mnt->mf_info); 119114402Sru 120114402Sru /* 121114402Sru * Compute prefix: 122114402Sru * 123114402Sru * If there is an option prefix then use that else 124114402Sru * If the parent had a prefix then use that with name 125114402Sru * of this node appended else 126114402Sru * Use the name of this node. 127114402Sru * 128114402Sru * That means if you want no prefix you must say so 129114402Sru * in the map. 130114402Sru */ 131114402Sru if (mf->mf_fo->opt_pref) { 132114402Sru /* allow pref:=null to set a real null prefix */ 133114402Sru if (STREQ(mf->mf_fo->opt_pref, "null")) { 134114402Sru mp->am_pref = strdup(""); 135114402Sru } else { 136114402Sru /* 137114402Sru * the prefix specified as an option 138114402Sru */ 139114402Sru mp->am_pref = strdup(mf->mf_fo->opt_pref); 140114402Sru } 141114402Sru } else { 142114402Sru /* 143114402Sru * else the parent's prefix 144114402Sru * followed by the name 145114402Sru * followed by / 146114402Sru */ 147114402Sru char *ppref = mp->am_parent->am_pref; 148114402Sru if (ppref == 0) 149114402Sru ppref = ""; 150114402Sru mp->am_pref = str3cat((char *) 0, ppref, mp->am_name, "/"); 151114402Sru } 152114402Sru 153114402Sru#ifdef HAVE_FS_AUTOFS 154114402Sru if (mf->mf_flags & MFF_IS_AUTOFS) { 155114402Sru char opts[SIZEOF_OPTS]; 156114402Sru int error; 157114402Sru 158114402Sru autofs_get_opts(opts, sizeof(opts), mp->am_autofs_fh); 159114402Sru 160114402Sru /* now do the mount */ 161114402Sru error = amfs_mount(mp, mf, opts); 162114402Sru if (error) { 163114402Sru errno = error; 164114402Sru plog(XLOG_FATAL, "amfs_auto_mount: amfs_mount failed: %m"); 165114402Sru return error; 166114402Sru } 167114402Sru } 168114402Sru#endif /* HAVE_FS_AUTOFS */ 169114402Sru 170114402Sru /* 171114402Sru * Attach a map cache 172114402Sru */ 173114402Sru amfs_mkcacheref(mf); 174114402Sru 175114402Sru return 0; 176114402Sru} 177114402Sru